CCM NG: Some work on the PageModelEditor
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5556 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
64fc78667d
commit
1d3b11e6e4
|
|
@ -1,6 +1,7 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactModal from "react-modal";
|
import * as ReactModal from "react-modal";
|
||||||
import {
|
import {
|
||||||
|
ComponentModel,
|
||||||
ContainerModel,
|
ContainerModel,
|
||||||
PageModel,
|
PageModel,
|
||||||
PageModelVersion,
|
PageModelVersion,
|
||||||
|
|
@ -183,6 +184,8 @@ interface PageModelComponentProps {
|
||||||
|
|
||||||
interface PageModelComponentState {
|
interface PageModelComponentState {
|
||||||
|
|
||||||
|
containers: ContainerModel[];
|
||||||
|
|
||||||
editMode: boolean;
|
editMode: boolean;
|
||||||
|
|
||||||
errorMsg: string | null;
|
errorMsg: string | null;
|
||||||
|
|
@ -201,6 +204,7 @@ class PageModelComponent
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
containers: this.props.pageModel.containers,
|
||||||
editMode: this.props.pageModel.pageModelId === 0,
|
editMode: this.props.pageModel.pageModelId === 0,
|
||||||
errorMsg: null,
|
errorMsg: null,
|
||||||
form: {
|
form: {
|
||||||
|
|
@ -512,9 +516,9 @@ interface ContainerListProps {
|
||||||
|
|
||||||
interface ContainerListState {
|
interface ContainerListState {
|
||||||
|
|
||||||
errorMsg: string;
|
|
||||||
containerName: string;
|
containerName: string;
|
||||||
containers: ContainerModel[];
|
containers: ContainerModel[];
|
||||||
|
errorMsg: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContainerListComponent
|
class ContainerListComponent
|
||||||
|
|
@ -525,10 +529,10 @@ class ContainerListComponent
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
errorMsg: "",
|
|
||||||
containers: props.containers,
|
|
||||||
containerName: "",
|
containerName: "",
|
||||||
}
|
containers: props.containers,
|
||||||
|
errorMsg: "",
|
||||||
|
};
|
||||||
|
|
||||||
this.addContainer = this.addContainer.bind(this);
|
this.addContainer = this.addContainer.bind(this);
|
||||||
this.deleteContainer = this.deleteContainer.bind(this);
|
this.deleteContainer = this.deleteContainer.bind(this);
|
||||||
|
|
@ -558,15 +562,22 @@ class ContainerListComponent
|
||||||
</div>}
|
</div>}
|
||||||
<ul className="containerList">
|
<ul className="containerList">
|
||||||
{this.state.containers
|
{this.state.containers
|
||||||
&& this.state.containers.map((container) =>
|
&& this.props.containers.map((container) =>
|
||||||
<li>
|
<ContainerModelComponent
|
||||||
<span>{container.key}</span>
|
ccmApplication={this.props.ccmApplication}
|
||||||
<button onClick={this.deleteContainer}
|
container={container}
|
||||||
data-containerKey={container.key}>
|
deleteContainer={this.deleteContainer}
|
||||||
<span className="fa fa-minus-circle"></span>
|
dispatcherPrefix={this.props.dispatcherPrefix}
|
||||||
Delete
|
errorMsg="" />)
|
||||||
</button>
|
// <li>
|
||||||
</li>)
|
// <span>{container.key}</span>
|
||||||
|
// <button
|
||||||
|
// // onClick={this.deleteContainer}
|
||||||
|
// data-containerKey={container.key}>
|
||||||
|
// <span className="fa fa-minus-circle"></span>
|
||||||
|
// Delete
|
||||||
|
// </button>
|
||||||
|
// </li>)
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>;
|
</div>;
|
||||||
|
|
@ -621,7 +632,7 @@ class ContainerListComponent
|
||||||
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}/`
|
||||||
|
|
@ -656,8 +667,8 @@ class ContainerListComponent
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
containers,
|
|
||||||
containerName: "",
|
containerName: "",
|
||||||
|
containers,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
@ -684,21 +695,22 @@ class ContainerListComponent
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private deleteContainer(event: React.MouseEvent<HTMLButtonElement>): void {
|
// private deleteContainer(event: React.MouseEvent<HTMLButtonElement>): void {
|
||||||
|
private deleteContainer(containerKey: string): void {
|
||||||
|
|
||||||
event.preventDefault();
|
// event.preventDefault();
|
||||||
|
|
||||||
const deleteButton: HTMLButtonElement
|
// const deleteButton: HTMLButtonElement
|
||||||
= event.target as HTMLButtonElement
|
// = event.target as HTMLButtonElement;
|
||||||
const containerKey: string = deleteButton
|
// const containerKey: string = deleteButton
|
||||||
.getAttribute("data-containerKey") as string;
|
// .getAttribute("data-containerKey") as string;
|
||||||
|
|
||||||
const init: RequestInit = {
|
const init: RequestInit = {
|
||||||
|
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
}
|
};
|
||||||
|
|
||||||
const url: string = `${this.props.dispatcherPrefix}`
|
const url: string = `${this.props.dispatcherPrefix}`
|
||||||
+ `/page-models/${this.props.ccmApplication}/`
|
+ `/page-models/${this.props.ccmApplication}/`
|
||||||
|
|
@ -720,7 +732,7 @@ class ContainerListComponent
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
containers,
|
containers,
|
||||||
})
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
@ -742,6 +754,47 @@ class ContainerListComponent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ContainerModelComponentProps {
|
||||||
|
|
||||||
|
ccmApplication: string;
|
||||||
|
container: ContainerModel;
|
||||||
|
deleteContainer: (key: string) => void;
|
||||||
|
dispatcherPrefix: string;
|
||||||
|
errorMsg: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ContainerModelComponent
|
||||||
|
extends React.Component<ContainerModelComponentProps, {}> {
|
||||||
|
|
||||||
|
constructor(props: ContainerModelComponentProps) {
|
||||||
|
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): React.ReactNode {
|
||||||
|
|
||||||
|
return <li>
|
||||||
|
<span>{this.props.container.key}</span>
|
||||||
|
<button
|
||||||
|
onClick={(event) => this.deleteContainer(
|
||||||
|
event,
|
||||||
|
this.props.container.key)}>
|
||||||
|
<span className="fa fa-minus-circle"></span>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
private deleteContainer(
|
||||||
|
event: React.MouseEvent<HTMLButtonElement>,
|
||||||
|
containerKey: string): void {
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
this.props.deleteContainer(containerKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// interface PageModelEditorProps {
|
// interface PageModelEditorProps {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
@ -759,9 +812,19 @@ interface PageModelEditorState {
|
||||||
selectedPageModel: PageModel | null;
|
selectedPageModel: PageModel | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ComponentInfo {
|
||||||
|
|
||||||
|
javaClass: string;
|
||||||
|
editorComponent: any;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PageModelEditor
|
class PageModelEditor
|
||||||
extends React.Component<{}, PageModelEditorState> {
|
extends React.Component<{}, PageModelEditorState> {
|
||||||
|
|
||||||
|
private static components: ComponentInfo[];
|
||||||
|
|
||||||
private static getDispatcherPrefix(): string {
|
private static getDispatcherPrefix(): string {
|
||||||
|
|
||||||
const dataElem: HTMLElement | null = document
|
const dataElem: HTMLElement | null = document
|
||||||
|
|
@ -798,6 +861,25 @@ class PageModelEditor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static registerComponent(component: ComponentInfo): void {
|
||||||
|
|
||||||
|
PageModelEditor.components = [
|
||||||
|
...PageModelEditor.components,
|
||||||
|
component,
|
||||||
|
];
|
||||||
|
|
||||||
|
PageModelEditor.components.sort((component1, component2) => {
|
||||||
|
|
||||||
|
if (component1.label < component2.label) {
|
||||||
|
return -1;
|
||||||
|
} else if (component1.label > component2.label) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
|
|
||||||
super(props);
|
super(props);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,21 @@
|
||||||
export { ContainerModel, PageModel, PageModelVersion, PublicationStatus };
|
export {
|
||||||
|
ComponentModel,
|
||||||
|
ContainerModel,
|
||||||
|
PageModel,
|
||||||
|
PageModelVersion,
|
||||||
|
PublicationStatus
|
||||||
|
};
|
||||||
|
|
||||||
|
interface ComponentModel {
|
||||||
|
|
||||||
|
componentModelId: number;
|
||||||
|
idAttribute: string;
|
||||||
|
classAttribute: string;
|
||||||
|
key: string;
|
||||||
|
modelUuid: string;
|
||||||
|
styleAttribute: string;
|
||||||
|
uuid: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface ContainerModel {
|
interface ContainerModel {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue