From a0e9183596f9c588ac4e9041807dd6145710dfc6 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 25 Nov 2020 21:32:19 +0100 Subject: [PATCH] Overview page for Application Admin --- .../applications/ApplicationController.java | 27 +++++ .../applications/ApplicationTypeInfoItem.java | 98 +++++++++++++++++++ .../applications/ApplicationsController.java | 68 ++++++++++++- .../admin/applications/ApplicationsPage.java | 2 +- .../DefaultApplicationController.java | 27 +++++ .../org/libreccm/web/ApplicationType.java | 7 ++ .../org/libreccm/ui/admin/applications.xhtml | 25 ----- .../admin/applications/applicationtypes.xhtml | 50 ++++++++++ .../ui/admin/categories/categorysystems.xhtml | 25 +---- .../org/libreccm/ui/AdminBundle.properties | 2 + .../org/libreccm/ui/AdminBundle_de.properties | 2 + 11 files changed, 285 insertions(+), 48 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationController.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationTypeInfoItem.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/applications/DefaultApplicationController.java delete mode 100644 ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications.xhtml create mode 100644 ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications/applicationtypes.xhtml diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationController.java new file mode 100644 index 000000000..f18aa74d6 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationController.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.applications; + +/** + * + * @author Jens Pelzetter + */ +public interface ApplicationController { + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationTypeInfoItem.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationTypeInfoItem.java new file mode 100644 index 000000000..6c58dca64 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationTypeInfoItem.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.applications; + +import java.util.Objects; + +/** + * + * @author Jens Pelzetter + */ +public class ApplicationTypeInfoItem implements + Comparable { + + private String name; + + private String title; + + private String description; + + private boolean singleton; + + private long numberOfInstances; + + protected ApplicationTypeInfoItem() { + // Nothing + } + + public String getName() { + return name; + } + + protected void setName(final String name) { + this.name = name; + } + + public String getTitle() { + return title; + } + + protected void setTitle(final String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + protected void setDescription(final String description) { + this.description = description; + } + + public boolean isSingleton() { + return singleton; + } + + protected void setSingleton(final boolean singleton) { + this.singleton = singleton; + } + + public long getNumberOfInstances() { + return numberOfInstances; + } + + protected void setNumberOfInstances(final long numberOfInstances) { + this.numberOfInstances = numberOfInstances; + } + + @Override + public int compareTo(final ApplicationTypeInfoItem other) { + if (other == null) { + return 1; + } + + int result = Objects.compare(title, other.getTitle(), String::compareTo); + if (result == 0) { + result = Objects.compare(name, other.getName(), String::compareTo); + } + + return result; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java index 0a9eff521..720442830 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsController.java @@ -19,13 +19,25 @@ package org.libreccm.ui.admin.applications; import org.libreccm.core.CoreConstants; +import org.libreccm.l10n.GlobalizationHelper; +import org.libreccm.l10n.LocalizedTextsUtil; import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.RequiresPrivilege; +import org.libreccm.web.ApplicationManager; +import org.libreccm.web.ApplicationRepository; +import org.libreccm.web.ApplicationType; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; import javax.mvc.Controller; +import javax.mvc.Models; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; /** * @@ -35,12 +47,64 @@ import javax.ws.rs.Path; @Controller @Path("/applications") public class ApplicationsController { + + @Inject + private ApplicationManager appManager; + @Inject + private ApplicationRepository appRepository; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private Models models; + @GET @Path("/") @AuthorizationRequired @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) - public String getApplications() { - return "org/libreccm/ui/admin/applications.xhtml"; + public String getApplicationTypes() { + final List appTypes = appManager + .getApplicationTypes() + .entrySet() + .stream() + .map(Map.Entry::getValue) + .map(this::buildTypeInfoItem) + .sorted() + .collect(Collectors.toList()); + + models.put("applicationTypes", appTypes); + + return "org/libreccm/ui/admin/applications/applicationtypes.xhtml"; } + + @GET + @Path("/{type}") + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + public String getApplicationInstances( + @PathParam("type") final String type + ) { + throw new UnsupportedOperationException(); + } + + private ApplicationTypeInfoItem buildTypeInfoItem( + final ApplicationType applicationType + ) { + final ApplicationTypeInfoItem item = new ApplicationTypeInfoItem(); + item.setName(applicationType.name()); + + final LocalizedTextsUtil textsUtil = globalizationHelper + .getLocalizedTextsUtil(applicationType.descBundle()); + item.setTitle(textsUtil.getText(applicationType.titleKey())); + item.setDescription(textsUtil.getText(applicationType.descKey())); + item.setSingleton(applicationType.singleton()); + item.setNumberOfInstances( + appRepository.findByType(applicationType.name()).size() + ); + + return item; + } + } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java index 185670232..48a7677c3 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/ApplicationsPage.java @@ -43,7 +43,7 @@ public class ApplicationsPage implements AdminPage { @Override public String getUriIdentifier() { return String.format( - "%s#getApplications", ApplicationsController.class.getSimpleName() + "%s#getApplicationTypes", ApplicationsController.class.getSimpleName() ); } diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/applications/DefaultApplicationController.java b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/DefaultApplicationController.java new file mode 100644 index 000000000..7f76e96a7 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/applications/DefaultApplicationController.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.admin.applications; + +/** + * + * @author Jens Pelzetter + */ +public class DefaultApplicationController implements ApplicationController { + +} diff --git a/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java b/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java index 5c5019960..285b56225 100644 --- a/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java +++ b/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java @@ -23,8 +23,12 @@ import com.arsdigita.ui.admin.applications.AbstractAppSettingsPane; import com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm; import com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane; +import org.libreccm.ui.admin.applications.ApplicationController; +import org.libreccm.ui.admin.applications.DefaultApplicationController; + import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -111,9 +115,12 @@ public @interface ApplicationType { * * @return */ + @SuppressWarnings("rawtypes") // Can't specify type here, otherwise problems in using classes. Class creator(); Class instanceForm() default DefaultApplicationInstanceForm.class; + + Class adminController() default DefaultApplicationController.class; Class settingsPane() default DefaultApplicationSettingsPane.class; diff --git a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications.xhtml b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications.xhtml deleted file mode 100644 index 25c5db283..000000000 --- a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications.xhtml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - -
-

#{AdminMessages['applications.label']}

-

Placeholder

-
-
- -
- diff --git a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications/applicationtypes.xhtml b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications/applicationtypes.xhtml new file mode 100644 index 000000000..15c80fe63 --- /dev/null +++ b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/applications/applicationtypes.xhtml @@ -0,0 +1,50 @@ + + + + + + + + + + + + +
+

#{AdminMessages['applications.label']}

+ +
    + +
  • +
    +

    + ${type.title} +

    + + + + #{AdminMessages['applications.types.singleton']} + + + #{AdminMessages.getMessage('applications.number_of_instances', [type.numberOfInstances])} + + + +
    +

    + ${type.description} +

    +
  • +
    +
+ +
+
+ +
+ diff --git a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/categories/categorysystems.xhtml b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/categories/categorysystems.xhtml index 8b3514435..779cbfa94 100644 --- a/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/categories/categorysystems.xhtml +++ b/ccm-core/src/main/resources/WEB-INF/views/org/libreccm/ui/admin/categories/categorysystems.xhtml @@ -1,9 +1,9 @@ ]> + xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> @@ -28,12 +28,7 @@ @@ -60,12 +55,7 @@ - - - + #{AdminMessages['categorysystems.table.actions.edit']} @@ -74,12 +64,7 @@ data-target="#confirm-delete-#{categorySystem.identifier}" data-toggle="modal" type="button"> - - - + #{AdminMessages['categorysystems.table.actions.delete']}