Просмотр исходного кода

[WIP] #2206 add AdminPluginAction page

igarashi 6 лет назад
Родитель
Сommit
96a5b16954

+ 94 - 0
src/main/java/org/codelibs/fess/app/web/admin/plugin/AdminPluginAction.java

@@ -0,0 +1,94 @@
+/*
+ * Copyright 2012-2019 CodeLibs Project and the Others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.codelibs.fess.app.web.admin.plugin;
+
+import org.codelibs.fess.helper.PluginHelper;
+import org.codelibs.fess.helper.PluginHelper.Artifact;
+import org.codelibs.fess.app.web.base.FessAdminAction;
+import org.codelibs.fess.util.RenderDataUtil;
+import org.lastaflute.web.Execute;
+import org.lastaflute.web.response.HtmlResponse;
+import org.lastaflute.web.ruts.process.ActionRuntime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class AdminPluginAction extends FessAdminAction {
+
+    private static final Logger logger = LoggerFactory.getLogger(AdminPluginAction.class);
+
+    @Resource
+    private PluginHelper pluginHelper;
+
+    @Override
+    protected void setupHtmlData(final ActionRuntime runtime) {
+        super.setupHtmlData(runtime);
+//        runtime.registerData("helpLink", systemHelper.getHelpLink(fessConfig.getOnlineHelpNamePlugin()));
+
+    }
+
+    @Execute
+    public HtmlResponse index() {
+        saveToken();
+        return asListHtml();
+    }
+
+    @Execute
+    public HtmlResponse delete(final PluginBean pluginBean) {
+        // TODO
+        try {
+            pluginHelper.deleteInstalledArtifact(new Artifact(pluginBean.name, pluginBean.version, null));
+        } catch (Exception e) {
+
+        }
+        return redirect(getClass());
+    }
+
+    @Execute
+    public HtmlResponse install(final InstallForm form) {
+        // TODO
+        return redirect(getClass());
+    }
+
+    private HtmlResponse asListHtml() {
+        return asHtml(path_AdminPlugin_AdminPluginJsp).renderWith(
+                data ->
+                        RenderDataUtil.register(data, "installedArtifactItems", getAllInstalledArtifacts()));
+    }
+
+    private List<PluginBean> getAllInstalledArtifacts() {
+        final List<PluginBean> result = new ArrayList<>();
+        for(PluginHelper.ArtifactType artifactType : PluginHelper.ArtifactType.values()) {
+            result.addAll(
+                    Arrays.stream(pluginHelper.getInstalledArtifacts(artifactType))
+                            .map(artifact -> mappingToBean(PluginHelper.ArtifactType.getType(artifactType.getId()).toString(), artifact)).collect(Collectors.toList()));
+        }
+        return result;
+    }
+
+    private PluginBean mappingToBean(final String artifactType, final Artifact artifact) {
+        final PluginBean pluginBean = new PluginBean();
+        pluginBean.artifactType = artifactType;
+        pluginBean.name = artifact.getName();
+        pluginBean.version = artifact.getVersion();
+        return pluginBean;
+    }
+}

+ 7 - 0
src/main/java/org/codelibs/fess/app/web/admin/plugin/PluginBean.java

@@ -0,0 +1,7 @@
+package org.codelibs.fess.app.web.admin.plugin;
+
+public class PluginBean {
+    public String artifactType;
+    public String name;
+    public String version;
+}

+ 1 - 1
src/main/java/org/codelibs/fess/helper/PluginHelper.java

@@ -227,7 +227,7 @@ public class PluginHelper {
             return id;
         }
 
-        public ArtifactType getType(final String name) {
+        static public ArtifactType getType(final String name) {
             if (name.startsWith(DATA_STORE.getId())) {
                 return DATA_STORE;
             }

+ 3 - 0
src/main/java/org/codelibs/fess/mylasta/action/FessHtmlPath.java

@@ -288,6 +288,9 @@ public interface FessHtmlPath {
     /** The path of the HTML: /admin/pathmap/admin_pathmap_edit.jsp */
     HtmlNext path_AdminPathmap_AdminPathmapEditJsp = new HtmlNext("/admin/pathmap/admin_pathmap_edit.jsp");
 
+    /** The path of the HTML: /admin/plugin/admin_plugin.jsp */
+    HtmlNext path_AdminPlugin_AdminPluginJsp = new HtmlNext("/admin/plugin/admin_plugin.jsp");
+
     /** The path of the HTML: /admin/relatedcontent/admin_relatedcontent.jsp */
     HtmlNext path_AdminRelatedcontent_AdminRelatedcontentJsp = new HtmlNext("/admin/relatedcontent/admin_relatedcontent.jsp");
 

+ 7 - 0
src/main/resources/fess_label.properties

@@ -974,3 +974,10 @@ labels.diagnostic_logs=Diagnostic
 labels.download_diagnostic_logs_button=Download Logs
 labels.reload_doc_index=Reload Doc Index
 labels.reload_doc_index_button=Reload
