2024-03-14 19:20:02 +08:00
|
|
|
import { Plugin, canMakeAssociationBlock, useCollection } from '@nocobase/client';
|
2023-12-23 15:16:41 +08:00
|
|
|
import { generateNTemplate } from '../locale';
|
|
|
|
import { CalendarV2 } from './calendar';
|
2024-03-14 14:13:11 +08:00
|
|
|
import { calendarBlockSettings } from './calendar/Calender.Settings';
|
2024-03-03 23:06:24 +08:00
|
|
|
import { CalendarCollectionTemplate } from './collection-templates/calendar';
|
2023-12-23 15:16:41 +08:00
|
|
|
import { CalendarBlockProvider, useCalendarBlockProps } from './schema-initializer/CalendarBlockProvider';
|
2024-03-14 14:13:11 +08:00
|
|
|
import {
|
|
|
|
CalendarActionInitializers_deprecated,
|
|
|
|
CalendarFormActionInitializers,
|
|
|
|
calendarActionInitializers,
|
|
|
|
deleteEventActionInitializer,
|
|
|
|
} from './schema-initializer/initializers';
|
2024-03-14 19:20:02 +08:00
|
|
|
import {
|
|
|
|
CalendarBlockInitializer,
|
|
|
|
RecordAssociationCalendarBlockInitializer,
|
|
|
|
useCreateAssociationCalendarBlock,
|
|
|
|
} from './schema-initializer/items';
|
|
|
|
import { useMemo } from 'react';
|
2024-03-27 18:06:28 +08:00
|
|
|
import { useCalendarBlockDecoratorProps } from './hooks/useCalendarBlockDecoratorProps';
|
2023-12-23 15:16:41 +08:00
|
|
|
|
|
|
|
export class PluginCalendarClient extends Plugin {
|
|
|
|
async load() {
|
2024-03-03 23:06:24 +08:00
|
|
|
this.app.dataSourceManager.addCollectionTemplates([CalendarCollectionTemplate]);
|
2024-03-14 14:13:11 +08:00
|
|
|
this.app.schemaInitializerManager.addItem('page:addBlock', 'dataBlocks.calendar', {
|
2023-12-23 15:16:41 +08:00
|
|
|
title: generateNTemplate('Calendar'),
|
|
|
|
Component: 'CalendarBlockInitializer',
|
|
|
|
});
|
2024-03-14 19:20:02 +08:00
|
|
|
this.app.schemaInitializerManager.addItem('popup:common:addBlock', 'dataBlocks.calendar', {
|
|
|
|
title: generateNTemplate('Calendar'),
|
|
|
|
Component: 'CalendarBlockInitializer',
|
|
|
|
useVisible() {
|
|
|
|
const collection = useCollection();
|
|
|
|
return useMemo(
|
|
|
|
() =>
|
|
|
|
collection.fields.some(
|
|
|
|
(field) => canMakeAssociationBlock(field) && ['hasMany', 'belongsToMany'].includes(field.type),
|
|
|
|
),
|
|
|
|
[collection.fields],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
useComponentProps() {
|
|
|
|
const { createAssociationCalendarBlock } = useCreateAssociationCalendarBlock();
|
|
|
|
|
|
|
|
return {
|
|
|
|
onlyCurrentDataSource: true,
|
|
|
|
filterCollections({ associationField }) {
|
|
|
|
if (associationField) {
|
|
|
|
return ['hasMany', 'belongsToMany'].includes(associationField.type);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
createBlockSchema: createAssociationCalendarBlock,
|
|
|
|
showAssociationFields: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-12-23 15:16:41 +08:00
|
|
|
this.app.addComponents({
|
|
|
|
CalendarBlockProvider,
|
2024-03-14 19:20:02 +08:00
|
|
|
CalendarBlockInitializer: CalendarBlockInitializer as any,
|
2023-12-23 15:16:41 +08:00
|
|
|
RecordAssociationCalendarBlockInitializer,
|
|
|
|
CalendarV2,
|
|
|
|
});
|
2024-03-27 18:06:28 +08:00
|
|
|
this.app.addScopes({ useCalendarBlockProps, useCalendarBlockDecoratorProps });
|
2024-03-03 23:06:24 +08:00
|
|
|
this.schemaSettingsManager.add(calendarBlockSettings);
|
2024-03-14 14:13:11 +08:00
|
|
|
this.app.schemaInitializerManager.add(CalendarActionInitializers_deprecated);
|
|
|
|
this.app.schemaInitializerManager.add(calendarActionInitializers);
|
2023-12-23 15:16:41 +08:00
|
|
|
this.app.schemaInitializerManager.add(CalendarFormActionInitializers);
|
2024-03-14 14:13:11 +08:00
|
|
|
this.app.schemaInitializerManager
|
|
|
|
.get('details:configureActions')
|
|
|
|
.add('enableActions.deleteEvent', deleteEventActionInitializer);
|
2023-12-23 15:16:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PluginCalendarClient;
|