From 722f5c210fc5109773b7d038840b4a39ee2bef89 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Mon, 15 Feb 2021 21:08:56 +0100 Subject: [PATCH] Progress on the category management for cms admin Former-commit-id: ec215c08aad419ee672cf71cb50a20be0dcff69c --- .../contentsections/CategoriesController.java | 60 +++++++- .../ui/contentsections/CategoryModel.java | 99 ++++++++++-- .../categorysystems/categorysystem.xhtml | 144 +++++++++++++++++- .../org/librecms/CmsAdminMessages.properties | 12 ++ .../librecms/CmsAdminMessages_de.properties | 12 ++ 5 files changed, 305 insertions(+), 22 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java index 6a094f920..3940368bc 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoriesController.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; @@ -173,7 +174,7 @@ public class CategoriesController { if (categoryPath.isEmpty()) { activePath = "/"; } else { - activePath = categoryPath; + activePath = String.format("/%s", categoryPath); } categorySystemModel.setCategoryTree( buildCategoryTree(domain, activePath) @@ -295,7 +296,7 @@ public class CategoriesController { } @POST - @Path("/{context}/categories/{categoryPath:(.+)?}/@title/edit/{locale}") + @Path("/{context}/categories/{categoryPath:(.+)?}/@title/locale") @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public String editTitle( @@ -441,7 +442,7 @@ public class CategoriesController { } @POST - @Path("/{context}/categories/{categoryPath:(.+)?}/@attributes") + @Path("/{context}/categories/{categoryPath:(.+)?}/@properties") @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public String updateCategory( @@ -923,7 +924,7 @@ public class CategoriesController { ); } final String path = categoryManager.getCategoryPath(category); - model.setActive(activePath.equals(path)); + model.setActive(activePath.startsWith(path)); model.setPath(path); if (!category.getSubCategories().isEmpty()) { model.setSubCategories( @@ -976,6 +977,57 @@ public class CategoriesController { model.setUniqueId(category.getUniqueId()); model.setUuid(category.getUuid()); model.setVisible(category.isVisible()); + + final List availableLocales = globalizationHelper + .getAvailableLocales(); + model.setLocalizedTitles( + category + .getTitle() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ) + ); + final Set titleLocales = category + .getTitle() + .getAvailableLocales(); + model.setUnusedTitleLocales( + availableLocales + .stream() + .filter(locale -> !titleLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); + + model.setLocalizedDescriptions( + category + .getDescription() + .getValues() + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ) + ) + ); + final Set descriptionLocales = category + .getDescription() + .getAvailableLocales(); + model.setUnusedDescriptionLocales( + availableLocales + .stream() + .filter(locale -> !descriptionLocales.contains(locale)) + .map(Locale::toString) + .collect(Collectors.toList()) + ); + return model; } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java index 23b7336f6..76c829315 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/CategoryModel.java @@ -7,43 +7,61 @@ package org.librecms.ui.contentsections; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * * @author Jens Pelzetter */ public class CategoryModel { - + private long categoryId; - + private String uuid; - + private String uniqueId; - + private String name; - + private String path; - + private String title; + private Map localizedTitles; + private String description; + private Map localizedDescriptions; + private boolean enabled; - + private boolean visible; - + private boolean abstractCategory; - + private List subCategories; - + private List objects; - + private long categoryOrder; + + private boolean hasUnusedTitleLocales; + private boolean hasUnusedDescriptionLocales; + + private List unusedTitleLocales; + + private List unusedDescriptionLocales; + + + public CategoryModel() { subCategories = new ArrayList<>(); objects = new ArrayList<>(); + localizedTitles = new HashMap<>(); + localizedDescriptions = new HashMap<>(); } public long getCategoryId() { @@ -53,11 +71,11 @@ public class CategoryModel { public void setCategoryId(final long categoryId) { this.categoryId = categoryId; } - + public String getUuid() { return uuid; } - + public void setUuid(final String uuid) { this.uuid = uuid; } @@ -149,7 +167,56 @@ public class CategoryModel { public void setCategoryOrder(final long categoryOrder) { this.categoryOrder = categoryOrder; } - - - + + public boolean isHasUnusedTitleLocales() { + return hasUnusedTitleLocales; + } + + public void setHasUnusedTitleLocales(final boolean hasUnusedTitleLocales) { + this.hasUnusedTitleLocales = hasUnusedTitleLocales; + } + + public Map getLocalizedTitles() { + return localizedTitles; + } + + public void setLocalizedTitles(Map localizedTitles) { + this.localizedTitles = localizedTitles; + } + + public Map getLocalizedDescriptions() { + return localizedDescriptions; + } + + public void setLocalizedDescriptions( + Map localizedDescriptions) { + this.localizedDescriptions = localizedDescriptions; + } + + public boolean isHasUnusedDescriptionLocales() { + return hasUnusedDescriptionLocales; + } + + public void setHasUnusedDescriptionLocales( + boolean hasUnusedDescriptionLocales) { + this.hasUnusedDescriptionLocales = hasUnusedDescriptionLocales; + } + + public List getUnusedTitleLocales() { + return unusedTitleLocales; + } + + public void setUnusedTitleLocales(List unusedTitleLocales) { + this.unusedTitleLocales = unusedTitleLocales; + } + + public List getUnusedDescriptionLocales() { + return unusedDescriptionLocales; + } + + public void setUnusedDescriptionLocales( + List unusedDescriptionLocales) { + this.unusedDescriptionLocales = unusedDescriptionLocales; + } + } diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/categorysystems/categorysystem.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/categorysystems/categorysystem.xhtml index 502fcf983..21281febd 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/categorysystems/categorysystem.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/categorysystems/categorysystem.xhtml @@ -58,7 +58,7 @@
#{CmsAdminMessages['contentsection.categorysystems.category.properties.id']}
-
#{CategorySystemModel.selectedCategory.id}
+
#{CategorySystemModel.selectedCategory.categoryId}
#{CmsAdminMessages['contentsection.categorysystems.category.properties.uuid']}
@@ -112,7 +112,147 @@
- + +
+ + +
+ +

#{CmsAdminMessages.getMessage("contentsection.categorysystems.category.titles.heading", [CategorySystemModel.selectedCategory.name])}

+ + +

#{CmsAdminMessages.getMessage("contentsection.categorysystems.category.descriptions.heading", [CategorySystemModel.selectedCategory.name])}

+ + + diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties index ddd79bf72..984d81583 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties @@ -165,3 +165,15 @@ contentsection.categorysystems.category.properties.visible.no=No contentsection.categorysystems.category.properties.abstract_category=Abstract category? contentsection.categorysystems.category.properties.abstract_category.yes=Yes contentsection.categorysystems.category.properties.abstract_category.no=No +contentsecton.categorysystems.category.properties.edit=Edit +contentsecton.categorysystems.category.properties.edit.dialog.title=Edit properties of category {0} +contentsecton.categorysystems.category.properties.edit.dialog.cancel=Cancel +contentsecton.categorysystems.category.properties.edit.dialog.save=Save +contentsecton.categorysystems.category.properties.edit.dialog.name.help=Name of the category. May only contain the letters, numbers and hypens. +contentsecton.categorysystems.category.properties.edit.dialog.name.label=Name +contentsecton.categorysystems.category.properties.edit.dialog.unique_id.help=Unique ID of the new category. Should be unique for the complete category system +contentsecton.categorysystems.category.properties.edit.dialog.unique_id.label=Unique ID +contentsecton.categorysystems.category.properties.edit.dialog.enabled.label=Enabled +contentsecton.categorysystems.category.properties.edit.dialog.visible.label=Visible? +contentsecton.categorysystems.category.properties.edit.dialog.abstract_category.label=Abstract? +contentsection.categorysystems.category.titles.heading=Localized Titles diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties index ab4c27176..8202791b0 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties @@ -165,3 +165,15 @@ contentsection.categorysystems.category.properties.visible.no=Nein contentsection.categorysystems.category.properties.abstract_category=Abstrakte Kategorie? contentsection.categorysystems.category.properties.abstract_category.yes=Ja contentsection.categorysystems.category.properties.abstract_category.no=Nein +contentsecton.categorysystems.category.properties.edit=Bearbeiten +contentsecton.categorysystems.category.properties.edit.dialog.title=Eigenschaften der Kategorie {0} bearbeiten +contentsecton.categorysystems.category.properties.edit.dialog.cancel=Abbrechen +contentsecton.categorysystems.category.properties.edit.dialog.save=Speichern +contentsecton.categorysystems.category.properties.edit.dialog.name.help=Name der Kategorie. Darf nur Buchstaben, Zahlen und den Bindestrich enthalten. +contentsecton.categorysystems.category.properties.edit.dialog.name.label=Name +contentsecton.categorysystems.category.properties.edit.dialog.unique_id.help=Eindeutige ID der Kategorie. Sollte innerhalb des gesamten Kategoriensystems eindeutig sein. +contentsecton.categorysystems.category.properties.edit.dialog.unique_id.label=Eindeutige ID +contentsecton.categorysystems.category.properties.edit.dialog.enabled.label=Aktiv? +contentsecton.categorysystems.category.properties.edit.dialog.visible.label=Sichtbar? +contentsecton.categorysystems.category.properties.edit.dialog.abstract_category.label=Abstrakt? +contentsection.categorysystems.category.titles.heading=Lokalisierte Titel