2022-02-14 13:57:13 +00:00
|
|
|
import path from 'path';
|
2022-08-20 15:23:13 +00:00
|
|
|
import { UniqueConstraintError } from 'sequelize';
|
|
|
|
|
|
|
|
import PluginErrorHandler from '@nocobase/plugin-error-handler';
|
|
|
|
import { Plugin } from '@nocobase/server';
|
2023-02-13 13:38:47 +00:00
|
|
|
import { Mutex } from 'async-mutex';
|
2022-08-20 15:23:13 +00:00
|
|
|
|
2022-02-16 17:06:42 +00:00
|
|
|
import { CollectionRepository } from '.';
|
2022-02-14 13:57:13 +00:00
|
|
|
import {
|
2022-10-28 07:09:14 +00:00
|
|
|
afterCreateForForeignKeyField,
|
2022-02-14 13:57:13 +00:00
|
|
|
afterCreateForReverseField,
|
|
|
|
beforeCreateForReverseField,
|
2022-10-28 07:09:14 +00:00
|
|
|
beforeDestroyForeignKey,
|
2023-04-04 02:52:47 +00:00
|
|
|
beforeInitOptions,
|
2022-02-14 13:57:13 +00:00
|
|
|
} from './hooks';
|
2022-10-31 14:45:39 +00:00
|
|
|
|
2022-11-16 04:53:58 +00:00
|
|
|
import { InheritedCollection } from '@nocobase/database';
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
import lodash, { castArray } from 'lodash';
|
2023-03-10 11:16:00 +00:00
|
|
|
import * as process from 'process';
|
|
|
|
import { CollectionModel, FieldModel } from './models';
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
import collectionActions from './resourcers/collections';
|
|
|
|
import viewResourcer from './resourcers/views';
|
|
|
|
|
|
|
|
import { beforeCreateForViewCollection } from './hooks/beforeCreateForViewCollection';
|
2022-02-14 13:57:13 +00:00
|
|
|
|
|
|
|
export class CollectionManagerPlugin extends Plugin {
|
2023-03-01 09:55:37 +00:00
|
|
|
public schema: string;
|
|
|
|
|
2022-02-14 13:57:13 +00:00
|
|
|
async beforeLoad() {
|
2023-03-01 09:55:37 +00:00
|
|
|
if (process.env.COLLECTION_MANAGER_SCHEMA) {
|
|
|
|
this.schema = process.env.COLLECTION_MANAGER_SCHEMA;
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:57:13 +00:00
|
|
|
this.app.db.registerModels({
|
|
|
|
CollectionModel,
|
|
|
|
FieldModel,
|
|
|
|
});
|
|
|
|
|
2022-06-17 02:25:59 +00:00
|
|
|
this.db.addMigrations({
|
|
|
|
namespace: 'collection-manager',
|
|
|
|
directory: path.resolve(__dirname, './migrations'),
|
|
|
|
context: {
|
|
|
|
plugin: this,
|
|
|
|
},
|
2022-06-14 07:46:48 +00:00
|
|
|
});
|
|
|
|
|
2022-02-16 17:06:42 +00:00
|
|
|
this.app.db.registerRepositories({
|
|
|
|
CollectionRepository,
|
|
|
|
});
|
|
|
|
|
2023-01-08 23:35:48 +00:00
|
|
|
this.app.acl.registerSnippet({
|
|
|
|
name: `pm.${this.name}.collections`,
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
actions: ['collections:*', 'collections.fields:*', 'dbViews:*'],
|
2023-01-08 23:35:48 +00:00
|
|
|
});
|
|
|
|
|
2023-03-01 09:55:37 +00:00
|
|
|
this.app.db.on('collections.beforeCreate', async (model) => {
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
if (this.app.db.inDialect('postgres') && this.schema && model.get('from') != 'db2cm' && !model.get('schema')) {
|
2023-03-01 09:55:37 +00:00
|
|
|
model.set('schema', this.schema);
|
2022-03-11 02:08:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
this.app.db.on('collections.beforeCreate', beforeCreateForViewCollection(this.db));
|
|
|
|
|
2023-03-01 09:55:37 +00:00
|
|
|
this.app.db.on(
|
|
|
|
'collections.afterCreateWithAssociations',
|
|
|
|
async (model: CollectionModel, { context, transaction }) => {
|
|
|
|
if (context) {
|
|
|
|
await model.migrate({
|
|
|
|
transaction,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
this.app.db.on('collections.beforeDestroy', async (model: CollectionModel, options) => {
|
|
|
|
await model.remove(options);
|
|
|
|
});
|
|
|
|
|
2022-02-14 13:57:13 +00:00
|
|
|
// 要在 beforeInitOptions 之前处理
|
|
|
|
this.app.db.on('fields.beforeCreate', beforeCreateForReverseField(this.app.db));
|
2022-11-16 04:53:58 +00:00
|
|
|
|
|
|
|
this.app.db.on('fields.beforeCreate', async (model, options) => {
|
|
|
|
const collectionName = model.get('collectionName');
|
|
|
|
const collection = this.app.db.getCollection(collectionName);
|
|
|
|
|
|
|
|
if (!collection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collection.isInherited() && (<InheritedCollection>collection).parentFields().has(model.get('name'))) {
|
|
|
|
model.set('overriding', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
this.app.db.on('fields.beforeValidate', async (model) => {
|
|
|
|
if (model.get('name') && model.get('name').includes('.')) {
|
|
|
|
model.set('field', model.get('name'));
|
|
|
|
model.set('name', model.get('name').replace(/\./g, '_'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-14 13:57:13 +00:00
|
|
|
this.app.db.on('fields.beforeCreate', async (model, options) => {
|
|
|
|
const type = model.get('type');
|
2022-10-14 09:22:32 +00:00
|
|
|
const fn = beforeInitOptions[type];
|
|
|
|
if (fn) {
|
|
|
|
await fn(model, { database: this.app.db });
|
2022-02-14 13:57:13 +00:00
|
|
|
}
|
2022-10-14 09:22:32 +00:00
|
|
|
});
|
2022-10-27 05:00:16 +00:00
|
|
|
|
2022-02-14 13:57:13 +00:00
|
|
|
this.app.db.on('fields.afterCreate', afterCreateForReverseField(this.app.db));
|
|
|
|
|
2022-08-20 15:23:13 +00:00
|
|
|
this.app.db.on('fields.afterCreate', async (model: FieldModel, { context, transaction }) => {
|
2022-02-14 13:57:13 +00:00
|
|
|
if (context) {
|
2022-08-24 03:51:14 +00:00
|
|
|
await model.migrate({
|
|
|
|
isNew: true,
|
2022-10-10 07:34:00 +00:00
|
|
|
transaction,
|
2022-08-24 03:51:14 +00:00
|
|
|
});
|
2022-02-14 13:57:13 +00:00
|
|
|
}
|
|
|
|
});
|
2022-11-04 01:04:53 +00:00
|
|
|
|
2022-10-28 07:09:14 +00:00
|
|
|
// after migrate
|
|
|
|
this.app.db.on('fields.afterCreate', afterCreateForForeignKeyField(this.app.db));
|
2022-02-16 17:06:42 +00:00
|
|
|
|
2023-03-01 09:55:37 +00:00
|
|
|
this.app.db.on('fields.beforeUpdate', async (model, options) => {
|
|
|
|
const newValue = options.values;
|
|
|
|
if (
|
|
|
|
model.get('reverseKey') &&
|
|
|
|
lodash.get(newValue, 'reverseField') &&
|
|
|
|
!lodash.get(newValue, 'reverseField.key')
|
|
|
|
) {
|
|
|
|
const field = await this.app.db
|
|
|
|
.getModel('fields')
|
|
|
|
.findByPk(model.get('reverseKey'), { transaction: options.transaction });
|
|
|
|
if (field) {
|
|
|
|
throw new Error('cant update field without a reverseField key');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-20 15:23:13 +00:00
|
|
|
this.app.db.on('fields.afterUpdate', async (model: FieldModel, { context, transaction }) => {
|
2022-10-14 01:56:16 +00:00
|
|
|
const prevOptions = model.previous('options');
|
|
|
|
const currentOptions = model.get('options');
|
|
|
|
|
2022-08-03 01:32:16 +00:00
|
|
|
if (context) {
|
2022-10-14 01:56:16 +00:00
|
|
|
const prev = prevOptions['unique'];
|
|
|
|
const next = currentOptions['unique'];
|
|
|
|
|
2022-08-23 00:59:36 +00:00
|
|
|
if (Boolean(prev) !== Boolean(next)) {
|
2023-02-13 13:38:47 +00:00
|
|
|
await model.syncUniqueIndex({ transaction });
|
2022-08-20 15:23:13 +00:00
|
|
|
}
|
2022-08-03 01:32:16 +00:00
|
|
|
}
|
2022-10-14 01:56:16 +00:00
|
|
|
|
|
|
|
const prevDefaultValue = prevOptions['defaultValue'];
|
|
|
|
const currentDefaultValue = currentOptions['defaultValue'];
|
|
|
|
|
|
|
|
if (prevDefaultValue != currentDefaultValue) {
|
|
|
|
await model.syncDefaultValue({ transaction, defaultValue: currentDefaultValue });
|
|
|
|
}
|
2022-11-10 13:28:33 +00:00
|
|
|
|
|
|
|
const prevOnDelete = prevOptions['onDelete'];
|
|
|
|
const currentOnDelete = currentOptions['onDelete'];
|
|
|
|
|
|
|
|
if (prevOnDelete != currentOnDelete) {
|
|
|
|
await model.syncReferenceCheckOption({ transaction });
|
|
|
|
}
|
2022-08-03 01:32:16 +00:00
|
|
|
});
|
|
|
|
|
2022-11-04 01:04:53 +00:00
|
|
|
this.app.db.on('fields.afterSaveWithAssociations', async (model: FieldModel, { context, transaction }) => {
|
2022-06-10 09:46:46 +00:00
|
|
|
if (context) {
|
|
|
|
await model.load({ transaction });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-28 07:09:14 +00:00
|
|
|
// before field remove
|
|
|
|
this.app.db.on('fields.beforeDestroy', beforeDestroyForeignKey(this.app.db));
|
2023-02-13 13:38:47 +00:00
|
|
|
|
|
|
|
const mutex = new Mutex();
|
2022-11-16 04:53:58 +00:00
|
|
|
this.app.db.on('fields.beforeDestroy', async (model: FieldModel, options) => {
|
2023-02-13 13:38:47 +00:00
|
|
|
await mutex.runExclusive(async () => {
|
|
|
|
await model.remove(options);
|
|
|
|
});
|
2022-06-11 12:46:30 +00:00
|
|
|
});
|
2022-04-18 10:57:21 +00:00
|
|
|
|
2022-11-16 04:53:58 +00:00
|
|
|
this.app.db.on('fields.afterDestroy', async (model: FieldModel, options) => {
|
|
|
|
const { transaction } = options;
|
|
|
|
const collectionName = model.get('collectionName');
|
|
|
|
const childCollections = this.db.inheritanceMap.getChildren(collectionName);
|
|
|
|
|
|
|
|
const childShouldRemoveField = Array.from(childCollections).filter((item) => {
|
|
|
|
const parents = Array.from(this.db.inheritanceMap.getParents(item))
|
|
|
|
.map((parent) => {
|
|
|
|
const collection = this.db.getCollection(parent);
|
|
|
|
const field = collection.getField(model.get('name'));
|
|
|
|
return field;
|
|
|
|
})
|
|
|
|
.filter(Boolean);
|
|
|
|
|
|
|
|
return parents.length == 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
await this.db.getCollection('fields').repository.destroy({
|
|
|
|
filter: {
|
|
|
|
name: model.get('name'),
|
|
|
|
collectionName: {
|
|
|
|
$in: childShouldRemoveField,
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
overriding: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
transaction,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
this.app.on('afterLoad', async (app, options) => {
|
|
|
|
if (options?.method === 'install') {
|
|
|
|
return;
|
2022-07-09 16:41:36 +00:00
|
|
|
}
|
|
|
|
const exists = await this.app.db.collectionExistsInDb('collections');
|
|
|
|
if (exists) {
|
2022-11-04 07:38:08 +00:00
|
|
|
try {
|
|
|
|
await this.app.db.getRepository<CollectionRepository>('collections').load();
|
|
|
|
} catch (error) {
|
2022-11-26 01:24:53 +00:00
|
|
|
this.app.logger.warn(error);
|
2022-11-04 07:38:08 +00:00
|
|
|
await this.app.db.sync();
|
2022-11-26 01:24:53 +00:00
|
|
|
|
2022-11-04 07:38:08 +00:00
|
|
|
try {
|
|
|
|
await this.app.db.getRepository<CollectionRepository>('collections').load();
|
|
|
|
} catch (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 16:41:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-18 12:26:11 +00:00
|
|
|
this.app.resourcer.use(async (ctx, next) => {
|
|
|
|
const { resourceName, actionName } = ctx.action;
|
|
|
|
if (resourceName === 'collections.fields' && actionName === 'update') {
|
|
|
|
const { updateAssociationValues = [] } = ctx.action.params;
|
|
|
|
updateAssociationValues.push('uiSchema');
|
|
|
|
ctx.action.mergeParams({
|
|
|
|
updateAssociationValues,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await next();
|
|
|
|
});
|
2022-03-11 02:10:57 +00:00
|
|
|
|
2022-04-24 02:14:46 +00:00
|
|
|
this.app.acl.allow('collections', 'list', 'loggedIn');
|
2022-02-14 13:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2023-01-08 04:45:02 +00:00
|
|
|
await this.importCollections(path.resolve(__dirname, './collections'));
|
2022-08-20 15:23:13 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
const errorHandlerPlugin = <PluginErrorHandler>this.app.getPlugin('error-handler');
|
2022-08-20 15:23:13 +00:00
|
|
|
errorHandlerPlugin.errorHandler.register(
|
2022-08-23 00:59:36 +00:00
|
|
|
(err) => {
|
|
|
|
return err instanceof UniqueConstraintError;
|
|
|
|
},
|
2022-08-20 15:23:13 +00:00
|
|
|
(err, ctx) => {
|
|
|
|
return ctx.throw(400, ctx.t(`The value of ${Object.keys(err.fields)} field duplicated`));
|
|
|
|
},
|
|
|
|
);
|
2022-11-15 12:37:26 +00:00
|
|
|
|
|
|
|
this.app.resourcer.use(async (ctx, next) => {
|
|
|
|
if (ctx.action.resourceName === 'collections.fields' && ['create', 'update'].includes(ctx.action.actionName)) {
|
|
|
|
ctx.action.mergeParams({
|
2023-03-10 11:16:00 +00:00
|
|
|
updateAssociationValues: ['reverseField'],
|
2022-11-15 12:37:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
await next();
|
|
|
|
});
|
2023-02-13 01:57:03 +00:00
|
|
|
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
this.app.resource(viewResourcer);
|
|
|
|
this.app.actions(collectionActions);
|
|
|
|
|
|
|
|
const handleFieldSource = (fields) => {
|
|
|
|
for (const field of castArray(fields)) {
|
|
|
|
if (field.get('source')) {
|
|
|
|
const [collectionSource, fieldSource] = field.get('source').split('.');
|
2023-04-04 02:52:47 +00:00
|
|
|
// find original field
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
const collectionField = this.app.db.getCollection(collectionSource).getField(fieldSource);
|
|
|
|
|
|
|
|
const newOptions = {};
|
2023-04-04 02:52:47 +00:00
|
|
|
|
|
|
|
// write original field options
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
lodash.merge(newOptions, collectionField.options);
|
2023-04-04 02:52:47 +00:00
|
|
|
|
|
|
|
// merge with current field options
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
lodash.mergeWith(newOptions, field.get(), (objValue, srcValue) => {
|
|
|
|
if (srcValue === null) {
|
|
|
|
return objValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-04 02:52:47 +00:00
|
|
|
// set final options
|
feat: database view collection (#1587)
* test: create view collection
* feat: view collection class
* feat: list view
* chore: skip sync view collection
* test: should create view collection in difference schema
* test: create view collection in collection manager
* feat: create view collection by user sql
* test: view resourcer
* feat: view collection
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* feat: view collection cannot be added, deleted, or modified
* refactor: connect to database view
* refactor: sync from database
* chore: rename list view sql
* chore: list view fields api
* chore: create collection without viewName
* feat: bring out fields when selecting a view
* chore: bring out fields when selecting a view
* feat: view field inference class
* chore: bring out fields when selecting a view
* chore: sync form database view
* chore: sync form database view
* refactor: view collection local
* feat: view get api
* feat: database type infer
* feat: integer map
* chore: remove from in view list
* chore: build error
* chore: uniq collection
* fix: typo
* chore: replace collection list source field
* fix: destroy view collection
* chore: timestamp field map
* refactor: interface avalableTypes
* refactor: interface avalableTypes
* chore: list fields test
* refactor: interface avalableTypes
* chore: uiSchema response in field source
* fix: view query
* chore: collection snippet
* refactor: view collection support preview
* fix: handle field source
* fix: typo
* fix: configure fileds title
* fix: configure fileds title
* fix: configure fileds title
* fix: sync from databse interface
* fix: sync from databse interface
* feat: set fields api
* fix: sync from databse fix
* feat: possibleTypes
* chore: fields get
* fix: sync from databse
* fix: list view test
* fix: view test in difference schema
* chore: comment
* feat: when there is only one source collection, the view is a subset of a Collection
* feat: view collection add field
* fix: inherit query with schema
* fix: test
* fix: ci test
* fix: test with schema
* chore: set pg default search path
* chore: mysql test
* fix: test with schema
* chore: test
* chore: action test
* chore: view column usage return type
* feat: mysql field inference
* fix: tableName
* chore: node sql parser
* fix: sql build
* fix: database build
* fix: mysql test
* feat: view collection uiSchema title
* fix: incorrect field source display when switching views
* refactor: view collection not allow modify
* fix: view collection is allow add, delete, and modify
* fix: mysql test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* fix: sqlite test
* chore: add id field as default target key
* style: style improve
* feat: load source field options
* style: style improve
* chore: disable remove column in view collection
* chore: support creating view collection with different schemas with the same name
* chore: support creating view collection with different schemas with the same name
* fix: query view in difference schema
* refactor: view collection viewname
* fix: query view collection in difference schema
* fix: field load
* chore: field options
* fix: mysql test
* fix: uiSchema component error when using a view field in a block
* fix: sqlite test
* chore: test
* fix: dump user views
* fix: view collection can be updated and edited in table block
* chore: sync from database display last field configuration
* chore: loadCollections
* chore: sync from database display last field configuration
* fix: field options merge issues
* style: preview table
* fix: view collection is allow using in kanban blocks
* refactor: code improve
* fix: view collection can be updated an edited in calendar block
* chore: disable infer field without interface
* feat: preview only shows source or interface fields
* fix: test
* refactor: locale
* feat: sql parser
* chore: remove node-sql-parser
* fix: yarn.lock
* test: view repository
* fix: view repository test
* chore: console.log
* chore: console.log
* fix: mysql without schema
* fix: mysql without schema
* chore: preview with field schema
* chore: tableActionInitializers
* style: preview style improve
* chore: parameter is filter when there is no filterByTk
* fix: preview pagination
* fix: preview pagination
* style: preview table style improve
* fix: sync from database loading
* chore: preview performance optimization
* chore: preview performance optimization
* feat: limit & offset
* chore: preview performance optimization
* test: field with dot column
* fix: datetime interface display
* fix: missing boolean type
* fix: sync
* fix: sync from database
* style: style improve
* style: style improve
* style: style improve
* chore: preview table
* chore: preview table
* chore: preview table
* fix: styling
---------
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
|
|
|
field.set('options', newOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.app.resourcer.use(async (ctx, next) => {
|
|
|
|
await next();
|
|
|
|
|
|
|
|
// handle collections:list
|
|
|
|
if (
|
|
|
|
ctx.action.resourceName === 'collections' &&
|
|
|
|
ctx.action.actionName == 'list' &&
|
|
|
|
ctx.action.params?.paginate == 'false'
|
|
|
|
) {
|
|
|
|
for (const collection of ctx.body) {
|
|
|
|
if (collection.get('view')) {
|
|
|
|
const fields = collection.fields;
|
|
|
|
handleFieldSource(fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//handle collections:fields:list
|
|
|
|
if (ctx.action.resourceName == 'collections.fields' && ctx.action.actionName == 'list') {
|
|
|
|
handleFieldSource(ctx.action.params?.paginate == 'false' ? ctx.body : ctx.body.rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx.action.resourceName == 'collections.fields' && ctx.action.actionName == 'get') {
|
|
|
|
handleFieldSource(ctx.body);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-13 01:57:03 +00:00
|
|
|
this.app.db.extendCollection({
|
|
|
|
name: 'collectionCategory',
|
|
|
|
namespace: 'collection-manager',
|
|
|
|
duplicator: 'required',
|
|
|
|
});
|
2022-02-14 13:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CollectionManagerPlugin;
|