From 4b6346e79a8832bb9dac6887c8e2b4b9f81325a3 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Thu, 19 Nov 2020 20:39:13 +0100 Subject: [PATCH] Views for managing categories --- .../categories/CategoryDetailsModel.java | 79 +++--- .../categories/CategoryFormController.java | 26 +- .../admin/categories/CategoryNodeModel.java | 53 +++- .../components/bootstrap/modalForm.xhtml | 11 +- .../libreccm/localizedStringEditor.xhtml | 15 +- .../categories/application-not-found.xhtml | 6 +- .../admin/categories/category-details.xhtml | 246 +++++++++++++++++- .../ui/admin/categories/category-form.xhtml | 194 +++++--------- .../admin/categories/category-not-found.xhtml | 20 +- .../categories/categorysystem-details.xhtml | 27 +- .../categories/categorysystem-form.xhtml | 7 +- .../categories/categorysystem-not-found.xhtml | 4 +- .../ui/admin/categories/categorysystems.xhtml | 6 +- .../org/libreccm/ui/AdminBundle.properties | 41 ++- .../org/libreccm/ui/AdminBundle_de.properties | 41 ++- 15 files changed, 534 insertions(+), 242 deletions(-) diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryDetailsModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryDetailsModel.java index e95901793..0aba4b14a 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryDetailsModel.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryDetailsModel.java @@ -19,6 +19,7 @@ package org.libreccm.ui.admin.categories; import org.libreccm.categorization.Category; +import org.libreccm.categorization.CategoryManager; import org.libreccm.ui.Message; import java.util.ArrayList; @@ -28,10 +29,10 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.TreeMap; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; import javax.inject.Named; import javax.transaction.Transactional; @@ -43,6 +44,9 @@ import javax.transaction.Transactional; @Named("CategoryDetailsModel") public class CategoryDetailsModel { + @Inject + private CategoryManager categoryManager; + private long categoryId; private String uuid; @@ -51,6 +55,8 @@ public class CategoryDetailsModel { private String name; + private String path; + private Map title; private Map description; @@ -69,6 +75,8 @@ public class CategoryDetailsModel { private final List messages; + private Set invalidFields; + public CategoryDetailsModel() { this.messages = new ArrayList<>(); } @@ -77,6 +85,10 @@ public class CategoryDetailsModel { return categoryId; } + public String getIdentifier() { + return String.format("ID-%d", categoryId); + } + public String getUuid() { return uuid; } @@ -89,6 +101,10 @@ public class CategoryDetailsModel { return name; } + public String getPath() { + return path; + } + public Map getTitle() { return Collections.unmodifiableMap(title); } @@ -117,37 +133,18 @@ public class CategoryDetailsModel { return parentCategory; } + protected void setParentCategory(final Category parent) { + parentCategory = buildCategoryNodeModel(parent); + } + public long getCategoryOrder() { return categoryOrder; } - /** - * Only for testing components - * @return - */ - public Map getOptions() { - final Map options = new TreeMap<>(); - options.put("alpha", "Option Alpha"); - options.put("bravo", "Option Bravo"); - options.put("charlie", "Option Charlie"); - options.put("delta", "Option Delta"); - options.put("echo", "Option Echo"); - return options; + public boolean isNew() { + return categoryId == 0; } - - public Set getSelectedOptions() { - final Set selectedOptions = new HashSet<>(); - selectedOptions.add("delta"); - return selectedOptions; - } - - public Set getMultipleSelectedOptions() { - final Set selectedOptions = new HashSet<>(); - selectedOptions.add("delta"); - selectedOptions.add("bravo"); - return selectedOptions; - } - + public List getMessages() { return Collections.unmodifiableList(messages); } @@ -156,6 +153,18 @@ public class CategoryDetailsModel { messages.add(message); } + public Set getInvalidFields() { + return Collections.unmodifiableSet(invalidFields); + } + + protected void addInvalidField(final String invalidField) { + invalidFields.add(invalidField); + } + + protected void setInvalidFields(final Set invalidFields) { + this.invalidFields = new HashSet<>(invalidFields); + } + @Transactional(Transactional.TxType.REQUIRED) protected void setCategory(final Category category) { Objects.requireNonNull(category); @@ -164,6 +173,7 @@ public class CategoryDetailsModel { uuid = category.getUuid(); uniqueId = category.getUniqueId(); name = category.getName(); + path = categoryManager.getCategoryPath(category); title = category .getTitle() .getValues() @@ -192,11 +202,22 @@ public class CategoryDetailsModel { subCategories = category .getSubCategories() .stream() - .map(CategoryNodeModel::new) + .map(this::buildCategoryNodeModel) .sorted() .collect(Collectors.toList()); - parentCategory = new CategoryNodeModel(category.getParentCategory()); + parentCategory = buildCategoryNodeModel(category.getParentCategory()); categoryOrder = category.getCategoryOrder(); } + private CategoryNodeModel buildCategoryNodeModel(final Category category) { + final CategoryNodeModel model = new CategoryNodeModel(); + model.setCategoryId(category.getObjectId()); + model.setUuid(category.getUuid()); + model.setUniqueId(category.getUniqueId()); + model.setName(category.getName()); + model.setPath(categoryManager.getCategoryPath(category)); + model.setCategoryOrder(category.getCategoryOrder()); + return model; + } + } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java index e08d94e18..3ecaa31b8 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryFormController.java @@ -76,23 +76,19 @@ public class CategoryFormController { private boolean enabled; @FormParam("visible") - private boolean visisble; + private boolean visible; @FormParam("abstractCategory") private boolean abstractCategory; - @FormParam("categoryOrder") - private long categoryOrder; - - @FormParam("parentCategoryIdentifier") - private String parentCategoryIdentifier; - @POST - @Path("/new") + @Path("/{parentCategoryIdentifier}/new") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @Transactional(Transactional.TxType.REQUIRED) - public String createCategory() { + public String createCategory( + @PathParam("parentCategoryIdentifier") final String parentCategoryIdentifier + ) { final Identifier parentIdentifier = identifierParser.parseIdentifier( parentCategoryIdentifier ); @@ -118,9 +114,8 @@ public class CategoryFormController { category.setUniqueId(uniqueId); category.setName(name); category.setEnabled(enabled); - category.setVisible(visisble); + category.setVisible(visible); category.setAbstractCategory(abstractCategory); - category.setCategoryOrder(categoryOrder); categoryRepository.save(category); categoryManager.addSubCategoryToCategory(category, parentCategory); @@ -152,7 +147,7 @@ public class CategoryFormController { final String categoryIdentifierParam ) { final Identifier identifier = identifierParser.parseIdentifier( - parentCategoryIdentifier + categoryIdentifierParam ); final Optional result; switch (identifier.getType()) { @@ -175,12 +170,11 @@ public class CategoryFormController { category.setUniqueId(uniqueId); category.setName(name); category.setEnabled(enabled); - category.setVisible(visisble); + category.setVisible(visible); category.setAbstractCategory(abstractCategory); - category.setCategoryOrder(categoryOrder); - + categoryRepository.save(category); - + return String.format( "redirect:categorymanager/categories/ID-%s", category.getObjectId() diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryNodeModel.java b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryNodeModel.java index d5776222e..f435f7a37 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryNodeModel.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/categories/CategoryNodeModel.java @@ -28,45 +28,70 @@ import java.util.Objects; */ public class CategoryNodeModel implements Comparable { - private final long categoryId; + private long categoryId; - private final String uuid; + private String uuid; - private final String uniqueId; + private String uniqueId; - private final String name; + private String name; + + private String path; - private final long categoryOrder; - - public CategoryNodeModel(final Category category) { - Objects.requireNonNull(category); - categoryId = category.getObjectId(); - uuid = category.getUuid(); - uniqueId = category.getUniqueId(); - categoryOrder = category.getCategoryOrder(); - name = category.getName(); - } + private long categoryOrder; public long getCategoryId() { return categoryId; } + protected void setCategoryId(final long categoryId) { + this.categoryId = categoryId; + } + + public String getIdentifier() { + return String.format("ID-%d", categoryId); + } + public String getUuid() { return uuid; } + + protected void setUuid(final String uuid) { + this.uuid = uuid; + } public String getUniqueId() { return uniqueId; } + + protected void setUniqueId(final String uniqueId) { + this.uniqueId = uniqueId; + } public String getName() { return name; } + + protected void setName(final String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + protected void setPath(final String path) { + this.path = path; + } public long getCategoryOrder() { return categoryOrder; } + protected void setCategoryOrder(final long categoryOrder) { + this.categoryOrder = categoryOrder; + } + @Override public int compareTo(final CategoryNodeModel other) { int result = Long.compare( diff --git a/ccm-core/src/main/resources/META-INF/resources/components/bootstrap/modalForm.xhtml b/ccm-core/src/main/resources/META-INF/resources/components/bootstrap/modalForm.xhtml index f4d918067..e62917ab6 100644 --- a/ccm-core/src/main/resources/META-INF/resources/components/bootstrap/modalForm.xhtml +++ b/ccm-core/src/main/resources/META-INF/resources/components/bootstrap/modalForm.xhtml @@ -19,7 +19,7 @@ type="String" />
-
-