From 896d663053dab54d1e3d715d108337de4e31b53a Mon Sep 17 00:00:00 2001 From: Steve Desmond Date: Tue, 14 Dec 2021 08:15:51 -0500 Subject: [PATCH] Include APs from stored readings in dropdown --- App.Tests/APFormTests.ts | 18 ++++++++++++++++++ App/SharedState.ts | 3 +-- App/ap-form.vue | 21 +++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/App.Tests/APFormTests.ts b/App.Tests/APFormTests.ts index dcdb72f2..95c6d35d 100644 --- a/App.Tests/APFormTests.ts +++ b/App.Tests/APFormTests.ts @@ -120,4 +120,22 @@ export default class APFormTests extends TestSuite { this.assert.notNull(checkbox.attributes("disabled")); this.assert.undefined(checkbox.attributes("checked")); } + + @Test() + async combinesDuplicateLabels() { + //arrange + const state = new AppViewModel(); + state.current = new Reading(0, new Point(0, 0), APFormTests.signals); + state.readings = [ + new Reading(1, new Point(3, 4), APFormTests.signals), + new Reading(2, new Point(5, 6), APFormTests.signals) + ]; + const component = mount(APForm, { data: () => ({ state: state }) }); + + //act + const signals = component.vm.access_points; + + //assert + this.assert.equal(2, signals.length); + } } \ No newline at end of file diff --git a/App/SharedState.ts b/App/SharedState.ts index f8cad85c..4243f743 100644 --- a/App/SharedState.ts +++ b/App/SharedState.ts @@ -1,4 +1,3 @@ import AppViewModel from "./AppViewModel"; -import Factory from "./Factory"; -export default new AppViewModel(Factory.signalService); \ No newline at end of file +export default new AppViewModel(); \ No newline at end of file diff --git a/App/ap-form.vue b/App/ap-form.vue index 98f587e0..97f984c2 100644 --- a/App/ap-form.vue +++ b/App/ap-form.vue @@ -27,19 +27,28 @@ import Vue from 'vue'; import AccessPoint from './AccessPoint'; import SharedState from "./SharedState"; +import Signal from "./Signal"; export default Vue.extend({ data: () => ({ state: SharedState, }), computed: { + all_signals(): Signal[] { + return [ ...this.state.current.signals, ...this.state.readings.flatMap(r => r.signals) ]; + }, + all_access_points(): AccessPoint[] { + return this.all_signals.map(s => + new AccessPoint(s.ssid, + this.state.group_by.frequency ? null : s.frequency, + this.state.group_by.ssid ? null : s.mac) + ) + }, access_points(): AccessPoint[] { - return this.state.current.signals.map(signal => - new AccessPoint(signal.ssid, - this.state.group_by.frequency ? null : signal.frequency, - this.state.group_by.ssid ? null : signal.mac) - ).sort((ap1, ap2) => ap1.compareTo(ap2)) - .filter((ap, index, array) => array.map(a => a.label()).indexOf(ap.label()) === index); + const labels = this.all_access_points.map(a => a.label()); + return this.all_access_points + .filter((ap, index) => labels.indexOf(ap.label()) === index) + .sort((ap1, ap2) => ap1.compareTo(ap2)); } } });