Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 4, 2022
2 parents d2094dc + 69816cf commit c084bb3
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/routes/excel_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 18 additions & 13 deletions packages/data-import/src/imports/ImportJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class ImportJson implements Base {
async readFile(filePath: string): Promise<Array<{ objectName: string, records: Array<any> }>> {
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")];

Expand All @@ -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则提前新建好
Expand All @@ -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)
}
}
Expand Down
24 changes: 20 additions & 4 deletions packages/data-import/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
export async function getUserSession(spaceId?: string): Promise<userSessionType|any> {
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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/data-import/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2022-11-30 16:17:07
* @LastEditors: [email protected]
* @LastEditTime: 2022-11-30 16:17:31
* @Description:
*/
export * from './userSessionType'
13 changes: 13 additions & 0 deletions packages/data-import/src/types/userSessionType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* @Author: [email protected]
* @Date: 2022-11-30 16:16:08
* @LastEditors: [email protected]
* @LastEditTime: 2022-11-30 16:16:47
* @Description:
*/
export type userSessionType = {
spaceId: string
userId: string
company_id: string
company_ids: string[]
}
2 changes: 2 additions & 0 deletions packages/objectql/src/driver/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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 = [];

Expand Down
10 changes: 5 additions & 5 deletions packages/standard-objects/spaces.object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "高级",
Expand Down
2 changes: 1 addition & 1 deletion services/service-plugin-amis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"access": "public"
},
"dependencies": {
"@steedos-widgets/amis-lib": "^0.0.11"
"@steedos-widgets/amis-lib": "^0.0.13"
},
"gitHead": "222df35b60965f1ee48d343156ff6e67250cb98c"
}
2 changes: 1 addition & 1 deletion services/standard-object-database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit c084bb3

Please sign in to comment.