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-94f89814c4dfpull/2/head
parent
e167943f49
commit
ba5a587b53
|
|
@ -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.");
|
||||||
|
|
@ -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