55 v-container
66 p( class ="body-2 mb-10" ) Lab hours are from 9:00 AM to 4:30 PM.
77 div( v-for ="day in days" : key= "day" )
8- v-row
9- v-col( cols ='3' )
10- p( class ="font-weight-medium body-2" ) {{day}}
11- v-col( cols ='4' )
12- timePicker( :index = 'startTime1' : day= 'day' )
13- v-col( cols ='4' )
14- timePicker( :index = 'endTime1' : day= 'day' )
15- v-col( cols ='1' )
16- v-btn( icon color ="#F2594B" v-on:click ="isHidden=true" )
17- v-icon mdi-plus-circle-outline
8+ div( v-if ="availabilityTimes[day].length===0" )
9+ v-row
10+ v-col( cols ='3' )
11+ p( class ="font-weight-medium body-2" ) {{day}}
12+ v-col( cols ='4' )
13+ timePicker( :day ='day' : index= 'startTime1' )
14+ v-col( cols ='4' )
15+ timePicker( :day ='day' : index= 'endTime1' )
16+ v-col( cols ='1' )
17+ v-btn( icon color ="#F2594B" @click ="updateAvailability(day)" )
18+ v-icon mdi-plus-circle-outline
19+ div( v-else )
20+ div( v-for ="(avItem, avIndex) in availabilityTimes[day]" : key= "day + avIndex.toString()" )
21+ v-row
22+ v-col( cols ='3' )
23+ p( class ="font-weight-medium body-2" ) {{day}}
24+ v-col( cols ='4' )
25+ timePicker( :day ='day' : index= 'startTime1' )
26+ v-col( cols ='4' )
27+ timePicker( :day ='day' : index= 'endTime1' )
28+ v-col( cols ='1' )
29+ v-btn( icon color ="#F2594B" @click ="updateAvailability(day)" )
30+ v-icon mdi-plus-circle-outline
1831 v-row( class ="mt-n6 mb-4" v-if ="isHidden" )
1932 v-col( cols ='3' )
2033 v-col( cols ='4' )
21- timePicker( :index = 'startTime2 ' : day = 'day ')
22- v-col( cols ='4' )
23- timePicker( :index = 'endTime2 ' : day = 'day ')
34+ timePicker( :day = 'day ' : index = 'startTime2 ')
35+ v-col( cols ='4' )
36+ timePicker( :day = 'day ' : index = 'endTime2 ')
2437 v-col( cols ='1' )
2538 v-row
2639 v-col.pt-4 ( cols ='3' )
27- p.pt-3 ( class ="font-weight-medium body-2" ) Max Hours
40+ p.pt-3 ( class ="font-weight-medium body-2" ) Max Hours
2841 v-col( cols ='3' )
29- v-text-field( v-model ="maxHours" @input ='formatMaxHours()' outlined dense )
42+ v-text-field( v-model ="maxHours" @input ='formatMaxHours()' outlined dense )
3043 v-card-actions
3144 v-spacer
3245 v-btn( color ="grey" text @click ="dialog = false" ) Cancel
3346 v-btn( color ="#F2594B" medium class ="white--text" @click ="postSched()" ) Submit
3447
3548 h3.mb-5 Previous Schedules
36- v-data-table( :headers ="headers"
37- :items ="schedules"
38- :items-per-page ="5"
39- item-key ='id'
40- class ="elevation-1"
41- :single-select ="singleSelect"
42- :loading ='loading'
49+ v-data-table( :headers ="headers"
50+ :items ="schedules"
51+ :items-per-page ="5"
52+ item-key ='id'
53+ class ="elevation-1"
54+ :single-select ="singleSelect"
55+ :loading ='loading'
4356 :loading-text ="loadingText"
4457 :sort-by ="['created']"
4558 :sort-desc ="[true]"
4659 )
4760 template( v-slot:item.actions ="{ item }" )
4861 v-icon( v-if ="item.status == 'Pending'" @click ="deleteAvail(item.id)" ) mdi-delete
62+
4963</template >
5064<script lang="ts">
5165import ' @mdi/font/css/materialdesignicons.css'
52- import { Component , Prop , Vue , Watch } from ' vue-property-decorator' ;
66+ import { Component , Prop , Vue , Watch } from ' vue-property-decorator'
5367import { mixins } from ' vue-class-component'
54- import Vuex from ' vuex' ;
68+ import Vuex from ' vuex'
5569import timePicker from ' @/components/global/timePicker.vue'
56- import store from ' @/store' ;
70+ import store from ' @/store'
5771import {formattedSchedule , schedule } from ' @/interfaces/GlobalTypes'
58-
5972import { ScheduleBase } from ' @/components/Bases/ScheduleBase'
6073
6174const axios = require (' axios' )
@@ -69,12 +82,21 @@ const axios = require('axios')
6982})
7083
7184export default class Availability extends ScheduleBase {
72-
73- private singleSelect: boolean = false ;
74- private loading: boolean = false ;
85+
86+ private singleSelect: boolean = false
87+ private loading: boolean = false
7588 private loadingText: string = ' The sched-o-matic is working hard on your request'
7689 private dialog: boolean = false
77- private schedules: formattedSchedule [] = [];
90+ private startTime1: string = " startTime1"
91+ private endTime1: string = " endTime1"
92+ private startTime2: string = " startTime2"
93+ private endTime2: string = " endTime2"
94+ private isHidden: boolean = false
95+ private availabilityTimes: { [x : string ]: any []; } = {}
96+ private days = [" Monday" , " Tuesday" , " Wednesday" , " Thursday" , " Friday" ]
97+ private time_suffixes = [' _start_1' , ' _start_2' , ' _end_1' , ' _end_2' ]
98+ private day_time_strings: string [] = []
99+ private schedules: formattedSchedule [] = []
78100
79101 headers = [
80102 {text: ' Submitted' , value: ' created' },
@@ -87,61 +109,79 @@ export default class Availability extends ScheduleBase {
87109 {text: ' Max Hours' , value: ' max_hours' },
88110 {text: ' Delete' , value: ' actions' },
89111 // d-none must have leading space in string to work. Hide from table but id is still attached
90- {text: ' Id' , value: ' id' , align: ' d-none' }
91- ];
92-
112+ {text: ' Id' , value: ' id' , align: ' d-none' }
113+ ]
93114
94115 constructor () {
95- super ();
116+ super ()
96117 }
97118
119+ updateAvailability(day : string ) {
120+ this .day_time_strings = []
121+ var day_abbrev = day .slice (0 , 3 ).toLowerCase ()
122+ for (var time of this .time_suffixes ) {
123+ this .day_time_strings .push (day_abbrev + time )
124+ }
125+ this .$axios .patch (' /schedules/availability/update' , {
126+ time_strings: this .day_time_strings ,
127+ sched_times: store .getters .getDaySched (day )
128+ })
129+ .then ((response : any ) => {
130+ var updated_time = this .formatDayTime (response .data .day )
131+ var index = this .schedules .length - 1
132+ this .schedules [index ][day_abbrev ] = updated_time
133+ })
134+ .catch (function (error : any ) {
135+ console .log (error )
136+ })
137+ }
98138
99139 created() {
100- this .loading = true ;
101- this .$axios .get (' /schedules/user/availability' )
140+ for (var day of this .days ) {
141+ this .availabilityTimes [day ] = []
142+ }
143+ this .loading = true
144+ this .$axios .get (' /schedules/user/availability' )
102145 .then (response => {
103146 response .data .forEach ((schedule : schedule ) => {
104- this .timeFormat (schedule , this .schedules )
105- });
106- this .loading = false ;
147+ this .formatScheduleTime (schedule , this .schedules )
148+ })
149+ this .loading = false
107150 })
108151 .catch (function (error : any ) {
109- console .log (error );
152+ console .log (error )
110153 })
111154 .then (function () {
112155 // always executed
113- });
156+ })
114157 }
115158
116-
117-
118159 postSched() {
119- let maxHoursDecimal = Number .parseFloat (this .maxHours ).toFixed (2 );
160+ let maxHoursDecimal = Number .parseFloat (this .maxHours ).toFixed (2 )
120161 this .$axios .post (' /schedules/availability/create' , {
121162 schedule: store .getters .timeValues ,
122163 maxHours: maxHoursDecimal
123164 })
124165 .then ((response : any ) => {
125- this .timeFormat (response .data ,this .schedules )
166+ this .formatScheduleTime (response .data ,this .schedules )
126167 })
127168 .catch (function (error : any ) {
128- console .log (error );
169+ console .log (error )
129170 })
130171 }
131172
132173 deleteAvail(id : number ) {
133174 this .$axios .delete (' /schedules/availability/delete/' + id )
134175 .then ((response : any ) => {
135- var removeIndex = this .schedules .map (item => item .id ).indexOf (id );
136- ~ removeIndex && this .schedules .splice (removeIndex , 1 );
176+ var removeIndex = this .schedules .map (item => item .id ).indexOf (id )
177+ ~ removeIndex && this .schedules .splice (removeIndex , 1 )
137178 })
138179 .catch (function (error : any ) {
139- console .log (error );
180+ console .log (error )
140181 })
141- }
142-
143-
182+ }
144183}
184+
145185 </script >
146186
147187<style scoped>
0 commit comments