From 9b6621aeb51597456dcfdf16d30b7785b4f2843d Mon Sep 17 00:00:00 2001 From: jensp Date: Sun, 17 Jun 2018 15:44:07 +0000 Subject: [PATCH] CCM NG: * Ignore IDEA files * Publishing PageModels from the PageModelEditor git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5535 8810af33-2d31-482b-a856-94f89814c4df Former-commit-id: 259a27079a6751e2870f7d07b8c88b125b0811ce --- .../org/libreccm/pagemodel/PageModel.java | 238 ++++++++++-------- .../libreccm/pagemodel/PageModelManager.java | 141 ++++++----- .../pagemodel/PageModelRepository.java | 2 +- .../org/libreccm/pagemodel/rs/PageModels.java | 37 ++- .../V7_0_0_26__page_model_last_modified.sql | 2 + .../V7_0_0_26__page_model_last_modified.sql | 2 + .../ccm-pagemodelseditor/PageModelsEditor.tsx | 76 +++++- .../ccm-pagemodelseditor/datatypes.ts | 9 +- 8 files changed, 330 insertions(+), 177 deletions(-) create mode 100644 ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_26__page_model_last_modified.sql create mode 100644 ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_26__page_model_last_modified.sql diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModel.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModel.java index 95ad6cf47..a594baf6a 100644 --- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModel.java +++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModel.java @@ -62,7 +62,6 @@ import javax.xml.bind.annotation.XmlTransient; * page. * * @author Jens Pelzetter - * * @see PageModelRepository * @see PageModelManager * @see PageRenderer @@ -71,102 +70,116 @@ import javax.xml.bind.annotation.XmlTransient; @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "PAGE_MODELS", schema = CoreConstants.DB_SCHEMA) @NamedQueries({ - @NamedQuery( - name = "PageModel.findAllDraftModels", - query = "SELECT p FROM PageModel p " - + "WHERE p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT") - , - @NamedQuery( - name = "PageModel.findAllLiveModels", - query = "SELECT p FROM PageModel p " - + "WHERE p.version = org.libreccm.pagemodel.PageModelVersion.LIVE") - , - @NamedQuery( - name = "PageModel.findDraftVersion", - query = "SELECT p FROM PageModel p " - + "WHERE p.modelUuid = :uuid " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT") - , - @NamedQuery( - name = "PageModel.hasLiveVersion", - query = "SELECT (CASE WHEN COUNT(p) > 0 THEN true ELSE False END) " - + "FROM PageModel p " - + "WHERE p.modelUuid = :uuid " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE" - ) - , - @NamedQuery( - name = "PageModel.findLiveVersion", - query = "SELECT p FROM PageModel p " - + "WHERE p.modelUuid = :uuid " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE") - , - @NamedQuery( - name = "PageModel.findDraftByApplication", - query = "SELECT p FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT" - ) - , - @NamedQuery( - name = "PageModel.findDraftByApplicationAndName", - query = "SELECT p FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.name = :name " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT" - ) - , - @NamedQuery( - name = "PageModel.countDraftByApplicationAndName", - query = "SELECT COUNT(p) FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT" - ) - , - @NamedQuery( - name = "PageModel.countDraftByApplication", - query = "SELECT COUNT(p) FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.DRAFT" - ) - , - @NamedQuery( - name = "PageModel.findLiveByApplication", - query = "SELECT p FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE") - , - @NamedQuery( - name = "PageModel.countLiveByApplication", - query = "SELECT COUNT(p) FROM PageModel p " - + "WHERE p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE") - , - @NamedQuery( - name = "PageModel.findLiveByApplicationAndName", - query = "SELECT p FROM PageModel p " - + "WHERE p.name = :name " - + "AND p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE" - ) - , - @NamedQuery( - name = "PageModel.countLiveByApplicationAndName", - query = "SELECT COUNT(p) FROM PageModel p " - + "WHERE p.name = :name " - + "AND p.application = :application " - + "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE" - ) -}) + @NamedQuery( + name = "PageModel.findAllDraftModels", + query = "SELECT p FROM PageModel p " + + "WHERE p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT") + , + @NamedQuery( + name = "PageModel.findAllLiveModels", + query = "SELECT p FROM PageModel p " + + "WHERE p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE") + , + @NamedQuery( + name = "PageModel.findDraftVersion", + query = "SELECT p FROM PageModel p " + + "WHERE p.modelUuid = :uuid " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT") + , + @NamedQuery( + name = "PageModel.hasLiveVersion", + query = + "SELECT (CASE WHEN COUNT(p) > 0 THEN true ELSE " + + "False END) " + + "FROM PageModel p " + + "WHERE p.modelUuid = :uuid " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE" + ) + , + @NamedQuery( + name = "PageModel.findLiveVersion", + query = "SELECT p FROM PageModel p " + + "WHERE p.modelUuid = :uuid " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE") + , + @NamedQuery( + name = "PageModel.findDraftByApplication", + query = "SELECT p FROM PageModel p " + + "WHERE p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT" + ) + , + @NamedQuery( + name = "PageModel.findDraftByApplicationAndName", + query = "SELECT p FROM PageModel p " + + "WHERE p.application = :application " + + "AND p.name = :name " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT" + ) + , + @NamedQuery( + name = "PageModel.countDraftByApplicationAndName", + query = "SELECT COUNT(p) FROM PageModel p " + + "WHERE p.name = :name " + + "AND p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT" + ) + , + @NamedQuery( + name = "PageModel.countDraftByApplication", + query = "SELECT COUNT(p) FROM PageModel p " + + "WHERE p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.DRAFT" + ) + , + @NamedQuery( + name = "PageModel.findLiveByApplication", + query = "SELECT p FROM PageModel p " + + "WHERE p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE") + , + @NamedQuery( + name = "PageModel.countLiveByApplication", + query = "SELECT COUNT(p) FROM PageModel p " + + "WHERE p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE") + , + @NamedQuery( + name = "PageModel.findLiveByApplicationAndName", + query = "SELECT p FROM PageModel p " + + "WHERE p.name = :name " + + "AND p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE" + ) + , + @NamedQuery( + name = "PageModel.countLiveByApplicationAndName", + query = "SELECT COUNT(p) FROM PageModel p " + + "WHERE p.name = :name " + + "AND p.application = :application " + + "AND p.version = org.libreccm.pagemodel" + + ".PageModelVersion.LIVE" + ) + }) @XmlRootElement(name = "pagemodel") public class PageModel implements Serializable { private static final long serialVersionUID = 7252512839926020978L; /** - * * The ID of the entity in the database. - * */ @Id @Column(name = "PAGE_MODEL_ID") @@ -175,11 +188,9 @@ public class PageModel implements Serializable { private long pageModelId; /** - * * The UUID of this {@code PageModel}. Please note that this UUID identifies * the dataset not the model. Therefore the draft and the live version have * different values for this field. - * */ @Column(name = "UUID", length = 255, nullable = false) @NotNull @@ -257,115 +268,142 @@ public class PageModel implements Serializable { private List containers; public PageModel() { + title = new LocalizedString(); description = new LocalizedString(); containers = new ArrayList<>(); } public long getPageModelId() { + return pageModelId; } protected void setPageModelId(final long pageModelId) { + this.pageModelId = pageModelId; } public String getUuid() { + return uuid; } protected void setUuid(final String uuid) { + this.uuid = uuid; } public String getModelUuid() { + return modelUuid; } protected void setModelUuid(final String modelUuid) { + this.modelUuid = modelUuid; } public String getName() { + return name; } public void setName(final String name) { + this.name = name; } public PageModelVersion getVersion() { + return version; } protected void setVersion(final PageModelVersion version) { + this.version = version; } public Date getLastModified() { + return lastModified; } protected void setLastModified(final Date lastModified) { + this.lastModified = new Date(lastModified.getTime()); } public LocalizedString getTitle() { + return title; } protected void setTitle(final LocalizedString title) { + Objects.requireNonNull(title); this.title = title; } public LocalizedString getDescription() { + return description; } protected void setDescription(final LocalizedString description) { + Objects.requireNonNull(description); this.description = description; } public CcmApplication getApplication() { + return application; } public void setApplication(final CcmApplication application) { + this.application = application; } public String getType() { + return type; } public void setType(final String type) { + this.type = type; } public List getContainers() { + return Collections.unmodifiableList(containers); } protected void setContainers(final List containers) { + this.containers = new ArrayList<>(containers); } protected void addContainer(final ContainerModel container) { + containers.add(container); } protected void removeContainer(final ContainerModel container) { + containers.remove(container); } protected void clearContainers() { + containers.clear(); } @Override public int hashCode() { + int hash = 7; hash = 71 * hash + (int) (pageModelId ^ (pageModelId >>> 32)); hash = 71 * hash + Objects.hashCode(uuid); @@ -378,6 +416,7 @@ public class PageModel implements Serializable { @Override public boolean equals(final Object obj) { + if (this == obj) { return true; } @@ -410,6 +449,7 @@ public class PageModel implements Serializable { } public boolean canEqual(final Object obj) { + return obj instanceof PageModel; } @@ -424,13 +464,13 @@ public class PageModel implements Serializable { public String toString(final String data) { return String.format("%s{ " - + "pageModelId = %d, " - + "uuid = %s, " - + "name = \"%s\", " - + "title = %s, " - + "description = %s, " - + "type = \"%s\"" - + " }", + + "pageModelId = %d, " + + "uuid = %s, " + + "name = \"%s\", " + + "title = %s, " + + "description = %s, " + + "type = \"%s\"" + + " }", super.toString(), pageModelId, uuid, diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java index d27a36128..97e5e0056 100644 --- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java +++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java @@ -85,15 +85,16 @@ public class PageModelManager { private PageModelRepository pageModelRepo; private final Map components - = new HashMap<>(); + = new HashMap<>(); /** * Called by CDI after an instance of this class is created. Initialises the - * {@link #components} by retrieving the data about all available - * {@link ComponentModel}s. + * {@link #components} by retrieving the data about all available {@link + * ComponentModel}s. */ @PostConstruct private void init() { + LOGGER.debug("Initalising {}...", PageModelManager.class.getName()); final ServiceLoader modules = ServiceLoader.load( @@ -127,11 +128,11 @@ public class PageModelManager { /** * Creates a new {@link PageModel} for the provided application. The method - * tries to retrieve the appropriate application by using - * {@link PageModelRepository#findLiveByApplicationAndName(org.libreccm.web.CcmApplication, java.lang.String)}. - * Please note that this method will always return the - * draft - * version of the page model. + * tries to retrieve the appropriate application by using {@link + * PageModelRepository#findLiveByApplicationAndName(org.libreccm.web + * .CcmApplication, + * java.lang.String)}. Please note that this method will always return the + * draft version of the page model. * * @param name The name of the new page model. Must be unique for the * application. @@ -149,16 +150,18 @@ public class PageModelManager { final String type) { Objects.requireNonNull(application, - "Can't create a page model for application null"); + "Can't create a page model for application " + + "null"); Objects.requireNonNull(name, "Then name of a Pagemodel can't be null."); if (name.isEmpty() - || name.matches("\\s*")) { + || name.matches("\\s*")) { throw new IllegalArgumentException( "The name of a PageModel can't be empty."); } LOGGER.debug( - "Creating new PageModel with name \"{}\" for application \"{}\" and type \"{}\".", + "Creating new PageModel with name \"{}\" for application \"{}\" " + + "and type \"{}\".", name, application.getPrimaryUrl(), type); @@ -169,12 +172,12 @@ public class PageModelManager { if (count > 0) { LOGGER.error("A page model with the name \"{}\" for the " - + "application \"{}\" already exists.", + + "application \"{}\" already exists.", name, application.getPrimaryUrl()); throw new IllegalArgumentException(String.format( "A page model with the name \"%s\" for the application \"%s\" " - + "already exists.", + + "already exists.", name, application.getPrimaryUrl())); } @@ -191,8 +194,8 @@ public class PageModelManager { /** * Retrieves the draft version of a {@link PageModel}. To invoke this method - * the current user needs a permission granting the - * {@link CoreConstants#PRIVILEGE_ADMIN} privilege. + * the current user needs a permission granting the {@link + * CoreConstants#PRIVILEGE_ADMIN} privilege. * * @param pageModel The {@link PageModel} for which the draft version is * retrieved. @@ -222,11 +225,12 @@ public class PageModelManager { * * @param pageModel The {@link PageModel} to check for a live version. * - * @return {@code true} if there is a live version for the provided - * {@link PageModel}, {@code false} otherwise. + * @return {@code true} if there is a live version for the provided {@link + * PageModel}, {@code false} otherwise. */ @Transactional(Transactional.TxType.REQUIRED) public boolean isLive(final PageModel pageModel) { + final TypedQuery query = entityManager.createNamedQuery( "PageModel.hasLiveVersion", Boolean.class); query.setParameter("uuid", pageModel.getModelUuid()); @@ -242,8 +246,8 @@ public class PageModelManager { * retrieved. * * @return An {@link Optional} containing the live version of the provided - * {@link PageModel} if there is a live version. Otherwise an empty - * {@link Optional} is returned. + * {@link PageModel} if there is a live version. Otherwise an empty + * {@link Optional} is returned. */ @Transactional(Transactional.TxType.REQUIRED) public Optional getLiveVersion(final PageModel pageModel) { @@ -280,10 +284,13 @@ public class PageModelManager { final PageModel draftModel = getDraftVersion(pageModel); final PageModel liveModel; + final boolean isLive; if (isLive(pageModel)) { + isLive = true; liveModel = getLiveVersion(draftModel).get(); } else { liveModel = new PageModel(); + isLive = false; } liveModel.setName(draftModel.getName()); @@ -312,11 +319,17 @@ public class PageModelManager { .getContainers() .stream() .map(this::publishContainerModel) - .forEach(liveContainerModel -> addContainerModel(pageModel, + .forEach(liveContainerModel -> addContainerModel(liveModel, liveContainerModel)); - liveModel.setLastModified(new Date()); + pageModelRepo.save(liveModel); + //if (isLive) { + // entityManager.merge(liveModel); + //} else { + // entityManager.persist(liveModel); + //} + LOGGER.debug("Successfully published PageModel \"{}\".", liveModel.getName()); return liveModel; @@ -332,18 +345,20 @@ public class PageModelManager { liveModel.setContainerUuid(draftModel.getContainerUuid()); final Styles draftStyles = draftModel.getStyles(); - final Styles liveStyles = new Styles(); - liveStyles.setStyleName(draftStyles.getStyleName()); - liveStyles.setRules(draftStyles - .getRules() - .stream() - .map(this::publishRule) - .collect(Collectors.toList())); - liveStyles.setMediaRules(draftStyles - .getMediaRules() - .stream() - .map(this::publishMediaRule) - .collect(Collectors.toList())); + if (draftStyles != null) { + final Styles liveStyles = new Styles(); + liveStyles.setStyleName(draftStyles.getStyleName()); + liveStyles.setRules(draftStyles + .getRules() + .stream() + .map(this::publishRule) + .collect(Collectors.toList())); + liveStyles.setMediaRules(draftStyles + .getMediaRules() + .stream() + .map(this::publishMediaRule) + .collect(Collectors.toList())); + } draftModel .getComponents() @@ -360,7 +375,7 @@ public class PageModelManager { Objects.requireNonNull(draftMediaRule); - final MediaRule liveMediaRule = new MediaRule(); + final MediaRule liveMediaRule = new MediaRule(); final MediaQuery liveMediaQuery = new MediaQuery(); liveMediaQuery .setMaxWidth(draftMediaRule.getMediaQuery().getMaxWidth()); @@ -370,10 +385,10 @@ public class PageModelManager { .setMinWidth(draftMediaRule.getMediaQuery().getMinWidth()); liveMediaRule.setRules(draftMediaRule - .getRules() - .stream() - .map(this::publishRule) - .collect(Collectors.toList())); + .getRules() + .stream() + .map(this::publishRule) + .collect(Collectors.toList())); return liveMediaRule; } @@ -385,10 +400,10 @@ public class PageModelManager { final Rule liveRule = new Rule(); liveRule.setSelector(draftRule.getSelector()); liveRule.setProperties(draftRule - .getProperties() - .stream() - .map(this::publishCssProperty) - .collect(Collectors.toList())); + .getProperties() + .stream() + .map(this::publishCssProperty) + .collect(Collectors.toList())); return liveRule; } @@ -414,9 +429,11 @@ public class PageModelManager { * @return The live version of the {@link ComponentModel}. */ @SuppressWarnings("unchecked") - private ComponentModel publishComponentModel(final ComponentModel draftModel) { + private ComponentModel publishComponentModel(final ComponentModel + draftModel) { - Objects.requireNonNull(draftModel, "Can't publish ComponentModel null."); + Objects.requireNonNull(draftModel, + "Can't publish ComponentModel null."); LOGGER.debug("Publishing ComponentModel \"{}\"...", draftModel.getKey()); @@ -447,9 +464,9 @@ public class PageModelManager { propertyDescriptor.getName(), draftModel.getKey()); - final Class propType = propertyDescriptor.getPropertyType(); - final Method readMethod = propertyDescriptor.getReadMethod(); - final Method writeMethod = propertyDescriptor.getWriteMethod(); + final Class propType = propertyDescriptor.getPropertyType(); + final Method readMethod = propertyDescriptor.getReadMethod(); + final Method writeMethod = propertyDescriptor.getWriteMethod(); if (propertyIsExcluded(propertyDescriptor.getName())) { continue; @@ -460,7 +477,7 @@ public class PageModelManager { } if (propType != null - && propType.isAssignableFrom(List.class)) { + && propType.isAssignableFrom(List.class)) { try { final List source = (List) readMethod @@ -469,30 +486,31 @@ public class PageModelManager { target.addAll(source); writeMethod.invoke(draftModel, target); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } } else if (propType != null - && propType.isAssignableFrom(Map.class)) { + && propType.isAssignableFrom(Map.class)) { final Map source; final Map target; try { - source = (Map) readMethod.invoke(draftModel); + source + = (Map) readMethod.invoke(draftModel); target = (Map) readMethod.invoke(liveModel); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } source.forEach((key, value) -> target.put(key, value)); } else if (propType != null - && propType.isAssignableFrom(Set.class)) { + && propType.isAssignableFrom(Set.class)) { final Set source; final Set target; @@ -501,8 +519,8 @@ public class PageModelManager { source = (Set) readMethod.invoke(draftModel); target = (Set) readMethod.invoke(liveModel); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } @@ -513,8 +531,8 @@ public class PageModelManager { value = readMethod.invoke(draftModel); writeMethod.invoke(liveModel, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } } @@ -534,9 +552,10 @@ public class PageModelManager { * @param name The name of the property. * * @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) { + final String[] excluded = new String[]{ "class", "uuid", @@ -570,7 +589,7 @@ public class PageModelManager { @Transactional(Transactional.TxType.REQUIRED) public void removeContainerModel(final PageModel pageModel, - final ContainerModel container) { + final ContainerModel container) { Objects.requireNonNull(pageModel); Objects.requireNonNull(container); diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelRepository.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelRepository.java index 65434fbbd..bbcb46ac0 100644 --- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelRepository.java +++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelRepository.java @@ -205,7 +205,7 @@ public class PageModelRepository extends AbstractEntityRepository{this.props.pageModel.version.toString()}
Description
{this.props.pageModel.description}
+
Last modified
+
{this.getLastModifiedDate()}
Last published
{this.getLastPublishedDate()}
PublicationStatus
{this.props.pageModel.publicationStatus}
-
Publish
-
{this.props.pageModel.publicationStatus === PublicationStatus.NOT_PUBLISHED}
-
Republish
-
{this.props.pageModel.publicationStatus === PublicationStatus.NEEDS_UPDATE}
- {this.props.pageModel.publicationStatus === PublicationStatus.NOT_PUBLISHED - && + {this.props.pageModel.publicationStatus === PublicationStatus.NOT_PUBLISHED.toString() + && } - {this.props.pageModel.publicationStatus === PublicationStatus.NEEDS_UPDATE - && + {this.props.pageModel.publicationStatus === PublicationStatus.NEEDS_UPDATE.toString() + && } ; } @@ -317,6 +315,18 @@ class PageModelComponent }); } + private getLastModifiedDate():string { + + if (this.props.pageModel.lastPublished === 0) { + return ""; + } else { + const lastModified: Date = new Date(); + lastModified.setTime(this.props.pageModel.lastModified); + + return lastModified.toISOString(); + } + } + private getLastPublishedDate(): string { if (this.props.pageModel.lastPublished === 0) { @@ -426,6 +436,53 @@ class PageModelComponent }); } + private publishPageModel(event: React.MouseEvent): void { + + event.preventDefault(); + + const headers: Headers = new Headers(); + //headers.append("Content-Type", "application/json"); + headers.append("Content-Type", "application/x-www-form-urlencoded"); + + //const formData: FormData = new FormData(); + //formData.set("action", "publish"); + //const data: URLSearchParams = new URLSearchParams(); + //data.append("action", "publish"); + + const init: RequestInit = { + + body: "action=publish", + credentials: "same-origin", + headers, + method: "POST", + } + + const url: string = `${this.props.dispatcherPrefix}` + + `/page-models/${this.props.ccmApplication}/` + + `${this.props.pageModel.name}` + + fetch(url, init) + .then((response: Response) => { + if (response.ok) { + + this.props.reload(); + } else { + this.setState({ + ...this.state, + errorMsg: `Failed to publish PageModel: ` + + ` ${response.status} ${response.statusText}`, + }); + } + }) + .catch((error) => { + this.setState({ + ...this.state, + errorMsg: `Failed to publish PageModel: ${error.message}`, + }) + }); + + } + } // interface PageModelEditorProps { @@ -551,11 +608,12 @@ class PageModelEditor ...this.state, selectedPageModel: { description: "", + lastModified: 0, lastPublished: 0, modelUuid: "", name: "", pageModelId: 0, - publicationStatus: PublicationStatus.NOT_PUBLISHED, + publicationStatus: PublicationStatus.NOT_PUBLISHED.toString(), title: "", type: "", uuid: "", diff --git a/ccm-pagemodelseditor/src/main/typescript/ccm-pagemodelseditor/datatypes.ts b/ccm-pagemodelseditor/src/main/typescript/ccm-pagemodelseditor/datatypes.ts index 4f25e870e..e6e582582 100644 --- a/ccm-pagemodelseditor/src/main/typescript/ccm-pagemodelseditor/datatypes.ts +++ b/ccm-pagemodelseditor/src/main/typescript/ccm-pagemodelseditor/datatypes.ts @@ -10,7 +10,8 @@ interface PageModel { type: string; uuid: string; version: PageModelVersion; - publicationStatus: PublicationStatus; + publicationStatus: string; + lastModified: number; lastPublished: number; } @@ -22,7 +23,7 @@ enum PageModelVersion { enum PublicationStatus { - NOT_PUBLISHED, - PUBLISHED, - NEEDS_UPDATE, + NOT_PUBLISHED = "NOT_PUBLISHED", + PUBLISHED = "PUBLISHED", + NEEDS_UPDATE = "NEEDS_UPDATE", } \ No newline at end of file