From e010e5a653c4e1c10bd21d326ec8882616bea09c Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 27 Apr 2021 21:14:30 +0200 Subject: [PATCH] Authoring steps are shown --- .../java/org/librecms/ui/CmsMessages.java | 4 + .../documents/MvcAuthoringStepService.java | 13 +- .../MvcArticlePropertiesStep.java | 124 ++++++++++-------- .../documents/authoringstep.xhtml | 14 +- .../article/article-basic-properties.xhtml | 102 +++++++------- 5 files changed, 145 insertions(+), 112 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java b/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java index 442d8732e..4fc8f9a62 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java +++ b/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java @@ -36,6 +36,10 @@ import javax.inject.Named; public class CmsMessages { private SortedMap messages; + + public CmsMessages() { + this.messages = new TreeMap<>(); + } public Map getMessages() { return Collections.unmodifiableSortedMap(messages); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStepService.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStepService.java index 60fa877fa..004b551ed 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStepService.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStepService.java @@ -23,6 +23,7 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; +import org.librecms.ui.contentsections.ContentSectionModel; import org.librecms.ui.contentsections.ContentSectionsUi; import java.util.Objects; @@ -48,12 +49,18 @@ public class MvcAuthoringStepService { @Inject private ContentItemRepository itemRepo; + @Inject + private ContentSectionModel sectionModel; + @Inject private ContentSectionsUi sectionsUi; @Inject private GlobalizationHelper globalizationHelper; + @Inject + private SelectedDocumentModel documentModel; + private ContentSection section; private ContentItem document; @@ -141,6 +148,7 @@ public class MvcAuthoringStepService { sectionIdentifier) ) ); + sectionModel.setSection(section); document = itemRepo .findByPath(section, documentPath) @@ -155,6 +163,7 @@ public class MvcAuthoringStepService { ) ) ); + documentModel.setContentItem(document); this.documentPath = itemManager.getItemPath(document); } @@ -185,7 +194,7 @@ public class MvcAuthoringStepService { ) .replace( String.format("{%s}", - MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME + MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME ), documentPath ) @@ -232,7 +241,7 @@ public class MvcAuthoringStepService { ) .replace( String.format("{%s}", - MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME + MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME ), documentPath ) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java index 8e5bf5f99..33dd66101 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticlePropertiesStep.java @@ -32,6 +32,8 @@ import org.librecms.ui.contentsections.documents.MvcAuthoringStep; import org.librecms.ui.contentsections.documents.MvcAuthoringStepService; import org.librecms.ui.contentsections.documents.MvcAuthoringSteps; +import java.util.Collections; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.ws.rs.Path; @@ -52,7 +54,6 @@ import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PathParam; - /** * Authoring step for editing the basic properties of an a {@link Article}. * @@ -109,6 +110,14 @@ public class MvcArticlePropertiesStep { @Inject private MvcAuthoringStepService stepService; + private Map titleValues; + + private List unusedTitleLocales; + + private Map descriptionValues; + + private List unusedDescriptionLocales; + @GET @Path("/") @Transactional(Transactional.TxType.REQUIRED) @@ -127,6 +136,56 @@ public class MvcArticlePropertiesStep { } if (itemPermissionChecker.canEditItem(stepService.getDocument())) { + titleValues = stepService + .getDocument() + .getTitle() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ); + + final Set titleLocales = stepService + .getDocument() + .getTitle() + .getAvailableLocales(); + + unusedTitleLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + + descriptionValues = stepService + .getDocument() + .getDescription() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ); + + final Set descriptionLocales = stepService + .getDocument() + .getDescription() + .getAvailableLocales(); + + unusedDescriptionLocales = globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !descriptionLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + return "org/librecms/ui/contenttypes/article/article-basic-properties.xhtml"; } else { return documentUi.showAccessDenied( @@ -135,6 +194,7 @@ public class MvcArticlePropertiesStep { articleMessageBundle.getMessage("article.edit.denied") ); } + } /** @@ -199,18 +259,7 @@ public class MvcArticlePropertiesStep { * @return The values of the localized title of the article. */ public Map getTitleValues() { - return stepService - .getDocument() - .getTitle() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); + return Collections.unmodifiableMap(titleValues); } /** @@ -219,16 +268,7 @@ public class MvcArticlePropertiesStep { * @return The locales for which no localized title has been defined yet. */ public List getUnusedTitleLocales() { - final Set titleLocales = stepService - .getDocument() - .getTitle() - .getAvailableLocales(); - return globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !titleLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); + return Collections.unmodifiableList(unusedTitleLocales); } /** @@ -367,16 +407,7 @@ public class MvcArticlePropertiesStep { * yet. */ public List getUnusedDescriptionLocales() { - final Set descriptionLocales = stepService - .getDocument() - .getDescription() - .getAvailableLocales(); - return globalizationHelper - .getAvailableLocales() - .stream() - .filter(locale -> !descriptionLocales.contains(locale)) - .map(Locale::toString) - .collect(Collectors.toList()); + return Collections.unmodifiableList(unusedDescriptionLocales); } /** @@ -385,18 +416,7 @@ public class MvcArticlePropertiesStep { * @return The values of the localized description of the article. */ public Map getDescriptionValues() { - return stepService - .getDocument() - .getDescription() - .getValues() - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue() - ) - ); + return Collections.unmodifiableMap(descriptionValues); } /** @@ -492,7 +512,7 @@ public class MvcArticlePropertiesStep { * * @param sectionIdentifier * @param documentPath - * @param localeParam The locale to remove. + * @param localeParam The locale to remove. * * @return A redirect to this authoring step. */ @@ -500,13 +520,13 @@ public class MvcArticlePropertiesStep { @Path("/title/@remove/{locale}") @Transactional(Transactional.TxType.REQUIRED) public String removeDescription( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) + @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) final String sectionIdentifier, @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) final String documentPath, @PathParam("locale") final String localeParam ) { - try { + try { stepService.setSectionAndDocument(sectionIdentifier, documentPath); } catch (ContentSectionNotFoundException ex) { return ex.showErrorMessage(); @@ -515,11 +535,11 @@ public class MvcArticlePropertiesStep { } if (itemPermissionChecker.canEditItem(stepService.getDocument())) { - final Locale locale = new Locale(localeParam); - stepService.getDocument().getDescription().removeValue(locale); - itemRepo.save(stepService.getDocument()); + final Locale locale = new Locale(localeParam); + stepService.getDocument().getDescription().removeValue(locale); + itemRepo.save(stepService.getDocument()); - return stepService.buildRedirectPathForStep(getClass()); + return stepService.buildRedirectPathForStep(getClass()); } else { return documentUi.showAccessDenied( stepService.getContentSection(), diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml index 598d96cda..76a79857c 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documents/authoringstep.xhtml @@ -1,12 +1,10 @@ ]> - +