From b584b895d689bdc61be675f685f2d3495390ca33 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 20 Mar 2021 17:37:51 +0100 Subject: [PATCH] EE MVC based AuthoringSteps --- .../java/org/librecms/ui/CmsMessages.java | 42 +++++ .../org/librecms/ui/CmsMessagesContext.java | 33 ++++ .../documents/AuthoringStepListEntry.java | 44 +++++ .../documents/ContentSectionNotFound.java | 7 + .../documents/ContentTypeNotAvailable.java | 7 + .../documents/CreateStepNotAvailable.java | 7 + .../documents/DocumentController.java | 5 +- .../documents/DocumentTypeClassNotFound.java | 7 + .../documents/FolderNotFound.java | 7 + .../documents/MvcAuthoringKit.java | 10 +- .../documents/MvcDocumentCreateStep.java | 24 ++- .../documents/SelectedDocumentModel.java | 78 +++++++- .../documents/TaskListEntry.java | 22 ++- .../ui/contenttypes/ArticleMessageBundle.java | 26 +++ .../ui/contenttypes/MvcArticleCreateStep.java | 176 +++++++++++++++++- .../MvcArticlePropertiesStep.java | 32 +++- .../documents/authoringstep.xhtml | 122 +++++++++++- .../article/article-basic-properties.xhtml | 64 +++++++ .../contenttypes/article/create-article.xhtml | 78 ++++++++ .../ui/contenttypes/ArticleBundle.properties | 0 .../contenttypes/ArticleBundle_de.properties | 0 21 files changed, 764 insertions(+), 27 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/CmsMessagesContext.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AuthoringStepListEntry.java create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contenttypes/ArticleMessageBundle.java create mode 100644 ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml create mode 100644 ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml rename ccm-cms/src/main/resources/{WEB-INF/views => }/org/librecms/ui/contenttypes/ArticleBundle.properties (100%) rename ccm-cms/src/main/resources/{WEB-INF/views => }/org/librecms/ui/contenttypes/ArticleBundle_de.properties (100%) diff --git a/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java b/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java new file mode 100644 index 000000000..3b42e857b --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/CmsMessages.java @@ -0,0 +1,42 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui; + +import java.util.Collections; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * Provides a facility for setting messages. + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsMessages") +public class CmsMessages { + + private SortedMap messages; + + public Map getMessages() { + return Collections.unmodifiableSortedMap(messages); + } + + public void addMessage( + final CmsMessagesContext context, final String message + ) { + messages.put(context.getValue(), message); + } + + public void setMessages(final SortedMap messages) { + this.messages = new TreeMap<>(messages); + } + + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/CmsMessagesContext.java b/ccm-cms/src/main/java/org/librecms/ui/CmsMessagesContext.java new file mode 100644 index 000000000..c7e4046f9 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/CmsMessagesContext.java @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui; + +/** + * + * @author Jens Pelzetter + */ +public enum CmsMessagesContext { + + PRIMARY("primary"), + SECONDARY("secondary"), + SUCCESS("success"), + DANGER("danger"), + WARNING("warning"), + INFO("info"), + LIGHT("light"), + DARK("dark"); + + private final String value; + + CmsMessagesContext(final String context) { + this.value = context; + } + + public String getValue() { + return value; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AuthoringStepListEntry.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AuthoringStepListEntry.java new file mode 100644 index 000000000..7ba0d0a2c --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/AuthoringStepListEntry.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contentsections.documents; + +/** + * + * @author Jens Pelzetter + */ +public class AuthoringStepListEntry { + + private String label; + + private String description; + + private String pathFragment; + + public String getLabel() { + return label; + } + + public void setLabel(final String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getPathFragment() { + return pathFragment; + } + + public void setPathFragment(final String pathFragment) { + this.pathFragment = pathFragment; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentSectionNotFound.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentSectionNotFound.java index 7a2d78606..f19a852a4 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentSectionNotFound.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentSectionNotFound.java @@ -9,6 +9,8 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; + import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -139,4 +141,9 @@ public class ContentSectionNotFound throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public Map getMessages() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentTypeNotAvailable.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentTypeNotAvailable.java index 63e108c96..66f3d5918 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentTypeNotAvailable.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/ContentTypeNotAvailable.java @@ -9,6 +9,8 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; + /** * A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by * the {@link DocumentController} to show an error message when the requested @@ -82,4 +84,9 @@ public class ContentTypeNotAvailable throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public Map getMessages() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CreateStepNotAvailable.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CreateStepNotAvailable.java index 0999f3cb9..52bfebff6 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CreateStepNotAvailable.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CreateStepNotAvailable.java @@ -9,6 +9,8 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; + /** * A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by * the {@link DocumentController} to show an error message when not create step @@ -82,4 +84,9 @@ public class CreateStepNotAvailable throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public Map getMessages() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java index 4f72b3c29..6f2ce44e9 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java @@ -49,7 +49,6 @@ import javax.ws.rs.PathParam; @RequestScoped @Path("/{sectionIdentifier}/documents") @Controller -@Named("CmsDocumentController") public class DocumentController { @Inject @@ -261,6 +260,8 @@ public class DocumentController { return new UnsupportedDocumentType(); } + models.put("authoringStep", authoringStepIdentifier); + selectedDocumentModel.setContentItem(item); authoringStep.setContentSection(section); @@ -351,6 +352,8 @@ public class DocumentController { .collect(Collectors.toList()) ); } + + models.put("authoringStep", "publish"); return "org/librecms/ui/contentsection/documents/publish.xhtml"; } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentTypeClassNotFound.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentTypeClassNotFound.java index 03d064ecc..56771a9a2 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentTypeClassNotFound.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentTypeClassNotFound.java @@ -9,6 +9,8 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; + /** * A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by * the {@link DocumentController} to show an error message when the requested @@ -82,4 +84,9 @@ class DocumentTypeClassNotFound throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public Map getMessages() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/FolderNotFound.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/FolderNotFound.java index d060d7740..72732370a 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/FolderNotFound.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/FolderNotFound.java @@ -9,6 +9,8 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; + /** * A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by * the {@link DocumentController} to show an error message when the requested @@ -82,4 +84,9 @@ public class FolderNotFound throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public Map getMessages() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringKit.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringKit.java index 23f9ad7f1..10db767bc 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringKit.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringKit.java @@ -10,7 +10,6 @@ import org.librecms.contentsection.ContentItem; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; - /** * Provides the steps for creating and viewing and editing a document (content * item). The classes provided for {@link #createStep()} and @@ -40,4 +39,13 @@ public @interface MvcAuthoringKit { */ Class[] authoringSteps(); + /** + * If set to {@code true} some authoring steps like categorization or + * related info are not shown. If set to {@code true} some of these steps + * can still be added by adding them to {@link #authoringSteps() }. + * + * @return {@code true} if the default steps should be excluded. + */ + boolean excludeDefaultAuthoringSteps() default false; + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java index d83670aca..cd0f7c402 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcDocumentCreateStep.java @@ -10,6 +10,7 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import java.util.Map; import java.util.ResourceBundle; import javax.inject.Named; @@ -60,12 +61,12 @@ public interface MvcDocumentCreateStep { /** * The current content section. - * + * * @return The current content section. */ ContentSection getContentSection(); - - /** + + /** * Convinient method for getting the label of the current content section. * * @return The label of the current content section. @@ -78,7 +79,7 @@ public interface MvcDocumentCreateStep { * @return The title of the current content section for the current locale. */ String getContentSectionTitle(); - + /** * The current content section is provided by the * {@link DocumentController}. @@ -89,18 +90,18 @@ public interface MvcDocumentCreateStep { /** * The parent folder of the new item. - * + * * @return The parent folder of the new item. */ Folder getFolder(); - + /** * Gets the path the the parent folder of the new item. - * + * * @return The path of the parent folder of the new item. */ String getFolderPath(); - + /** * The parent folder of the new item is provided by the * {@link DocumentController}. @@ -109,6 +110,13 @@ public interface MvcDocumentCreateStep { */ void setFolder(final Folder folder); + /** + * Gets messages from the create step. + * + * @return + */ + Map getMessages(); + /** * Endpoint displaying the create form. * diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/SelectedDocumentModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/SelectedDocumentModel.java index 4f30485fd..c1fa5c17e 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/SelectedDocumentModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/SelectedDocumentModel.java @@ -19,12 +19,14 @@ import org.librecms.contentsection.FolderManager; import org.librecms.contentsection.privileges.ItemPrivileges; import org.librecms.ui.contentsections.FolderBreadcrumbsModel; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Instance; import javax.inject.Inject; import javax.inject.Named; @@ -39,12 +41,15 @@ public class SelectedDocumentModel { @Inject private AssignableTaskManager taskManager; + @Inject + private Instance authoringSteps; + @Inject private ContentItemManager itemManager; @Inject private FolderManager folderManager; - + @Inject private GlobalizationHelper globalizationHelper; @@ -56,17 +61,29 @@ public class SelectedDocumentModel { private ContentItem item; + private String itemName; + private String itemTitle; private String itemPath; private List parentFolderBreadcrumbs; + private List authoringStepsList; + + private boolean excludeDefaultAuthoringSteps; + private Workflow workflow; + private String workflowName; + private TaskListEntry currentTask; private List allTasks; + + public String getItemName() { + return itemName; + } public String getItemTitle() { return itemTitle; @@ -80,6 +97,18 @@ public class SelectedDocumentModel { return Collections.unmodifiableList(parentFolderBreadcrumbs); } + public List getAuthoringStepsList() { + return Collections.unmodifiableList(authoringStepsList); + } + + public boolean getExcludeDefaultAuthoringSteps() { + return excludeDefaultAuthoringSteps; + } + + public String getWorkflowName() { + return workflowName; + } + public List getAllTasks() { return Collections.unmodifiableList(allTasks); } @@ -96,6 +125,7 @@ public class SelectedDocumentModel { void setContentItem(final ContentItem item) { this.item = Objects.requireNonNull(item); + itemName = item.getDisplayName(); itemTitle = globalizationHelper.getValueFromLocalizedString( item.getTitle() ); @@ -105,7 +135,15 @@ public class SelectedDocumentModel { .stream() .map(this::buildFolderBreadcrumbsModel) .collect(Collectors.toList()); + excludeDefaultAuthoringSteps = item + .getClass() + .getAnnotation(MvcAuthoringKit.class) + .excludeDefaultAuthoringSteps(); + authoringStepsList = buildAuthoringStepsList(item); workflow = item.getWorkflow(); + workflowName = globalizationHelper.getValueFromLocalizedString( + workflow.getName() + ); allTasks = workflow .getTasks() .stream() @@ -136,6 +174,7 @@ public class SelectedDocumentModel { private TaskListEntry buildTaskListEntry(final AssignableTask task) { final TaskListEntry entry = new TaskListEntry(); + entry.setTaskUuid(task.getUuid()); entry.setLabel( globalizationHelper.getValueFromLocalizedString( task.getLabel() @@ -153,8 +192,45 @@ public class SelectedDocumentModel { .map(user -> taskManager.isAssignedTo(task, user)) .orElse(false) ); + entry.setLocked(task.isLocked()); return entry; } + private List buildAuthoringStepsList( + final ContentItem item + ) { + final MvcAuthoringKit authoringKit = item + .getClass() + .getAnnotation(MvcAuthoringKit.class); + + final Class[] stepClasses = authoringKit + .authoringSteps(); + + return Arrays + .stream(stepClasses) + .map(authoringSteps::select) + .filter(instance -> instance.isResolvable()) + .map(Instance::get) + .map(this::buildAuthoringStepListEntry) + .collect(Collectors.toList()); + } + + private AuthoringStepListEntry buildAuthoringStepListEntry( + final MvcAuthoringStep step + ) { + final AuthoringStepListEntry entry = new AuthoringStepListEntry(); + entry.setDescription(step.getDescription()); + entry.setLabel(step.getLabel()); + entry.setPathFragment(readAuthoringStepPathFragment(step)); + return entry; + } + + private String readAuthoringStepPathFragment(final MvcAuthoringStep step) { + return step + .getClass() + .getAnnotation(AuthoringStepPathFragment.class) + .value(); + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/TaskListEntry.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/TaskListEntry.java index be6e8da85..5638fa36d 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/TaskListEntry.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/TaskListEntry.java @@ -13,8 +13,10 @@ import org.libreccm.workflow.TaskState; */ public class TaskListEntry { + private String taskUuid; + private String label; - + private String description; private TaskState taskState; @@ -23,6 +25,16 @@ public class TaskListEntry { private boolean assignedToCurrentUser; + private boolean locked; + + public String getTaskUuid() { + return taskUuid; + } + + public void setTaskUuid(final String taskUuid) { + this.taskUuid = taskUuid; + } + public String getLabel() { return label; } @@ -63,4 +75,12 @@ public class TaskListEntry { this.description = description; } + public boolean isLocked() { + return locked; + } + + public void setLocked(final boolean locked) { + this.locked = locked; + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/ArticleMessageBundle.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/ArticleMessageBundle.java new file mode 100644 index 000000000..40a0d1391 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/ArticleMessageBundle.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.librecms.ui.contenttypes; + +import org.libreccm.ui.AbstractMessagesBean; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Named("CmsArticleMessageBundle") +public class ArticleMessageBundle extends AbstractMessagesBean { + + @Override + protected String getMessageBundle() { + return ArticleStepsConstants.BUNDLE; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java index f06c25918..6b74b75fa 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleCreateStep.java @@ -19,8 +19,13 @@ import javax.inject.Named; import org.librecms.ui.contentsections.documents.MvcDocumentCreateStep; +import java.util.Collections; import java.util.Locale; +import java.util.Map; import java.util.Optional; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.mvc.Models; @@ -32,7 +37,7 @@ import javax.ws.rs.FormParam; * @author Jens Pelzetter */ @RequestScoped -@Named +@Named("CmsArticleCreateStep") public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ @Inject @@ -54,6 +59,8 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ private Folder folder; + private SortedMap messages; + @FormParam("name") private String name; @@ -69,6 +76,10 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ @FormParam("selectedWorkflow") private String selectedWorkflow; + public MvcArticleCreateStep() { + messages = new TreeMap<>(); + } + @Override public Class
getDocumentType() { return Article.class; @@ -90,28 +101,28 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ public ContentSection getContentSection() { return section; } - + @Override public String getContentSectionLabel() { return section.getLabel(); } - + @Override public String getContentSectionTitle() { return globalizationHelper .getValueFromLocalizedString(section.getTitle()); } - + @Override public void setContentSection(final ContentSection section) { this.section = section; } - + @Override public Folder getFolder() { return folder; } - + @Override public String getFolderPath() { return folderManager.getFolderPath(folder); @@ -122,13 +133,75 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ this.folder = folder; } + @Override + public Map getMessages() { + return Collections.unmodifiableSortedMap(messages); + } + + public void addMessage(final String context, final String message) { + messages.put(context, message); + } + + public void setMessages(final SortedMap messages) { + this.messages = new TreeMap<>(messages); + } + +// @GET +// @Path("/") @Override public String showCreateForm() { return "org/librecms/ui/contenttypes/article/create-article.xhtml"; } +// @POST +// @Path("/") @Override public String createContentItem() { + if (name == null || name.isEmpty()) { + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.name.error.missing") + ); + } + + if (!name.matches("^([a-zA-Z0-9_-]*)$")) { + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.name.error.invalid") + ); + } + + if (title == null || title.isEmpty()) { + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.title.error.missing") + ); + } + + if (summary == null || summary.isEmpty()) { + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.summary.error.missing") + ); + } + + if (initialLocale == null || initialLocale.isEmpty()) { + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.initial_locale.error.missing") + ); + } + final Optional workflowResult = section .getWorkflowTemplates() .stream() @@ -136,10 +209,30 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ .findAny(); if (!workflowResult.isPresent()) { - models.put("section", section.getLabel()); - models.put("selectedWorkflow", selectedWorkflow); + messages.put( + "danger", + globalizationHelper.getLocalizedTextsUtil( + getBundle() + ).getText("createstep.workflow.error.not_available") + ); + } - return "org/librecms/ui/contentsection/documents/workflow-not-available.xhtml"; + if (!messages.isEmpty()) { + final String folderPath = getFolderPath(); + if (folderPath.isEmpty() || "/".equals(folderPath)) { + return String.format( + "/@contentsections/%s/documents/@create/%s", + section.getLabel(), + getDocumentType().getName() + ); + } else { + return String.format( + "/@contentsections/%s/documents/%s/@create/%s", + section.getLabel(), + folderPath, + getDocumentType().getName() + ); + } } final Locale locale = new Locale(initialLocale); @@ -165,4 +258,69 @@ public class MvcArticleCreateStep implements MvcDocumentCreateStep
{ ); } + public String getName() { + return name; + } + + public String getTitle() { + return title; + } + + public String getSummary() { + return summary; + } + + public String getInitialLocale() { + return initialLocale; + } + + public String getSelectedWorkflow() { + if (selectedWorkflow == null || selectedWorkflow.isEmpty()) { + return section + .getContentTypes() + .stream() + .filter( + type -> type.getContentItemClass().equals( + Article.class.getName() + ) + ) + .findAny() + .map(type -> type.getDefaultWorkflow()) + .map( + workflow -> globalizationHelper.getValueFromLocalizedString( + workflow.getName() + ) + ) + .orElse(""); + } else { + return selectedWorkflow; + } + } + + public Map getAvailableLocales() { + return globalizationHelper + .getAvailableLocales() + .stream() + .collect(Collectors.toMap( + Locale::toString, + locale -> locale.getDisplayLanguage( + globalizationHelper.getNegotiatedLocale() + ) + )); + } + + public Map getAvailableWorkflows() { + return section + .getWorkflowTemplates() + .stream() + .collect( + Collectors.toMap( + workflow -> workflow.getUuid(), + workflow -> globalizationHelper.getValueFromLocalizedString( + workflow.getName() + ) + ) + ); + } + } 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 71cb64c1f..706b570b7 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 @@ -8,7 +8,6 @@ package org.librecms.ui.contenttypes; import org.libreccm.core.UnexpectedErrorException; import org.libreccm.l10n.GlobalizationHelper; import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemL10NManager; import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; @@ -23,10 +22,13 @@ import javax.ws.rs.Path; import org.librecms.ui.contentsections.documents.MvcAuthoringStep; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; +import javax.inject.Named; import javax.transaction.Transactional; import javax.ws.rs.FormParam; import javax.ws.rs.POST; @@ -40,6 +42,7 @@ import javax.ws.rs.PathParam; @Controller @Path("/") @AuthoringStepPathFragment(MvcArticlePropertiesStep.PATH_FRAGMENT) +@Named("CmsArticlePropertiesStep") public class MvcArticlePropertiesStep implements MvcAuthoringStep { static final String PATH_FRAGMENT = "basicproperties"; @@ -50,7 +53,6 @@ public class MvcArticlePropertiesStep implements MvcAuthoringStep { @Inject private ContentItemManager itemManager; - @Inject private FolderManager folderManager; @@ -141,7 +143,7 @@ public class MvcArticlePropertiesStep implements MvcAuthoringStep { } @POST - @Path("/name/{locale}") + @Path("/name") @Transactional(Transactional.TxType.REQUIRED) public String updateName(@FormParam("name") final String name) { document.setDisplayName(name); @@ -170,6 +172,18 @@ public class MvcArticlePropertiesStep implements MvcAuthoringStep { ) ); } + + public List getUnusedTitleLocales() { + final Set titleLocales = document + .getTitle() + .getAvailableLocales(); + return globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + } @POST @Path("/title/@add") @@ -227,6 +241,18 @@ public class MvcArticlePropertiesStep implements MvcAuthoringStep { ); } + public List getUnusedDescriptionLocales() { + final Set descriptionLocales = document + .getDescription() + .getAvailableLocales(); + return globalizationHelper + .getAvailableLocales() + .stream() + .filter(locale -> !descriptionLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()); + } + public Map getDescriptionValues() { return document .getDescription() 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 43a6042fc..9e43c8b7e 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 @@ -8,7 +8,7 @@
- + - +
+

#{CmsAdminMessages['contentsection.document.authoring.workflow.title']}

+

+ #{CmsAdminMessages['contentsection.document.authoring.workflow.active_workflow_label']}: + #{CmsSelectedDocumentModel.workflowName} + +

+

+ #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task']}: } + + + #{CmsSelectedDocumentModel.currentTask.label} + + + #{CmsAdminMessages['contentsection.document.authoring.workflow.active_task.none']}: } + + + + +

+ + +
+
+ + +
+ + +
+ + + + + + + + + + +

+

#{CmsAdminMessages['contentsection.document.authoring.steps.title']}

+ +
+ + + + +
diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml new file mode 100644 index 000000000..98cfd1d88 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml @@ -0,0 +1,64 @@ +]> + + + +

#{CmsArticleMessageBundle['basicproperties.name.header']}

+ +
+
+                #{CmsArticlePropertiesStep.name}
+            
+ + +
+ + + + + +
+ diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml new file mode 100644 index 000000000..aff9bdb22 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/create-article.xhtml @@ -0,0 +1,78 @@ +]> + + + + + + + + + +
+ + + + + + + + + + + + #{CmsArticleMessageBundle['createform.cancel']} + + + + + +
+ +
+ diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/ArticleBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties similarity index 100% rename from ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/ArticleBundle.properties rename to ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/ArticleBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties similarity index 100% rename from ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/ArticleBundle_de.properties rename to ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties