@steedos/standard-object-database 2.7.10-beta.1 → 2.7.10-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  name: design_field_layout
2
2
  is_enable: true
3
3
  label: 设计字段布局
4
- 'on': record_only
4
+ 'on': record_more
5
+ sort: 80
@@ -1,5 +1,4 @@
1
1
  name: design_fields_layout
2
2
  is_enable: true
3
- label: 设计对象(Beta)
4
- 'on': record_more
5
- sort: 80
3
+ label: 设计对象
4
+ 'on': record_only
@@ -184,7 +184,16 @@
184
184
  "visible_on": {
185
185
  "amis": {
186
186
  "type": "input-formula",
187
- "name": "formula",
187
+ "evalMode": false,
188
+ "variableMode": "tabs",
189
+ "variables": "${visibleOnVariables}",
190
+ "visibleOn": "${visibleOnVariables}",
191
+ "id": "u:618105d5bfad"
192
+ }
193
+ },
194
+ "formula": {
195
+ "amis": {
196
+ "type": "input-formula",
188
197
  "evalMode": false,
189
198
  "variableMode": "tabs",
190
199
  "variables": "${visibleOnVariables}",
@@ -2,7 +2,7 @@
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-06-02 17:45:15
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2024-09-11 11:49:37
5
+ * @LastEditTime: 2024-10-17 12:02:21
6
6
  * @Description:
7
7
  -->
8
8
  <html>
@@ -11,6 +11,15 @@
11
11
  <script src="/unpkg.com/axios@0.26.1/dist/axios.min.js"></script>
12
12
  <script src="https://unpkg.steedos.cn/flowbite@2.3.0/dist/flowbite.min.js"></script>
13
13
  <script src="https://cdn.tailwindcss.com"></script>
14
+ <link href="/toast/toastr.min.css" rel="stylesheet" />
15
+ <script src="/jquery.min.js" ></script>
16
+ <script src="/toast/toastr.min.js"></script>
17
+ <style>
18
+ #toast-container.toast-bottom-center>div, #toast-container.toast-top-center>div {
19
+ width: 450px;
20
+ opacity: 1;
21
+ }
22
+ </style>
14
23
  </head>
15
24
 
16
25
  <body>
@@ -185,7 +194,7 @@
185
194
 
186
195
  }
187
196
 
188
- return await axios.post(
197
+ const result = await axios.post(
189
198
  `${rootUrl}/service/api/object_fields/amis/design/schema?oid=${oid}`,
190
199
  {
191
200
  withCredentials: true,
@@ -199,15 +208,130 @@
199
208
  // handle error
200
209
  console.log(error);
201
210
  });
211
+ const actionNames = ['insert', 'update', 'delete'];
212
+
213
+ toastr.options = {
214
+ "closeButton": true,
215
+ "debug": false,
216
+ "newestOnTop": false,
217
+ "progressBar": false,
218
+ "positionClass": "toast-top-center",
219
+ "preventDuplicates": false,
220
+ "onclick": null,
221
+ "showDuration": "300",
222
+ "hideDuration": "1000",
223
+ "timeOut": "5000",
224
+ "extendedTimeOut": "1000",
225
+ "showEasing": "swing",
226
+ "hideEasing": "linear",
227
+ "showMethod": "fadeIn",
228
+ "hideMethod": "fadeOut"
229
+ }
230
+
231
+ actionNames.forEach(function(actionName){
232
+ const actionData = result.data.data[actionName];
233
+ let actionLabel = '';
234
+ if(actionName === 'insert'){
235
+ actionLabel = '新增';
236
+ }else if(actionName === 'update'){
237
+ actionLabel = '更新';
238
+ }else if(actionName === 'delete'){
239
+ actionLabel = '删除';
240
+ }
241
+ if(actionData.error && actionData.error.length > 0){
242
+ actionData.error.forEach((error)=>{
243
+ toastr.warning(error.message, `${actionLabel}字段「${error.fieldLabel}(${error.fieldName})」失败:`);
244
+ })
245
+ }
246
+ })
247
+ return result;
202
248
  };
203
249
  window.addEventListener('message', function (event) {
204
250
  const { data } = event;
205
251
  if (data) {
206
252
  if(data.type === 'builder.loaded'){
207
253
  comp.messageFrame('builder.EditorPropsChanged', { editorProps : JSON.stringify({
254
+ onChange: function(value){
255
+ const fields = [];
256
+ _.each(value.body, (bodyItem)=>{
257
+ if(bodyItem.type === 'steedos-field-group'){
258
+ let groupName = bodyItem.title;
259
+ _.each(bodyItem.body, (field)=>{
260
+ if(_.startsWith(field.type, 'sfield-')){
261
+
262
+ if(field.config && field.config.amis){
263
+ delete field.config.amis.name
264
+ delete field.config.amis.mode
265
+ }
266
+
267
+ fields.push(Object.assign({}, field.config, {group: groupName}));
268
+ }
269
+ })
270
+ }else if(_.startsWith(bodyItem.type, 'sfield-')){
271
+ if(bodyItem.config && bodyItem.config.amis){
272
+ delete bodyItem.config.amis.name
273
+ delete bodyItem.config.amis.mode
274
+ }
275
+ fields.push(Object.assign({}, bodyItem.config, {group: '通用'}));
276
+ }
277
+ })
278
+
279
+
280
+ const variables = [];
281
+
282
+ _.each(_.groupBy(fields, 'group'), (v, k)=>{
283
+ if(k=== '通用'){
284
+ _.each(v, (field)=>{
285
+ variables.push({
286
+ label: field.label,
287
+ value: field.name
288
+ })
289
+ })
290
+ }else{
291
+ variables.push({
292
+ label: k,
293
+ children: _.map(v, (field)=>{
294
+ return {
295
+ label: field.label,
296
+ value: field.name
297
+ }
298
+ })
299
+ })
300
+ }
301
+ })
302
+ window._objectFieldsVariables = variables;
303
+ },
208
304
  onDndAccept: function(event){
209
305
  return true;
210
306
  },
307
+ beforeDelete: function(event){
308
+ const toastConfig = {
309
+ "closeButton": true,
310
+ "debug": false,
311
+ "newestOnTop": false,
312
+ "progressBar": false,
313
+ "positionClass": "toast-top-center",
314
+ "preventDuplicates": false,
315
+ "onclick": null,
316
+ "showDuration": "300",
317
+ "hideDuration": "1000",
318
+ "timeOut": "5000",
319
+ "extendedTimeOut": "1000",
320
+ "showEasing": "swing",
321
+ "hideEasing": "linear",
322
+ "showMethod": "fadeIn",
323
+ "hideMethod": "fadeOut"
324
+ }
325
+ if(event.context.schema.type.startsWith('sfield') && event.context.schema.config.is_system){
326
+ parent.toastr.warning('禁止删除系统字段', '', toastConfig)
327
+ return event.preventDefault();
328
+ };
329
+
330
+ if(event.context.schema.type.startsWith('sfield') && event.context.schema.config.name === 'name'){
331
+ parent.toastr.warning('禁止删除名称字段', '', toastConfig)
332
+ return event.preventDefault();
333
+ }
334
+ },
211
335
  onInit: function(){
212
336
  // 创建一个新的 style 元素
213
337
  var style = document.createElement('style');
@@ -2,6 +2,7 @@ var _ = require("underscore");
2
2
  var objectql = require('@steedos/objectql');
3
3
  var clone = require('clone');
4
4
  var objectCore = require('./objects.core.js');
5
+ var lodash = require('lodash');
5
6
 
6
7
  const objectFieldsFind = function (filter) {
7
8
  return objectql.wrapAsync(async function () {
@@ -31,7 +32,7 @@ function getFieldName(objectName, fieldName, spaceId, oldFieldName){
31
32
  if(object && object.datasource && object.datasource != 'default'){
32
33
  return fieldName;
33
34
  }else{
34
- if(fieldName != 'name' && fieldName != 'owner'){
35
+ if(!lodash.includes(['name', 'owner', 'created', 'created_by', 'modified', 'modified_by'], fieldName) ){
35
36
  return objectql._makeNewFieldName(fieldName, spaceId, oldFieldName);
36
37
  }else{
37
38
  return fieldName
@@ -470,7 +471,7 @@ var triggers = {
470
471
  }
471
472
 
472
473
  checkName(doc._name);
473
- if(['name','owner','parent','children'].indexOf(doc._name)>-1){
474
+ if(['name','owner','parent','children'].indexOf(doc._name)>-1 || doc._name && doc.is_system){
474
475
  doc.name = doc._name;
475
476
  }else{
476
477
  doc.name = getFieldName(doc.object,doc._name,doc.space);
@@ -322,6 +322,7 @@ let objectTriggers = {
322
322
  object: doc.name,
323
323
  owner: userId,
324
324
  _name: "created",
325
+ name: "created",
325
326
  label: "创建时间",
326
327
  space: doc.space,
327
328
  type: "datetime",
@@ -335,6 +336,7 @@ let objectTriggers = {
335
336
  object: doc.name,
336
337
  owner: userId,
337
338
  _name: "created_by",
339
+ name: "created_by",
338
340
  label: "创建人",
339
341
  space: doc.space,
340
342
  type: "lookup",
@@ -348,6 +350,7 @@ let objectTriggers = {
348
350
  object: doc.name,
349
351
  owner: userId,
350
352
  _name: "modified",
353
+ name: "modified",
351
354
  label: "修改时间",
352
355
  space: doc.space,
353
356
  type: "datetime",
@@ -361,9 +364,9 @@ let objectTriggers = {
361
364
  object: doc.name,
362
365
  owner: userId,
363
366
  _name: "modified_by",
367
+ name: "modified_by",
364
368
  label: "修改人",
365
369
  space: doc.space,
366
- space: doc.space,
367
370
  type: "lookup",
368
371
  reference_to: 'users',
369
372
  group: '',
@@ -315,7 +315,15 @@ module.exports = {
315
315
  _.map(objectFields, (objectField)=>{
316
316
  if(!objectField.group){
317
317
  objectField.group = '通用'
318
- }
318
+ };
319
+ delete objectField.owner;
320
+ delete objectField.space;
321
+ delete objectField.created;
322
+ delete objectField.modified;
323
+ delete objectField.created_by;
324
+ delete objectField.modified_by;
325
+ delete objectField.company_id;
326
+ delete objectField.company_ids;
319
327
  })
320
328
 
321
329
  return {
@@ -326,12 +334,13 @@ module.exports = {
326
334
  data: {
327
335
  objectName
328
336
  },
329
- className: "steedos-amis-form steedos-field-layout-page m-4",
337
+ className: "steedos-amis-form steedos-field-layout-page",
330
338
  body: _.map(_.groupBy(_.orderBy(objectFields, function(o) { return o.sort_no || 100 }), 'group'), (items, groupName)=>{
331
339
  const group = getGroup(groupName)
332
340
  return {
333
341
  type: 'steedos-field-group',
334
342
  title: group.group_name,
343
+ collapsable: true,
335
344
  collapsed: group.collapsed,
336
345
  visible_on: group.visible_on,
337
346
  body: _.map(items, (field)=>{
@@ -376,22 +385,32 @@ module.exports = {
376
385
  return {}
377
386
  }
378
387
  let sort_no = 50;
379
- _.each(schema.body, (group)=>{
380
- if(group.type === 'steedos-field-group'){
381
- const groupName = group.title;
382
- _.each(group.body, (field)=>{
388
+ _.each(schema.body, (bodyItem)=>{
389
+ if(bodyItem.type === 'steedos-field-group'){
390
+ const groupName = bodyItem.title;
391
+ _.each(bodyItem.body, (field)=>{
383
392
  if(_.startsWith(field.type, 'sfield-')){
384
- fields.push(Object.assign({}, field.config, {group: groupName, sort_no, _name: field.name}));
393
+
394
+ if(field.config && field.config.amis){
395
+ delete field.config.amis.name
396
+ delete field.config.amis.mode
397
+ }
398
+
399
+ fields.push(Object.assign({}, field.config, {group: groupName, sort_no, _name: field.config.name}));
385
400
  sort_no += 50;
386
401
  }
387
402
  })
388
403
  groups.push({
389
- group_name: group.title,
390
- collapsed: group.collapsed,
391
- visible_on: group.visible_on
404
+ group_name: bodyItem.title,
405
+ collapsed: bodyItem.collapsed,
406
+ visible_on: bodyItem.visible_on
392
407
  })
393
- }else if(_.startsWith(field.type, 'sfield-')){
394
- fields.push(Object.assign({}, field.config, {sort_no, _name: field.name}));
408
+ }else if(_.startsWith(bodyItem.type, 'sfield-')){
409
+ if(bodyItem.config && bodyItem.config.amis){
410
+ delete bodyItem.config.amis.name
411
+ delete bodyItem.config.amis.mode
412
+ }
413
+ fields.push(Object.assign({}, bodyItem.config, {sort_no, _name: bodyItem.config.name}));
395
414
  sort_no += 50;
396
415
  }
397
416
  })
@@ -423,10 +442,11 @@ module.exports = {
423
442
 
424
443
  // 循环需要增加的字段
425
444
  for (const fieldName of insertFields) {
445
+ const newId = await object_fields._makeNewID();
446
+ const now = new Date();
447
+ const field = _.find(fields, { name: fieldName });
426
448
  try {
427
- const newId = await object_fields._makeNewID();
428
- const now = new Date();
429
- const field = _.find(fields, { name: fieldName });
449
+
430
450
  const doc = Object.assign({}, field, {
431
451
  _id: newId,
432
452
  owner: userSession.userId,
@@ -445,7 +465,11 @@ module.exports = {
445
465
  await object_fields.directInsert(doc);
446
466
  log.insert.success.push(fieldName);
447
467
  } catch (e) {
448
- log.insert.error.push(fieldName);
468
+ log.insert.error.push({
469
+ fieldName: fieldName,
470
+ fieldLabel: field.label,
471
+ message: steedosI18n.t(e.message, null, 'zh-CN')
472
+ });
449
473
  console.error(`新增字段 ${fieldName} 时出错:`, e);
450
474
  }
451
475
  }
@@ -453,32 +477,45 @@ module.exports = {
453
477
  // 循环需要修改的字段
454
478
  const now = new Date();
455
479
  for (const fieldName of updateFields) {
480
+ const field = _.find(fields, { name: fieldName });
456
481
  try {
457
- const field = _.find(fields, { name: fieldName });
458
482
  const id = _.find(dbFields, { name: fieldName })._id;
459
483
  const submitField = _.omit(field, ['name', '_name']);
460
484
 
461
485
  if(submitField.type === "summary"){
462
486
  await initSummaryDoc(submitField);
463
487
  }
488
+ if(submitField){
489
+ delete submitField._id;
490
+ }
464
491
  await object_fields.directUpdate(id, Object.assign({}, submitField, {
465
492
  modified: now,
466
493
  modified_by: userSession.userId
467
494
  }));
468
495
  log.update.success.push(fieldName);
469
496
  } catch (e) {
470
- log.update.error.push(fieldName);
497
+ log.update.error.push({
498
+ fieldName: fieldName,
499
+ fieldLabel: field.label,
500
+ message: steedosI18n.t(e.message, null, 'zh-CN')
501
+ });
471
502
  console.log(`dbFields`, fieldName, dbFields)
472
503
  console.error(`更新字段 ${fieldName} 时出错:`, e);
473
504
  }
474
505
  }
475
506
  // 循环需要删除的字段
476
507
  for (const fieldName of deleteFields) {
508
+ const field = _.find(dbFields, { name: fieldName })._id;
477
509
  try {
478
- const id = _.find(dbFields, { name: fieldName })._id;
510
+ const id = field._id;
479
511
  await object_fields.directDelete(id);
480
512
  log.delete.success.push(fieldName);
481
513
  } catch (e) {
514
+ log.delete.error.push({
515
+ fieldName: fieldName,
516
+ fieldLabel: field.label,
517
+ message: steedosI18n.t(e.message, null, 'zh-CN')
518
+ });
482
519
  log.delete.error.push(fieldName);
483
520
  console.error(`删除字段 ${fieldName} 时出错:`, e);
484
521
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.7.10-beta.1",
3
+ "version": "2.7.10-beta.11",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -12,14 +12,14 @@
12
12
  "description": "steedos package",
13
13
  "dependencies": {
14
14
  "@steedos-widgets/amis-lib": "^1.0.22",
15
- "@steedos/metadata-core": "2.7.10-beta.1",
16
- "@steedos/service-object-mixin": "2.7.10-beta.1",
17
- "@steedos/standard-objects": "2.7.10-beta.1",
15
+ "@steedos/metadata-core": "2.7.10-beta.11",
16
+ "@steedos/service-object-mixin": "2.7.10-beta.11",
17
+ "@steedos/standard-objects": "2.7.10-beta.11",
18
18
  "amis-formula": "~6.3.0",
19
19
  "clone": "^2.1.2",
20
20
  "moleculer-bullmq": "3.0.0"
21
21
  },
22
22
  "repository": {},
23
23
  "license": "MIT",
24
- "gitHead": "abc4dfba3bd5f3df2244bd2f1fdf61e38d59723f"
24
+ "gitHead": "8be70858573845de1c3b6cf45ba96f626c87282e"
25
25
  }
@@ -2,7 +2,7 @@
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 1985-10-26 16:15:00
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2024-09-24 15:00:31
5
+ * @LastEditTime: 2024-10-10 15:58:37
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
@@ -169,7 +169,7 @@ module.exports = {
169
169
 
170
170
 
171
171
  const tab_items = app.tab_items || {};
172
- tab_items[`object_${obj.name}`] = {
172
+ tab_items[`object_${obj.name.replace(/__c$/, "")}`] = {
173
173
  group: groupId
174
174
  }
175
175
 
@@ -273,7 +273,7 @@ module.exports = {
273
273
  fullPath: "/service/api/apps/create_by_design"
274
274
  },
275
275
  async handler(ctx) {
276
- const { code, name } = ctx.params;
276
+ const { code, name, icon } = ctx.params;
277
277
  const userSession = ctx.meta.user;
278
278
 
279
279
  if(!code || !name){
@@ -288,7 +288,7 @@ module.exports = {
288
288
  mobile : true,
289
289
  visible : true,
290
290
  showSidebar : true,
291
- icon_slds : "account",
291
+ icon_slds : icon || "account",
292
292
  }, userSession);
293
293
  }
294
294
  },