From 09ec3d808c89745d134a051c8e4d53de9eff6833 Mon Sep 17 00:00:00 2001 From: Matthew Topol Date: Fri, 8 Feb 2019 20:00:15 -0500 Subject: [PATCH] Fix up the handling of events and different schedules --- .env.development | 2 +- src/App.vue | 5 ----- src/components/NavBar.vue | 11 ++++------- src/mixins/grid-mixin.ts | 16 +++++++++++++++- src/router.ts | 32 ++------------------------------ src/store/index.ts | 8 ++++++++ src/store/states.ts | 1 + 7 files changed, 31 insertions(+), 44 deletions(-) diff --git a/.env.development b/.env.development index 8006690..c5801fb 100644 --- a/.env.development +++ b/.env.development @@ -1 +1 @@ -VUE_APP_BACKEND_HOST=http://fxdeva16.factset.com:8090 +VUE_APP_BACKEND_HOST=http://localhost:8090 diff --git a/src/App.vue b/src/App.vue index f9396d8..021572e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -27,13 +27,8 @@ import EventDialog from '@/components/EventDialog.vue'; }, }) export default class Layout extends Vue { - @Action('fetchScheds') public fetchScheds!: () => Promise; @Getter('auth/admin') public isAdmin!: boolean; public drawer = null; - - public mounted() { - this.fetchScheds(); - } } diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 04e68c6..868c850 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -54,20 +54,17 @@ export default class NavBar extends Vue { @State('schedules') public items!: Schedule[]; @Getter('auth/userfavs') public userfavs!: number[]; @Mutation('showModal') public showModal!: (payload: {ev: Event, color: string}) => void; - - public get select(): number { - return this.items.findIndex((s) => s.id === this.$route.params.id); - } + @Getter('curSchedule') public curSchedule!: Schedule; public get favs(): Event[] { - if (this.items.length <= this.select) { return []; } + if (!this.items.length) { return []; } - return this.items[this.select].events.filter((e) => this.userfavs.includes(e.id)) + return this.curSchedule.events.filter((e) => this.userfavs.includes(e.id)) .sort((a, b) => a.start.diff(b.start)); } public eventColor(ev: Event): string { - return this.items[this.select].colorMap[ev.room]; + return this.curSchedule.colorMap[ev.room]; } } diff --git a/src/mixins/grid-mixin.ts b/src/mixins/grid-mixin.ts index 3cdc790..f7eb87d 100644 --- a/src/mixins/grid-mixin.ts +++ b/src/mixins/grid-mixin.ts @@ -1,12 +1,26 @@ -import { Component, Prop, Vue } from 'vue-property-decorator'; +import { Component, Prop, Watch, Vue } from 'vue-property-decorator'; import { Schedule } from '@/api/schedule'; +import { Mutation, Action } from 'vuex-class'; import moment from 'moment'; @Component export default class GridMixin extends Vue { @Prop(Number) public id!: number; + @Action('fetchScheds') public fetchScheds!: () => Promise; + @Mutation('setCurSchedule') public setSched!: (id: number) => void; + public pixelHeight = 50; + public async mounted() { + await this.fetchScheds(); + this.setSched(this.id); + } + + @Watch('id') + public load(val: number) { + this.setSched(this.id); + } + public get times(): string[] { if (!this.sched) { return []; } return this.sched.times(); diff --git a/src/router.ts b/src/router.ts index fefbe70..1feaa5e 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,31 +1,3 @@ -<<<<<<< Updated upstream -import Vue from 'vue'; -import VueRouter, { Route } from 'vue-router'; -Vue.use(VueRouter); - -export default new VueRouter({ - mode: 'history', - base: process.env.BASE_URL, - routes: [ - { path: '/', redirect: '/rooms' }, - { - path: '/rooms', name: 'home', - component: () => import(/* webpackChunkName: "group-app" */ '@/views/RoomGrid.vue'), - }, - { - path: '/agenda', name: 'agenda', - component: () => import(/* webpackChunkName: "group-app" */ '@/views/Agenda.vue'), - }, - { - path: '/events', name: 'events', - component: () => import(/* webpackChunkName: "group-app" */ '@/views/Events.vue'), - }, - { - path: '/callback', component: () => import(/* webpackChunkName: "group-auth" */ '@/views/Auth.vue'), name: 'auth', - }, - ], -}); -======= import Vue from 'vue'; import VueRouter, { Route } from 'vue-router'; Vue.use(VueRouter); @@ -53,8 +25,8 @@ export default new VueRouter({ component: () => import(/* webpackChunkName: "group-app" */ '@/views/Events.vue'), }, { - path: '/callback', component: () => import(/* webpackChunkName: "group-auth" */ '@/views/Auth.vue'), name: 'auth', + path: '/callback', component: () => import(/* webpackChunkName: "group-auth" */ '@/views/Auth.vue'), + name: 'auth', }, ], }); ->>>>>>> Stashed changes diff --git a/src/store/index.ts b/src/store/index.ts index da90ed4..3137db1 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -15,6 +15,7 @@ export default new Vuex.Store({ }, state: { schedules: [], + curSchedule: 0, showModal: false, modalEvent: null, modalColor: '', @@ -23,8 +24,15 @@ export default new Vuex.Store({ getScheduleById: (state) => (id: number) => { return state.schedules.find((s) => s.id === id); }, + curSchedule(state: RootState): Schedule { + return state.schedules[state.curSchedule]; + }, }, mutations: { + setCurSchedule(state: RootState, id: number) { + state.curSchedule = state.schedules.findIndex((s) => s.id === id); + state.schedules[state.curSchedule].loadEvents(); + }, setScheds(state: RootState, scheds: Schedule[]) { state.schedules = scheds; }, diff --git a/src/store/states.ts b/src/store/states.ts index 3ea0eb4..e6c9e5e 100644 --- a/src/store/states.ts +++ b/src/store/states.ts @@ -22,4 +22,5 @@ export interface RootState { showModal: boolean; modalEvent: Event | null; modalColor: string; + curSchedule: number; }