60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { innerRoutes, privateRoutes } from './routes';
|
|
import { FG_Plugin } from '@flaschengeist/types';
|
|
import { defineAsyncComponent } from 'vue';
|
|
import { EventNotification, InvitationData, InvitationResponseData } from './events';
|
|
import { useEventStore } from './store';
|
|
|
|
const EventTypes = {
|
|
_mask_: 0xf0,
|
|
invitation: 0x00,
|
|
invite: 0x01,
|
|
transfer: 0x02,
|
|
invitation_response: 0x10,
|
|
invitation_accepted: 0x10,
|
|
invitation_rejected: 0x11,
|
|
};
|
|
|
|
function transpile(msg: FG_Plugin.Notification) {
|
|
const message = msg as EventNotification;
|
|
message.icon = 'mdi-calendar';
|
|
if ((message.data.type & EventTypes._mask_) === EventTypes.invitation) {
|
|
message.accept = () => {
|
|
const store = useEventStore();
|
|
return store.acceptInvitation((<InvitationData>message.data).invitation);
|
|
};
|
|
|
|
message.reject = () => {
|
|
const store = useEventStore();
|
|
return store.rejectInvitation((<InvitationData>message.data).invitation);
|
|
};
|
|
|
|
message.link = { name: 'events-requests' };
|
|
} else if ((message.data.type & EventTypes._mask_) === EventTypes.invitation_response) {
|
|
message.link = {
|
|
name: 'events-single-view',
|
|
params: { id: (<InvitationResponseData>message.data).event },
|
|
};
|
|
}
|
|
return message;
|
|
}
|
|
|
|
const plugin: FG_Plugin.Plugin = {
|
|
id: 'dev.flaschengeist.events',
|
|
name: 'Event schedule',
|
|
innerRoutes,
|
|
internalRoutes: privateRoutes,
|
|
requiredModules: [['events']],
|
|
version: '0.0.1',
|
|
notification: transpile,
|
|
widgets: [
|
|
{
|
|
priority: 0,
|
|
name: 'stats',
|
|
permissions: [],
|
|
widget: defineAsyncComponent(() => import('./components/Widget.vue')),
|
|
},
|
|
],
|
|
};
|
|
|
|
export default plugin;
|