Refactor dashlet factory into its own index file, so it's obvious where to add them.

This commit is contained in:
Herbert Wolverson 2024-06-26 13:42:37 -05:00
parent ab240de711
commit d1f37ed164
2 changed files with 35 additions and 35 deletions

View File

@ -1,12 +1,7 @@
import {subscribeWS, resetWS} from "../pubsub/ws";
import {ThroughputBpsDash} from "./throughput_bps_dash";
import {ThroughputPpsDash} from "./throughput_pps_dash";
import {ShapedUnshapedDash} from "./shaped_unshaped_dash";
import {TrackedFlowsCount} from "./tracked_flow_count_dash";
import {ThroughputRingDash} from "./throughput_ring_dash";
import {RttHistoDash} from "./rtt_histo_dash";
import {darkBackground, modalContent} from "../helpers/our_modals";
import {heading5Icon, theading} from "../helpers/builders";
import {DashletMenu, widgetFactory} from "./dashlet_index";
export class Dashboard {
// Takes the name of the parent div to start building the dashboard
@ -50,7 +45,7 @@ export class Dashboard {
#filterWidgetList() {
this.dashlets = [];
for (let i=0; i<this.dashletIdentities.length; i++) {
let widget = this.#factory(i);
let widget = widgetFactory(this.dashletIdentities[i].tag, i);
if (widget == null) continue; // Skip build
widget.size = this.dashletIdentities[i].size;
this.dashlets.push(widget);
@ -104,24 +99,6 @@ export class Dashboard {
return false;
}
#factory(count) {
let widgetName = this.dashletIdentities[count].tag;
let widget = null;
switch (widgetName) {
case "throughputBps": widget = new ThroughputBpsDash(count); break;
case "throughputPps": widget = new ThroughputPpsDash(count); break;
case "shapedUnshaped": widget = new ShapedUnshapedDash(count); break;
case "trackedFlowsCount": widget = new TrackedFlowsCount(count); break;
case "throughputRing": widget = new ThroughputRingDash(count); break;
case "rttHistogram": widget = new RttHistoDash(count); break;
default: {
console.log("I don't know how to construct a widget of type [" + widgetName + "]");
return null;
}
}
return widget;
}
editMode() {
let darken = darkBackground("darkEdit");
let content = modalContent("darkEdit");
@ -516,13 +493,4 @@ class Layout {
let template = JSON.stringify(dashletIdentities);
localStorage.setItem("dashboardLayout", template);
}
}
const DashletMenu = [
{ name: "Throughput Bits/Second", tag: "throughputBps", size: 3 },
{ name: "Throughput Packets/Second", tag: "throughputPps", size: 3 },
{ name: "Shaped/Unshaped Pie", tag: "shapedUnshaped", size: 3 },
{ name: "Tracked Flows Counter", tag: "trackedFlowsCount", size: 3 },
{ name: "Last 5 Minutes Throughput", tag: "throughputRing", size: 6 },
{ name: "Round-Trip Time Histogram", tag: "rttHistogram", size: 6 },
];
}

View File

@ -0,0 +1,32 @@
import {ThroughputBpsDash} from "./throughput_bps_dash";
import {ThroughputPpsDash} from "./throughput_pps_dash";
import {ShapedUnshapedDash} from "./shaped_unshaped_dash";
import {TrackedFlowsCount} from "./tracked_flow_count_dash";
import {ThroughputRingDash} from "./throughput_ring_dash";
import {RttHistoDash} from "./rtt_histo_dash";
export const DashletMenu = [
{ name: "Throughput Bits/Second", tag: "throughputBps", size: 3 },
{ name: "Throughput Packets/Second", tag: "throughputPps", size: 3 },
{ name: "Shaped/Unshaped Pie", tag: "shapedUnshaped", size: 3 },
{ name: "Tracked Flows Counter", tag: "trackedFlowsCount", size: 3 },
{ name: "Last 5 Minutes Throughput", tag: "throughputRing", size: 6 },
{ name: "Round-Trip Time Histogram", tag: "rttHistogram", size: 6 },
];
export function widgetFactory(widgetName, count) {
let widget = null;
switch (widgetName) {
case "throughputBps": widget = new ThroughputBpsDash(count); break;
case "throughputPps": widget = new ThroughputPpsDash(count); break;
case "shapedUnshaped": widget = new ShapedUnshapedDash(count); break;
case "trackedFlowsCount": widget = new TrackedFlowsCount(count); break;
case "throughputRing": widget = new ThroughputRingDash(count); break;
case "rttHistogram": widget = new RttHistoDash(count); break;
default: {
console.log("I don't know how to construct a widget of type [" + widgetName + "]");
return null;
}
}
return widget;
}