Change array structure

This commit is contained in:
Rob Vella 2020-07-31 02:31:08 -07:00
parent 175b976f40
commit c55f408428
3 changed files with 13 additions and 15 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
yarn-error.log yarn-error.log
storage/* storage/*
/vendor/

24
app.js
View File

@ -6,11 +6,10 @@
*/ */
Vue.component('lt-node-link', { Vue.component('lt-node-link', {
template: `<a :href='uri' target="_blank">{{ node }}</a>`, template: `<a :href='getUrl()' target="_blank">{{ node }}</a>`,
props: ['node', 'type'], props: ['node', 'type'],
data() { data() {
return { return {
uri: '',
urlMap: { urlMap: {
0: '#', 0: '#',
1: 'http://stats.allstarlink.org/nodeinfo.cgi?node=', 1: 'http://stats.allstarlink.org/nodeinfo.cgi?node=',
@ -18,8 +17,10 @@ Vue.component('lt-node-link', {
} }
} }
}, },
mounted() { methods: {
this.uri = this.urlMap[this.type] + this.node; getUrl() {
return this.urlMap[this.type] + this.node;
}
} }
}); });
@ -34,10 +35,7 @@ let App = new Vue({
uri: 'fetchData.php', uri: 'fetchData.php',
lastData: null, lastData: null,
logs: [], logs: [],
nodes: { nodes: {},
1: [],
2: []
},
nodeTypeLabels: { nodeTypeLabels: {
0: 'Unknown', 0: 'Unknown',
1: 'Allstar', 1: 'Allstar',
@ -87,8 +85,8 @@ let App = new Vue({
}, },
getNodeInfo(node, type) { getNodeInfo(node, type) {
if (typeof this.nodes[type][node] !== "undefined") { if (typeof this.nodes[type+node] !== "undefined") {
let info = this.nodes[type][node]; let info = this.nodes[type+node];
if (typeof info.callsign === "undefined") return; if (typeof info.callsign === "undefined") return;
return `${info.callsign} ${info.desc} ${info.location}`; return `${info.callsign} ${info.desc} ${info.location}`;
} else { } else {
@ -133,13 +131,13 @@ let App = new Vue({
// if (typeof this.nodes[type][node] === "undefined") { // if (typeof this.nodes[type][node] === "undefined") {
// this.nodes[type][node] = null; // this.nodes[type][node] = null;
// return this.fetchNodeInfo(node, type); // return this.fetchNodeInfo(node, type);
if (this.nodes[type][node]) { if (this.nodes[type+node]) {
// Don't even call fetchNode** // Don't even call fetchNode**
return this.nodes[type][node]; return this.nodes[type+node];
} }
axios.get(this.uri + '?cmd=node&type='+type+'&node='+node).then(({data}) => { axios.get(this.uri + '?cmd=node&type='+type+'&node='+node).then(({data}) => {
this.nodes[type][node] = data; this.nodes[type+node] = data;
}); });
}, },

View File

@ -29,8 +29,6 @@ return;
function fetchNodeInfoAllstar($node) { function fetchNodeInfoAllstar($node) {
$db = fetchAllStarDb(); $db = fetchAllStarDb();
if (empty($node)) return [];
$db = explode("\n", $db); $db = explode("\n", $db);
foreach ($db as $row) { foreach ($db as $row) {
$row = explode("|", $row); $row = explode("|", $row);