Skip to content

Commit

Permalink
Include APs from stored readings in dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDesmond-ca committed Dec 14, 2021
1 parent 961c471 commit 896d663
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
18 changes: 18 additions & 0 deletions App.Tests/APFormTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions App/SharedState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AppViewModel from "./AppViewModel";
import Factory from "./Factory";

export default new AppViewModel(Factory.signalService);
export default new AppViewModel();
21 changes: 15 additions & 6 deletions App/ap-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
Expand Down

0 comments on commit 896d663

Please sign in to comment.