-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathFreeBusy.vue
304 lines (290 loc) Β· 8.16 KB
/
FreeBusy.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!--
- @copyright Copyright (c) 2019 Georg Ehrke <[email protected]>
-
- @author Georg Ehrke <[email protected]>
-
- @license AGPL-3.0-or-later
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<Modal size="large"
:title="$t('calendar', 'Availability of attendees, resources and rooms')"
@close="$emit('close')">
<div class="modal__content modal--scheduler">
<div v-if="loadingIndicator" class="loading-indicator">
<div class="icon-loading" />
</div>
<FullCalendar ref="freeBusyFullCalendar"
:options="options" />
<div class="freebusy-caption">
<div class="freebusy-caption__calendar-user-types" />
<div class="freebusy-caption__colors">
<div v-for="color in colorCaption" :key="color.color" class="freebusy-caption-item">
<div class="freebusy-caption-item__color" :style="{ 'background-color': color.color }" />
<div class="freebusy-caption-item__label">
{{ color.label }}
</div>
</div>
</div>
</div>
</div>
<DatePicker ref="datePicker"
:date="currentDate"
:is-all-day="true"
@change="setCurrentDate" />
</Modal>
</template>
<script>
// Import FullCalendar itself
import FullCalendar from '@fullcalendar/vue'
import resourceTimelinePlugin from '@fullcalendar/resource-timeline'
// Import event sources
import freeBusyBlockedForAllEventSource from '../../../fullcalendar/eventSources/freeBusyBlockedForAllEventSource.js'
import freeBusyFakeBlockingEventSource from '../../../fullcalendar/eventSources/freeBusyFakeBlockingEventSource.js'
import freeBusyResourceEventSource from '../../../fullcalendar/eventSources/freeBusyResourceEventSource.js'
// Import localization plugins
import { getDateFormattingConfig } from '../../../fullcalendar/localization/dateFormattingConfig.js'
import { getFullCalendarLocale } from '../../../fullcalendar/localization/localeProvider.js'
import momentPluginFactory from '../../../fullcalendar/localization/momentPlugin.js'
// Import timezone plugins
import VTimezoneNamedTimezone from '../../../fullcalendar/timezones/vtimezoneNamedTimezoneImpl.js'
import {
mapGetters,
mapState,
} from 'vuex'
import { NcModal as Modal } from '@nextcloud/vue'
import DatePicker from '../../Shared/DatePicker.vue'
import { getColorForFBType } from '../../../utils/freebusy.js'
export default {
name: 'FreeBusy',
components: {
FullCalendar,
DatePicker,
Modal,
},
props: {
/**
* The organizer object.
* See /src/models/attendee.js for details
*/
organizer: {
type: Object,
required: true,
},
/**
* The attendee objects.
* See /src/models/attendee.js for details
*/
attendees: {
type: Array,
required: true,
},
/**
* The start-date to query free-busy information from
*/
startDate: {
type: Date,
required: true,
},
/**
* The end-date to query free-busy information from
*/
endDate: {
type: Date,
required: true,
},
},
data() {
return {
loadingIndicator: true,
currentDate: this.startDate,
}
},
computed: {
...mapGetters({
timezoneId: 'getResolvedTimezone',
}),
...mapState({
showWeekends: state => state.settings.showWeekends,
showWeekNumbers: state => state.settings.showWeekNumbers,
timezone: state => state.settings.timezone,
}),
/**
* FullCalendar Plugins
*
* @return {(PluginDef)[]}
*/
plugins() {
return [
resourceTimelinePlugin,
momentPluginFactory(this.$store),
VTimezoneNamedTimezone,
]
},
eventSources() {
return [
freeBusyResourceEventSource(
this._uid,
this.organizer.attendeeProperty,
this.attendees.map((a) => a.attendeeProperty)
),
freeBusyFakeBlockingEventSource(
this._uid,
this.resources,
this.startDate,
this.endDate
),
freeBusyBlockedForAllEventSource(
this.organizer.attendeeProperty,
this.attendees.map((a) => a.attendeeProperty),
this.resources
),
]
},
resources() {
const resources = []
for (const attendee of [this.organizer, ...this.attendees]) {
let title = attendee.commonName || attendee.uri.slice(7)
if (attendee === this.organizer) {
title = this.$t('calendar', '{organizer} (organizer)', {
organizer: title,
})
}
resources.push({
id: attendee.attendeeProperty.email,
title,
})
}
// Sort the resources by ID, just like fullcalendar does. This ensures that
// the fake blocking event can know the first and last resource reliably
// ref https://fullcalendar.io/docs/resourceOrder
resources.sort((a, b) => (a.id > b.id) - (a.id < b.id))
return resources
},
/**
* List of possible Free-Busy values.
* This is used as legend.
*
* @return {({color: string, label: string})[]}
*/
colorCaption() {
return [{
// TRANSLATORS: free as in available
label: this.$t('calendar', 'Free'),
color: getColorForFBType('FREE'),
}, {
label: this.$t('calendar', 'Busy (tentative)'),
color: getColorForFBType('BUSY-TENTATIVE'),
}, {
label: this.$t('calendar', 'Busy'),
color: getColorForFBType('BUSY'),
}, {
label: this.$t('calendar', 'Out of office'),
color: getColorForFBType('BUSY-UNAVAILABLE'),
}, {
label: this.$t('calendar', 'Unknown'),
color: getColorForFBType('UNKNOWN'),
}]
},
/**
* Configuration options for FullCalendar
* Please see https://fullcalendar.io/docs#toc for details
*
* @return {object}
*/
options() {
return {
// Initialization:
initialView: 'resourceTimelineDay',
initialDate: this.startDate,
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
// Data
eventSources: this.eventSources,
resources: this.resources,
// Events
datesSet: function({ start }) {
// Keep the current date in sync
this.setCurrentDate(start, true)
}.bind(this),
// Plugins
plugins: this.plugins,
// Interaction:
editable: false,
selectable: false,
// Localization:
...getDateFormattingConfig(),
...getFullCalendarLocale(),
// Rendering
height: 'auto',
loading: this.loading,
// Timezones:
timeZone: this.timezoneId,
// Formatting of the title
// will produce something like "Tuesday, September 18, 2018"
// ref https://fullcalendar.io/docs/date-formatting
titleFormat: {
month: 'long',
year: 'numeric',
day: 'numeric',
weekday: 'long',
},
}
},
},
mounted() {
// Move file picker into the right header menu
// TODO: make this a slot once fullcalendar support it
// ref https://github.com/fullcalendar/fullcalendar-vue/issues/14
// ref https://github.com/fullcalendar/fullcalendar-vue/issues/126
const picker = this.$refs.datePicker
// Remove from original position
picker.$el.parentNode.removeChild(picker.$el)
// Insert into calendar
this.$el.querySelector('.fc-toolbar-chunk:last-child').appendChild(picker.$el)
},
methods: {
loading(isLoading) {
this.loadingIndicator = isLoading
},
setCurrentDate(date, updatedViaCalendar) {
this.currentDate = date
if (!updatedViaCalendar) {
const calendar = this.$refs.freeBusyFullCalendar.getApi()
calendar.gotoDate(date)
}
},
},
}
</script>
<style lang='scss' scoped>
.modal__content {
padding: 50px;
//when the calendar is open, it's cut at the bottom, adding a margin fixes it
margin-bottom: 95px;
}
::v-deep .mx-input{
height: 38px !important;
}
</style>
<style lang="scss">
.blocking-event-free-busy {
// Show the blocking event above any other blocks, especially the *blocked for all* one
z-index: 3 !important;
}
.free-busy-block {
opacity: 0.7 !important;
}
</style>