Use nested config structure

This commit is contained in:
Zaid Abdulla committed 2018-12-26 00:22:07 -08:00
1 parent 581a510960
commit 30dbf0cf40
15 files changed
+366 -251

No files matched your search

+3
View File
@@ -11,6 +11,7 @@ import * as devicePage from "./device-page";
import * as errorPage from "./error-page";
import * as faultsPage from "./faults-page";
import Authorizer from "../common/authorizer";
import * as funcCache from "../common/func-cache";
window.authorizer = new Authorizer(window.permissionSets);
@@ -68,6 +69,8 @@ function pagify(pageName, page) {
return component;
}
setInterval(funcCache.purge, 120000);
m.route(document.body, "/overview", {
"/login": pagify("login", loginPage),
"/overview": pagify("overview", overviewPage),
+7 -3
View File
@@ -1,17 +1,21 @@
"use strict";
import m from "mithril";
import * as config from "../config";
import config from "../config";
import * as store from "../store";
import * as funcCache from "../../common/func-cache";
import Filter from "../../common/filter";
const CHARTS = config.get("ui.overview.charts");
const CHARTS = config.ui.overview.charts;
const component = {
view: vnode => {
const device = vnode.attrs.device;
const chart = CHARTS[vnode.attrs.chart];
for (let slice of Object.values(chart.slices)) {
const filter = store.unpackFilter(slice.filter);
const filter = store.unpackFilter(
funcCache.get(Filter.parse, slice.filter)
);
if (filter.test(device)) {
const dot = m(
"svg",
+1 -38
View File
@@ -1,40 +1,3 @@
"use strict";
import * as Filter from "../common/filter";
const configFile = window.clientConfig;
const cache = {};
function parse(name, value) {
if (/^ui\.overview\.charts\.[^.]+\.slices\.[^.]+\.filter$/.test(name))
return new Filter(value);
return value;
}
function get(name) {
let v = cache[name];
if (v === undefined) {
v = configFile[name];
if (v != null) {
v = parse(name, v);
} else {
const prefix = `${name}.`;
for (let k of Object.keys(configFile))
if (k.startsWith(prefix)) {
v = v || {};
let ar = k.slice(prefix.length).split(".");
let ref = v;
for (let a of ar.slice(0, -1)) ref = ref[a] = ref[a] || {};
ref[ar[ar.length - 1]] = parse(k, configFile[k]);
}
}
if (v) cache[name] = v;
else cache[name] = null;
}
return v;
}
export { get };
export default window.clientConfig;
+2 -2
View File
@@ -2,7 +2,7 @@
import m from "mithril";
import * as config from "./config";
import config from "./config";
import Filter from "../common/filter";
import * as store from "./store";
import * as components from "./components";
@@ -25,7 +25,7 @@ const component = {
let dev = store.fetch("devices", vnode.attrs.deviceFilter).value;
if (!dev.length) return "Loading";
const conf = config.get("ui.device");
const conf = config.ui.device;
const cmps = [];
for (let c of Object.values(conf))
+3 -3
View File
@@ -2,7 +2,7 @@
import m from "mithril";
import * as config from "./config";
import config from "./config";
import filterComponent from "./filter-component";
import * as filterParser from "../common/filter-parser";
import Filter from "../common/filter";
@@ -17,7 +17,7 @@ function init(args) {
return reject(new Error("You are not authorized to view this page"));
let filter = new Filter(args.filter);
let indexParameters = Object.values(config.get("ui.index")).map(p =>
let indexParameters = Object.values(config.ui.index).map(p =>
Object.assign({}, p, {
parameter: filterParser.parseParameter(p.parameter)
})
@@ -302,7 +302,7 @@ const component = {
return [
m("h1", "Listing devices"),
m(filterComponent, {
predefined: Object.values(config.get("ui.filters")),
predefined: Object.values(config.ui.filters),
filter: vnode.attrs.filter ? vnode.attrs.filter.ast : null,
onChange: onFilterChanged
}),
+10 -6
View File
@@ -1,23 +1,27 @@
"use strict";
import m from "mithril";
import * as config from "./config";
import config from "./config";
import * as store from "./store";
import pieChartComponent from "./pie-chart-component";
import Filter from "../common/filter";
import * as funcCache from "../common/func-cache";
const GROUPS = config.get("ui.overview.groups");
const GROUPS = config.ui.overview.groups;
const CHARTS = {};
for (let group of Object.values(GROUPS))
for (let chartName of Object.values(group["charts"]))
CHARTS[chartName] = config.get("ui.overview.charts")[chartName];
CHARTS[chartName] = config.ui.overview.charts[chartName];
function queryCharts(charts) {
charts = Object.assign({}, charts);
for (let [chartName, chart] of Object.entries(charts)) {
charts[chartName] = chart = Object.assign({}, chart);
chart.slices = Object.assign({}, chart.slices);
for (let [sliceName, slice] of Object.entries(chart.slices)) {
const filter = funcCache.get(Filter.parse, slice.filter);
chart.slices[sliceName] = slice = Object.assign({}, slice);
slice.count = store.count("devices", slice.filter);
slice.count = store.count("devices", filter);
}
}
return charts;
@@ -33,7 +37,7 @@ const init = function() {
};
const component = {
view: () => {
view: vnode => {
document.title = "Overview - GenieACS";
let children = [];
for (let group of Object.values(GROUPS)) {
@@ -41,7 +45,7 @@ const component = {
let groupChildren = [];
for (let chartName of Object.values(group.charts)) {
const chart = CHARTS[chartName];
const chart = vnode.attrs.charts[chartName];
let chartChildren = [];
if (chart.label) chartChildren.push(m("h2", chart.label));
+2 -2
View File
@@ -28,7 +28,7 @@ const drawChart = function(chartData) {
"a",
{
href: `/#!/devices/?${m.buildQueryString({
filter: slice.filter.toString()
filter: slice.filter
})}`
},
slice.count.value || 0
@@ -68,7 +68,7 @@ const drawChart = function(chartData) {
"a",
{
href: `/#!/devices/?${m.buildQueryString({
filter: slice.filter.toString()
filter: slice.filter
})}`
},
[
+2 -1
View File
@@ -2,8 +2,9 @@
import m from "mithril";
import Filter from "../common/filter";
import * as config from "./config";
import config from "./config";
import * as filterParser from "../common/filter-parser";
import * as funcCache from "../common/func-cache";
let fulfillTimestamp = 0;