Added a Config page. Currently unreachable.
This commit is contained in:
parent
b115a9cb4f
commit
ee19d84434
11 changed files with 157 additions and 27 deletions
79
src/wa/server/page/ConfigPage.java
Normal file
79
src/wa/server/page/ConfigPage.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2015 ezivkoc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.page;
|
||||
|
||||
import wa.server.WAContext;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A dynamic configuration page where a list of the same
|
||||
* Bean type can be configured
|
||||
*
|
||||
* Created by Ziver on 2015-07-27.
|
||||
*/
|
||||
public class ConfigPage implements WAPage{
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String TMPL_FILE = "WebContent/page/ConfigPage.tmpl";
|
||||
|
||||
private WAServiceConfig config;
|
||||
|
||||
|
||||
public ConfigPage(WAServiceConfig conf) {
|
||||
this.config = conf;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Templator htmlResponse(WAContext context,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
try {
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
return tmpl;
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataNode jsonResponse(WAContext context,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,15 +56,16 @@ public class ServicePage implements WAPage {
|
|||
this.rootStatusPage = new ServiceStatusPage(pluginManager);
|
||||
this.statusPages = new ArrayList<>();
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAService plugin : services) {
|
||||
statusPages.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
|
||||
WANavigation serviceNav = nav.getSubNav(plugin.getName());
|
||||
WANavigation serviceNav = nav.createSubNav(plugin.getName());
|
||||
serviceNav.setResource(plugin);
|
||||
for(WAServiceConfig conf : plugin.getConfigurations()){
|
||||
//serviceNav.getSubNav(conf.getName()).setResource(conf);
|
||||
serviceNav.createSubNav(conf.getName())
|
||||
.setResource(new ConfigPage(conf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ public class ServiceStatusPage implements WAPage {
|
|||
public ServiceStatusPage(PluginManager pluginManager){
|
||||
this.services = pluginManager.toArray(WAServiceStatus.class);
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).getSubNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(ServicePage.NAVIGATION_NAME)
|
||||
.createSubNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
package wa.server.page;
|
||||
|
||||
import wa.server.WAAbstractPage;
|
||||
import wa.server.WAContext;
|
||||
import wa.server.page.struct.WANavigation;
|
||||
import wa.server.plugin.WAStatus;
|
||||
|
|
@ -44,10 +43,10 @@ public class StatusPage implements WAPage {
|
|||
public StatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAStatus.class);
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAStatus plugin : plugins)
|
||||
nav.getSubNav(plugin.getName()).setResource(plugin);
|
||||
nav.createSubNav(plugin.getName()).setResource(plugin);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,18 +57,25 @@ public class WANavigation implements Iterable{
|
|||
public List<WANavigation> getSubNavs() {
|
||||
return subNav;
|
||||
}
|
||||
public WANavigation getSubNav(String name) {
|
||||
private WANavigation getSubNav(String name) {
|
||||
for(WANavigation nav : subNav) {
|
||||
if(nav.equals(name))
|
||||
return nav;
|
||||
}
|
||||
WANavigation nav = new WANavigation(name);
|
||||
this.addSubNav(nav);
|
||||
return nav;
|
||||
return null;
|
||||
}
|
||||
private void addSubNav(WANavigation subNav) {
|
||||
this.subNav.add(subNav);
|
||||
subNav.setParentNav(this );
|
||||
/**
|
||||
* Will create a new subnav if it does not already exist or return the existing one.
|
||||
*/
|
||||
public WANavigation createSubNav(String name) {
|
||||
WANavigation nav = getSubNav(name);
|
||||
if(nav != null)
|
||||
return nav;
|
||||
|
||||
nav = new WANavigation(name);
|
||||
nav.setParentNav(this);
|
||||
subNav.add(nav);
|
||||
return nav;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
|
@ -97,8 +104,8 @@ public class WANavigation implements Iterable{
|
|||
public static List<WANavigation> getRootNav(){
|
||||
return rootNav.getSubNavs();
|
||||
}
|
||||
public static WANavigation getRootNav(String name){
|
||||
return rootNav.getSubNav(name);
|
||||
public static WANavigation createRootNav(String name){
|
||||
return rootNav.createSubNav(name);
|
||||
}
|
||||
|
||||
public static List<WANavigation> getNavBreadcrumb(Map<String, String> request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue