Key/value settings template

28-10-2019
The db stored key/value entity "settings" and the virtual one in server/entities.ts ``` import "stdlib/native" import * as orm from "stdlib/orm" function init() { orm.register({ name: "settings", permissionFlags: "", label: "@@ConfiguraciĆ³n", pluralLabel: "@@Configuraciones", properties: [ { name: "name", type: "string" }, { name: "value", type: "string" }, ], constraints: [ { type: "unique", columns: ["name"] } ] }) orm.register({ name: "virtualSettings", permissionFlags: "R", transient: true, idProperty: false, auditProperties: false, label: "@@Settings", pluralLabel: "@@Settings", properties: [ { name: "login", type: "string", label: "Login" }, { name: "password", type: "encrypted", label: "Password" }, { name: "idioma", type: "string", size: 5, label: "Idioma" }, { name: "server", type: "string", size: 100, label: "Server" }, { name: "sistema", type: "string", size: 30, label: "Sistema" }, ] }) } ``` Server handlers in server/main.ts ``` import "stdlib/native" import * as web from "stdlib/web" import * as orm from "stdlib/orm" import * as settings from "stdlib/settings" import "entities" import "stdlib/ormapi" import "installer" function init() { web.addApi({ url: "/autocheckin/loadConfig.api", handler: loadConfigHandler }) web.addApi({ url: "/autocheckin/saveConfig.api", handler: saveAppconfigHandler }) } function loadConfigHandler(c: web.Context) { let config = settings.load() c.response.writeJSON(config) } function saveAppconfigHandler(c: web.Context) { let entity = orm.getEntity("autocheckin.virtualSettings") let model = settings.parseValues(c.request.values, entity.properties, c) settings.save(model, entity.properties) } ``` Client handler in client/admin/main.ts ``` S.addRoute("/admin/eticadata/config", () => { let detail = new admin.EntityDetail("eticadata.virtualSettings", { singleRowLoadURL: "/eticadata/loadConfig.api", singleRowSaveURL: "/eticadata/saveConfig.api", }) detail.load() let view = new admin.AdminView("padding") let tile = new S.Tile() view.content.appendChild(tile.element) tile.element.appendChild(detail.element) S.setView(view) }) ```