From 0144f0afe490782e178cae4ed51971f47c25b6e5 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Sat, 16 Jan 2021 21:34:55 +0100 Subject: [PATCH] simple abm info --- app/index.html | 1 + app/js/components/abm-info.js | 28 ++++++++++++++++++++ app/js/components/nav-bar.js | 4 +-- app/js/components/node-detail.js | 45 ++++++++++++++++++++++++++++++++ app/js/components/node-info.js | 22 ++-------------- app/js/main.js | 3 +++ app/js/util/compute_abm_nodes.js | 16 ++++++++++++ 7 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 app/js/components/abm-info.js diff --git a/app/index.html b/app/index.html index 71f14d5..b26b2dc 100644 --- a/app/index.html +++ b/app/index.html @@ -26,6 +26,7 @@ + diff --git a/app/js/components/abm-info.js b/app/js/components/abm-info.js new file mode 100644 index 0000000..de3713c --- /dev/null +++ b/app/js/components/abm-info.js @@ -0,0 +1,28 @@ +Vue.component("abm-info", { + props: ["abm_key"], + created: function(){ + this.abm = mtinfo.abm_labels[this.abm_key]; + + //TODO: debug + console.log(this.abm, this.abm_key); + }, + template: /*html*/` +
+

{{ abm_key }}

+

Chance: {{ abm.chance }}

+

Interval: {{ abm.interval }}

+

Nodenames

+ +

Neighbors

+ +
+ ` +}); diff --git a/app/js/components/nav-bar.js b/app/js/components/nav-bar.js index 75d92a7..12b6501 100644 --- a/app/js/components/nav-bar.js +++ b/app/js/components/nav-bar.js @@ -10,8 +10,8 @@ Vue.component("nav-bar", { diff --git a/app/js/components/node-detail.js b/app/js/components/node-detail.js index 44d3427..9cf07bf 100644 --- a/app/js/components/node-detail.js +++ b/app/js/components/node-detail.js @@ -1,6 +1,35 @@ Vue.component("node-detail", { props: ["node"], + created: function(){ + let abms = []; + let abm_neighbors = []; + + if (mtinfo.abm_nodenames[this.name]){ + abms.push(mtinfo.abm_nodenames[this.name]); + } + if (mtinfo.abm_neighbors[this.name]){ + abm_neighbors.push(mtinfo.abm_neighbors[this.name]); + } + if (this.node.groups){ + Object.keys(this.node.groups).forEach(function(group){ + const name = "group:" + group; + if (mtinfo.abm_nodenames[name]){ + abms.push(mtinfo.abm_nodenames[name]); + } + if (mtinfo.abm_neighbors[name]){ + abm_neighbors.push(mtinfo.abm_neighbors[name]); + } + }); + } + + this.abms = abms; + this.abm_neighbors = abm_neighbors; + + //TODO: debug + console.log("abms", this.abms); + console.log("abm_neighbors", this.abm_neighbors); + }, template: /*html*/`

{{ node.description }} {{ node.name }}

@@ -18,6 +47,22 @@ Vue.component("node-detail", { {{ group }} {{ node.groups[group] }} +

ABMS

+ +

Neighbor ABMS

+
` }); diff --git a/app/js/components/node-info.js b/app/js/components/node-info.js index 5b4526b..20d8827 100644 --- a/app/js/components/node-info.js +++ b/app/js/components/node-info.js @@ -2,28 +2,10 @@ Vue.component("node-info", { props: ["name"], created: function(){ - //TODO: debug - const nodename = this.name; const nodedef = mtinfo.nodes[this.name]; - console.log(nodedef); - if (mtinfo.abm_nodenames[this.name]){ - console.log("abm nodename", mtinfo.abm_nodenames[this.name]); - } - if (mtinfo.abm_neighbors[this.name]){ - console.log("abm neighbor", mtinfo.abm_neighbors[this.name]); - } - if (nodedef.groups){ - Object.keys(nodedef.groups).forEach(function(group){ - const name = "group:" + group; - if (mtinfo.abm_nodenames[name]){ - console.log("abm group nodename", mtinfo.abm_nodenames[name]); - } - if (mtinfo.abm_neighbors[name]){ - console.log("abm group neighbor", mtinfo.abm_neighbors[name]); - } - }); - } + //TODO: debug + console.log(nodedef); }, computed: { previewImage: function(){ diff --git a/app/js/main.js b/app/js/main.js index b59d94d..bfec9a7 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -9,6 +9,9 @@ const router = new VueRouter({ },{ path: "/nodes/:name", component: { template: `` } + },{ + path: "/abms/:abm_key", + component: { template: `` } }] }); diff --git a/app/js/util/compute_abm_nodes.js b/app/js/util/compute_abm_nodes.js index e15815f..4728d93 100644 --- a/app/js/util/compute_abm_nodes.js +++ b/app/js/util/compute_abm_nodes.js @@ -8,6 +8,20 @@ mtinfo.abm_neighbors[nodename_or_group] = abm mtinfo.abm_nodenames = {}; mtinfo.abm_neighbors = {}; +mtinfo.abm_labels = {}; + +function register_abm_label(abm, index){ + const key = (abm.label || "abm") + (index ? ("_" + index) : ""); + if (!mtinfo.abm_labels[key]){ + // create + mtinfo.abm_labels[key] = abm; + abm.key = key; + + } else { + // try another index + register_abm_label(abm, index || 1); + } +} mtinfo.abm.forEach(function(abm){ abm.nodenames.forEach(function(nodename){ @@ -22,4 +36,6 @@ mtinfo.abm.forEach(function(abm){ }); } } + + register_abm_label(abm); });