Big changes
This commit is contained in:
parent
f2b4cfdec7
commit
c6d2981b12
15 changed files with 203 additions and 205 deletions
24
src/wa/server/page/MainPage.java
Executable file
24
src/wa/server/page/MainPage.java
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
package wa.server.page;
|
||||
|
||||
import wa.server.WAContext;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-07-23.
|
||||
*/
|
||||
public class MainPage extends WAPage {
|
||||
|
||||
|
||||
public MainPage(){
|
||||
super("/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Templator htmlResponse(WAContext context, HttpHeader client_info, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -42,21 +42,25 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class ServiceStatusPage extends WAPage {
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
|
||||
public static final String PAGE_NAME = "status";
|
||||
public static final String NAVIGATION_NAME = "Service Status";
|
||||
private static final String TMPL_FILE = "WebContent/page/ServiceStatusPage.tmpl";
|
||||
|
||||
private ArrayList<WAServiceStatus> services;
|
||||
|
||||
|
||||
public ServiceStatusPage(WAServiceStatus ss){
|
||||
services = new ArrayList<>();
|
||||
services.add(ss);
|
||||
}
|
||||
|
||||
public ServiceStatusPage(){
|
||||
super(WAServicePage.NAVIGATION_NAME +"/"+ PAGE_NAME);
|
||||
this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class);
|
||||
|
||||
Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME)
|
||||
.createSubNav(NAVIGATION_NAME).setWeight(-100);
|
||||
.createSubNav(getPageName(), NAVIGATION_NAME).setWeight(-100);
|
||||
}
|
||||
public ServiceStatusPage(WAServiceStatus ss){
|
||||
services = new ArrayList<>();
|
||||
services.add(ss);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,122 +1,139 @@
|
|||
/*
|
||||
* 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.WAConfigEntry;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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 extends 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,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
try {
|
||||
List<?> confObjs = config.getConfigData();
|
||||
ArrayList<Configurator<WAConfigEntry>> confList = new ArrayList<>();
|
||||
for(Object obj : confObjs){
|
||||
confList.add(new Configurator(obj));
|
||||
}
|
||||
|
||||
// Actions
|
||||
int index = Integer.parseInt(request.get("id"));
|
||||
Configurator<WAConfigEntry> target = findObj(confList, index);
|
||||
switch (request.get("action")){
|
||||
case "create":
|
||||
target = new Configurator(config.createConfig()).applyConfiguration();
|
||||
case "modify":
|
||||
target.setValues(request).applyConfiguration();
|
||||
break;
|
||||
case "delete":
|
||||
config.deleteConfig(index);
|
||||
break;
|
||||
case "enable":
|
||||
target.getObject().setEnabled(true);
|
||||
break;
|
||||
case "disable":
|
||||
target.getObject().setEnabled(false);
|
||||
break;
|
||||
}
|
||||
|
||||
// Prepare Output
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("params", Configurator.getConfiguration(
|
||||
config.getConfigClass()));
|
||||
tmpl.set("data", confList);
|
||||
return tmpl;
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataNode jsonResponse(WAContext context,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static Configurator<WAConfigEntry> findObj(List<Configurator<WAConfigEntry>> list, int id){
|
||||
for (Configurator<WAConfigEntry> conf : list) {
|
||||
if(conf.getObject().getId() == id)
|
||||
return conf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.WAConfigEntry;
|
||||
import wa.server.plugin.WAServiceStatus;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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 abstract class WAConfigPage extends WAPage {
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String TEMPLATE = "WebContent/page/ConfigPage.tmpl";
|
||||
|
||||
|
||||
|
||||
public WAConfigPage(String serviceName, String name, String niceName) {
|
||||
super(WAServicePage.NAVIGATION_NAME +"/"+ serviceName +"/"+ name);
|
||||
WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME).createSubNav(serviceName)
|
||||
.createSubNav(name, niceName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Templator htmlResponse(WAContext context,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
try {
|
||||
List<?> confObjs = getConfigData();
|
||||
ArrayList<Configurator<WAConfigEntry>> confList = new ArrayList<>();
|
||||
for(Object obj : confObjs){
|
||||
confList.add(new Configurator(obj));
|
||||
}
|
||||
|
||||
// Actions
|
||||
int id = Integer.parseInt(request.get("id"));
|
||||
Configurator<WAConfigEntry> target = findObj(confList, id);
|
||||
switch (request.get("action")){
|
||||
case "create":
|
||||
target = new Configurator(createConfig()).applyConfiguration();
|
||||
case "modify":
|
||||
target.setValues(request).applyConfiguration();
|
||||
break;
|
||||
case "delete":
|
||||
deleteConfig(id);
|
||||
break;
|
||||
case "enable":
|
||||
target.getObject().setEnabled(true);
|
||||
break;
|
||||
case "disable":
|
||||
target.getObject().setEnabled(false);
|
||||
break;
|
||||
}
|
||||
|
||||
// Prepare Output
|
||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||
tmpl.set("params", Configurator.getConfiguration(
|
||||
getConfigClass()));
|
||||
tmpl.set("data", confList);
|
||||
return tmpl;
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static Configurator<WAConfigEntry> findObj(List<Configurator<WAConfigEntry>> list, int id){
|
||||
for (Configurator<WAConfigEntry> conf : list) {
|
||||
if(conf.getObject().getId() == id)
|
||||
return conf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract WAConfigEntry createConfig();
|
||||
public abstract void deleteConfig(int id);
|
||||
|
||||
/**
|
||||
* Configure service with current configuration data
|
||||
*/
|
||||
public abstract void configure() throws Exception;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return a list of configuration objects, the object
|
||||
* configuration can be changed with the
|
||||
* {@link zutil.ui.Configurator} class.
|
||||
*/
|
||||
public abstract List<? extends WAConfigEntry> getConfigData();
|
||||
|
||||
/**
|
||||
* @return the class that contains the configuration data
|
||||
*/
|
||||
public abstract Class<? extends WAConfigEntry> getConfigClass();
|
||||
}
|
||||
|
|
@ -51,6 +51,10 @@ public abstract class WAPage implements HttpPage{
|
|||
|
||||
|
||||
public WAPage() {
|
||||
this(null);
|
||||
}
|
||||
public WAPage(String pageName) {
|
||||
this.pageName = pageName;
|
||||
try {
|
||||
tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
} catch(IOException e){
|
||||
|
|
@ -104,9 +108,6 @@ public abstract class WAPage implements HttpPage{
|
|||
}
|
||||
|
||||
|
||||
public void setPageName(String pageName){
|
||||
this.pageName = pageName;
|
||||
}
|
||||
public String getPageName(){
|
||||
return pageName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ package wa.server.page;
|
|||
import wa.server.WAContext;
|
||||
import wa.server.plugin.WAInstaller;
|
||||
import wa.server.plugin.WALog;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import wa.server.plugin.WAServiceStatus;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
|
|
@ -34,9 +33,7 @@ import zutil.parser.Templator;
|
|||
import zutil.ui.Navigation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -52,11 +49,11 @@ public abstract class WAServicePage extends WAPage {
|
|||
private LogPage logPage;
|
||||
|
||||
|
||||
public WAServicePage(String pageName, String serviceName){
|
||||
super.setPageName("service/"+pageName);
|
||||
public WAServicePage(String name, String niceName){
|
||||
super("service/"+name);
|
||||
|
||||
Navigation rootNav = WAContext.getRootNav().createSubNav(NAVIGATION_NAME).setWeight(100);
|
||||
Navigation serviceNav = rootNav.createSubNav(getPageName(), serviceName);
|
||||
WAContext.getRootNav().createSubNav(NAVIGATION_NAME).setWeight(100)
|
||||
.createSubNav(getPageName(), niceName);
|
||||
|
||||
statusPage = new ServiceStatusPage(getStatus());
|
||||
logPage = new LogPage(getLog());
|
||||
|
|
@ -97,4 +94,5 @@ public abstract class WAServicePage extends WAPage {
|
|||
* @return a installer object that will install the service or null if the installer is not available
|
||||
*/
|
||||
public abstract WAInstaller getInstaller();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ public abstract class WAStatusPage extends WAPage {
|
|||
public static final String NAVIGATION_NAME = "Status";
|
||||
|
||||
|
||||
public WAStatusPage(String subPageName, String niceName){
|
||||
super.setPageName("status/"+subPageName);
|
||||
public WAStatusPage(String name, String niceName){
|
||||
super("status/"+name);
|
||||
|
||||
WAContext.getRootNav().createSubNav(NAVIGATION_NAME)
|
||||
.setWeight(0).createSubNav(this.getPageName(), niceName);
|
||||
.setWeight(-100).createSubNav(this.getPageName(), niceName);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue