rdv: add calendar user selector widget

This commit is contained in:
nobohan 2021-08-17 12:07:24 +02:00
parent 02a9e21f62
commit f2d79919f0
7 changed files with 144 additions and 26 deletions

View File

@ -1,17 +1,20 @@
<template> <template>
<concerned-groups></concerned-groups> <concerned-groups></concerned-groups>
<calendar-user-selector></calendar-user-selector>
<calendar-event></calendar-event> <calendar-event></calendar-event>
</template> </template>
<script> <script>
import ConcernedGroups from 'ChillActivityAssets/vuejs/Activity/components/ConcernedGroups.vue'; import ConcernedGroups from 'ChillActivityAssets/vuejs/Activity/components/ConcernedGroups.vue';
import CalendarEvent from '../_components/CalendarEvent/CalendarEvent.vue'; import CalendarEvent from '../_components/CalendarEvent/CalendarEvent.vue';
import CalendarUserSelector from '../_components/CalendarUserSelector/CalendarUserSelector.vue';
export default { export default {
name: "App", name: "App",
components: { components: {
ConcernedGroups, ConcernedGroups,
CalendarEvent CalendarEvent,
CalendarUserSelector,
} }
} }
</script> </script>

View File

@ -1,5 +1,6 @@
import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'
import { calendarEventMessages } from '../_components/CalendarEvent/js/i18n' import { calendarEventMessages } from '../_components/CalendarEvent/js/i18n'
import { calendarUserSelectorMessages } from '../_components/CalendarUserSelector/js/i18n';
const appMessages = { const appMessages = {
fr: { fr: {
@ -16,6 +17,7 @@ const appMessages = {
Object.assign(appMessages.fr, personMessages.fr); Object.assign(appMessages.fr, personMessages.fr);
Object.assign(appMessages.fr, calendarEventMessages.fr); Object.assign(appMessages.fr, calendarEventMessages.fr);
Object.assign(appMessages.fr, calendarUserSelectorMessages.fr);
export { export {
appMessages appMessages

View File

@ -34,15 +34,13 @@ export default {
] : [], ] : [],
initialDate: window.startDate !== undefined ? window.startDate : new Date(), initialDate: window.startDate !== undefined ? window.startDate : new Date(),
//events: this.displayEvents(), //events: this.displayEvents(),
eventSources: [ eventSources: this.getEventsSources(),
this.displayEventSource1(),
this.displayEventSource2(),
],
selectable: true, selectable: true,
select: this.onDateSelect, select: this.onDateSelect,
eventChange: this.onEventChange, eventChange: this.onEventChange,
selectMirror: true, selectMirror: true,
editable: true, editable: true,
lazyFetching: false, // To fetch at maximum
headerToolbar: { headerToolbar: {
left: 'prev,next today', left: 'prev,next today',
center: 'title', center: 'title',
@ -53,32 +51,48 @@ export default {
} }
}, },
methods: { methods: {
getCalendarRanges() { getCalendarRanges(userId) {
console.log('get Calendar Ranges'); console.log('get Calendar Ranges');
fetchCalendarRanges().then(calendarRanges => new Promise((resolve, reject) => { return fetchCalendarRanges().then(calendarRanges => new Promise((resolve, reject) => {
console.log(calendarRanges);
this.calendarRanges = calendarRanges.results; this.calendarRanges = calendarRanges.results;
this.calendarRanges = [ let source = { //TODO transform the results above into a object as following
{ events: [
title : 'event1', {
start : '2021-07-01' title: 'Event1',
}, start: '2021-07-04T09:30:00'
{ },
title : 'event2', {
start : '2021-07-05', title: 'Event2',
end : '2021-07-07' start: '2021-07-05T09:30:00'
}, }
{ ],
title : 'event3', color: 'red', // an option!
start : '2021-07-09T12:30:00', textColor: 'white' // an option!
allDay : false // will make the time show };
} this.calendarRanges = source;
];
resolve() resolve()
})) }))
.catch((error) => { .catch((error) => {
this.errorMsg.push(error.message); this.errorMsg.push(error.message);
}); });
}, },
getEventsSources() { // soit on appelle cette function plus tard, soit on gère différement l'asynchroniété
let userId = 1;
let arr = [
this.displayEventSource1(),
this.displayEventSource2(),
fetchCalendarRanges().then(response => {
console.log(response)
return response
// if (response.ok) { return response.results }
})
//this.calendarRanges
];
console.log(arr);
return arr;
},
displayEvents() { //TODO WIP displayEvents() { //TODO WIP
return [ return [
{ {

View File

@ -1,7 +1,7 @@
/* /*
* Endpoint chill_api_single_country__index * Endpoint chill_api_single_calendar_range
* method GET, get Country Object * method GET, get Calendar ranges
* @returns {Promise} a promise containing all Country object * @returns {Promise} a promise containing all Calendar ranges objects
*/ */
const fetchCalendarRanges = () => { const fetchCalendarRanges = () => {
const url = `/api/1.0/calendar/calendar-range.json?item_per_page=1000`; const url = `/api/1.0/calendar/calendar-range.json?item_per_page=1000`;

View File

@ -0,0 +1,63 @@
<template>
<h2 class="chill-red">{{ $t('choose_your_calendar_user') }}</h2>
<div>
<VueMultiselect
name="field"
id="calendarUserSelector"
v-model="values"
track-by="id"
label="value"
:custom-label="transName"
:placeholder="$t('select_user')"
:multiple="true"
:close-on-select="false"
:allow-empty="true"
:options="users">
<template slot="selection" slot-scope="{ values, search, isOpen }">
<span class="multiselect__single" v-if="values.length && !isOpen">{{ values.length }} options selected</span>
</template>
</VueMultiselect>
<div>
<ul>
</ul>
</div>
</div>
</template>
<script>
import { getUniqueUserCalendarRanges } from './js/api'
import VueMultiselect from 'vue-multiselect';
export default {
name: 'CalendarUserSelector',
components: { VueMultiselect },
data() {
return {
errorMsg: {},
userCalendarRanges: [],
values: [],
// selectedValues: []
}
},
computed: {
users() {
return this.userCalendarRanges;
}
},
methods: {
init() {
this.userCalendarRanges = getUniqueUserCalendarRanges();
},
transName(value) {
return `${value.username}`;
},
// selectUser(value) {
// this.selectedValues.push(value);
// }
},
mounted() {
this.init();
}
}
</script>

View File

@ -0,0 +1,25 @@
/*
* Endpoint chill_api_single_calendar_range
* method GET, get Calendar ranges
* @returns {Promise} a promise containing all Calendar ranges objects
*/
const fetchCalendarRanges = () => {
const url = `/api/1.0/calendar/calendar-range.json?item_per_page=1000`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
const getUniqueUserCalendarRanges = () => { //TODO build the array with fetchCalendarRanges
return [
{userId: 1, username: 'blop'},
{userId: 2, username: 'blup'}
];
}
export {
fetchCalendarRanges,
getUniqueUserCalendarRanges
};

View File

@ -0,0 +1,11 @@
const calendarUserSelectorMessages = {
fr: {
choose_your_calendar_user: "Afficher les calendriers",
select_user: "Sélectionnez des calendriers"
}
};
export {
calendarUserSelectorMessages
};