Introduction of Javascript modules for frontend
This commit is contained in:
parent
c27f1030b6
commit
47f730b76e
4 changed files with 96 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ package se.hal;
|
|||
|
||||
import se.hal.daemon.HalExternalWebDaemon;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.intf.HalJavascriptModule.HalJsModule;
|
||||
import se.hal.page.StartupWebPage;
|
||||
import se.hal.struct.PluginConfig;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -141,6 +142,15 @@ public class HalServer {
|
|||
registerPage(it.next());
|
||||
for (Iterator<HalWebPage> it = pluginManager.getSingletonIterator(HalWebPage.class); it.hasNext(); )
|
||||
registerPage(it.next());
|
||||
for (Iterator<HalJavascriptModule> it = pluginManager.getSingletonIterator(HalJavascriptModule.class); it.hasNext(); ) {
|
||||
HalJsModule[] jsModules = it.next().getJavascriptModules();
|
||||
|
||||
if (jsModules != null) {
|
||||
for (HalJsModule module : jsModules)
|
||||
HalWebPage.addJavascriptModule(module);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Startup failed.", e);
|
||||
|
|
|
|||
50
hal-core/src/se/hal/intf/HalJavascriptModule.java
Normal file
50
hal-core/src/se/hal/intf/HalJavascriptModule.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package se.hal.intf;
|
||||
|
||||
/**
|
||||
* A plugin interface for configuring Javascript modules
|
||||
*/
|
||||
public interface HalJavascriptModule {
|
||||
|
||||
/**
|
||||
* @return a List of Objects defining the Javascript configuration
|
||||
*/
|
||||
HalJsModule[] getJavascriptModules();
|
||||
|
||||
|
||||
/**
|
||||
* Defines configuration for a Javascript module to be loaded during webpage generation.
|
||||
*/
|
||||
class HalJsModule {
|
||||
private String moduleName;
|
||||
private String scriptPath;
|
||||
|
||||
public HalJsModule(String moduleName, String scriptPath) {
|
||||
this.moduleName = moduleName;
|
||||
this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
public String getModuleName() {
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
public String getScriptPath() {
|
||||
return scriptPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares a Javascript module to be assigned to a specific web address.
|
||||
*/
|
||||
class HalJsModulePage extends HalJsModule {
|
||||
private String page;
|
||||
|
||||
public HalJsModulePage(String moduleName, String scriptPath, String page) {
|
||||
super(moduleName, scriptPath);
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package se.hal.intf;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalJavascriptModule.HalJsModule;
|
||||
import se.hal.intf.HalJavascriptModule.HalJsModulePage;
|
||||
import se.hal.struct.User;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
|
@ -11,6 +13,7 @@ import zutil.parser.Templator;
|
|||
import zutil.ui.Navigation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -23,6 +26,8 @@ public abstract class HalWebPage implements HttpPage{
|
|||
|
||||
private static Navigation rootNav = Navigation.createRootNav();
|
||||
private static Navigation userNav = Navigation.createRootNav();
|
||||
private static List<HalJsModule> jsModules = new ArrayList<>();
|
||||
private static List<HalJsModulePage> jsPages = new ArrayList<>();
|
||||
|
||||
private String pageId;
|
||||
private boolean showSubNav;
|
||||
|
|
@ -76,6 +81,8 @@ public abstract class HalWebPage implements HttpPage{
|
|||
main.setAll(data);
|
||||
main.set("navigation", navigationTemplate);
|
||||
main.set("side_navigation", subNavigationTemplate);
|
||||
main.set("javascriptModules", jsModules);
|
||||
main.set("javascriptPages", jsPages);
|
||||
main.set("content", httpRespond(session, cookie, request));
|
||||
|
||||
out.print(main.compile());
|
||||
|
|
@ -97,7 +104,12 @@ public abstract class HalWebPage implements HttpPage{
|
|||
public static Navigation getUserNav(){
|
||||
return userNav;
|
||||
}
|
||||
public static void addJavascriptModule(HalJsModule module) {
|
||||
jsModules.add(module);
|
||||
|
||||
if (module instanceof HalJsModulePage)
|
||||
jsPages.add((HalJsModulePage) module);
|
||||
}
|
||||
|
||||
public abstract Templator httpRespond(
|
||||
Map<String, Object> session,
|
||||
|
|
|
|||
24
hal-core/src/se/hal/page/JavascriptModules.java
Normal file
24
hal-core/src/se/hal/page/JavascriptModules.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.intf.HalJavascriptModule;
|
||||
|
||||
public class JavascriptModules implements HalJavascriptModule {
|
||||
|
||||
@Override
|
||||
public HalJsModule[] getJavascriptModules() {
|
||||
return new HalJsModule[] {
|
||||
new HalJsModule("AlertStore", "./js/vue/stores/AlertStore.js"),
|
||||
new HalJsModule("EventStore", "./js/vue/stores/EventStore.js"),
|
||||
new HalJsModule("SensorStore", "./js/vue/stores/SensorStore.js"),
|
||||
|
||||
new HalJsModule("AlertComponent", "./js/vue/components/AlertComponent.js"),
|
||||
new HalJsModule("AlertListComponent", "./js/vue/components/AlertListComponent.js"),
|
||||
|
||||
new HalJsModule("EventActionComponent", "./js/vue/components/EventActionComponent.js"),
|
||||
new HalJsModulePage("EventDetailPageComponent", "./js/vue/components/EventDetailPageComponent.js", "/event/:id"),
|
||||
new HalJsModulePage("EventOverviewPageComponent", "./js/vue/components/EventOverviewPageComponent.js", "/event_overview"),
|
||||
new HalJsModule("EventTableComponent", "./js/vue/components/EventTableComponent.js"),
|
||||
new HalJsModule("EventTableRowComponent", "./js/vue/components/EventTableRowComponent.js"),
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue