@steedos/service-ui 2.4.0-beta.8 → 2.4.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-ui",
3
- "version": "2.4.0-beta.8",
3
+ "version": "2.4.0",
4
4
  "main": "package.service.js",
5
5
  "keywords": [
6
6
  "steedos"
@@ -11,9 +11,9 @@
11
11
  "description": "steedos package",
12
12
  "repository": {},
13
13
  "dependencies": {
14
- "@steedos/core": "2.4.0-beta.8",
15
- "@steedos/i18n": "2.4.0-beta.8",
16
- "@steedos/objectql": "2.4.0-beta.8",
14
+ "@steedos/core": "2.4.0",
15
+ "@steedos/i18n": "2.4.0",
16
+ "@steedos/objectql": "2.4.0",
17
17
  "express": "4.18.1"
18
18
  },
19
19
  "license": "MIT",
@@ -21,5 +21,5 @@
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  },
24
- "gitHead": "61fe4ff720d68127dadcd728b9bc465b62c38855"
24
+ "gitHead": "70a4e7417d8d86c47cf5c7e3bbe0e89f2cee4222"
25
25
  }
@@ -0,0 +1,170 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2023-02-26 15:22:12
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2023-03-01 14:55:05
6
+ * @Description:
7
+ */
8
+ try {
9
+ Steedos.authRequest = function (url, options) {
10
+ var userSession = Creator.USER_CONTEXT;
11
+ var spaceId = userSession.spaceId;
12
+ var authToken = userSession.authToken
13
+ ? userSession.authToken
14
+ : userSession.user.authToken;
15
+ var result = null;
16
+ url = Steedos.absoluteUrl(url);
17
+ try {
18
+ var authorization = "Bearer " + spaceId + "," + authToken;
19
+ var headers = [
20
+ {
21
+ name: "Content-Type",
22
+ value: "application/json",
23
+ },
24
+ {
25
+ name: "Authorization",
26
+ value: authorization,
27
+ },
28
+ ];
29
+
30
+ var defOptions = {
31
+ type: "get",
32
+ url: url,
33
+ dataType: "json",
34
+ contentType: "application/json",
35
+ beforeSend: function (XHR) {
36
+ if (headers && headers.length) {
37
+ return headers.forEach(function (header) {
38
+ return XHR.setRequestHeader(header.name, header.value);
39
+ });
40
+ }
41
+ },
42
+ success: function (data) {
43
+ result = data;
44
+ },
45
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
46
+ console.error(XMLHttpRequest.responseJSON);
47
+ if (
48
+ XMLHttpRequest.responseJSON &&
49
+ XMLHttpRequest.responseJSON.error
50
+ ) {
51
+ const errorInfo = XMLHttpRequest.responseJSON.error;
52
+ result = { error: errorInfo };
53
+ let errorMsg;
54
+ if (errorInfo.reason) {
55
+ errorMsg = errorInfo.reason;
56
+ } else if (errorInfo.message) {
57
+ errorMsg = errorInfo.message;
58
+ } else {
59
+ errorMsg = errorInfo;
60
+ }
61
+ toastr.error(t(errorMsg.replace(/:/g, ":")));
62
+ } else {
63
+ toastr.error(XMLHttpRequest.responseJSON);
64
+ }
65
+ },
66
+ };
67
+ $.ajax(Object.assign({}, defOptions, options));
68
+ return result;
69
+ } catch (err) {
70
+ console.error(err);
71
+ toastr.error(err);
72
+ }
73
+ };
74
+
75
+ window.UI_SCHEMA_CACHE = {};
76
+
77
+ const setUISchemaCache = (key, value) => {
78
+ UI_SCHEMA_CACHE[key] = value;
79
+ };
80
+
81
+ const getUISchemaCache = (key) => {
82
+ return _.cloneDeep(UI_SCHEMA_CACHE[key]);
83
+ };
84
+
85
+ const hasUISchemaCache = (key) => {
86
+ return _.has(UI_SCHEMA_CACHE, key);
87
+ };
88
+
89
+ function formatUISchemaCache(objectName, uiSchema) {
90
+ setUISchemaCache(objectName, uiSchema);
91
+ _.each(uiSchema.fields, (field) => {
92
+ try {
93
+ if (
94
+ field.type === "lookup" &&
95
+ field._reference_to &&
96
+ _.isString(field._reference_to)
97
+ ) {
98
+ field.reference_to = eval(`(${field._reference_to})`)();
99
+ }
100
+ } catch (exception) {
101
+ field.reference_to = undefined;
102
+ console.error(exception);
103
+ }
104
+ });
105
+ _.each(uiSchema.list_views, (v, k) => {
106
+ v.name = k;
107
+ if (!_.has(v, "columns")) {
108
+ v.columns = uiSchema.list_views.all.columns;
109
+ }
110
+ });
111
+ }
112
+
113
+ window.getUISchemaSync = (objectName, force) => {
114
+ if (!objectName) {
115
+ return;
116
+ }
117
+ if (hasUISchemaCache(objectName) && !force) {
118
+ return getUISchemaCache(objectName);
119
+ }
120
+ let uiSchema = null;
121
+ try {
122
+ const url = `/service/api/@${objectName.replace(/\./g, "_")}/uiSchema`;
123
+ uiSchema = Steedos.authRequest(url, {
124
+ type: "GET",
125
+ async: false,
126
+ });
127
+
128
+ if (!uiSchema) {
129
+ return;
130
+ }
131
+ formatUISchemaCache(objectName, uiSchema);
132
+ } catch (error) {
133
+ console.error(`getUISchema`, objectName, error);
134
+ setUISchemaCache(objectName, null);
135
+ }
136
+ return getUISchemaCache(objectName);
137
+ };
138
+
139
+ window.getFirstListView = (objectName) => {
140
+ const uiSchema = window.getUISchemaSync(objectName);
141
+ return _.first(_.sortBy(_.values(uiSchema.list_views), "sort_no"));
142
+ };
143
+
144
+ window.getAppsSync = () => {
145
+ const url = "/service/api/apps/menus";
146
+ const apps = Steedos.authRequest(url, {
147
+ type: "GET",
148
+ async: false,
149
+ });
150
+ return apps;
151
+ };
152
+
153
+ window.Steedos.getFirstApp = ()=>{
154
+ const apps = window.getAppsSync();
155
+ return _.first(apps);
156
+ }
157
+
158
+ window.Creator.getObjectRecord = (objectName, recordId, select_fields, expand)=>{
159
+ return Creator.odata.get(objectName, recordId, select_fields, expand)
160
+ }
161
+
162
+ window.Creator.isSpaceAdmin = ()=>{
163
+ return Creator.USER_CONTEXT.user.is_space_admin;
164
+ }
165
+
166
+
167
+ Creator.steedosInit.set(true);
168
+ } catch (error) {
169
+ console.error(error);
170
+ }