Progress on ConfigPage

This commit is contained in:
Ziver Koc 2016-07-28 23:30:03 +02:00
parent 9997bcd91a
commit b995063b43
14 changed files with 59 additions and 42 deletions

View file

@ -1,10 +1,15 @@
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">Service Status</div>
<div class="panel-heading">{{name}}</div>
<div class="panel-body">
<table class="table table-hover">
<table class="table table-hover table-condensed">
<thead><tr>
{{#params}}<th>{{.getNiceName()}}</th>{{/params}}
{{#params}}
<th>{{.getNiceName()}}</th>
{{/params}}
<th>
<button type="button" class="btn btn-default pull-left" data-toggle="modal" data-target="#configureModal">+</button>
</th>
</tr></thead>
{{#data}}
<tr {{#.disabled}}class="active"{{/.disabled}}>
@ -39,7 +44,6 @@
</table>
</div>
<div class="panel-footer clearfix">
<button type="button" class="btn btn-default pull-left" data-toggle="modal" data-target="#configureModal">+</button>
<button type="button" class="btn btn-primary pull-right">Apply Configuration</button>
</div>
</div>
@ -68,12 +72,6 @@
{{#.isTypeBoolean()}}
<input type="checkbox" class="form-control" id="{{.getName()}}">
{{/.isTypeBoolean()}}
<!--
<select class="form-control" id="sselect" placeholder="">
<option value="volvo">-- Chose an Option --</option>
<option value="saab">Saab</option>
</select>
-->
</div>
</div>
{{/params}}

View file

@ -106,9 +106,9 @@
<a data-toggle="collapse" data-parent="#side-bar" href="#{{.getName()}}_collapse">
{{.getName()}} <b class="caret"></b>
</a>
<ul id="{{.name}}_collapse" class="side-sub-menu collapse nav nav-pills nav-stacked ">
<ul id="{{.getName()}}_collapse" class="side-sub-menu collapse nav nav-pills nav-stacked ">
{{#.getSubNavs()}}
<li><a href="{{.url}}">{{.getName()}}</a></li>
<li><a href="{{.getURL()}}">{{.getName()}}</a></li>
{{/.getSubNavs()}}
</ul>
</li>

View file

@ -36,6 +36,7 @@ import zutil.plugin.PluginManager;
import zutil.ui.Navigation;
import java.io.File;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -85,13 +86,11 @@ public class WAContext {
protected static void initialize(){
try {
pluginManager = new PluginManager();
rootNav = Navigation.createRootNav();
// Setup DB
File dbFile = WAConstants.getConfigFile(WAConstants.DB_FILE);
File defDbFile = WAConstants.getConfigFile(WAConstants.DB_DEFAULT_FILE);
if (!defDbFile.exists())
throw new NoSuchFileException("Deafult DB missing: "+defDbFile.getAbsolutePath());
db = new DBConnection(DBConnection.DBMS.SQLite, dbFile.getAbsolutePath());
DBConnection defaultDB = new DBConnection(DBConnection.DBMS.SQLite, defDbFile.getAbsolutePath());
int defaultDBVersion = Integer.parseInt(defaultDB.exec(
@ -116,6 +115,11 @@ public class WAContext {
handler.upgrade();
}
// Setup fields
pluginManager = new PluginManager();
rootNav = Navigation.createRootNav();
// Http Server setup
httpServer = new HttpServer(80);
httpServer.setDefaultPage(new HttpFilePage(FileUtil.find("WebContent/")));
httpServer.start();
@ -132,7 +136,10 @@ public class WAContext {
return httpServer;
}
public static void registerWaPage(WAPage page){
httpServer.setPage(page.getPageName(), page);
if (page.getPageName() != null) {
logger.info("Registering new WAPage: "+ page.getPageName());
httpServer.setPage(page.getPageName(), page);
}
}
public static Navigation getRootNav(){
return rootNav;

View file

@ -32,7 +32,6 @@ import zutil.parser.Templator;
import zutil.ui.Configurator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -51,22 +50,24 @@ public class ConfigPage extends WAPage {
private Class<? extends WAConfiguration> configClass;
private String name;
public ConfigPage(Class<? extends WAConfiguration> configClass) {
super(getPageName(configClass));
this.configClass = configClass;
WAConfiguration.WAConfig params = configClass.getAnnotation(WAConfiguration.WAConfig.class);
WAContext.getRootNav()
.createSubNav(WAServicePage.NAVIGATION_NAME)
.createSubNav(params.serviceName())
.createSubNav(this.getPageName(), params.name());
this.name = params.name();
}
private static String getPageName(Class<? extends WAConfiguration> configClass){
WAConfiguration.WAConfig params = configClass.getAnnotation(WAConfiguration.WAConfig.class);
if (params != null) {
WAContext.getRootNav()
.createSubNav(WAServicePage.PAGE_NAME)
.createSubNav(params.service())
.createSubNav(params.id(), params.name());
return WAServicePage.PAGE_NAME +"/"+ params.service() +"/"+ params.id();
}
return null;
return WAServicePage.PAGE_NAME +"/"+ params.servicePage() +"/"+ params.pageName();
}
@ -84,8 +85,8 @@ public class ConfigPage extends WAPage {
// Actions
if (request.containsKey("action")) {
int id = -1;
if (request.containsKey("id"))
id = Integer.parseInt(request.get("id"));
if (request.containsKey("pageName"))
id = Integer.parseInt(request.get("pageName"));
WAConfiguration target = getConfig(id);
switch (request.get("action")) {
case "create":
@ -109,6 +110,7 @@ public class ConfigPage extends WAPage {
// Prepare Output
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
tmpl.set("name", name);
tmpl.set("params", Configurator.getConfiguration(configClass));
tmpl.set("data", objList);
return tmpl;

View file

@ -52,14 +52,13 @@ public class ServiceStatusPage extends WAPage {
public ServiceStatusPage(){
super(WAServicePage.NAVIGATION_NAME +"/"+ PAGE_NAME);
super(WAServicePage.PAGE_NAME);
this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class);
Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME)
.createSubNav(getPageName(), NAVIGATION_NAME).setWeight(-100);
}
public ServiceStatusPage(WAServiceStatus ss){
super(WAServicePage.NAVIGATION_NAME);
services = new ArrayList<>();
services.add(ss);
}

View file

@ -50,7 +50,9 @@ public abstract class WAPage implements HttpPage{
private String pageName;
private Templator tmpl;
public WAPage() {
this(null);
}
public WAPage(String pageName) {
this.pageName = pageName;
try {

View file

@ -1,15 +1,23 @@
package wa.server.plugin;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Ziver on 2016-07-27.
*/
public abstract class WAConfiguration{
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WAConfig{
String id();
String pageName();
String name();
String service();
String servicePage(); // TODO: this is horrible design!
String serviceName(); // TODO: this is horrible design!
}

View file

@ -6,7 +6,7 @@ import zutil.ui.Configurator;
import java.io.PrintStream;
@WAConfiguration.WAConfig(service=ApacheService.PAGE_NAME, id="proxy", name="Proxy")
@WAConfiguration.WAConfig(servicePage=ApacheService.SERVICE_NAME, serviceName=ApacheService.NAVIGATION_NAME, pageName ="proxy", name="Proxy")
public class ApacheConfigProxy extends ApacheAbstractConfig {
@Configurator.Configurable("Proxy Target")

View file

@ -6,7 +6,7 @@ import zutil.ui.Configurator;
import java.io.PrintStream;
@WAConfiguration.WAConfig(service=ApacheService.PAGE_NAME, id="vhost", name="VirtualHost")
@WAConfiguration.WAConfig(servicePage=ApacheService.SERVICE_NAME, serviceName=ApacheService.NAVIGATION_NAME, pageName ="vhost", name="VirtualHost")
public class ApacheConfigVirtualHost extends ApacheAbstractConfig {
@Configurator.Configurable("Document Root")

View file

@ -4,6 +4,7 @@
"interfaces": [
{"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheService"},
{"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"},
{"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheConfigVirtualHost"}
{"wa.server.plugin.WAConfiguration": "wa.server.plugin.apache.ApacheConfigProxy"},
{"wa.server.plugin.WAConfiguration": "wa.server.plugin.apache.ApacheConfigVirtualHost"}
]
}

View file

@ -84,10 +84,10 @@ public class HDDStatus extends WAStatusPage {
node.set("mount", hdd.getDirName());
if (idMap.containsKey(device))
node.set("id", idMap.get(device));
node.set("pageName", idMap.get(device));
else {
idMap.put(device, nextId);
node.set("id", nextId++);
node.set("pageName", nextId++);
}
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());

View file

@ -76,10 +76,10 @@ public class NetStatus extends WAStatusPage {
for( String intfName : intfNameList ){
DataNode intfNode = new DataNode(DataNode.DataType.Map);
if(idMap.containsKey(intfName))
intfNode.set("id", idMap.get(intfName));
intfNode.set("pageName", idMap.get(intfName));
else{
idMap.put(intfName, nextId);
intfNode.set("id", nextId++);
intfNode.set("pageName", nextId++);
}
NetInterfaceStat net_stat = sigar.getNetInterfaceStat(intfName);

View file

@ -139,7 +139,7 @@ function updateRoutingTable(){
<tr><th>Flags</th><td class="net-flags"></td></tr>
</table>
</div>
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
<!--<div><canvas pageName="hdd-io" height="400"></canvas></div>-->
</div>
</div></div>
</div>

View file

@ -46,7 +46,7 @@ public class UPSStatus extends WAStatusPage {
DataNode upsRoot = new DataNode(DataNode.DataType.List);
for (NutUPSClient.UPSDevice ups : nutClient.getUPSList()){
DataNode upsNode = new DataNode(DataNode.DataType.Map);
upsNode.set("id", ups.getId());
upsNode.set("pageName", ups.getId());
upsNode.set("model", ups.getModelName());
upsNode.set("desc", ups.getDescription());
upsNode.set("charge", ups.getBatteryCharge());