From 10c891d9497417f212335ff005abec3441bad730 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 4 Jan 2021 20:53:30 +0800 Subject: [PATCH] feat: add calendar view --- packages/app/package.json | 2 + packages/app/src/api/index.ts | 2 +- .../src/api/migrations/add-fields-to-views.ts | 19 + .../form.fields/remote-select/index.tsx | 3 +- .../src/components/views/Calendar/index.tsx | 230 +++++++ .../src/components/views/Calendar/style.less | 634 ++++++++++++++++++ .../src/components/views/Form/DrawerForm.tsx | 4 +- packages/app/src/components/views/index.tsx | 2 + .../src/collections/views.ts | 113 +++- .../plugin-collections/src/models/field.ts | 2 +- 10 files changed, 1006 insertions(+), 5 deletions(-) create mode 100644 packages/app/src/api/migrations/add-fields-to-views.ts create mode 100644 packages/app/src/components/views/Calendar/index.tsx create mode 100644 packages/app/src/components/views/Calendar/style.less diff --git a/packages/app/package.json b/packages/app/package.json index cd70268a91..54c107241f 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -32,6 +32,7 @@ "@nocobase/plugin-collections": "^0.3.0-alpha.0", "@nocobase/plugin-pages": "^0.3.0-alpha.0", "@nocobase/server": "^0.3.0-alpha.0", + "@types/react-big-calendar": "^0.24.8", "@umijs/preset-react": "1.x", "@umijs/test": "^3.2.23", "ahooks": "^2.9.3", @@ -41,6 +42,7 @@ "nodemon": "^2.0.6", "prettier": "^1.19.1", "react": "16.14.0", + "react-big-calendar": "^0.30.0", "react-dom": "16.14.0", "react-sortable-hoc": "^1.11.0", "styled-components": "^5.2.1", diff --git a/packages/app/src/api/index.ts b/packages/app/src/api/index.ts index 697e2e435c..967bafb6f3 100644 --- a/packages/app/src/api/index.ts +++ b/packages/app/src/api/index.ts @@ -86,7 +86,7 @@ api.resourcer.use(async (ctx: actions.Context, next) => { if (appends.length) { ctx.action.setParam('fields.appends', appends); } - console.log('ctx.action.params.fields', ctx.action.params.fields, except, appends); + // console.log('ctx.action.params.fields', ctx.action.params.fields, except, appends); } await next(); }); diff --git a/packages/app/src/api/migrations/add-fields-to-views.ts b/packages/app/src/api/migrations/add-fields-to-views.ts new file mode 100644 index 0000000000..e176a100c5 --- /dev/null +++ b/packages/app/src/api/migrations/add-fields-to-views.ts @@ -0,0 +1,19 @@ +import api from '../app'; +import Database from '@nocobase/database'; + +(async () => { + await api.loadPlugins(); + const database: Database = api.database; + await api.database.sync({ + tables: ['views'], + }); + const [Collection, Page, User] = database.getModels(['collections', 'pages', 'users']); + const table = database.getTable('views'); + const collection = await Collection.findByName('views'); + console.log(table.getOptions().fields); + await collection.updateAssociations({ + fields: table.getOptions().fields, + }, { + migrate: false, + }); +})(); diff --git a/packages/app/src/components/form.fields/remote-select/index.tsx b/packages/app/src/components/form.fields/remote-select/index.tsx index 103aefb8fc..18d84f0e8a 100644 --- a/packages/app/src/components/form.fields/remote-select/index.tsx +++ b/packages/app/src/components/form.fields/remote-select/index.tsx @@ -14,7 +14,7 @@ import api from '@/api-client'; import { Spin } from '@nocobase/client' function RemoteSelectComponent(props) { - const { value, onChange, disabled, resourceName, associatedKey, filter, labelField, valueField = 'id', objectValue } = props; + const { value, onChange, disabled, resourceName, associatedKey, filter, labelField, valueField = 'id', objectValue, placeholder } = props; const { data = [], loading = true } = useRequest(() => { return api.resource(resourceName).list({ associatedKey, @@ -26,6 +26,7 @@ function RemoteSelectComponent(props) { return ( <>