From 7db6a2ca6fb7e9fc29dac964ac10c517b39f863f Mon Sep 17 00:00:00 2001 From: Byran Date: Thu, 1 Dec 2022 19:31:04 +0800 Subject: [PATCH 1/7] =?UTF-8?q?SaaS=E7=89=88=EF=BC=9A=E4=B8=BB=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20&=20demo=E6=95=B0=E6=8D=AE=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=20#3961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data-import/src/imports/ImportJson.ts | 31 +++++++++++-------- packages/data-import/src/index.ts | 24 +++++++++++--- packages/data-import/src/types/index.ts | 8 +++++ .../data-import/src/types/userSessionType.ts | 13 ++++++++ 4 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 packages/data-import/src/types/index.ts create mode 100644 packages/data-import/src/types/userSessionType.ts diff --git a/packages/data-import/src/imports/ImportJson.ts b/packages/data-import/src/imports/ImportJson.ts index f083e553ce..f302542f79 100644 --- a/packages/data-import/src/imports/ImportJson.ts +++ b/packages/data-import/src/imports/ImportJson.ts @@ -6,7 +6,7 @@ import { syncMatchFiles } from '@steedos/metadata-core'; const path = require('path'); const fs = require("fs"); import { EJSON } from 'bson' -import { preCreateCollection } from '..'; +import { formatResults, preCreateCollection } from '..'; const transactionOptions: any = { readPreference: 'primary', @@ -40,7 +40,7 @@ export default class ImportJson implements Base { async readFile(filePath: string): Promise }>> { let results: any = [] const filePatten = [ - path.join(filePath, "**", "*.data.json"), + path.join(filePath, "**", "*.data.json"), "!" + path.join(filePath, "**", "*.flow.data.json"), "!" + path.join(filePath, "node_modules")]; @@ -54,10 +54,15 @@ export default class ImportJson implements Base { } async fileRecordsToDB(filePath: string) { - var dbManager = new DbManager(this.userSession); + const userSession = this.userSession + const { spaceId, userId, company_id, company_ids } = userSession + var dbManager = new DbManager(userSession); const now = new Date() try { - const results: any = await this.readFile(filePath); + let results: any = await this.readFile(filePath); + + results = formatResults(results, userSession) + await dbManager.connect(); // 如果库中没有collection则提前新建好 @@ -78,21 +83,21 @@ export default class ImportJson implements Base { delete record.created_by; await dbManager.update(result.objectName, { _id: record._id }, Object.assign(record, { modified: now, - modified_by: this.userSession.userId, - company_id: this.userSession.company_id, - company_ids: this.userSession.company_ids, + modified_by: userId, + company_id: company_id, + company_ids: company_ids, })) } else { await dbManager.insert(result.objectName, Object.assign(record, { _id: record._id || new ObjectId().toHexString(), - space: this.userSession.spaceId, - owner: this.userSession.userId, + space: spaceId, + owner: userId, created: now, - created_by: this.userSession.userId, + created_by: userId, modified: now, - modified_by: this.userSession.userId, - company_id: this.userSession.company_id, - company_ids: this.userSession.company_ids, + modified_by: userId, + company_id: company_id, + company_ids: company_ids, }), false) } } diff --git a/packages/data-import/src/index.ts b/packages/data-import/src/index.ts index c928010415..aff59dba46 100644 --- a/packages/data-import/src/index.ts +++ b/packages/data-import/src/index.ts @@ -4,13 +4,18 @@ import { getSteedosConfig } from '@steedos/objectql' import ImportJson from './imports/ImportJson' import ImportCsv from './imports/ImportCsv' import ImportFlow from './imports/ImportFlow' +import { userSessionType } from './types' -export async function getUserSession(): Promise { +export async function getUserSession(spaceId?: string): Promise { var dbManager = new DbManager({}); const now = new Date() try { await dbManager.connect(); - const space = await dbManager.findOne('spaces', {}, false); + const selector = {} + if (spaceId) { + selector['_id'] = spaceId + } + const space = await dbManager.findOne('spaces', selector, false); if (!space) { return; } @@ -61,13 +66,24 @@ type readFileResult = { readonly records: any[] } +/** + * 将数据中的${space_id}替换为spaceId值 + * @param results + * @param userSession + * @returns new results + */ +export function formatResults (results: readFileResult[], userSession: userSessionType): readFileResult[] { + const { spaceId, userId } = userSession + return JSON.parse(JSON.stringify(results).replace(/\${space_id}/g, spaceId).replace(/\${space_owner_id}/g, userId)) +} + /** * * @param {*} filePath 要导入数据的文件夹路径 * @param {*} onlyInsert 仅导入,在导入数据之前先检查,如果存在任意一条记录,则不执行导入 */ -export async function importData(filePath: string, onlyInsert: boolean = true) { - const userSession = await getUserSession() +export async function importData(filePath: string, onlyInsert: boolean = true, spaceId?: string) { + const userSession = await getUserSession(spaceId) if (isEmpty(userSession)) { return; } diff --git a/packages/data-import/src/types/index.ts b/packages/data-import/src/types/index.ts new file mode 100644 index 0000000000..b770565071 --- /dev/null +++ b/packages/data-import/src/types/index.ts @@ -0,0 +1,8 @@ +/* + * @Author: sunhaolin@hotoa.com + * @Date: 2022-11-30 16:17:07 + * @LastEditors: sunhaolin@hotoa.com + * @LastEditTime: 2022-11-30 16:17:31 + * @Description: + */ +export * from './userSessionType' \ No newline at end of file diff --git a/packages/data-import/src/types/userSessionType.ts b/packages/data-import/src/types/userSessionType.ts new file mode 100644 index 0000000000..bcfc7a02b9 --- /dev/null +++ b/packages/data-import/src/types/userSessionType.ts @@ -0,0 +1,13 @@ +/* + * @Author: sunhaolin@hotoa.com + * @Date: 2022-11-30 16:16:08 + * @LastEditors: sunhaolin@hotoa.com + * @LastEditTime: 2022-11-30 16:16:47 + * @Description: + */ +export type userSessionType = { + spaceId: string + userId: string + company_id: string + company_ids: string[] +} \ No newline at end of file From 9ada14b89469e5af611d2fb2ab08c8cd54a96616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E4=BA=AE=E8=BE=89?= Date: Thu, 1 Dec 2022 15:30:37 +0000 Subject: [PATCH 2/7] amis lib 0.0.12 --- services/service-plugin-amis/package.json | 2 +- services/standard-object-database/package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/service-plugin-amis/package.json b/services/service-plugin-amis/package.json index cd43383862..1edfed5a06 100644 --- a/services/service-plugin-amis/package.json +++ b/services/service-plugin-amis/package.json @@ -11,7 +11,7 @@ "access": "public" }, "dependencies": { - "@steedos-widgets/amis-lib": "^0.0.11" + "@steedos-widgets/amis-lib": "^0.0.12" }, "gitHead": "222df35b60965f1ee48d343156ff6e67250cb98c" } diff --git a/services/standard-object-database/package.json b/services/standard-object-database/package.json index 41e8bb24bf..d03b47ccb6 100644 --- a/services/standard-object-database/package.json +++ b/services/standard-object-database/package.json @@ -11,7 +11,7 @@ ], "description": "steedos package", "dependencies": { - "@steedos-widgets/amis-lib": "^0.0.11" + "@steedos-widgets/amis-lib": "^0.0.12" }, "repository": {}, "license": "MIT", diff --git a/yarn.lock b/yarn.lock index e56276e36e..99a725c4ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4416,10 +4416,10 @@ dependencies: react-required-if "^1.0.3" -"@steedos-widgets/amis-lib@^0.0.11": - version "0.0.11" - resolved "https://registry.yarnpkg.com/@steedos-widgets/amis-lib/-/amis-lib-0.0.11.tgz#5bc395bbf72ffe9b0a8acd45260f98c7fb7897c5" - integrity sha512-B6V8a2Qfaos8PO+kK3TqEQmQoocVhcigty5T4XZciAbvGN0RjGWTq416zW+rkZfIKX59VmtdV4EMl1sJps7u2Q== +"@steedos-widgets/amis-lib@^0.0.12": + version "0.0.12" + resolved "https://registry.yarnpkg.com/@steedos-widgets/amis-lib/-/amis-lib-0.0.12.tgz#ba4a88540edc2d2270797f6624da02cbb44af743" + integrity sha512-A8p12uxLL8PpSNZitw8+UI8bBT6SHIuKk4Vr1swUSSD78KFrFta7xUOmonExAaCr9g/beJ2/ODxeZWfWPJkhHA== dependencies: lodash "^4.17.21" From 792b1b0db38d2bf9705b135bf941b2d19c493625 Mon Sep 17 00:00:00 2001 From: Byran Date: Fri, 2 Dec 2022 10:38:10 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8C=BA=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E5=90=8E=EF=BC=8C=E5=B7=A5=E4=BD=9C=E5=8C=BAid?= =?UTF-8?q?=E3=80=81=E6=A0=B9=E7=BB=84=E7=BB=87id=E3=80=81=E6=A0=B9?= =?UTF-8?q?=E5=88=86=E9=83=A8id=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= =?UTF-8?q?=EF=BC=8C=E9=83=BD=E6=98=AF=E7=94=A8=E5=B7=A5=E4=BD=9C=E5=8C=BA?= =?UTF-8?q?id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SaaS版:主数据 & demo数据初始化 #3961 --- packages/standard-objects/spaces.object.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/standard-objects/spaces.object.js b/packages/standard-objects/spaces.object.js index 4de938613d..a5826c9544 100644 --- a/packages/standard-objects/spaces.object.js +++ b/packages/standard-objects/spaces.object.js @@ -54,10 +54,10 @@ function onCreateSpace(spaceDoc){ let companyDB = Creator.getCollection("company"); let companyId = companyDB._makeNewID(); let companyDoc = { - _id: companyId, + _id: spaceId, name: spaceName, - organization: companyId, - company_id: companyId, + organization: spaceId, + company_id: spaceId, space: spaceId, owner: userId, created_by: userId, @@ -69,12 +69,12 @@ function onCreateSpace(spaceDoc){ let orgDB = Creator.getCollection("organizations"); let orgDoc = { - _id: companyId, + _id: spaceId, name: spaceName, fullname: spaceName, is_company: true, users: [userId], - company_id: companyId, + company_id: spaceId, space: spaceId, owner: userId, created_by: userId, From f7a6bb09c91bf50960bb5431bf6ef3557446516a Mon Sep 17 00:00:00 2001 From: Byran Date: Fri, 2 Dec 2022 15:44:16 +0800 Subject: [PATCH 4/7] fix TypeError: Cannot read property 'db' of undefined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SaaS版:主数据 & demo数据初始化 #3961 导入数据包含公式字段导致 --- packages/objectql/src/driver/mongo.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/objectql/src/driver/mongo.ts b/packages/objectql/src/driver/mongo.ts index 3b64dca4d1..b2922e36fe 100644 --- a/packages/objectql/src/driver/mongo.ts +++ b/packages/objectql/src/driver/mongo.ts @@ -253,6 +253,7 @@ export class SteedosMongoDriver implements SteedosDriver { } async directAggregate(tableName: string, query: SteedosQueryOptions, externalPipeline: any[], userId?: SteedosIDType) { + await this.connect(); let collection = this.collection(tableName); let pipeline = []; if(query.filters){ @@ -267,6 +268,7 @@ export class SteedosMongoDriver implements SteedosDriver { } async directAggregatePrefixalPipeline(tableName: string, query: SteedosQueryOptions, prefixalPipeline: any[], userId?: SteedosIDType) { + await this.connect(); let collection = this.collection(tableName); let pipeline = []; From bffcd63a3f3b20a5a83827d98bae641b4d44bc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=A4=A7=E9=9B=AA?= <2291335922@qq.com> Date: Fri, 2 Dec 2022 18:05:40 +0800 Subject: [PATCH 5/7] =?UTF-8?q?#3965=20=E5=AF=BC=E5=87=BAexcel=E6=97=B6boo?= =?UTF-8?q?lean=E5=AD=97=E6=AE=B5=E6=9C=AA=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/routes/excel_export.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/routes/excel_export.ts b/packages/core/src/routes/excel_export.ts index 3817722575..6a5c97b375 100644 --- a/packages/core/src/routes/excel_export.ts +++ b/packages/core/src/routes/excel_export.ts @@ -188,9 +188,9 @@ const key2value = async function (fieldValue, fieldConfig, userSession) { switch (fieldConfig.type) { case "boolean": if (fieldValue) { - return '是'; + return TAPi18n.__("form_field_checkbox_yes", {}, userSession.language); } else { - return '否'; + return TAPi18n.__("form_field_checkbox_no", {}, userSession.language); } case "select": let options = fieldConfig.options; From 5f3799e67d64d2c874e4245b4e43511c2ccfd728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=A4=A7=E9=9B=AA?= <2291335922@qq.com> Date: Sat, 3 Dec 2022 17:09:57 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=B0=E7=89=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E9=A1=B9=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/steedos/steedos-webapp-nextjs/issues/59 --- .../pages/listview_form.page.amis.json | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/services/service-plugin-amis/main/default/pages/listview_form.page.amis.json b/services/service-plugin-amis/main/default/pages/listview_form.page.amis.json index 24f34c60de..7efa37fec5 100644 --- a/services/service-plugin-amis/main/default/pages/listview_form.page.amis.json +++ b/services/service-plugin-amis/main/default/pages/listview_form.page.amis.json @@ -399,6 +399,49 @@ }, "id": "u:51174159a42e" }, + { + "type": "fieldSet", + "title": "搜索项", + "collapsable": true, + "body": [ + { + "label": "默认可搜索字段", + "type": "transfer", + "name": "searchable_fields", + "options": [], + "selectMode": "list", + "searchable": true, + "searchApi": "", + "sortable": true, + "mode": "normal", + "searchResultMode": "list", + "joinValues": false, + "extractValue": true, + "source": { + "method": "get", + "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/options", + "headers": { + "Authorization": "Bearer ${context.tenantId},${context.authToken}" + }, + "data": null, + "requestAdaptor": "", + "adaptor": "", + "sendOn": "!!this.object_name" + }, + "visibleOn": "!!this.object_name", + "className": "col-span-2 m-0", + "en-US": { + "label": "searchable fields" + }, + "multiple": true + } + ], + "collapsed": true, + "visibleOn": "!!this.object_name", + "en-US": { + "title": "searchable" + } + }, { "type": "fieldSet", "title": "高级", From 69816cf93ac4399b22e8c93a8bc8a7b7a84e1233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E4=BA=AE=E8=BE=89?= Date: Sun, 4 Dec 2022 15:44:03 +0000 Subject: [PATCH 7/7] @steedos-widgets/amis-lib 0.0.13 --- services/service-plugin-amis/package.json | 2 +- services/standard-object-database/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/service-plugin-amis/package.json b/services/service-plugin-amis/package.json index 1edfed5a06..c75c6e9d1b 100644 --- a/services/service-plugin-amis/package.json +++ b/services/service-plugin-amis/package.json @@ -11,7 +11,7 @@ "access": "public" }, "dependencies": { - "@steedos-widgets/amis-lib": "^0.0.12" + "@steedos-widgets/amis-lib": "^0.0.13" }, "gitHead": "222df35b60965f1ee48d343156ff6e67250cb98c" } diff --git a/services/standard-object-database/package.json b/services/standard-object-database/package.json index d03b47ccb6..e6c068deb9 100644 --- a/services/standard-object-database/package.json +++ b/services/standard-object-database/package.json @@ -11,7 +11,7 @@ ], "description": "steedos package", "dependencies": { - "@steedos-widgets/amis-lib": "^0.0.12" + "@steedos-widgets/amis-lib": "^0.0.13" }, "repository": {}, "license": "MIT",