From fa7a74080d542c0c9a6f195211464bf46f8998f3 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 25 Aug 2020 20:34:58 +0200 Subject: [PATCH] Serving HTML and resources for Admin UI --- ccm-bundle-devel-wildfly/pom.xml | 1 + ccm-core/pom.xml | 3 +- .../ccm-admin-systeminformation/package.json | 5 +- .../java/org/libreccm/ui/admin/AdminUi.java | 17 +++- .../org/libreccm/ui/admin/AdminUiApp.java | 11 ++- .../org/libreccm/ui/admin/DashboardApp.java | 89 ++++++++++++++++++ .../ui/admin/SystemInformationApp.java | 92 +++++++++++++++++++ .../org/libreccm/ui/admin.properties | 19 ++++ .../org/libreccm/ui/admin_de.properties | 19 ++++ .../templates/admin-ui/admin-ui.html.ftl | 4 +- 10 files changed, 251 insertions(+), 9 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/DashboardApp.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/admin/SystemInformationApp.java create mode 100644 ccm-core/src/main/resources/org/libreccm/ui/admin.properties create mode 100644 ccm-core/src/main/resources/org/libreccm/ui/admin_de.properties diff --git a/ccm-bundle-devel-wildfly/pom.xml b/ccm-bundle-devel-wildfly/pom.xml index 94c353d00..b4d2ff85c 100644 --- a/ccm-bundle-devel-wildfly/pom.xml +++ b/ccm-bundle-devel-wildfly/pom.xml @@ -200,6 +200,7 @@ jar assets/ + _admin/ diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index 48b4ecf30..88e026b52 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -308,7 +308,8 @@ true - target/generated-resources/@admin + target/generated-resources/_admin + _admin diff --git a/ccm-core/src/ccm-admin-systeminformation/package.json b/ccm-core/src/ccm-admin-systeminformation/package.json index 0868154d0..a8a48351a 100644 --- a/ccm-core/src/ccm-admin-systeminformation/package.json +++ b/ccm-core/src/ccm-admin-systeminformation/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "serve": "vue-cli-service serve", - "build": "vue-cli-service build --dest ../../target/generated-resources/@admin/systeminformation", + "build": "vue-cli-service build --dest ../../target/generated-resources/_admin/systeminformation", "lint": "vue-cli-service lint" }, "dependencies": { @@ -35,6 +35,9 @@ "typescript": "~3.9.3", "vue-template-compiler": "^2.6.11" }, + "vue": { + "filenameHashing": false + }, "eslintConfig": { "root": true, "env": { diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUi.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUi.java index 2bc71911c..a85c9d740 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUi.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUi.java @@ -35,6 +35,7 @@ import java.io.StringWriter; import java.util.HashMap; import java.util.Map; +import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.servlet.ServletContext; @@ -61,9 +62,10 @@ public class AdminUi { @Inject private ServletContext servletContext; - private final Configuration configuration; + private Configuration configuration; - public AdminUi() { + @PostConstruct + private void init() { configuration = new Configuration(Configuration.VERSION_2_3_30); configuration.setDefaultEncoding("UTF-8"); configuration @@ -84,6 +86,15 @@ public class AdminUi { ); } + @GET + @Path("/") + @Produces(MediaType.TEXT_HTML) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + public String getDashboard() { + return getApp("dashboard"); + } + @GET @Path("/{appName}") @Produces(MediaType.TEXT_HTML) @@ -113,7 +124,7 @@ public class AdminUi { final Map data = new HashMap<>(); data.put("adminUiApps", adminUiApps.getAdminUiApps()); - data.put("activeApp", appName); + data.put("activeApp", app); final StringWriter writer = new StringWriter(); try { diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUiApp.java b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUiApp.java index 24b0105c6..da92874c3 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUiApp.java +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/AdminUiApp.java @@ -55,13 +55,20 @@ public interface AdminUiApp { int getOrder(); /** - * Path portion of the URL of the JavaScript file providing the Admin UI + * Path portion of the URL of the JavaScript file(s) providing the Admin UI * App. * * @return */ - String getJsFileUrl(); + String[] getJsFilesUrls(); + /** + * Path portion of the URL of the CSS file(s) of the application. + * + * @return + */ + String[] getCssFilesUrls(); + /** * Name of the icon from the Bootstrap Icons set * diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardApp.java b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardApp.java new file mode 100644 index 000000000..ba74aef1e --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/DashboardApp.java @@ -0,0 +1,89 @@ +/* + * 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; + +import org.libreccm.l10n.GlobalizationHelper; + +import java.util.Optional; +import java.util.ResourceBundle; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class DashboardApp implements AdminUiApp { + + private ResourceBundle adminBundle; + + @Inject + private GlobalizationHelper globalizationHelper; + + @PostConstruct + private void init() { + adminBundle = ResourceBundle.getBundle( + "org.libreccm.ui.admin", globalizationHelper.getNegotiatedLocale() + ); + } + + @Override + public String getName() { + return "dashboard"; + } + + @Override + public String getLabel() { + return adminBundle.getString("dashboard.label"); + } + + @Override + public String getDescription() { + return adminBundle.getString("dashboard.description"); + } + + @Override + public int getOrder() { + return 1; + } + + @Override + public String[] getJsFilesUrls() { + return new String[]{}; + } + + @Override + public String[] getCssFilesUrls() { + return new String[]{}; + } + + @Override + public Optional getIconName() { + return Optional.of("house-fill"); + } + + @Override + public Optional getSymbolUrl() { + return Optional.empty(); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/admin/SystemInformationApp.java b/ccm-core/src/main/java/org/libreccm/ui/admin/SystemInformationApp.java new file mode 100644 index 000000000..2d0457e94 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/admin/SystemInformationApp.java @@ -0,0 +1,92 @@ +/* + * 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; + +import org.libreccm.l10n.GlobalizationHelper; + +import java.util.Optional; +import java.util.ResourceBundle; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class SystemInformationApp implements AdminUiApp { + + private ResourceBundle adminBundle; + + @Inject + private GlobalizationHelper globalizationHelper; + + @PostConstruct + private void init() { + adminBundle = ResourceBundle.getBundle( + "org.libreccm.ui.admin", globalizationHelper.getNegotiatedLocale() + ); + } + + @Override + public String getName() { + return "systeminformation"; + } + + @Override + public String getLabel() { + return adminBundle.getString("systeminformation.label"); + } + + @Override + public String getDescription() { + return adminBundle.getString("systeminformation.description"); + } + + @Override + public int getOrder() { + return 20; + } + + @Override + public String[] getJsFilesUrls() { + return new String[]{ + "/@admin/systeminformation/js/app.js", + "/@admin/systeminformation/js/chunk-vendors.js",}; + } + + @Override + public String[] getCssFilesUrls() { + return new String[]{ + "/@admin/systeminformation/css/app.css",}; + } + + @Override + public Optional getIconName() { + return Optional.of("info-circle"); + } + + @Override + public Optional getSymbolUrl() { + return Optional.empty(); + } + +} diff --git a/ccm-core/src/main/resources/org/libreccm/ui/admin.properties b/ccm-core/src/main/resources/org/libreccm/ui/admin.properties new file mode 100644 index 000000000..9778dafd5 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/ui/admin.properties @@ -0,0 +1,19 @@ +# 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 + +systeminformation.label=System Information +systeminformation.description=Shows several system properties \ No newline at end of file diff --git a/ccm-core/src/main/resources/org/libreccm/ui/admin_de.properties b/ccm-core/src/main/resources/org/libreccm/ui/admin_de.properties new file mode 100644 index 000000000..7172f9cdc --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/ui/admin_de.properties @@ -0,0 +1,19 @@ +# 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 + +systeminformation.label=System Informationen +systeminformation.description=Zeigt verschiedene Eigenschaften des Systems \ No newline at end of file diff --git a/ccm-core/src/main/resources/templates/admin-ui/admin-ui.html.ftl b/ccm-core/src/main/resources/templates/admin-ui/admin-ui.html.ftl index 4b36811d8..2466e9e08 100644 --- a/ccm-core/src/main/resources/templates/admin-ui/admin-ui.html.ftl +++ b/ccm-core/src/main/resources/templates/admin-ui/admin-ui.html.ftl @@ -6,8 +6,8 @@

Admin UI

    - <#list adminUis as adminUi> -
  • {{adminUi.name}}
  • + <#list adminUiApps as app> +
  • ${app.name}