CCM NG: PageModelsEditor First parts for UI for managing the containers in a PageModel
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5536 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
0803a107e3
commit
c5b07faf06
|
|
@ -72,7 +72,7 @@ public class ContainerModel implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "CONTAINER_ID")
|
@Column(name = "CONTAINER_ID")
|
||||||
@XmlElement(name = "ocntainer-model-id")
|
@XmlElement(name = "container-model-id")
|
||||||
private long containerId;
|
private long containerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import com.arsdigita.kernel.KernelConfig;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
import org.libreccm.core.CoreConstants;
|
import org.libreccm.core.CoreConstants;
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.pagemodel.ContainerModel;
|
||||||
import org.libreccm.pagemodel.PageModel;
|
import org.libreccm.pagemodel.PageModel;
|
||||||
import org.libreccm.pagemodel.PageModelManager;
|
import org.libreccm.pagemodel.PageModelManager;
|
||||||
import org.libreccm.pagemodel.PageModelRepository;
|
import org.libreccm.pagemodel.PageModelRepository;
|
||||||
|
|
@ -47,8 +48,10 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides RESTful endpoints for retrieving, creating, updating and deleting
|
* Provides RESTful endpoints for retrieving, creating, updating and deleting
|
||||||
|
|
@ -293,6 +296,7 @@ public class PageModels {
|
||||||
|
|
||||||
return Json
|
return Json
|
||||||
.createObjectBuilder()
|
.createObjectBuilder()
|
||||||
|
.add("containers", mapContainersToJson(pageModel))
|
||||||
.add("description",
|
.add("description",
|
||||||
globalizationHelper
|
globalizationHelper
|
||||||
.getValueFromLocalizedString(pageModel.getDescription()))
|
.getValueFromLocalizedString(pageModel.getDescription()))
|
||||||
|
|
@ -312,6 +316,29 @@ public class PageModels {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsonArray mapContainersToJson(final PageModel pageModel) {
|
||||||
|
|
||||||
|
final JsonArrayBuilder containers = Json.createArrayBuilder();
|
||||||
|
|
||||||
|
pageModel
|
||||||
|
.getContainers()
|
||||||
|
.stream()
|
||||||
|
.map(this::mapContainerToJson)
|
||||||
|
.forEach(container -> containers.add(container));
|
||||||
|
|
||||||
|
return containers.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject mapContainerToJson(final ContainerModel container) {
|
||||||
|
|
||||||
|
return Json
|
||||||
|
.createObjectBuilder()
|
||||||
|
.add("containerUuid", container.getContainerUuid())
|
||||||
|
.add("key", container.getKey())
|
||||||
|
.add("uuid", container.getUuid())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the {@link PublicationStatus} of the provided PageModel.
|
* Check if the {@link PublicationStatus} of the provided PageModel.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {PageModel, PageModelVersion, PublicationStatus} from "./datatypes";
|
import {
|
||||||
|
ContainerModel,
|
||||||
|
PageModel,
|
||||||
|
PageModelVersion,
|
||||||
|
PublicationStatus
|
||||||
|
} from "./datatypes";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
PageModelEditor,
|
PageModelEditor,
|
||||||
|
|
@ -291,11 +296,15 @@ class PageModelComponent
|
||||||
}}>Edit
|
}}>Edit
|
||||||
</button>
|
</button>
|
||||||
{this.props.pageModel.publicationStatus === PublicationStatus.NOT_PUBLISHED.toString()
|
{this.props.pageModel.publicationStatus === PublicationStatus.NOT_PUBLISHED.toString()
|
||||||
&& <button onClick={(event) => this.publishPageModel(event)}>Publish</button>
|
&& <button
|
||||||
|
onClick={(event) => this.publishPageModel(event)}>Publish</button>
|
||||||
}
|
}
|
||||||
{this.props.pageModel.publicationStatus === PublicationStatus.NEEDS_UPDATE.toString()
|
{this.props.pageModel.publicationStatus === PublicationStatus.NEEDS_UPDATE.toString()
|
||||||
&& <button onClick={(event) => this.publishPageModel(event)}>Republish</button>
|
&& <button
|
||||||
|
onClick={(event) => this.publishPageModel(event)}>Republish</button>
|
||||||
}
|
}
|
||||||
|
<ContainerListComponent
|
||||||
|
containers={this.props.pageModel.containers}/>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -405,11 +414,11 @@ class PageModelComponent
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
headers,
|
headers,
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}
|
};
|
||||||
|
|
||||||
const url: string = `${this.props.dispatcherPrefix}`
|
const url: string = `${this.props.dispatcherPrefix}`
|
||||||
+ `/page-models/${this.props.ccmApplication}/`
|
+ `/page-models/${this.props.ccmApplication}/`
|
||||||
+ `${this.props.pageModel.name}`
|
+ `${this.props.pageModel.name}`;
|
||||||
|
|
||||||
fetch(url, init)
|
fetch(url, init)
|
||||||
.then((response: Response) => {
|
.then((response: Response) => {
|
||||||
|
|
@ -455,11 +464,11 @@ class PageModelComponent
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
headers,
|
headers,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
}
|
};
|
||||||
|
|
||||||
const url: string = `${this.props.dispatcherPrefix}`
|
const url: string = `${this.props.dispatcherPrefix}`
|
||||||
+ `/page-models/${this.props.ccmApplication}/`
|
+ `/page-models/${this.props.ccmApplication}/`
|
||||||
+ `${this.props.pageModel.name}`
|
+ `${this.props.pageModel.name}`;
|
||||||
|
|
||||||
fetch(url, init)
|
fetch(url, init)
|
||||||
.then((response: Response) => {
|
.then((response: Response) => {
|
||||||
|
|
@ -485,6 +494,30 @@ class PageModelComponent
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ContainerListProps {
|
||||||
|
|
||||||
|
containers: ContainerModel[],
|
||||||
|
}
|
||||||
|
|
||||||
|
class ContainerListComponent extends React.Component<ContainerListProps, {}> {
|
||||||
|
|
||||||
|
public render(): React.ReactNode {
|
||||||
|
return <div className="containerList">
|
||||||
|
<button>Add container</button>
|
||||||
|
<ul className="containerList">
|
||||||
|
{this.props.containers
|
||||||
|
&& this.props.containers.map((container) =>
|
||||||
|
<li>
|
||||||
|
<span>{container.key}</span>
|
||||||
|
<button>Down</button>
|
||||||
|
<button>Up</button>
|
||||||
|
<button>Delete</button>
|
||||||
|
</li>)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// interface PageModelEditorProps {
|
// interface PageModelEditorProps {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
@ -549,8 +582,8 @@ class PageModelEditor
|
||||||
<span>+</span> Create new PageModel
|
<span>+</span> Create new PageModel
|
||||||
</button>
|
</button>
|
||||||
<PageModelsList
|
<PageModelsList
|
||||||
ccmApplication={this.getCcmApplication()}
|
ccmApplication={PageModelEditor.getCcmApplication()}
|
||||||
dispatcherPrefix={this.getDispatcherPrefix()}
|
dispatcherPrefix={PageModelEditor.getDispatcherPrefix()}
|
||||||
pageModels={this.state.pageModels}
|
pageModels={this.state.pageModels}
|
||||||
selectPageModel={(selectedPageModel: PageModel) => {
|
selectPageModel={(selectedPageModel: PageModel) => {
|
||||||
this.setState((state: PageModelEditorState) => {
|
this.setState((state: PageModelEditorState) => {
|
||||||
|
|
@ -588,8 +621,8 @@ class PageModelEditor
|
||||||
}
|
}
|
||||||
{this.state.selectedPageModel !== null &&
|
{this.state.selectedPageModel !== null &&
|
||||||
<PageModelComponent
|
<PageModelComponent
|
||||||
ccmApplication={this.getCcmApplication()}
|
ccmApplication={PageModelEditor.getCcmApplication()}
|
||||||
dispatcherPrefix={this.getDispatcherPrefix()}
|
dispatcherPrefix={PageModelEditor.getDispatcherPrefix()}
|
||||||
pageModel={this.state.selectedPageModel}
|
pageModel={this.state.selectedPageModel}
|
||||||
reload={() => {
|
reload={() => {
|
||||||
this.reload();
|
this.reload();
|
||||||
|
|
@ -607,6 +640,7 @@ class PageModelEditor
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
selectedPageModel: {
|
selectedPageModel: {
|
||||||
|
containers: [],
|
||||||
description: "",
|
description: "",
|
||||||
lastModified: 0,
|
lastModified: 0,
|
||||||
lastPublished: 0,
|
lastPublished: 0,
|
||||||
|
|
@ -627,10 +661,10 @@ class PageModelEditor
|
||||||
const init: RequestInit = {
|
const init: RequestInit = {
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}
|
};
|
||||||
|
|
||||||
const url: string = `${this.getDispatcherPrefix()}`
|
const url: string = `${PageModelEditor.getDispatcherPrefix()}`
|
||||||
+ `/page-models/${this.getCcmApplication()}`;
|
+ `/page-models/${PageModelEditor.getCcmApplication()}`;
|
||||||
|
|
||||||
fetch(url, init)
|
fetch(url, init)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
@ -682,7 +716,7 @@ class PageModelEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private getDispatcherPrefix(): string {
|
private static getDispatcherPrefix(): string {
|
||||||
|
|
||||||
const dataElem: HTMLElement | null = document
|
const dataElem: HTMLElement | null = document
|
||||||
.querySelector("#page-models-editor.react-data");
|
.querySelector("#page-models-editor.react-data");
|
||||||
|
|
@ -700,7 +734,7 @@ class PageModelEditor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCcmApplication(): string {
|
private static getCcmApplication(): string {
|
||||||
|
|
||||||
const dataElem: HTMLElement | null = document
|
const dataElem: HTMLElement | null = document
|
||||||
.querySelector("#page-models-editor.react-data");
|
.querySelector("#page-models-editor.react-data");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
export { PageModel, PageModelVersion, PublicationStatus };
|
export { ContainerModel, PageModel, PageModelVersion, PublicationStatus };
|
||||||
|
|
||||||
|
interface ContainerModel {
|
||||||
|
|
||||||
|
containerUuid: string;
|
||||||
|
key: string;
|
||||||
|
uuid: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface PageModel {
|
interface PageModel {
|
||||||
|
|
||||||
|
containers: ContainerModel[],
|
||||||
description: string;
|
description: string;
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue