UI for managing settings

ccm-docs
Jens Pelzetter 2020-10-23 21:38:18 +02:00
parent 48c2faff70
commit d6ba57414c
3 changed files with 209 additions and 0 deletions

View File

@ -36,6 +36,7 @@ public class ConfigurationPage implements AdminPage {
public Set<Class<?>> getControllerClasses() { public Set<Class<?>> getControllerClasses() {
final Set<Class<?>> classes = new HashSet<>(); final Set<Class<?>> classes = new HashSet<>();
classes.add(ConfigurationController.class); classes.add(ConfigurationController.class);
classes.add(SettingsController.class);
return classes; return classes;
} }

View File

@ -0,0 +1,102 @@
/*
* 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.configuration;
import org.libreccm.configuration.ConfigurationInfo;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.SettingInfo;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedTextsUtil;
import java.util.Objects;
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.Path;
import javax.ws.rs.PathParam;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Controller
@RequestScoped
@Path("/configuration/{configurationClass}")
public class SettingsController {
@Inject
private ConfigurationManager confManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private Models models;
@Path("/")
public String showSettings(
@PathParam("configurationClass") final String configurationClass
) {
final Class<?> confClass;
try {
confClass = Class.forName(configurationClass);
} catch(ClassNotFoundException ex) {
models.put("configurationClass", configurationClass);
return "org/libreccm/ui/admin/configuration/configuration-class-not-found.xhtml";
}
final Object conf = confManager.findConfiguration(confClass);
final ConfigurationInfo confInfo = confManager.getConfigurationInfo(
confClass
);
confInfo
.getSettings()
.entrySet()
.stream()
.map(info -> buildSettingsTableEntry(info.getValue(), conf))
.sorted()
.collect(Collectors.toList());
return "org/libreccm/ui/admin/configuration/settings.xhtml";
}
private SettingsTableEntry buildSettingsTableEntry(
final SettingInfo settingInfo, final Object conf
) {
Objects.requireNonNull(settingInfo);
final LocalizedTextsUtil textsUtil = globalizationHelper
.getLocalizedTextsUtil(settingInfo.getDescBundle());
final SettingsTableEntry entry = new SettingsTableEntry();
entry.setName(settingInfo.getName());
entry.setValueType(settingInfo.getValueType());
entry.setDefaultValue(settingInfo.getDefaultValue());
entry.setLabel(textsUtil.getText(settingInfo.getLabelKey()));
entry.setDescription(textsUtil.getText(settingInfo.getDescKey()));
return entry;
}
}

View File

@ -0,0 +1,106 @@
/*
* 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.configuration;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingsTableEntry implements Comparable<SettingsTableEntry> {
private String name;
private String valueType;
private String defaultValue;
private String value;
private String label;
private String description;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getValueType() {
return valueType;
}
public void setValueType(final String valueType) {
this.valueType = valueType;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(final String defaultValue) {
this.defaultValue = defaultValue;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getValue() {
return value;
}
public void setValue(final String value) {
this.value = value;
}
@Override
public int compareTo(final SettingsTableEntry other) {
int result = Objects.compare(
label,
Objects.requireNonNull(other).getLabel(),
String::compareTo
);
if (result == 0) {
result = Objects.compare(
name,
other.getName(),
String::compareTo
);
}
return result;
}
}