From 48aa6c724a884a45cc832f22978dbf8ab6c49491 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 1 Apr 2021 19:37:18 +0200 Subject: [PATCH] [events] Can send invitations and transfers --- .../components/overview/slots/JobSlot.vue | 67 +++++++++---------- src/plugins/events/plugin.ts | 24 ++++++- src/plugins/events/store/index.ts | 2 +- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/src/plugins/events/components/overview/slots/JobSlot.vue b/src/plugins/events/components/overview/slots/JobSlot.vue index da81a34..a592e69 100644 --- a/src/plugins/events/components/overview/slots/JobSlot.vue +++ b/src/plugins/events/components/overview/slots/JobSlot.vue @@ -15,7 +15,7 @@ Uhr - + @@ -74,7 +74,7 @@ color="white" :text-color="scope.opt.is_backup ? 'primary' : 'secondary'" class="q-ma-none" - @remove="remove(scope.opt.userid, scope.removeAtIndex, scope.index)" + @remove="remove(scope.opt, scope.removeAtIndex, scope.index)" > service.value).value; const job = await store.updateJob(props.eventId, props.modelValue.id, { user: service.value, }); @@ -161,11 +168,28 @@ export default defineComponent({ } } - async function remove(userid: string, rem: (i: number) => void, index: number) { - if (userid === mainStore.currentUser.userid || hasPermission(PERMISSIONS.ASSIGN_OTHER)) { - console.log('YES REM'); + async function remove(service: FG.Service, rem: (i: number) => void, index: number) { + if ( + service.userid === mainStore.currentUser.userid || + hasPermission(PERMISSIONS.ASSIGN_OTHER) + ) { rem(index); - await signOutFromJob(); + try { + const job = await store.updateJob(props.eventId, props.modelValue.id, { + user: Object.assign({}, service, { value: -service.value }), + }); + emit('update:modelValue', job); + } catch (error) { + console.warn(error); + Notify.create({ + group: false, + type: 'negative', + message: 'Fehler beim Austragen als Dienst', + timeout: 10000, + progress: true, + actions: [{ icon: 'mdi-close', color: 'white' }], + }); + } } } @@ -193,37 +217,12 @@ export default defineComponent({ return sum < props.modelValue.required_services && !is; }); - async function signOutFromJob() { - const newService: FG.Service = { - userid: mainStore.currentUser.userid, - is_backup: false, - value: -1, - }; - try { - const job = await store.updateJob(props.eventId, props.modelValue.id, { - user: newService, - }); - emit('update:modelValue', job); - } catch (error) { - console.warn(error); - Notify.create({ - group: false, - type: 'negative', - message: 'Fehler beim Austragen als Dienst', - timeout: 10000, - progress: true, - actions: [{ icon: 'mdi-close', color: 'white' }], - }); - } - } - return { enroll, availableUsers, canEdit, isEnrolled, enrolled, - signOutFromJob, enrollDialog, canEnroll, remove, diff --git a/src/plugins/events/plugin.ts b/src/plugins/events/plugin.ts index 70ec71d..1e6dce2 100644 --- a/src/plugins/events/plugin.ts +++ b/src/plugins/events/plugin.ts @@ -2,13 +2,35 @@ import { defineAsyncComponent } from 'vue'; import { innerRoutes, privateRoutes } from './routes'; import { FG_Plugin } from 'src/plugins'; +interface EventNotification extends FG_Plugin.Notification { + data: { type: NotificationType }; +} + +enum NotificationType { + REQUEST = 0x10, + ACCEPTED = 0x11, + REJECTED = 0x12, +} + +function transpile(n: FG.Notification) { + const notification = Object.assign({}, n); + if (notification.data.type === NotificationType.REQUEST) + notification.accept = () => + new Promise((r) => { + console.log('REQUEST ACCEPTED'); + r(); + }); + return notification; +} + const plugin: FG_Plugin.Plugin = { - name: 'Events', + name: 'events', innerRoutes, internalRoutes: privateRoutes, requiredModules: ['User'], requiredBackendModules: ['events'], version: '0.0.2', + notification: transpile, widgets: [ { priority: 0, diff --git a/src/plugins/events/store/index.ts b/src/plugins/events/store/index.ts index 08a66b2..5645581 100644 --- a/src/plugins/events/store/index.ts +++ b/src/plugins/events/store/index.ts @@ -148,7 +148,7 @@ export const useScheduleStore = defineStore({ async updateJob(eventId: number, jobId: number, service: FG.Service | UserService) { try { - const { data } = await api.put(`/events/${eventId}/jobs/${jobId}`, service); + const { data } = await api.put(`/events/${eventId}/${jobId}`, service); fixJob(data); return data; } catch (error) {