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; 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 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 = []; 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, 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": "高级", diff --git a/services/service-plugin-amis/package.json b/services/service-plugin-amis/package.json index cd43383862..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.11" + "@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 41e8bb24bf..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.11" + "@steedos-widgets/amis-lib": "^0.0.13" }, "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"