Progress on ConfigPage
This commit is contained in:
parent
9997bcd91a
commit
b995063b43
14 changed files with 59 additions and 42 deletions
|
|
@ -1,10 +1,15 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Service Status</div>
|
<div class="panel-heading">{{name}}</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover table-condensed">
|
||||||
<thead><tr>
|
<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>
|
</tr></thead>
|
||||||
{{#data}}
|
{{#data}}
|
||||||
<tr {{#.disabled}}class="active"{{/.disabled}}>
|
<tr {{#.disabled}}class="active"{{/.disabled}}>
|
||||||
|
|
@ -39,7 +44,6 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer clearfix">
|
<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>
|
<button type="button" class="btn btn-primary pull-right">Apply Configuration</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -68,12 +72,6 @@
|
||||||
{{#.isTypeBoolean()}}
|
{{#.isTypeBoolean()}}
|
||||||
<input type="checkbox" class="form-control" id="{{.getName()}}">
|
<input type="checkbox" class="form-control" id="{{.getName()}}">
|
||||||
{{/.isTypeBoolean()}}
|
{{/.isTypeBoolean()}}
|
||||||
<!--
|
|
||||||
<select class="form-control" id="sselect" placeholder="">
|
|
||||||
<option value="volvo">-- Chose an Option --</option>
|
|
||||||
<option value="saab">Saab</option>
|
|
||||||
</select>
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/params}}
|
{{/params}}
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,9 @@
|
||||||
<a data-toggle="collapse" data-parent="#side-bar" href="#{{.getName()}}_collapse">
|
<a data-toggle="collapse" data-parent="#side-bar" href="#{{.getName()}}_collapse">
|
||||||
{{.getName()}} <b class="caret"></b>
|
{{.getName()}} <b class="caret"></b>
|
||||||
</a>
|
</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()}}
|
{{#.getSubNavs()}}
|
||||||
<li><a href="{{.url}}">{{.getName()}}</a></li>
|
<li><a href="{{.getURL()}}">{{.getName()}}</a></li>
|
||||||
{{/.getSubNavs()}}
|
{{/.getSubNavs()}}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import zutil.plugin.PluginManager;
|
||||||
import zutil.ui.Navigation;
|
import zutil.ui.Navigation;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -85,13 +86,11 @@ public class WAContext {
|
||||||
|
|
||||||
protected static void initialize(){
|
protected static void initialize(){
|
||||||
try {
|
try {
|
||||||
pluginManager = new PluginManager();
|
|
||||||
rootNav = Navigation.createRootNav();
|
|
||||||
|
|
||||||
|
|
||||||
// Setup DB
|
// Setup DB
|
||||||
File dbFile = WAConstants.getConfigFile(WAConstants.DB_FILE);
|
File dbFile = WAConstants.getConfigFile(WAConstants.DB_FILE);
|
||||||
File defDbFile = WAConstants.getConfigFile(WAConstants.DB_DEFAULT_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());
|
db = new DBConnection(DBConnection.DBMS.SQLite, dbFile.getAbsolutePath());
|
||||||
DBConnection defaultDB = new DBConnection(DBConnection.DBMS.SQLite, defDbFile.getAbsolutePath());
|
DBConnection defaultDB = new DBConnection(DBConnection.DBMS.SQLite, defDbFile.getAbsolutePath());
|
||||||
int defaultDBVersion = Integer.parseInt(defaultDB.exec(
|
int defaultDBVersion = Integer.parseInt(defaultDB.exec(
|
||||||
|
|
@ -116,6 +115,11 @@ public class WAContext {
|
||||||
handler.upgrade();
|
handler.upgrade();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup fields
|
||||||
|
pluginManager = new PluginManager();
|
||||||
|
rootNav = Navigation.createRootNav();
|
||||||
|
|
||||||
|
// Http Server setup
|
||||||
httpServer = new HttpServer(80);
|
httpServer = new HttpServer(80);
|
||||||
httpServer.setDefaultPage(new HttpFilePage(FileUtil.find("WebContent/")));
|
httpServer.setDefaultPage(new HttpFilePage(FileUtil.find("WebContent/")));
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
|
|
@ -132,7 +136,10 @@ public class WAContext {
|
||||||
return httpServer;
|
return httpServer;
|
||||||
}
|
}
|
||||||
public static void registerWaPage(WAPage page){
|
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(){
|
public static Navigation getRootNav(){
|
||||||
return rootNav;
|
return rootNav;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import zutil.parser.Templator;
|
||||||
import zutil.ui.Configurator;
|
import zutil.ui.Configurator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -51,22 +50,24 @@ public class ConfigPage extends WAPage {
|
||||||
|
|
||||||
|
|
||||||
private Class<? extends WAConfiguration> configClass;
|
private Class<? extends WAConfiguration> configClass;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
public ConfigPage(Class<? extends WAConfiguration> configClass) {
|
public ConfigPage(Class<? extends WAConfiguration> configClass) {
|
||||||
super(getPageName(configClass));
|
super(getPageName(configClass));
|
||||||
this.configClass = 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){
|
private static String getPageName(Class<? extends WAConfiguration> configClass){
|
||||||
WAConfiguration.WAConfig params = configClass.getAnnotation(WAConfiguration.WAConfig.class);
|
WAConfiguration.WAConfig params = configClass.getAnnotation(WAConfiguration.WAConfig.class);
|
||||||
if (params != null) {
|
return WAServicePage.PAGE_NAME +"/"+ params.servicePage() +"/"+ params.pageName();
|
||||||
WAContext.getRootNav()
|
|
||||||
.createSubNav(WAServicePage.PAGE_NAME)
|
|
||||||
.createSubNav(params.service())
|
|
||||||
.createSubNav(params.id(), params.name());
|
|
||||||
return WAServicePage.PAGE_NAME +"/"+ params.service() +"/"+ params.id();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,8 +85,8 @@ public class ConfigPage extends WAPage {
|
||||||
// Actions
|
// Actions
|
||||||
if (request.containsKey("action")) {
|
if (request.containsKey("action")) {
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if (request.containsKey("id"))
|
if (request.containsKey("pageName"))
|
||||||
id = Integer.parseInt(request.get("id"));
|
id = Integer.parseInt(request.get("pageName"));
|
||||||
WAConfiguration target = getConfig(id);
|
WAConfiguration target = getConfig(id);
|
||||||
switch (request.get("action")) {
|
switch (request.get("action")) {
|
||||||
case "create":
|
case "create":
|
||||||
|
|
@ -109,6 +110,7 @@ public class ConfigPage extends WAPage {
|
||||||
|
|
||||||
// Prepare Output
|
// Prepare Output
|
||||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||||
|
tmpl.set("name", name);
|
||||||
tmpl.set("params", Configurator.getConfiguration(configClass));
|
tmpl.set("params", Configurator.getConfiguration(configClass));
|
||||||
tmpl.set("data", objList);
|
tmpl.set("data", objList);
|
||||||
return tmpl;
|
return tmpl;
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,13 @@ public class ServiceStatusPage extends WAPage {
|
||||||
|
|
||||||
|
|
||||||
public ServiceStatusPage(){
|
public ServiceStatusPage(){
|
||||||
super(WAServicePage.NAVIGATION_NAME +"/"+ PAGE_NAME);
|
super(WAServicePage.PAGE_NAME);
|
||||||
this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class);
|
this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class);
|
||||||
|
|
||||||
Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME)
|
Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME)
|
||||||
.createSubNav(getPageName(), NAVIGATION_NAME).setWeight(-100);
|
.createSubNav(getPageName(), NAVIGATION_NAME).setWeight(-100);
|
||||||
}
|
}
|
||||||
public ServiceStatusPage(WAServiceStatus ss){
|
public ServiceStatusPage(WAServiceStatus ss){
|
||||||
super(WAServicePage.NAVIGATION_NAME);
|
|
||||||
services = new ArrayList<>();
|
services = new ArrayList<>();
|
||||||
services.add(ss);
|
services.add(ss);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,9 @@ public abstract class WAPage implements HttpPage{
|
||||||
private String pageName;
|
private String pageName;
|
||||||
private Templator tmpl;
|
private Templator tmpl;
|
||||||
|
|
||||||
|
public WAPage() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
public WAPage(String pageName) {
|
public WAPage(String pageName) {
|
||||||
this.pageName = pageName;
|
this.pageName = pageName;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
package wa.server.plugin;
|
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.
|
* Created by Ziver on 2016-07-27.
|
||||||
*/
|
*/
|
||||||
public abstract class WAConfiguration{
|
public abstract class WAConfiguration{
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
public @interface WAConfig{
|
public @interface WAConfig{
|
||||||
String id();
|
String pageName();
|
||||||
String name();
|
String name();
|
||||||
String service();
|
String servicePage(); // TODO: this is horrible design!
|
||||||
|
String serviceName(); // TODO: this is horrible design!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import zutil.ui.Configurator;
|
||||||
import java.io.PrintStream;
|
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 {
|
public class ApacheConfigProxy extends ApacheAbstractConfig {
|
||||||
|
|
||||||
@Configurator.Configurable("Proxy Target")
|
@Configurator.Configurable("Proxy Target")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import zutil.ui.Configurator;
|
||||||
import java.io.PrintStream;
|
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 {
|
public class ApacheConfigVirtualHost extends ApacheAbstractConfig {
|
||||||
|
|
||||||
@Configurator.Configurable("Document Root")
|
@Configurator.Configurable("Document Root")
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
"interfaces": [
|
"interfaces": [
|
||||||
{"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheService"},
|
{"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheService"},
|
||||||
{"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"},
|
{"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"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -84,10 +84,10 @@ public class HDDStatus extends WAStatusPage {
|
||||||
node.set("mount", hdd.getDirName());
|
node.set("mount", hdd.getDirName());
|
||||||
|
|
||||||
if (idMap.containsKey(device))
|
if (idMap.containsKey(device))
|
||||||
node.set("id", idMap.get(device));
|
node.set("pageName", idMap.get(device));
|
||||||
else {
|
else {
|
||||||
idMap.put(device, nextId);
|
idMap.put(device, nextId);
|
||||||
node.set("id", nextId++);
|
node.set("pageName", nextId++);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());
|
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());
|
||||||
|
|
|
||||||
|
|
@ -76,10 +76,10 @@ public class NetStatus extends WAStatusPage {
|
||||||
for( String intfName : intfNameList ){
|
for( String intfName : intfNameList ){
|
||||||
DataNode intfNode = new DataNode(DataNode.DataType.Map);
|
DataNode intfNode = new DataNode(DataNode.DataType.Map);
|
||||||
if(idMap.containsKey(intfName))
|
if(idMap.containsKey(intfName))
|
||||||
intfNode.set("id", idMap.get(intfName));
|
intfNode.set("pageName", idMap.get(intfName));
|
||||||
else{
|
else{
|
||||||
idMap.put(intfName, nextId);
|
idMap.put(intfName, nextId);
|
||||||
intfNode.set("id", nextId++);
|
intfNode.set("pageName", nextId++);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetInterfaceStat net_stat = sigar.getNetInterfaceStat(intfName);
|
NetInterfaceStat net_stat = sigar.getNetInterfaceStat(intfName);
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ function updateRoutingTable(){
|
||||||
<tr><th>Flags</th><td class="net-flags"></td></tr>
|
<tr><th>Flags</th><td class="net-flags"></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
|
<!--<div><canvas pageName="hdd-io" height="400"></canvas></div>-->
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -46,7 +46,7 @@ public class UPSStatus extends WAStatusPage {
|
||||||
DataNode upsRoot = new DataNode(DataNode.DataType.List);
|
DataNode upsRoot = new DataNode(DataNode.DataType.List);
|
||||||
for (NutUPSClient.UPSDevice ups : nutClient.getUPSList()){
|
for (NutUPSClient.UPSDevice ups : nutClient.getUPSList()){
|
||||||
DataNode upsNode = new DataNode(DataNode.DataType.Map);
|
DataNode upsNode = new DataNode(DataNode.DataType.Map);
|
||||||
upsNode.set("id", ups.getId());
|
upsNode.set("pageName", ups.getId());
|
||||||
upsNode.set("model", ups.getModelName());
|
upsNode.set("model", ups.getModelName());
|
||||||
upsNode.set("desc", ups.getDescription());
|
upsNode.set("desc", ups.getDescription());
|
||||||
upsNode.set("charge", ups.getBatteryCharge());
|
upsNode.set("charge", ups.getBatteryCharge());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue