mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-06-02 06:57:02 +00:00
Add GUI Router
This commit is contained in:
parent
79fb080e9f
commit
c3e9d1b179
68
app/index.js
68
app/index.js
|
@ -1,32 +1,54 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// index.js
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// The entrypoint on WelsonJS GUI envionment
|
||||
|
||||
var FILE = require("lib/file");
|
||||
var OldBrowser = require("lib/oldbrowser");
|
||||
var Router = require("lib/router").Router;
|
||||
|
||||
var token;
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.readFile("token.txt", FILE.CdoCharset.CdoUTF_8);
|
||||
}
|
||||
// using jsrender
|
||||
Router.setRender(function(filename, data) {
|
||||
var template = OldBrowser.setContent(FILE.readFile(filename, FILE.CdoCharset.CdoUTF_8));
|
||||
var tmpl = $.templates(template);
|
||||
return tmpl.render(data);
|
||||
});
|
||||
|
||||
OldBrowser.setContent(FILE.readFile("app\\signin.html", FILE.CdoCharset.CdoUTF_8));
|
||||
// main
|
||||
Router.add('/', function(render) {
|
||||
render("app\\signin.html", {});
|
||||
|
||||
document.getElementById("loginform").onsubmit = function(ev) {
|
||||
ev.preventDefault();
|
||||
};
|
||||
var token;
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.readFile("token.txt", FILE.CdoCharset.CdoUTF_8);
|
||||
}
|
||||
|
||||
if (FILE.fileExists("credential.json")) {
|
||||
var credential = JSON.parse(FILE.readFile("credential.json", FILE.CdoCharset.CdoUTF_8));
|
||||
document.getElementById("txt_email").value = credential.email;
|
||||
document.getElementById("txt_password").value = credential.password;
|
||||
}
|
||||
|
||||
document.getElementById("btn_submit").onclick = function() {
|
||||
var credential = {
|
||||
"email": document.getElementById("txt_email").value,
|
||||
"password": document.getElementById("txt_password").value
|
||||
document.getElementById("loginform").onsubmit = function(ev) {
|
||||
ev.preventDefault();
|
||||
};
|
||||
|
||||
FILE.writeFile("credential.json", JSON.stringify(credential), FILE.CdoCharset.CdoUTF_8);
|
||||
};
|
||||
|
||||
if (FILE.fileExists("credential.json")) {
|
||||
var credential = JSON.parse(FILE.readFile("credential.json", FILE.CdoCharset.CdoUTF_8));
|
||||
document.getElementById("txt_email").value = credential.email;
|
||||
document.getElementById("txt_password").value = credential.password;
|
||||
}
|
||||
|
||||
document.getElementById("btn_submit").onclick = function() {
|
||||
var credential = {
|
||||
"email": document.getElementById("txt_email").value,
|
||||
"password": document.getElementById("txt_password").value
|
||||
};
|
||||
|
||||
FILE.writeFile("credential.json", JSON.stringify(credential), FILE.CdoCharset.CdoUTF_8);
|
||||
};
|
||||
});
|
||||
|
||||
// test
|
||||
Router.add('/test', function(render) {
|
||||
var profile = JSON.parse(FILE.readFile("data/test-oss-20231030.json", FILE.CdoCharset.CdoUTF_8));
|
||||
|
||||
render("app\\test.html", {
|
||||
"profile": profile
|
||||
});
|
||||
});
|
||||
|
||||
// go
|
||||
Router.go('/');
|
||||
|
|
40
lib/router.js
Normal file
40
lib/router.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
function RouterObject() {
|
||||
this.RouteModel = function(path, callback) {
|
||||
this.path = path;
|
||||
this.callback = callback;
|
||||
};
|
||||
this.Routes = [];
|
||||
this.render = function(filename, data) {
|
||||
console.warn(typeof data !== "undefined" ? "DATA EXISTS" : "NO DATA");
|
||||
console.warn(filename + " cannot be rendered");
|
||||
};
|
||||
|
||||
this.setRender = function(render) {
|
||||
this.render = render;
|
||||
}
|
||||
|
||||
this.add = function(path, callback) {
|
||||
this.Routes.push(new this.RouteModel(path, callback));
|
||||
}
|
||||
|
||||
this.go = function(path) {
|
||||
var model = this.Routes.find(function(x) {
|
||||
return (x.path == path);
|
||||
});
|
||||
|
||||
if (typeof model !== "undefined") {
|
||||
try {
|
||||
model.callback(this.render);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.Router = new RouterObject();
|
||||
|
||||
exports.VERSIONINFO = "URI Router (router.js) version 0.1";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
|
@ -1,7 +1,9 @@
|
|||
// testloader
|
||||
// testloader.js
|
||||
|
||||
// load libraries
|
||||
var FILE = require("lib/file");
|
||||
|
||||
// load the test profile
|
||||
var profile = JSON.parse(FILE.readFile("data/test-oss-20231030.json", FILE.CdoCharset.CdoUTF_8));
|
||||
|
||||
// implement the tests
|
||||
|
@ -15,7 +17,7 @@ var test_implements = {
|
|||
"registry_write": function() {},
|
||||
|
||||
"wmi_create_object": function() {},
|
||||
|
||||
|
||||
"wmi_execute_query": function() {},
|
||||
|
||||
"wmi_result_query": function() {},
|
||||
|
|
Loading…
Reference in New Issue
Block a user