+
+labels.plugin_management=Plugin Manager
+labels.plugin_list_name=Plugin List
+labels.plugin_type=Type
+labels.plugin_name=Name
+labels.plugin_version=Version
+labels.plugin_delete=Delete

+ 119 - 0
src/main/webapp/WEB-INF/view/admin/plugin/admin_plugin.jsp

@@ -0,0 +1,119 @@
+<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title><la:message key="labels.admin_brand_title" /> | <la:message
+            key="labels.plugin_management" /></title>
+    <jsp:include page="/WEB-INF/view/common/admin/head.jsp"></jsp:include>
+</head>
+<body class="hold-transition skin-blue sidebar-mini">
+<div class="wrapper">
+    <jsp:include page="/WEB-INF/view/common/admin/header.jsp"></jsp:include>
+    <jsp:include page="/WEB-INF/view/common/admin/sidebar.jsp">
+        <jsp:param name="menuCategoryType" value="log" />
+        <jsp:param name="menuType" value="plugin" />
+    </jsp:include>
+    <div class="content-wrapper">
+        <section class="content-header">
+            <h1>
+                <la:message key="labels.plugin_management" />
+            </h1>
+            <jsp:include page="/WEB-INF/view/common/admin/crud/breadcrumb.jsp"></jsp:include>
+        </section>
+        <section class="content">
+            <div class="row">
+                <div class="col-md-12">
+                    <div class="box box-primary">
+                        <!-- /.box-header -->
+
+                        <div class="box-body">
+                            <%-- Message --%>
+                            <div>
+                                <la:info id="msg" message="true">
+                                    <div class="alert alert-info">${msg}</div>
+                                </la:info>
+                                <la:errors />
+                            </div>
+                            <%-- List --%>
+                            <div class="data-wrapper">
+                                <div class="row">
+                                    <div class="col-sm-12">
+                                        <table class="table table-bordered table-striped dataTable">
+                                            <tbody>
+                                            <tr>
+                                                <th><la:message key="labels.plugin_type" /></th>
+                                                <th><la:message key="labels.plugin_name" /></th>
+                                                <th><la:message key="labels.plugin_version" /></th>
+                                                <th></th>
+                                            </tr>
+                                            <c:forEach var="artifact" varStatus="s"
+                                                       items="${installedArtifactItems}">
+                                                <tr>
+                                                    <td>${f:h(artifact.artifactType)}</td>
+                                                    <td>${f:h(artifact.name)}</td>
+                                                    <td>${f:h(artifact.version)}</td>
+                                                    <td>
+
+                                                        <button type="button" class="btn btn-danger" name="delete"
+                                                                data-toggle="modal" data-target="#confirmToDelete"
+                                                                value="<la:message key="labels.crud_button_delete" />">
+                                                            <em class="fa fa-trash"></em>
+                                                            <la:message key="labels.crud_button_delete" />
+                                                        </button>
+                                                        <div class="modal modal-danger fade" id="confirmToDelete" tabindex="-1"
+                                                             role="dialog">
+                                                            <div class="modal-dialog">
+                                                                <div class="modal-content">
+                                                                    <div class="modal-header">
+                                                                        <button type="button" class="close" data-dismiss="modal"
+                                                                                aria-label="Close">
+                                                                            <span aria-hidden="true">×</span>
+                                                                        </button>
+                                                                        <h4 class="modal-title">
+                                                                            <la:message key="labels.crud_title_delete" />
+                                                                        </h4>
+                                                                    </div>
+                                                                    <div class="modal-body">
+                                                                        <p>
+                                                                            <la:message key="labels.crud_delete_confirmation" />
+                                                                        </p>
+                                                                    </div>
+                                                                    <div class="modal-footer">
+                                                                        <button type="button" class="btn btn-outline pull-left"
+                                                                                data-dismiss="modal">
+                                                                            <la:message key="labels.crud_button_cancel" />
+                                                                        </button>
+                                                                        <button type="submit" class="btn btn-outline btn-danger"
+                                                                                name="delete"
+                                                                                value="<la:message key="labels.crud_button_delete" />">
+                                                                            <em class="fa fa-trash"></em>
+                                                                            <la:message key="labels.crud_button_delete" />
+                                                                        </button>
+                                                                    </div>
+                                                                </div>
+                                                            </div>
+                                                        </div>
+
+                                                    </td>
+                                                </tr>
+                                            </c:forEach>
+                                            </tbody>
+                                        </table>
+                                    </div>
+                                </div>
+                            </div>
+                            <!-- /.data-wrapper -->
+                        </div>
+                        <!-- /.box-body -->
+                    </div>
+                    <!-- /.box -->
+                </div>
+            </div>
+        </section>
+    </div>
+    <jsp:include page="/WEB-INF/view/common/admin/footer.jsp"></jsp:include>
+</div>
+<jsp:include page="/WEB-INF/view/common/admin/foot.jsp"></jsp:include>
+</body>
+</html>
+