@steedos/standard-ui 2.2.55-beta.16

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.
@@ -0,0 +1,135 @@
1
+ const _ = require('underscore');
2
+ const clone = require("clone");
3
+ const objectql = require("@steedos/objectql");
4
+ const i18n = require("@steedos/i18n");
5
+ const auth = require("@steedos/auth");
6
+ const InternalData = require('@steedos/standard-objects').internalData;
7
+ const SERVICE_NAME = `~database-apps`;
8
+ const permissions = {
9
+ allowEdit: false,
10
+ allowDelete: false,
11
+ allowRead: true,
12
+ }
13
+
14
+ const baseRecord = {
15
+ is_system:true,
16
+ visible: true,
17
+ record_permissions:permissions
18
+ }
19
+
20
+ const getLng = async function(userId){
21
+ const userSession = await auth.getSessionByUserId(userId);
22
+ return userSession ? userSession.language : null;
23
+ }
24
+
25
+ module.exports = {
26
+ afterFind: async function () {
27
+ const { spaceId } = this;
28
+ let query = InternalData.parserFilters(this.query.filters);
29
+ let isSystem = query.is_system;
30
+ if(!_.isEmpty(isSystem) || _.isBoolean(isSystem)){
31
+ if(_.isObject(isSystem) && isSystem["$ne"]){
32
+ return;
33
+ }
34
+ }
35
+ if(_.isArray(this.data.values)){
36
+ let lng = await getLng(this.userId);
37
+ let self = this;
38
+ let allApps = clone(await objectql.getAppConfigs(this.spaceId));
39
+ let apps = {}
40
+ _.each(allApps, function(app){
41
+ if(app.is_creator){
42
+ apps[app._id] = app
43
+ }
44
+ })
45
+ i18n.translationApps(lng, apps)
46
+ _.each(apps, function(app){
47
+ app.name = app.label
48
+ if(!_.find(self.data.values, function(item){return item.code === app._id || item._id === app._id})){
49
+ self.data.values.push(Object.assign({code: app._id}, clone(app), baseRecord));
50
+ }
51
+ })
52
+ // console.log(`find this.query`, self.query, objectql.getSteedosSchema().metadataDriver.find(self.data.values, this.query, spaceId))
53
+ self.data.values = objectql.getSteedosSchema().metadataDriver.find(self.data.values, self.query, spaceId);
54
+ }
55
+ },
56
+ afterAggregate: async function () {
57
+ const { spaceId } = this;
58
+ let query = InternalData.parserFilters(this.query.filters);
59
+ let isSystem = query.is_system;
60
+ if(!_.isEmpty(isSystem) || _.isBoolean(isSystem)){
61
+ if(_.isObject(isSystem) && isSystem["$ne"]){
62
+ return;
63
+ }
64
+ }
65
+ if(_.isArray(this.data.values)){
66
+ let lng = await getLng(this.userId);
67
+ let self = this;
68
+ let allApps = clone(await objectql.getAppConfigs(this.spaceId));
69
+ let apps = {}
70
+ _.each(allApps, function(app){
71
+ if(app.is_creator){
72
+ apps[app._id] = app
73
+ }
74
+ })
75
+ i18n.translationApps(lng, apps)
76
+ _.each(apps, function(app){
77
+ app.name = app.label
78
+ if(!_.find(self.data.values, function(item){return item.code === app._id || item._id === app._id})){
79
+ self.data.values.push(Object.assign({code: app._id}, clone(app), baseRecord));
80
+ }
81
+ })
82
+ }
83
+ // 获取的apps根据保存的值进行过滤
84
+ // const allData = this.data.values;
85
+ // const firstFilterKey = _.keys(query)[0];
86
+ // this.data.values = _.filter(allData, (item)=>{
87
+ // return item[firstFilterKey] === query[firstFilterKey];
88
+ // })
89
+ // console.log(`afterAggregate this.query`, this.query, objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId))
90
+ this.data.values = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
91
+ },
92
+ afterCount: async function () {
93
+ try {
94
+ this.query.fields.push('name');
95
+ this.query.fields.push('code');
96
+ } catch (error) {
97
+
98
+ }
99
+ let result = await objectql.getObject('apps').find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
100
+ this.data.values = result.length
101
+ },
102
+ afterFindOne: async function () {
103
+ let id = this.id;
104
+ if(id && _.isEmpty(this.data.values)){
105
+ let lng = await getLng(this.userId);
106
+ let app = await objectql.getAppConfig(id);
107
+ // let allApps = clone(await objectql.getAppConfigs(this.spaceId));
108
+ // let apps = {}
109
+ // _.each(allApps, function(app){
110
+ // if(app._id === id && app.is_creator){
111
+ // apps[app._id] = app
112
+ // }
113
+ // })
114
+ i18n.translationApp(lng, app._id, app)
115
+ Object.assign(this.data.values, Object.assign({code: app._id}, clone(app), baseRecord))
116
+ // let sefl = this;
117
+ // _.each(apps, function(app){
118
+ // app.name = app.label
119
+ // Object.assign(sefl.data.values, Object.assign({code: app._id}, clone(app), baseRecord))
120
+ // })
121
+ }
122
+ },
123
+ // afterInsert: async function () {
124
+ // const record = await this.getObject('apps').findOne(this.doc._id);
125
+ // await objectql.addAppConfig(record, SERVICE_NAME)
126
+ // },
127
+ // afterUpdate: async function () {
128
+ // const record = await this.getObject('apps').findOne(this.id);
129
+ // await objectql.addAppConfig(record, SERVICE_NAME)
130
+ // },
131
+ // afterDelete: async function(){
132
+ // let id = this.id;
133
+ // objectql.removeApp(id)
134
+ // }
135
+ }
@@ -0,0 +1,35 @@
1
+ const _ = require('underscore');
2
+ const objectql = require("@steedos/objectql");
3
+
4
+ const SERVICE_NAME = `~database-tabs`;
5
+
6
+ const permissions = {
7
+ allowEdit: false,
8
+ allowDelete: false,
9
+ allowRead: true,
10
+ }
11
+
12
+ const baseRecord = {
13
+ is_system:true,
14
+ visible: true,
15
+ record_permissions:permissions
16
+ }
17
+
18
+ module.exports = {
19
+ // afterInsert: async function () {
20
+ // const record = await this.getObject('tabs').findOne(this.doc._id);
21
+ // await objectql.addTabConfig(record, SERVICE_NAME)
22
+ // },
23
+ // afterUpdate: async function () {
24
+ // const {doc, previousDoc} = this;
25
+ // const record = await this.getObject('tabs').findOne(this.id);
26
+ // if(doc.name != previousDoc.name){
27
+ // await objectql.removeTab(previousDoc.name)
28
+ // }
29
+ // await objectql.addTabConfig(record, SERVICE_NAME)
30
+ // },
31
+ // afterDelete: async function(){
32
+ // let previousDoc = this.previousDoc;
33
+ // await objectql.removeTab(previousDoc.name)
34
+ // }
35
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ * @Author: sunhaolin@hotoa.com
3
+ * @Date: 2021-09-10 16:44:24
4
+ * @LastEditors: sunhaolin@hotoa.com
5
+ * @LastEditTime: 2022-07-30 09:56:44
6
+ * @Description:
7
+ */
8
+ const util = require('@steedos/standard-objects').util;
9
+ const _ = require('lodash');
10
+ module.exports = {
11
+ listenTo: 'tabs',
12
+
13
+ beforeInsert: async function(){
14
+ const { object_name, doc } = this;
15
+ await util.checkAPIName(object_name, 'name', doc.name, undefined);
16
+ },
17
+
18
+ beforeUpdate: async function(){
19
+ const {object_name, doc, spaceId, id} = this;
20
+ if(_.has(doc, 'name')){
21
+ await util.checkAPIName(object_name, 'name', doc.name, id);
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,85 @@
1
+ const objectql = require('@steedos/objectql');
2
+ const auth = require('@steedos/auth');
3
+ const _ = require('underscore');
4
+ async function getAll(){
5
+ const schema = objectql.getSteedosSchema();
6
+ const configs = await objectql.registerTab.getAll(schema.broker)
7
+ const dataList = _.pluck(configs, 'metadata');
8
+
9
+ _.each(dataList, function(item){
10
+ if(!item._id){
11
+ item._id = `${item.name}`
12
+ }
13
+ })
14
+ return dataList;
15
+ }
16
+
17
+ async function get(apiName){
18
+ const schema =objectql.getSteedosSchema();
19
+ const config = await objectql.registerTab.get(schema.broker, apiName)
20
+ return config ? config.metadata : null;
21
+ }
22
+
23
+ module.exports = {
24
+ listenTo: 'tabs',
25
+
26
+ afterFind: async function(){
27
+ const { spaceId } = this;
28
+ let dataList = await getAll();
29
+ const values = [];
30
+ if(dataList){
31
+ dataList.forEach((doc)=>{
32
+ if(!_.find(this.data.values, (value)=>{
33
+ return value._id === doc._id
34
+ })){
35
+ this.data.values.push(doc);
36
+ }
37
+ })
38
+ const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
39
+ if(records.length > 0){
40
+ this.data.values = records;
41
+ }else{
42
+ this.data.values.length = 0;
43
+ }
44
+ }
45
+ },
46
+ afterAggregate: async function(){
47
+ const { spaceId } = this;
48
+ let dataList = await getAll();
49
+ const values = [];
50
+ if(dataList){
51
+ dataList.forEach((doc)=>{
52
+ if(!_.find(this.data.values, (value)=>{
53
+ return value._id === doc._id
54
+ })){
55
+ this.data.values.push(doc);
56
+ };
57
+ })
58
+ const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
59
+ if(records.length > 0){
60
+ this.data.values = records;
61
+ }else{
62
+ this.data.values.length = 0;
63
+ }
64
+ }
65
+ },
66
+ afterCount: async function(){
67
+ try {
68
+ this.query.fields.push('name');
69
+ this.query.fields.push('code');
70
+ } catch (error) {
71
+
72
+ }
73
+ let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
74
+ this.data.values = result.length;
75
+ },
76
+ afterFindOne: async function(){
77
+ if(_.isEmpty(this.data.values)){
78
+ let id = this.id
79
+ let data = await get(id);
80
+ if(data){
81
+ this.data.values = data;
82
+ }
83
+ }
84
+ }
85
+ }
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@steedos/standard-ui",
3
+ "version": "2.2.55-beta.16",
4
+ "main": "package.service.js",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "keywords": [
10
+ "steedos"
11
+ ],
12
+ "description": "steedos package",
13
+ "repository": {},
14
+ "license": "MIT",
15
+ "dependencies": {}
16
+ }
@@ -0,0 +1,75 @@
1
+ /*
2
+ * @Author: sunhaolin@hotoa.com
3
+ * @Date: 2022-07-29 09:40:31
4
+ * @LastEditors: sunhaolin@hotoa.com
5
+ * @LastEditTime: 2022-07-29 14:37:14
6
+ * @Description:
7
+ */
8
+ "use strict";
9
+ const project = require('./package.json');
10
+ const packageName = project.name;
11
+ const packageLoader = require('@steedos/service-meteor-package-loader');
12
+ /**
13
+ * @typedef {import('moleculer').Context} Context Moleculer's Context
14
+ */
15
+ module.exports = {
16
+ name: packageName,
17
+ namespace: "steedos",
18
+ mixins: [packageLoader],
19
+ /**
20
+ * Settings
21
+ */
22
+ settings: {
23
+ packageInfo: {
24
+ path: __dirname,
25
+ name: packageName
26
+ }
27
+ },
28
+
29
+ /**
30
+ * Dependencies
31
+ */
32
+ dependencies: ['~packages-standard-objects'],
33
+
34
+ /**
35
+ * Actions
36
+ */
37
+ actions: {
38
+
39
+ },
40
+
41
+ /**
42
+ * Events
43
+ */
44
+ events: {
45
+
46
+ },
47
+
48
+ /**
49
+ * Methods
50
+ */
51
+ methods: {
52
+
53
+ },
54
+
55
+ /**
56
+ * Service created lifecycle event handler
57
+ */
58
+ async created() {
59
+
60
+ },
61
+
62
+ /**
63
+ * Service started lifecycle event handler
64
+ */
65
+ async started() {
66
+
67
+ },
68
+
69
+ /**
70
+ * Service stopped lifecycle event handler
71
+ */
72
+ async stopped() {
73
+
74
+ }
75
+ };
package/public/.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 静态公开资源文件
2
+
3
+ - 此文件夹中的文件自动添加到根路由
package/src/.md ADDED
@@ -0,0 +1,3 @@
1
+ ### src
2
+
3
+ - 软件包不会加载此文件夹下的文件, 可用于存放ts文件等
package/webapp/.md ADDED
@@ -0,0 +1 @@
1
+ - 存放web项目