[events] Can send invitations and transfers

This commit is contained in:
Ferdinand Thiessen 2021-04-01 19:37:18 +02:00
parent 43dcd0579e
commit 48aa6c724a
3 changed files with 57 additions and 36 deletions

View File

@ -15,7 +15,7 @@
Uhr
</q-card-section>
<q-card-actions align="around">
<q-btn style="width: 47.5%" color="primary" label="Eintragen" @click="enroll" />
<q-btn style="width: 47.5%" color="primary" label="Eintragen" @click="enroll()" />
<q-toggle
v-model="service.is_backup"
style="width: 47.5%"
@ -29,14 +29,14 @@
style="width: 47.5%"
color="negative"
label="Übertragen"
@click="transfer"
@click="enroll(true)"
/>
<q-btn
v-if="!iam(service.userid)"
style="width: 47.5%"
color="secondary"
label="Einladen"
@click="invite"
@click="enroll(false, true)"
/>
</q-card-actions>
</q-card>
@ -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)"
>
<q-avatar :color="scope.opt.is_backup ? 'primary' : 'secondary'" text-color="white">
<img
@ -142,8 +142,15 @@ export default defineComponent({
return uid === mainStore.currentUser.userid;
}
async function enroll() {
async function enroll(transfer = false, invite = false) {
try {
dialog.value = false;
if (transfer)
service.value = Object.assign({}, service.value, {
replace: mainStore.currentUser.userid,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
else if (invite) delete (<any>service.value).value;
const job = await store.updateJob(props.eventId, props.modelValue.id, {
user: <FG.Service>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,

View File

@ -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 = <EventNotification>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,

View File

@ -148,7 +148,7 @@ export const useScheduleStore = defineStore({
async updateJob(eventId: number, jobId: number, service: FG.Service | UserService) {
try {
const { data } = await api.put<FG.Job>(`/events/${eventId}/jobs/${jobId}`, service);
const { data } = await api.put<FG.Job>(`/events/${eventId}/${jobId}`, service);
fixJob(data);
return data;
} catch (error) {