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

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.
@@ -42,7 +42,7 @@ router.get('/api/amisObjectFieldsDesign', core.requireAuthentication, async func
42
42
  } else if (req.query.locale == "zh-cn") {
43
43
  locale = "zh-CN";
44
44
  }
45
- const retUrl = __meteor_runtime_config__.ROOT_URL + '/app/admin/objects/view/' + req.query.oid
45
+ const retUrl = req.query.retUrl || __meteor_runtime_config__.ROOT_URL + '/app/admin/objects/view/' + req.query.oid
46
46
  const steedosBuilderUrl = process.env.STEEDOS_BUILDER_URL || 'https://builder.steedos.cn';
47
47
  const builderHost = `${steedosBuilderUrl}/object?${assetUrl}retUrl=${retUrl}&locale=${locale}&isObjectDesign=1&pType=objectDesign`;
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.7.9-beta.4",
3
+ "version": "2.7.10-beta.1",
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.9-beta.4",
16
- "@steedos/service-object-mixin": "2.7.9-beta.4",
17
- "@steedos/standard-objects": "2.7.9-beta.4",
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",
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": "3162f373294a238808d1b55cc876cdc2edcf5d19"
24
+ "gitHead": "abc4dfba3bd5f3df2244bd2f1fdf61e38d59723f"
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-03-20 14:30:13
5
+ * @LastEditTime: 2024-09-24 15:00:31
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
@@ -14,6 +14,10 @@ const validator = require('validator');
14
14
  const triggers = require('./src/triggers');
15
15
  const { checkAPIName } = require('@steedos/standard-objects').util
16
16
 
17
+ const { customAlphabet } = require('nanoid');
18
+ const { group } = require('console');
19
+ const nanoid = customAlphabet('1234567890abcdef', 10)
20
+
17
21
  /**
18
22
  * @typedef {import('moleculer').Context} Context Moleculer's Context
19
23
  */
@@ -133,6 +137,475 @@ module.exports = {
133
137
  await checkAPIName(objectName, fieldName, fieldValue, recordId, filters)
134
138
  }
135
139
  },
140
+ create_object: {
141
+ rest: {
142
+ method: "POST",
143
+ fullPath: "/service/api/objects/create_by_design"
144
+ },
145
+ async handler(ctx) {
146
+ const { appId, groupId, name, label, icon } = ctx.params;
147
+ const userSession = ctx.meta.user;
148
+
149
+ if(!appId){
150
+ return;
151
+ }
152
+
153
+ const records = await this.getObject('apps').find({
154
+ filters: ['code', '=', appId]
155
+ });
156
+ const app = records.length > 0 ? records[0] : null;
157
+
158
+ if(!app){
159
+ return ;
160
+ }
161
+
162
+ // 1 创建对象
163
+ const obj = await this.getObject('objects').insert({
164
+ name: name || `o_${nanoid(5)}`,
165
+ label: label || '未命名对象',
166
+ datasource: 'default',
167
+ icon: icon || 'account'
168
+ }, userSession);
169
+
170
+
171
+ const tab_items = app.tab_items || {};
172
+ tab_items[`object_${obj.name}`] = {
173
+ group: groupId
174
+ }
175
+
176
+ await this.getObject('apps').update(app._id, {
177
+ tab_items
178
+ }, userSession);
179
+
180
+ return obj;
181
+ }
182
+ },
183
+ create_app_group: {
184
+ rest: {
185
+ method: "POST",
186
+ fullPath: "/service/api/apps/create_app_group_by_design"
187
+ },
188
+ async handler(ctx) {
189
+ const { appId, name, defaultOpen, oldName } = ctx.params;
190
+ const userSession = ctx.meta.user;
191
+
192
+ if(!appId){
193
+ return {};
194
+ }
195
+
196
+ const records = await this.getObject('apps').find({
197
+ filters: ['code', '=', appId]
198
+ });
199
+ const app = records.length > 0 ? records[0] : null;
200
+
201
+ if(!app){
202
+ return {};
203
+ }
204
+
205
+ await this.getObject('apps').update(app._id, {
206
+ $push: {
207
+ tab_groups: {
208
+ group_name: name,
209
+ default_open: defaultOpen
210
+ }
211
+ }
212
+ }, userSession);
213
+
214
+ return {};
215
+ }
216
+ },
217
+ update_app_group: {
218
+ rest: {
219
+ method: "POST",
220
+ fullPath: "/service/api/apps/update_app_group_by_design"
221
+ },
222
+ async handler(ctx) {
223
+ const { appId, name, defaultOpen, oldName } = ctx.params;
224
+ const userSession = ctx.meta.user;
225
+
226
+ if(!oldName){
227
+ return {}
228
+ }
229
+
230
+ if(!appId){
231
+ return {};
232
+ }
233
+
234
+ const records = await this.getObject('apps').find({
235
+ filters: ['code', '=', appId]
236
+ });
237
+ const app = records.length > 0 ? records[0] : null;
238
+
239
+ if(!app){
240
+ return {};
241
+ };
242
+
243
+ const tab_groups = app.tab_groups;
244
+
245
+ const tab_items = app.tab_items;
246
+
247
+ _.each(tab_groups, (tGroup)=>{
248
+ if(tGroup.group_name == oldName){
249
+ tGroup.group_name = name;
250
+ tGroup.default_open = defaultOpen
251
+ }
252
+ });
253
+
254
+
255
+ _.each(tab_items, (tItem, key)=>{
256
+ if(tItem.group === oldName){
257
+ tab_items[key] = {
258
+ group: name
259
+ }
260
+ }
261
+ })
262
+
263
+ await this.getObject('apps').update(app._id, {
264
+ tab_groups, tab_items
265
+ }, userSession);
266
+
267
+ return {};
268
+ }
269
+ },
270
+ create_by_design: {
271
+ rest: {
272
+ method: "POST",
273
+ fullPath: "/service/api/apps/create_by_design"
274
+ },
275
+ async handler(ctx) {
276
+ const { code, name } = ctx.params;
277
+ const userSession = ctx.meta.user;
278
+
279
+ if(!code || !name){
280
+ return {};
281
+ }
282
+
283
+ return await this.getObject('apps').insert({
284
+ name: name,
285
+ code: code,
286
+ sort : 9100,
287
+ is_creator : true,
288
+ mobile : true,
289
+ visible : true,
290
+ showSidebar : true,
291
+ icon_slds : "account",
292
+ }, userSession);
293
+ }
294
+ },
295
+ update_app_by_design: {
296
+ rest: {
297
+ method: "POST",
298
+ fullPath: "/service/api/apps/update_app_by_design"
299
+ },
300
+ async handler(ctx) {
301
+ const { appId, tab_groups, tab_items } = ctx.params;
302
+ const userSession = ctx.meta.user;
303
+
304
+ if(!appId){
305
+ return {};
306
+ }
307
+
308
+ const records = await this.getObject('apps').find({
309
+ filters: ['code', '=', appId]
310
+ });
311
+ const app = records.length > 0 ? records[0] : null;
312
+
313
+ if(!app){
314
+ return {};
315
+ }
316
+
317
+ await this.getObject('apps').update(app._id, {
318
+ tab_groups: tab_groups,
319
+ tab_items: tab_items
320
+ }, userSession);
321
+
322
+ }
323
+ },
324
+ update_app_tabs_by_design: {
325
+ rest: {
326
+ method: "POST",
327
+ fullPath: "/service/api/apps/update_app_tabs_by_design"
328
+ },
329
+ async handler(ctx) {
330
+ const { appId, addTabNames, groupId } = ctx.params;
331
+ const userSession = ctx.meta.user;
332
+
333
+ if(!appId){
334
+ return {};
335
+ }
336
+
337
+ const records = await this.getObject('apps').find({
338
+ filters: ['code', '=', appId]
339
+ });
340
+ const app = records.length > 0 ? records[0] : null;
341
+
342
+ if(!app){
343
+ return {};
344
+ }
345
+
346
+ const tab_items = app.tab_items || {};
347
+
348
+ _.each(addTabNames, (tabName)=>{
349
+ if(tabName){
350
+ tab_items[tabName] = {
351
+ group: groupId
352
+ }
353
+ }
354
+ })
355
+
356
+ await this.getObject('apps').update(app._id, {
357
+ tab_items
358
+ }, userSession);
359
+
360
+ }
361
+ },
362
+ create_link_tab_by_design: {
363
+ rest: {
364
+ method: "POST",
365
+ fullPath: "/service/api/tabs/create_link_tab_by_design"
366
+ },
367
+ async handler(ctx) {
368
+ const { appId, groupId, name, label, icon, url } = ctx.params;
369
+ const userSession = ctx.meta.user;
370
+
371
+ if(!appId){
372
+ return;
373
+ }
374
+
375
+ const records = await this.getObject('apps').find({
376
+ filters: ['code', '=', appId]
377
+ });
378
+ const app = records.length > 0 ? records[0] : null;
379
+
380
+ if(!app){
381
+ return ;
382
+ }
383
+
384
+ const tab = await this.getObject('tabs').insert({
385
+ name: name || `t_${nanoid(5)}`,
386
+ label: label || '未命名选项卡',
387
+ icon: icon || 'account',
388
+ mobile : true,
389
+ desktop : true,
390
+ is_new_window : false,
391
+ is_use_iframe : true,
392
+ type : "url",
393
+ url : url,
394
+ }, userSession);
395
+
396
+
397
+ const tab_items = app.tab_items || {};
398
+ tab_items[tab.name] = {
399
+ group: groupId
400
+ }
401
+ await this.getObject('apps').update(app._id, {
402
+ tab_items
403
+ }, userSession);
404
+
405
+ return tab;
406
+ }
407
+ },
408
+ update_link_tab_by_design: {
409
+ rest: {
410
+ method: "POST",
411
+ fullPath: "/service/api/tabs/update_link_tab_by_design"
412
+ },
413
+ async handler(ctx) {
414
+ const { appId, groupId, name, label, icon, url } = ctx.params;
415
+ const userSession = ctx.meta.user;
416
+
417
+ if(!appId){
418
+ return;
419
+ }
420
+
421
+ const records = await this.getObject('apps').find({
422
+ filters: ['code', '=', appId]
423
+ });
424
+ const app = records.length > 0 ? records[0] : null;
425
+
426
+ if(!app){
427
+ return ;
428
+ }
429
+
430
+ const dbTab = await this.getObject('tabs').find({
431
+ filters: ['name', '=', name]
432
+ }, userSession);
433
+
434
+ if(dbTab.length > 0){
435
+ const tab = await this.getObject('tabs').update(dbTab[0]._id, {
436
+ name: name,
437
+ label: label,
438
+ icon: icon,
439
+ url : url,
440
+ }, userSession);
441
+ return tab;
442
+ }
443
+ return dbTab;
444
+ }
445
+ },
446
+ create_page_by_design: {
447
+ rest: {
448
+ method: "POST",
449
+ fullPath: "/service/api/pages/create_page_by_design"
450
+ },
451
+ async handler(ctx) {
452
+ const { appId, groupId, name, label, icon } = ctx.params;
453
+ const userSession = ctx.meta.user;
454
+
455
+ if(!appId){
456
+ return;
457
+ }
458
+
459
+ const records = await this.getObject('apps').find({
460
+ filters: ['code', '=', appId]
461
+ });
462
+ const app = records.length > 0 ? records[0] : null;
463
+
464
+ if(!app){
465
+ return ;
466
+ }
467
+
468
+ const page = await this.getObject('pages').insert({
469
+ name: name || `t_${nanoid(5)}`,
470
+ label : label,
471
+ is_active : true,
472
+ render_engine : "amis",
473
+ type : "app"
474
+ }, userSession);
475
+
476
+ const tab = await this.getObject('tabs').insert({
477
+ name: `page_${page.name}`,
478
+ mobile : true,
479
+ desktop : true,
480
+ is_new_window : false,
481
+ is_use_iframe : false,
482
+ icon : icon,
483
+ type : "page",
484
+ label : label,
485
+ page : page.name,
486
+ }, userSession);
487
+
488
+
489
+ const tab_items = app.tab_items || {};
490
+ tab_items[tab.name] = {
491
+ group: groupId
492
+ }
493
+ await this.getObject('apps').update(app._id, {
494
+ tab_items
495
+ }, userSession);
496
+
497
+ return page;
498
+ }
499
+ },
500
+ delete_app_tab: {
501
+ rest: {
502
+ method: "POST",
503
+ fullPath: "/service/api/apps/delete_app_tab"
504
+ },
505
+ async handler(ctx) {
506
+ const { appId, tabName } = ctx.params;
507
+ const userSession = ctx.meta.user;
508
+
509
+ if(!appId){
510
+ return;
511
+ }
512
+
513
+ const records = await this.getObject('apps').find({
514
+ filters: ['code', '=', appId]
515
+ });
516
+ const app = records.length > 0 ? records[0] : null;
517
+
518
+ if(!app){
519
+ return ;
520
+ }
521
+
522
+
523
+ const tab_items = app.tab_items || {};
524
+
525
+ delete tab_items[tabName]
526
+
527
+ await this.getObject('apps').update(app._id, {
528
+ tab_items
529
+ }, userSession);
530
+
531
+ return app;
532
+ }
533
+ },
534
+ delete_app_group: {
535
+ rest: {
536
+ method: "POST",
537
+ fullPath: "/service/api/apps/delete_app_group"
538
+ },
539
+ async handler(ctx) {
540
+ const { appId, groupName } = ctx.params;
541
+ const userSession = ctx.meta.user;
542
+
543
+ if(!appId){
544
+ return;
545
+ }
546
+
547
+ const records = await this.getObject('apps').find({
548
+ filters: ['code', '=', appId]
549
+ });
550
+ const app = records.length > 0 ? records[0] : null;
551
+
552
+ if(!app){
553
+ return ;
554
+ }
555
+
556
+ const tab_groups = app.tab_groups || [];
557
+ const newTabGroups = [];
558
+
559
+ _.each(tab_groups, (tGroup)=>{
560
+ if(tGroup.group_name != groupName){
561
+ newTabGroups.push(tGroup);
562
+ }
563
+ });
564
+ await this.getObject('apps').update(app._id, {
565
+ tab_groups: newTabGroups
566
+ }, userSession);
567
+
568
+ return app;
569
+ }
570
+ },
571
+ move_app_tab: {
572
+ rest: {
573
+ method: "POST",
574
+ fullPath: "/service/api/apps/move_app_tab"
575
+ },
576
+ async handler(ctx) {
577
+ const { appId, tabName, groupName, oldGroupName } = ctx.params;
578
+ const userSession = ctx.meta.user;
579
+
580
+ if(!appId){
581
+ return;
582
+ }
583
+
584
+ const records = await this.getObject('apps').find({
585
+ filters: ['code', '=', appId]
586
+ });
587
+ const app = records.length > 0 ? records[0] : null;
588
+
589
+ if(!app){
590
+ return ;
591
+ }
592
+
593
+
594
+ const tab_items = app.tab_items || {};
595
+
596
+ _.each(tab_items, (item, k)=>{
597
+ if(k === tabName){
598
+ tab_items[k].group = groupName == 0 ? '' : groupName
599
+ }
600
+ })
601
+
602
+ await this.getObject('apps').update(app._id, {
603
+ tab_items
604
+ }, userSession);
605
+
606
+ return app;
607
+ }
608
+ },
136
609
  },
137
610
 
138
611
  /**