From 07bfdc9acfe8f06d82a9aa062a7da878d5cf77cf Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Tue, 12 Sep 2017 13:55:55 -0700 Subject: [PATCH] Clean up and simplify the Salmon Run admin dialog --- .../splatoon/SalmonRunAdminDialog.vue | 68 +++++++------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/src/js/components/splatoon/SalmonRunAdminDialog.vue b/src/js/components/splatoon/SalmonRunAdminDialog.vue index 433b7df..c345f6d 100644 --- a/src/js/components/splatoon/SalmonRunAdminDialog.vue +++ b/src/js/components/splatoon/SalmonRunAdminDialog.vue @@ -5,7 +5,7 @@

Salmon Run Times

- +
{{ event.start_time | date }} @@ -16,15 +16,15 @@
-
- - +
-
-
-
+
+
+
@@ -83,9 +83,8 @@ export default { SplatoonStages.find(stage => stage.id == '999903'), ], weaponSearchTerm: '', - selectedStartTime: null, - stageSelections: {}, - weaponSelections: {}, + schedules: null, + selectedSchedule: null, }; }, computed: { @@ -94,34 +93,14 @@ export default { return Object.values(this.weapons).filter(weapon => weapon.name.toLowerCase().indexOf(this.weaponSearchTerm) > -1); }, output() { - let schedules = this.coopCalendar.map(event => { - let schedule = Object.assign({}, event); - delete schedule.stage; - delete schedule.weapons; - - let stage = this.stageSelections[event.start_time]; - if (stage) - schedule.stage = { id: stage.id, name: stage.name }; - - let weapons = this.weaponSelections[event.start_time]; - if (weapons && weapons.length) - schedule.weapons = weapons; - - return schedule; - }); - return JSON.stringify(schedules); + return JSON.stringify(this.schedules); }, }, created() { this.updateWeapons(); // Load existing weapon/map selections - for (event of this.coopCalendar) { - if (event.stage) - Vue.set(this.stageSelections, event.start_time, Object.assign({}, event.stage)); - if (event.weapons) - Vue.set(this.weaponSelections, event.start_time, event.weapons.slice()); - } + this.schedules = (this.coopCalendar) ? JSON.parse(JSON.stringify(this.coopCalendar)) : []; }, methods: { updateWeapons() { @@ -129,26 +108,29 @@ export default { .then(response => this.weapons = response.data); }, setStage(stage) { - if (this.selectedStartTime) - Vue.set(this.stageSelections, this.selectedStartTime, stage); + if (this.selectedSchedule) + Vue.set(this.selectedSchedule, 'stage', stage); }, - clearStage(startTime) { - Vue.delete(this.stageSelections, startTime); + clearStage(schedule) { + Vue.delete(schedule, 'stage'); }, addWeapon(weapon) { - if (!this.selectedStartTime) + if (!this.selectedSchedule) return; - if (!this.weaponSelections[this.selectedStartTime]) - Vue.set(this.weaponSelections, this.selectedStartTime, []); + if (!this.selectedSchedule.weapons) + Vue.set(this.selectedSchedule, 'weapons', []); - this.weaponSelections[this.selectedStartTime].push(weapon); + this.selectedSchedule.weapons.push(weapon); this.weaponSearchTerm = ''; }, - removeWeapon(startTime, weapon) { - let index = this.weaponSelections[startTime].indexOf(weapon); - this.weaponSelections[startTime].splice(index, 1); + removeWeapon(schedule, weapon) { + let index = schedule.weapons.indexOf(weapon); + schedule.weapons.splice(index, 1); + + if (!schedule.weapons.length) + Vue.delete(schedule, 'weapons'); }, }, }