CCM NG: Creating new containers from the PageModels Editor (does work completly yet)
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5539 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: f559f7a3c8
pull/2/head
parent
32769a10dc
commit
9b6588eced
|
|
@ -85,7 +85,7 @@ public class PageModelManager {
|
||||||
private PageModelRepository pageModelRepo;
|
private PageModelRepository pageModelRepo;
|
||||||
|
|
||||||
private final Map<String, PageModelComponentModel> components
|
private final Map<String, PageModelComponentModel> components
|
||||||
= new HashMap<>();
|
= new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by CDI after an instance of this class is created. Initialises the
|
* Called by CDI after an instance of this class is created. Initialises the
|
||||||
|
|
@ -151,17 +151,17 @@ public class PageModelManager {
|
||||||
|
|
||||||
Objects.requireNonNull(application,
|
Objects.requireNonNull(application,
|
||||||
"Can't create a page model for application "
|
"Can't create a page model for application "
|
||||||
+ "null");
|
+ "null");
|
||||||
Objects.requireNonNull(name, "Then name of a Pagemodel can't be null.");
|
Objects.requireNonNull(name, "Then name of a Pagemodel can't be null.");
|
||||||
if (name.isEmpty()
|
if (name.isEmpty()
|
||||||
|| name.matches("\\s*")) {
|
|| name.matches("\\s*")) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"The name of a PageModel can't be empty.");
|
"The name of a PageModel can't be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Creating new PageModel with name \"{}\" for application \"{}\" "
|
"Creating new PageModel with name \"{}\" for application \"{}\" "
|
||||||
+ "and type \"{}\".",
|
+ "and type \"{}\".",
|
||||||
name,
|
name,
|
||||||
application.getPrimaryUrl(),
|
application.getPrimaryUrl(),
|
||||||
type);
|
type);
|
||||||
|
|
@ -172,12 +172,12 @@ public class PageModelManager {
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
LOGGER.error("A page model with the name \"{}\" for the "
|
LOGGER.error("A page model with the name \"{}\" for the "
|
||||||
+ "application \"{}\" already exists.",
|
+ "application \"{}\" already exists.",
|
||||||
name,
|
name,
|
||||||
application.getPrimaryUrl());
|
application.getPrimaryUrl());
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"A page model with the name \"%s\" for the application \"%s\" "
|
"A page model with the name \"%s\" for the application \"%s\" "
|
||||||
+ "already exists.",
|
+ "already exists.",
|
||||||
name,
|
name,
|
||||||
application.getPrimaryUrl()));
|
application.getPrimaryUrl()));
|
||||||
}
|
}
|
||||||
|
|
@ -246,8 +246,8 @@ public class PageModelManager {
|
||||||
* retrieved.
|
* retrieved.
|
||||||
*
|
*
|
||||||
* @return An {@link Optional} containing the live version of the provided
|
* @return An {@link Optional} containing the live version of the provided
|
||||||
* {@link PageModel} if there is a live version. Otherwise an empty
|
* {@link PageModel} if there is a live version. Otherwise an empty
|
||||||
* {@link Optional} is returned.
|
* {@link Optional} is returned.
|
||||||
*/
|
*/
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<PageModel> getLiveVersion(final PageModel pageModel) {
|
public Optional<PageModel> getLiveVersion(final PageModel pageModel) {
|
||||||
|
|
@ -349,15 +349,15 @@ public class PageModelManager {
|
||||||
final Styles liveStyles = new Styles();
|
final Styles liveStyles = new Styles();
|
||||||
liveStyles.setStyleName(draftStyles.getStyleName());
|
liveStyles.setStyleName(draftStyles.getStyleName());
|
||||||
liveStyles.setRules(draftStyles
|
liveStyles.setRules(draftStyles
|
||||||
.getRules()
|
.getRules()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::publishRule)
|
.map(this::publishRule)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
liveStyles.setMediaRules(draftStyles
|
liveStyles.setMediaRules(draftStyles
|
||||||
.getMediaRules()
|
.getMediaRules()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::publishMediaRule)
|
.map(this::publishMediaRule)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
draftModel
|
draftModel
|
||||||
|
|
@ -375,7 +375,7 @@ public class PageModelManager {
|
||||||
|
|
||||||
Objects.requireNonNull(draftMediaRule);
|
Objects.requireNonNull(draftMediaRule);
|
||||||
|
|
||||||
final MediaRule liveMediaRule = new MediaRule();
|
final MediaRule liveMediaRule = new MediaRule();
|
||||||
final MediaQuery liveMediaQuery = new MediaQuery();
|
final MediaQuery liveMediaQuery = new MediaQuery();
|
||||||
liveMediaQuery
|
liveMediaQuery
|
||||||
.setMaxWidth(draftMediaRule.getMediaQuery().getMaxWidth());
|
.setMaxWidth(draftMediaRule.getMediaQuery().getMaxWidth());
|
||||||
|
|
@ -385,10 +385,10 @@ public class PageModelManager {
|
||||||
.setMinWidth(draftMediaRule.getMediaQuery().getMinWidth());
|
.setMinWidth(draftMediaRule.getMediaQuery().getMinWidth());
|
||||||
|
|
||||||
liveMediaRule.setRules(draftMediaRule
|
liveMediaRule.setRules(draftMediaRule
|
||||||
.getRules()
|
.getRules()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::publishRule)
|
.map(this::publishRule)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
return liveMediaRule;
|
return liveMediaRule;
|
||||||
}
|
}
|
||||||
|
|
@ -400,10 +400,10 @@ public class PageModelManager {
|
||||||
final Rule liveRule = new Rule();
|
final Rule liveRule = new Rule();
|
||||||
liveRule.setSelector(draftRule.getSelector());
|
liveRule.setSelector(draftRule.getSelector());
|
||||||
liveRule.setProperties(draftRule
|
liveRule.setProperties(draftRule
|
||||||
.getProperties()
|
.getProperties()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::publishCssProperty)
|
.map(this::publishCssProperty)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
return liveRule;
|
return liveRule;
|
||||||
}
|
}
|
||||||
|
|
@ -429,8 +429,7 @@ public class PageModelManager {
|
||||||
* @return The live version of the {@link ComponentModel}.
|
* @return The live version of the {@link ComponentModel}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private ComponentModel publishComponentModel(final ComponentModel
|
private ComponentModel publishComponentModel(final ComponentModel draftModel) {
|
||||||
draftModel) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(draftModel,
|
Objects.requireNonNull(draftModel,
|
||||||
"Can't publish ComponentModel null.");
|
"Can't publish ComponentModel null.");
|
||||||
|
|
@ -464,9 +463,9 @@ public class PageModelManager {
|
||||||
propertyDescriptor.getName(),
|
propertyDescriptor.getName(),
|
||||||
draftModel.getKey());
|
draftModel.getKey());
|
||||||
|
|
||||||
final Class<?> propType = propertyDescriptor.getPropertyType();
|
final Class<?> propType = propertyDescriptor.getPropertyType();
|
||||||
final Method readMethod = propertyDescriptor.getReadMethod();
|
final Method readMethod = propertyDescriptor.getReadMethod();
|
||||||
final Method writeMethod = propertyDescriptor.getWriteMethod();
|
final Method writeMethod = propertyDescriptor.getWriteMethod();
|
||||||
|
|
||||||
if (propertyIsExcluded(propertyDescriptor.getName())) {
|
if (propertyIsExcluded(propertyDescriptor.getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -477,7 +476,7 @@ public class PageModelManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propType != null
|
if (propType != null
|
||||||
&& propType.isAssignableFrom(List.class)) {
|
&& propType.isAssignableFrom(List.class)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final List<Object> source = (List<Object>) readMethod
|
final List<Object> source = (List<Object>) readMethod
|
||||||
|
|
@ -486,13 +485,13 @@ public class PageModelManager {
|
||||||
target.addAll(source);
|
target.addAll(source);
|
||||||
writeMethod.invoke(draftModel, target);
|
writeMethod.invoke(draftModel, target);
|
||||||
} catch (IllegalAccessException
|
} catch (IllegalAccessException
|
||||||
| IllegalArgumentException
|
| IllegalArgumentException
|
||||||
| InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (propType != null
|
} else if (propType != null
|
||||||
&& propType.isAssignableFrom(Map.class)) {
|
&& propType.isAssignableFrom(Map.class)) {
|
||||||
|
|
||||||
final Map<Object, Object> source;
|
final Map<Object, Object> source;
|
||||||
final Map<Object, Object> target;
|
final Map<Object, Object> target;
|
||||||
|
|
@ -502,15 +501,15 @@ public class PageModelManager {
|
||||||
= (Map<Object, Object>) readMethod.invoke(draftModel);
|
= (Map<Object, Object>) readMethod.invoke(draftModel);
|
||||||
target = (Map<Object, Object>) readMethod.invoke(liveModel);
|
target = (Map<Object, Object>) readMethod.invoke(liveModel);
|
||||||
} catch (IllegalAccessException
|
} catch (IllegalAccessException
|
||||||
| IllegalArgumentException
|
| IllegalArgumentException
|
||||||
| InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
source.forEach((key, value) -> target.put(key, value));
|
source.forEach((key, value) -> target.put(key, value));
|
||||||
|
|
||||||
} else if (propType != null
|
} else if (propType != null
|
||||||
&& propType.isAssignableFrom(Set.class)) {
|
&& propType.isAssignableFrom(Set.class)) {
|
||||||
|
|
||||||
final Set<Object> source;
|
final Set<Object> source;
|
||||||
final Set<Object> target;
|
final Set<Object> target;
|
||||||
|
|
@ -519,8 +518,8 @@ public class PageModelManager {
|
||||||
source = (Set<Object>) readMethod.invoke(draftModel);
|
source = (Set<Object>) readMethod.invoke(draftModel);
|
||||||
target = (Set<Object>) readMethod.invoke(liveModel);
|
target = (Set<Object>) readMethod.invoke(liveModel);
|
||||||
} catch (IllegalAccessException
|
} catch (IllegalAccessException
|
||||||
| IllegalArgumentException
|
| IllegalArgumentException
|
||||||
| InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -531,8 +530,8 @@ public class PageModelManager {
|
||||||
value = readMethod.invoke(draftModel);
|
value = readMethod.invoke(draftModel);
|
||||||
writeMethod.invoke(liveModel, value);
|
writeMethod.invoke(liveModel, value);
|
||||||
} catch (IllegalAccessException
|
} catch (IllegalAccessException
|
||||||
| IllegalArgumentException
|
| IllegalArgumentException
|
||||||
| InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +551,7 @@ public class PageModelManager {
|
||||||
* @param name The name of the property.
|
* @param name The name of the property.
|
||||||
*
|
*
|
||||||
* @return {@code true} if the property is excluded from the publishing
|
* @return {@code true} if the property is excluded from the publishing
|
||||||
* process, {@link false} if not.
|
* process, {@link false} if not.
|
||||||
*/
|
*/
|
||||||
private boolean propertyIsExcluded(final String name) {
|
private boolean propertyIsExcluded(final String name) {
|
||||||
|
|
||||||
|
|
@ -583,8 +582,8 @@ public class PageModelManager {
|
||||||
pageModel.addContainer(container);
|
pageModel.addContainer(container);
|
||||||
container.setPageModel(pageModel);
|
container.setPageModel(pageModel);
|
||||||
|
|
||||||
pageModelRepo.save(pageModel);
|
|
||||||
containerModelRepo.save(container);
|
containerModelRepo.save(container);
|
||||||
|
pageModelRepo.save(pageModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,8 @@ class PageModelComponent
|
||||||
<ContainerListComponent
|
<ContainerListComponent
|
||||||
ccmApplication={this.props.ccmApplication}
|
ccmApplication={this.props.ccmApplication}
|
||||||
containers={this.props.pageModel.containers}
|
containers={this.props.pageModel.containers}
|
||||||
dispatcherPrefix={this.props.dispatcherPrefix} />
|
dispatcherPrefix={this.props.dispatcherPrefix}
|
||||||
|
pageModelName={this.props.pageModel.name} />
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -506,11 +507,14 @@ interface ContainerListProps {
|
||||||
ccmApplication: string;
|
ccmApplication: string;
|
||||||
containers: ContainerModel[];
|
containers: ContainerModel[];
|
||||||
dispatcherPrefix: string;
|
dispatcherPrefix: string;
|
||||||
|
pageModelName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContainerListState {
|
interface ContainerListState {
|
||||||
|
|
||||||
|
errorMsg: string;
|
||||||
newContainerName: string;
|
newContainerName: string;
|
||||||
|
containers: ContainerModel[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContainerListComponent
|
class ContainerListComponent
|
||||||
|
|
@ -521,10 +525,13 @@ class ContainerListComponent
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
errorMsg: "",
|
||||||
|
containers: props.containers,
|
||||||
newContainerName: "",
|
newContainerName: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addContainer = this.addContainer.bind(this);
|
this.addContainer = this.addContainer.bind(this);
|
||||||
|
this.updateNewContainerName = this.updateNewContainerName.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
|
|
@ -542,9 +549,14 @@ class ContainerListComponent
|
||||||
Add container
|
Add container
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
{this.state.errorMsg !== ""
|
||||||
|
&& <div className="errorPanel">
|
||||||
|
<span className="fa fa-exclamation-triangle"></span>
|
||||||
|
{this.state.errorMsg}
|
||||||
|
</div>}
|
||||||
<ul className="containerList">
|
<ul className="containerList">
|
||||||
{this.props.containers
|
{this.state.containers
|
||||||
&& this.props.containers.map((container) =>
|
&& this.state.containers.map((container) =>
|
||||||
<li>
|
<li>
|
||||||
<span>{container.key}</span>
|
<span>{container.key}</span>
|
||||||
<button>
|
<button>
|
||||||
|
|
@ -582,6 +594,15 @@ class ContainerListComponent
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (this.state.newContainerName === null
|
||||||
|
|| this.state.newContainerName === "") {
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
errorMsg: "A container needs a name!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const headers: Headers = new Headers();
|
const headers: Headers = new Headers();
|
||||||
headers.append("Content-Type", "application/json");
|
headers.append("Content-Type", "application/json");
|
||||||
|
|
||||||
|
|
@ -595,7 +616,47 @@ class ContainerListComponent
|
||||||
|
|
||||||
const url: string = `${this.props.dispatcherPrefix}`
|
const url: string = `${this.props.dispatcherPrefix}`
|
||||||
+ `/page-models/${this.props.ccmApplication}/`
|
+ `/page-models/${this.props.ccmApplication}/`
|
||||||
|
+ `${this.props.pageModelName}`
|
||||||
|
+ `/containers/`
|
||||||
+ `${this.state.newContainerName}`;
|
+ `${this.state.newContainerName}`;
|
||||||
|
|
||||||
|
fetch(url, init)
|
||||||
|
.then((response: Response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
|
||||||
|
response
|
||||||
|
.json()
|
||||||
|
.then((newContainer) => {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
containers: [
|
||||||
|
...this.state.containers,
|
||||||
|
newContainer],
|
||||||
|
newContainerName: "",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
errorMsg: `Failed to parse response: `
|
||||||
|
+ `${error.message}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
errorMsg: `Failed to create new container: `
|
||||||
|
+ `${response.status} ${response.statusText}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.setState({
|
||||||
|
...this.state,
|
||||||
|
errorMsg: `Failed to create new container: `
|
||||||
|
+ `${error.message}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2040,6 +2040,18 @@ form.pagemodeleditor.propertiesForm {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.errorPanel {
|
||||||
|
|
||||||
|
border: 2px solid #f00;
|
||||||
|
border-radius: 1em;
|
||||||
|
|
||||||
|
color: #f00;
|
||||||
|
|
||||||
|
margin: 1em 0;
|
||||||
|
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
/* dialog.pageModelEditor {
|
/* dialog.pageModelEditor {
|
||||||
|
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue