Overview page for Application Admin

ccm-docs
Jens Pelzetter 2020-11-25 21:32:19 +01:00
parent 82974ede3a
commit 99f65ecc06
11 changed files with 285 additions and 48 deletions

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface ApplicationController {
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ApplicationTypeInfoItem implements
Comparable<ApplicationTypeInfoItem> {
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;
}
}

View File

@ -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<ApplicationTypeInfoItem> 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;
}
}

View File

@ -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()
);
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class DefaultApplicationController implements ApplicationController {
}

View File

@ -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<? extends ApplicationCreator> creator();
Class<? extends AbstractAppInstanceForm> instanceForm() default DefaultApplicationInstanceForm.class;
Class<? extends ApplicationController> adminController() default DefaultApplicationController.class;
Class<? extends AbstractAppSettingsPane> settingsPane() default DefaultApplicationSettingsPane.class;

View File

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml">
<ui:param name="activePage" value="applications" />
<ui:param name="title" value="#{AdminMessages['applications.label']}" />
<ui:define name="breadcrumb">
<li class="breadcrumb-item active">
#{AdminMessages['applications.label']}
</li>
</ui:define>
<ui:define name="main">
<div class="container">
<h1>#{AdminMessages['applications.label']}</h1>
<p>Placeholder</p>
</div>
</ui:define>
</ui:composition>
</html>

View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml">
<ui:param name="activePage" value="applications" />
<ui:param name="title" value="#{AdminMessages['applications.label']}" />
<ui:define name="breadcrumb">
<li class="breadcrumb-item active">
#{AdminMessages['applications.label']}
</li>
</ui:define>
<ui:define name="main">
<div class="container">
<h1>#{AdminMessages['applications.label']}</h1>
<ul class="list-group">
<c:forEach items="#{applicationTypes}" var="type">
<li class="list-group-item">
<div class="d-flex w-100 justify-content-between align-items-center">
<h2>
<a href="#{mvc.uri('ApplicationsController#getApplicationInstances', {'type': type.name})}">${type.title}</a>
</h2>
<small class="badge badge-info badge-pill">
<c:choose>
<c:when test="#{type.singleton}">
#{AdminMessages['applications.types.singleton']}
</c:when>
<c:otherwise>
#{AdminMessages.getMessage('applications.number_of_instances', [type.numberOfInstances])}
</c:otherwise>
</c:choose>
</small>
</div>
<p>
${type.description}
</p>
</li>
</c:forEach>
</ul>
</div>
</ui:define>
</ui:composition>
</html>

View File

@ -1,9 +1,9 @@
<!DOCTYPE html [<!ENTITY times '&#215;'>]>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:bootstrap="http://xmlns.jcp.org/jsf/composite/components/bootstrap"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:xlink="http://www.w3.org/1999/xlink">
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/views/org/libreccm/ui/admin/ccm-admin.xhtml">
<ui:param name="activePage" value="categories" />
@ -28,12 +28,7 @@
<div class="text-right mb-2">
<a class="btn btn-secondary"
href="#{mvc.uri('CategorySystemsController#newCategorySystem')}">
<svg class="bi"
width="1em"
height="1em"
fill="currentColor">
<use xlink:href="#{request.contextPath}/assets/bootstrap/bootstrap-icons.svg#plus-circle" />
</svg>
<bootstrap:svgIcon icon="plus-circle" />
<span>#{AdminMessages['categorysystems.add']}</span>
</a>
</div>
@ -60,12 +55,7 @@
<td>
<a class="btn btn-info"
href="#{mvc.uri('CategorySystemsController#getCategorySystemDetails', { 'categorySystemIdentifier': categorySystem.identifier })}">
<svg class="bi"
width="1em"
height="1em"
fill="currentColor">
<use xlink:href="#{request.contextPath}/assets/bootstrap/bootstrap-icons.svg#pen" />
</svg>
<bootstrap:svgIcon icon="pen"/>
#{AdminMessages['categorysystems.table.actions.edit']}
</a>
</td>
@ -74,12 +64,7 @@
data-target="#confirm-delete-#{categorySystem.identifier}"
data-toggle="modal"
type="button">
<svg class="bi"
width="1em"
height="1em"
fill="currentColor">
<use xlink:href="#{request.contextPath}/assets/bootstrap/bootstrap-icons.svg#x-circle" />
</svg>
<bootstrap:svgIcon icon="x-circle" />
#{AdminMessages['categorysystems.table.actions.delete']}
</button>
<div class="modal"

View File

@ -490,3 +490,5 @@ sites.form.defaulttheme.label=Default Theme
sites.form.buttons.cancel=Cancel
sites.form.buttons.create=Create Site
sites.form.buttons.save=Save
applications.types.singleton=Singleton
applications.number_of_instances={0} instances

View File

@ -490,3 +490,5 @@ sites.form.defaulttheme.label=Standard Theme
sites.form.buttons.cancel=Abbrechen
sites.form.buttons.create=Site anlegen
sites.form.buttons.save=Speichern
applications.types.singleton=Singleton
applications.number_of_instances={0} Instanzen