|
1
|
+/*
|
|
2
|
+ * Copyright © 2016-2019 The Thingsboard Authors
|
|
3
|
+ *
|
|
4
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+ * you may not use this file except in compliance with the License.
|
|
6
|
+ * You may obtain a copy of the License at
|
|
7
|
+ *
|
|
8
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+ *
|
|
10
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
11
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+ * See the License for the specific language governing permissions and
|
|
14
|
+ * limitations under the License.
|
|
15
|
+ */
|
|
16
|
+import './custom-action-pretty-editor.scss';
|
|
17
|
+import customActionPrettyEditorTemplate from './custom-action-pretty-editor.tpl.html';
|
|
18
|
+
|
|
19
|
+import 'brace/ext/language_tools';
|
|
20
|
+import 'brace/ext/searchbox';
|
|
21
|
+import 'brace/mode/html';
|
|
22
|
+import 'brace/mode/css';
|
|
23
|
+import 'brace/snippets/text';
|
|
24
|
+import 'brace/snippets/html';
|
|
25
|
+import 'brace/snippets/css';
|
|
26
|
+
|
|
27
|
+import beautify from 'js-beautify';
|
|
28
|
+import Split from "split.js";
|
|
29
|
+
|
|
30
|
+const html_beautify = beautify.html;
|
|
31
|
+const css_beautify = beautify.css;
|
|
32
|
+
|
|
33
|
+export default angular.module('thingsboard.directives.customActionPrettyEditor', [])
|
|
34
|
+ .directive('tbCustomActionPrettyEditor', CustomActionPrettyEditor)
|
|
35
|
+ .name;
|
|
36
|
+
|
|
37
|
+/*@ngInject*/
|
|
38
|
+function CustomActionPrettyEditor($compile, $templateCache, $window, $timeout) {
|
|
39
|
+
|
|
40
|
+ var linker = function (scope, element, attrs, ngModelCtrl) {
|
|
41
|
+ var template = $templateCache.get(customActionPrettyEditorTemplate);
|
|
42
|
+ element.html(template);
|
|
43
|
+ var ace_editors = [];
|
|
44
|
+ scope.fullscreen = false;
|
|
45
|
+ scope.htmlEditorOptions = {
|
|
46
|
+ useWrapMode: true,
|
|
47
|
+ mode: 'html',
|
|
48
|
+ advanced: {
|
|
49
|
+ enableSnippets: true,
|
|
50
|
+ enableBasicAutocompletion: true,
|
|
51
|
+ enableLiveAutocompletion: true
|
|
52
|
+ },
|
|
53
|
+ onLoad: function (_ace) {
|
|
54
|
+ ace_editors.push(_ace);
|
|
55
|
+ }
|
|
56
|
+ };
|
|
57
|
+ scope.cssEditorOptions = {
|
|
58
|
+ useWrapMode: true,
|
|
59
|
+ mode: 'css',
|
|
60
|
+ advanced: {
|
|
61
|
+ enableSnippets: true,
|
|
62
|
+ enableBasicAutocompletion: true,
|
|
63
|
+ enableLiveAutocompletion: true
|
|
64
|
+ },
|
|
65
|
+ onLoad: function (_ace) {
|
|
66
|
+ ace_editors.push(_ace);
|
|
67
|
+ }
|
|
68
|
+ };
|
|
69
|
+
|
|
70
|
+ scope.addResource = addResource;
|
|
71
|
+ scope.beautifyCss = beautifyCss;
|
|
72
|
+ scope.beautifyHtml = beautifyHtml;
|
|
73
|
+ scope.removeResource = removeResource;
|
|
74
|
+ scope.toggleFullscreen = toggleFullscreen;
|
|
75
|
+
|
|
76
|
+ var sampleJsFunction = "/* There are three examples: for delete, edit and add entity */\n" +
|
|
77
|
+ "/* Delete entity example */\n" +
|
|
78
|
+ "//\n" +
|
|
79
|
+ "//var $injector = widgetContext.$scope.$injector;\n" +
|
|
80
|
+ "//var $mdDialog = $injector.get('$mdDialog'),\n" +
|
|
81
|
+ "// $document = $injector.get('$document'),\n" +
|
|
82
|
+ "// types = $injector.get('types'),\n" +
|
|
83
|
+ "// assetService = $injector.get('assetService'),\n" +
|
|
84
|
+ "// deviceService = $injector.get('deviceService')\n" +
|
|
85
|
+ "// $rootScope = $injector.get('$rootScope'),\n" +
|
|
86
|
+ "// $q = $injector.get('$q');\n" +
|
|
87
|
+ "//\n" +
|
|
88
|
+ "//openDeleteEntityDialog();\n" +
|
|
89
|
+ "//\n" +
|
|
90
|
+ "//function openDeleteEntityDialog() {\n" +
|
|
91
|
+ "// var title = 'Delete ' + entityId.entityType\n" +
|
|
92
|
+ "// .toLowerCase() + ' ' +\n" +
|
|
93
|
+ "// entityName;\n" +
|
|
94
|
+ "// var content = 'Are you sure you want to delete the ' +\n" +
|
|
95
|
+ "// entityId.entityType.toLowerCase() + ' ' +\n" +
|
|
96
|
+ "// entityName + '?';\n" +
|
|
97
|
+ "// var confirm = $mdDialog.confirm()\n" +
|
|
98
|
+ "// .targetEvent($event)\n" +
|
|
99
|
+ "// .title(title)\n" +
|
|
100
|
+ "// .htmlContent(content)\n" +
|
|
101
|
+ "// .ariaLabel(title)\n" +
|
|
102
|
+ "// .cancel('Cancel')\n" +
|
|
103
|
+ "// .ok('Delete');\n" +
|
|
104
|
+ "// $mdDialog.show(confirm).then(function() {\n" +
|
|
105
|
+ "// deleteEntity();\n" +
|
|
106
|
+ "// })\n" +
|
|
107
|
+ "//}\n" +
|
|
108
|
+ "//\n" +
|
|
109
|
+ "//function deleteEntity() {\n" +
|
|
110
|
+ "// deleteEntityPromise(entityId).then(\n" +
|
|
111
|
+ "// function success() {\n" +
|
|
112
|
+ "// updateAliasData();\n" +
|
|
113
|
+ "// },\n" +
|
|
114
|
+ "// function fail() {\n" +
|
|
115
|
+ "// showErrorDialog();\n" +
|
|
116
|
+ "// }\n" +
|
|
117
|
+ "// );\n" +
|
|
118
|
+ "//}\n" +
|
|
119
|
+ "//\n" +
|
|
120
|
+ "//function deleteEntityPromise(entityId) {\n" +
|
|
121
|
+ "// if (entityId.entityType == types.entityType.asset) {\n" +
|
|
122
|
+ "// return assetService.deleteAsset(entityId.id);\n" +
|
|
123
|
+ "// } else if (entityId.entityType == types.entityType.device) {\n" +
|
|
124
|
+ "// return deviceService.deleteDevice(entityId.id);\n" +
|
|
125
|
+ "// }\n" +
|
|
126
|
+ "//}\n" +
|
|
127
|
+ "//\n" +
|
|
128
|
+ "//function updateAliasData() {\n" +
|
|
129
|
+ "// var aliasIds = [];\n" +
|
|
130
|
+ "// for (var id in widgetContext.aliasController.resolvedAliases) {\n" +
|
|
131
|
+ "// aliasIds.push(id);\n" +
|
|
132
|
+ "// }\n" +
|
|
133
|
+ "// var tasks = [];\n" +
|
|
134
|
+ "// aliasIds.forEach(function(aliasId) {\n" +
|
|
135
|
+ "// widgetContext.aliasController.setAliasUnresolved(aliasId);\n" +
|
|
136
|
+ "// tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" +
|
|
137
|
+ "// });\n" +
|
|
138
|
+ "// $q.all(tasks).then(function() {\n" +
|
|
139
|
+ "// $rootScope.$broadcast('entityAliasesChanged', aliasIds);\n" +
|
|
140
|
+ "// });\n" +
|
|
141
|
+ "//}\n" +
|
|
142
|
+ "//\n" +
|
|
143
|
+ "//function showErrorDialog() {\n" +
|
|
144
|
+ "// var title = 'Error';\n" +
|
|
145
|
+ "// var content = 'An error occurred while deleting the entity. Please try again.';\n" +
|
|
146
|
+ "// var alert = $mdDialog.alert()\n" +
|
|
147
|
+ "// .title(title)\n" +
|
|
148
|
+ "// .htmlContent(content)\n" +
|
|
149
|
+ "// .ariaLabel(title)\n" +
|
|
150
|
+ "// .parent(angular.element($document[0].body))\n" +
|
|
151
|
+ "// .targetEvent($event)\n" +
|
|
152
|
+ "// .multiple(true)\n" +
|
|
153
|
+ "// .clickOutsideToClose(true)\n" +
|
|
154
|
+ "// .ok('CLOSE');\n" +
|
|
155
|
+ "// $mdDialog.show(alert);\n" +
|
|
156
|
+ "//}\n" +
|
|
157
|
+ "//\n" +
|
|
158
|
+ "/* Edit entity example */\n" +
|
|
159
|
+ "//\n" +
|
|
160
|
+ "//var $injector = widgetContext.$scope.$injector;\n" +
|
|
161
|
+ "//var $mdDialog = $injector.get('$mdDialog'),\n" +
|
|
162
|
+ "// $document = $injector.get('$document'),\n" +
|
|
163
|
+ "// $q = $injector.get('$q'),\n" +
|
|
164
|
+ "// types = $injector.get('types'),\n" +
|
|
165
|
+ "// $rootScope = $injector.get('$rootScope'),\n" +
|
|
166
|
+ "// entityService = $injector.get('entityService'),\n" +
|
|
167
|
+ "// attributeService = $injector.get('attributeService'),\n" +
|
|
168
|
+ "// entityRelationService = $injector.get('entityRelationService');\n" +
|
|
169
|
+ "//\n" +
|
|
170
|
+ "//openEditEntityDialog();\n" +
|
|
171
|
+ "//\n" +
|
|
172
|
+ "//function openEditEntityDialog() {\n" +
|
|
173
|
+ "// $mdDialog.show({\n" +
|
|
174
|
+ "// controller: ['$scope','$mdDialog', EditEntityDialogController],\n" +
|
|
175
|
+ "// controllerAs: 'vm',\n" +
|
|
176
|
+ "// template: htmlTemplate,\n" +
|
|
177
|
+ "// locals: {\n" +
|
|
178
|
+ "// entityId: entityId\n" +
|
|
179
|
+ "// },\n" +
|
|
180
|
+ "// parent: angular.element($document[0].body),\n" +
|
|
181
|
+ "// targetEvent: $event,\n" +
|
|
182
|
+ "// multiple: true,\n" +
|
|
183
|
+ "// clickOutsideToClose: false\n" +
|
|
184
|
+ "// });\n" +
|
|
185
|
+ "//}\n" +
|
|
186
|
+ "//\n" +
|
|
187
|
+ "//function EditEntityDialogController($scope,$mdDialog) {\n" +
|
|
188
|
+ "// var vm = this;\n" +
|
|
189
|
+ "// vm.entityId = entityId;\n" +
|
|
190
|
+ "// vm.entityName = entityName;\n" +
|
|
191
|
+ "// vm.entityType = entityId.entityType;\n" +
|
|
192
|
+ "// vm.allowedEntityTypes = [types.entityType.asset, types.entityType.device];\n" +
|
|
193
|
+ "// vm.allowedRelatedEntityTypes = [];\n" +
|
|
194
|
+ "// vm.entitySearchDirection = types.entitySearchDirection;\n" +
|
|
195
|
+ "// vm.attributes = {};\n" +
|
|
196
|
+ "// vm.serverAttributes = {};\n" +
|
|
197
|
+ "// vm.relations = [];\n" +
|
|
198
|
+ "// vm.newRelations = [];\n" +
|
|
199
|
+ "// vm.relationsToDelete = [];\n" +
|
|
200
|
+ "// getEntityInfo();\n" +
|
|
201
|
+ "// \n" +
|
|
202
|
+ "// vm.addRelation = function() {\n" +
|
|
203
|
+ "// var relation = {\n" +
|
|
204
|
+ "// direction: null,\n" +
|
|
205
|
+ "// relationType: null,\n" +
|
|
206
|
+ "// relatedEntity: null\n" +
|
|
207
|
+ "// };\n" +
|
|
208
|
+ "// vm.newRelations.push(relation);\n" +
|
|
209
|
+ "// $scope.editEntityForm.$setDirty();\n" +
|
|
210
|
+ "// };\n" +
|
|
211
|
+ "// vm.removeRelation = function(index) {\n" +
|
|
212
|
+ "// if (index > -1) {\n" +
|
|
213
|
+ "// vm.newRelations.splice(index, 1);\n" +
|
|
214
|
+ "// $scope.editEntityForm.$setDirty();\n" +
|
|
215
|
+ "// }\n" +
|
|
216
|
+ "// };\n" +
|
|
217
|
+ "// vm.removeOldRelation = function(index, relation) {\n" +
|
|
218
|
+ "// if (index > -1) {\n" +
|
|
219
|
+ "// vm.relations.splice(index, 1);\n" +
|
|
220
|
+ "// vm.relationsToDelete.push(relation);\n" +
|
|
221
|
+ "// $scope.editEntityForm.$setDirty();\n" +
|
|
222
|
+ "// }\n" +
|
|
223
|
+ "// };\n" +
|
|
224
|
+ "// vm.save = function() {\n" +
|
|
225
|
+ "// saveAttributes();\n" +
|
|
226
|
+ "// saveRelations();\n" +
|
|
227
|
+ "// $scope.editEntityForm.$setPristine();\n" +
|
|
228
|
+ "// };\n" +
|
|
229
|
+ "// vm.cancel = function() {\n" +
|
|
230
|
+ "// $mdDialog.hide();\n" +
|
|
231
|
+ "// };\n" +
|
|
232
|
+ "// \n" +
|
|
233
|
+ "// function getEntityAttributes(attributes) {\n" +
|
|
234
|
+ "// for (var i = 0; i < attributes.length; i++) {\n" +
|
|
235
|
+ "// vm.attributes[attributes[i].key] = attributes[i].value; \n" +
|
|
236
|
+ "// }\n" +
|
|
237
|
+ "// vm.serverAttributes = angular.copy(vm.attributes);\n" +
|
|
238
|
+ "// }\n" +
|
|
239
|
+ "// \n" +
|
|
240
|
+ "// function getEntityRelations(relations) {\n" +
|
|
241
|
+ "// var relationsFrom = relations[0];\n" +
|
|
242
|
+ "// var relationsTo = relations[1];\n" +
|
|
243
|
+ "// for (var i=0; i < relationsFrom.length; i++) {\n" +
|
|
244
|
+ "// var relation = {\n" +
|
|
245
|
+ "// direction: types.entitySearchDirection.from,\n" +
|
|
246
|
+ "// relationType: relationsFrom[i].type,\n" +
|
|
247
|
+ "// relatedEntity: relationsFrom[i].to\n" +
|
|
248
|
+ "// };\n" +
|
|
249
|
+ "// vm.relations.push(relation);\n" +
|
|
250
|
+ "// }\n" +
|
|
251
|
+ "// for (var i=0; i < relationsTo.length; i++) {\n" +
|
|
252
|
+ "// var relation = {\n" +
|
|
253
|
+ "// direction: types.entitySearchDirection.to,\n" +
|
|
254
|
+ "// relationType: relationsTo[i].type,\n" +
|
|
255
|
+ "// relatedEntity: relationsTo[i].from\n" +
|
|
256
|
+ "// };\n" +
|
|
257
|
+ "// vm.relations.push(relation);\n" +
|
|
258
|
+ "// }\n" +
|
|
259
|
+ "// }\n" +
|
|
260
|
+ "// \n" +
|
|
261
|
+ "// function getEntityInfo() {\n" +
|
|
262
|
+ "// entityService.getEntity(entityId.entityType, entityId.id).then(\n" +
|
|
263
|
+ "// function(entity) {\n" +
|
|
264
|
+ "// vm.entity = entity;\n" +
|
|
265
|
+ "// vm.type = vm.entity.type;\n" +
|
|
266
|
+ "// });\n" +
|
|
267
|
+ "// attributeService.getEntityAttributesValues(entityId.entityType, entityId.id, 'SERVER_SCOPE').then(\n" +
|
|
268
|
+ "// function(data){\n" +
|
|
269
|
+ "// if (data.length) {\n" +
|
|
270
|
+ "// getEntityAttributes(data);\n" +
|
|
271
|
+ "// }\n" +
|
|
272
|
+ "// });\n" +
|
|
273
|
+ "// $q.all([entityRelationService.findInfoByFrom(entityId.id, entityId.entityType), entityRelationService.findInfoByTo(entityId.id, entityId.entityType)]).then(\n" +
|
|
274
|
+ "// function(relations){\n" +
|
|
275
|
+ "// getEntityRelations(relations);\n" +
|
|
276
|
+ "// });\n" +
|
|
277
|
+ "// }\n" +
|
|
278
|
+ "// \n" +
|
|
279
|
+ "// function saveAttributes() {\n" +
|
|
280
|
+ "// var attributesArray = [];\n" +
|
|
281
|
+ "// for (var key in vm.attributes) {\n" +
|
|
282
|
+ "// if (vm.attributes[key] !== vm.serverAttributes[key]) {\n" +
|
|
283
|
+ "// attributesArray.push({key: key, value: vm.attributes[key]});\n" +
|
|
284
|
+ "// }\n" +
|
|
285
|
+ "// }\n" +
|
|
286
|
+ "// if (attributesArray.length > 0) {\n" +
|
|
287
|
+ "// attributeService.saveEntityAttributes(entityId.entityType, entityId.id, \"SERVER_SCOPE\", attributesArray);\n" +
|
|
288
|
+ "// } \n" +
|
|
289
|
+ "// }\n" +
|
|
290
|
+ "// \n" +
|
|
291
|
+ "// function saveRelations() {\n" +
|
|
292
|
+ "// var tasks = [];\n" +
|
|
293
|
+ "// for (var i=0; i < vm.newRelations.length; i++) {\n" +
|
|
294
|
+ "// var relation = {\n" +
|
|
295
|
+ "// type: vm.newRelations[i].relationType\n" +
|
|
296
|
+ "// };\n" +
|
|
297
|
+ "// if (vm.newRelations[i].direction == types.entitySearchDirection.from) {\n" +
|
|
298
|
+ "// relation.to = vm.newRelations[i].relatedEntity;\n" +
|
|
299
|
+ "// relation.from = entityId;\n" +
|
|
300
|
+ "// } else {\n" +
|
|
301
|
+ "// relation.to = entityId;\n" +
|
|
302
|
+ "// relation.from = vm.newRelations[i].relatedEntity;\n" +
|
|
303
|
+ "// }\n" +
|
|
304
|
+ "// tasks.push(entityRelationService.saveRelation(relation));\n" +
|
|
305
|
+ "// }\n" +
|
|
306
|
+ "// for (var i=0; i < vm.relationsToDelete.length; i++) {\n" +
|
|
307
|
+ "// var relation = {\n" +
|
|
308
|
+ "// type: vm.relationsToDelete[i].relationType\n" +
|
|
309
|
+ "// };\n" +
|
|
310
|
+ "// if (vm.relationsToDelete[i].direction == types.entitySearchDirection.from) {\n" +
|
|
311
|
+ "// relation.to = vm.relationsToDelete[i].relatedEntity;\n" +
|
|
312
|
+ "// relation.from = entityId;\n" +
|
|
313
|
+ "// } else {\n" +
|
|
314
|
+ "// relation.to = entityId;\n" +
|
|
315
|
+ "// relation.from = vm.relationsToDelete[i].relatedEntity;\n" +
|
|
316
|
+ "// }\n" +
|
|
317
|
+ "// tasks.push(entityRelationService.deleteRelation(relation.from.id, relation.from.entityType, relation.type, relation.to.id, relation.to.entityType));\n" +
|
|
318
|
+ "// }\n" +
|
|
319
|
+ "// $q.all(tasks).then(function(){\n" +
|
|
320
|
+ "// vm.relations = vm.relations.concat(vm.newRelations);\n" +
|
|
321
|
+ "// vm.newRelations = [];\n" +
|
|
322
|
+ "// vm.relationsToDelete = [];\n" +
|
|
323
|
+ "// updateAliasData();\n" +
|
|
324
|
+ "// });\n" +
|
|
325
|
+ "// }\n" +
|
|
326
|
+ "// \n" +
|
|
327
|
+ "// function updateAliasData() {\n" +
|
|
328
|
+ "// var aliasIds = [];\n" +
|
|
329
|
+ "// for (var id in widgetContext.aliasController.resolvedAliases) {\n" +
|
|
330
|
+ "// aliasIds.push(id);\n" +
|
|
331
|
+ "// }\n" +
|
|
332
|
+ "// var tasks = [];\n" +
|
|
333
|
+ "// aliasIds.forEach(function(aliasId) {\n" +
|
|
334
|
+ "// widgetContext.aliasController.setAliasUnresolved(aliasId);\n" +
|
|
335
|
+ "// tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" +
|
|
336
|
+ "// });\n" +
|
|
337
|
+ "// $q.all(tasks).then(function() {\n" +
|
|
338
|
+ "// $rootScope.$broadcast('entityAliasesChanged', aliasIds);\n" +
|
|
339
|
+ "// });\n" +
|
|
340
|
+ "// }\n" +
|
|
341
|
+ "//}\n" +
|
|
342
|
+ "//\n" +
|
|
343
|
+ "/* Add entity example */\n" +
|
|
344
|
+ "//\n" +
|
|
345
|
+ "//var $injector = widgetContext.$scope.$injector;\n" +
|
|
346
|
+ "//var $mdDialog = $injector.get('$mdDialog'),\n" +
|
|
347
|
+ "// $document = $injector.get('$document'),\n" +
|
|
348
|
+ "// $q = $injector.get('$q'),\n" +
|
|
349
|
+ "// $rootScope = $injector.get('$rootScope'),\n" +
|
|
350
|
+ "// types = $injector.get('types'),\n" +
|
|
351
|
+ "// assetService = $injector.get('assetService'),\n" +
|
|
352
|
+ "// deviceService = $injector.get('deviceService'),\n" +
|
|
353
|
+ "// attributeService = $injector.get('attributeService'),\n" +
|
|
354
|
+ "// entityRelationService = $injector.get('entityRelationService');\n" +
|
|
355
|
+ "//\n" +
|
|
356
|
+ "//openAddEntityDialog();\n" +
|
|
357
|
+ "//\n" +
|
|
358
|
+ "//function openAddEntityDialog() {\n" +
|
|
359
|
+ "// $mdDialog.show({\n" +
|
|
360
|
+ "// controller: ['$scope','$mdDialog', AddEntityDialogController],\n" +
|
|
361
|
+ "// controllerAs: 'vm',\n" +
|
|
362
|
+ "// template: htmlTemplate,\n" +
|
|
363
|
+ "// locals: {\n" +
|
|
364
|
+ "// entityId: entityId\n" +
|
|
365
|
+ "// },\n" +
|
|
366
|
+ "// parent: angular.element($document[0].body),\n" +
|
|
367
|
+ "// targetEvent: $event,\n" +
|
|
368
|
+ "// multiple: true,\n" +
|
|
369
|
+ "// clickOutsideToClose: false\n" +
|
|
370
|
+ "// });\n" +
|
|
371
|
+ "//}\n" +
|
|
372
|
+ "//\n" +
|
|
373
|
+ "//function AddEntityDialogController($scope, $mdDialog) {\n" +
|
|
374
|
+ "// var vm = this;\n" +
|
|
375
|
+ "// vm.allowedEntityTypes = [types.entityType.asset, types.entityType.device];\n" +
|
|
376
|
+ "// vm.allowedRelatedEntityTypes = [];\n" +
|
|
377
|
+ "// vm.entitySearchDirection = types.entitySearchDirection;\n" +
|
|
378
|
+ "// vm.attributes = {};\n" +
|
|
379
|
+ "// vm.relations = [];\n" +
|
|
380
|
+ "// \n" +
|
|
381
|
+ "// vm.addRelation = function() {\n" +
|
|
382
|
+ "// var relation = {\n" +
|
|
383
|
+ "// direction: null,\n" +
|
|
384
|
+ "// relationType: null,\n" +
|
|
385
|
+ "// relatedEntity: null\n" +
|
|
386
|
+ "// };\n" +
|
|
387
|
+ "// vm.relations.push(relation);\n" +
|
|
388
|
+ "// };\n" +
|
|
389
|
+ "// vm.removeRelation = function(index) {\n" +
|
|
390
|
+ "// if (index > -1) {\n" +
|
|
391
|
+ "// vm.relations.splice(index, 1);\n" +
|
|
392
|
+ "// }\n" +
|
|
393
|
+ "// };\n" +
|
|
394
|
+ "// vm.save = function() {\n" +
|
|
395
|
+ "// $scope.addEntityForm.$setPristine();\n" +
|
|
396
|
+ "// saveEntityPromise().then(\n" +
|
|
397
|
+ "// function (entity) {\n" +
|
|
398
|
+ "// saveAttributes(entity.id);\n" +
|
|
399
|
+ "// saveRelations(entity.id);\n" +
|
|
400
|
+ "// $mdDialog.hide();\n" +
|
|
401
|
+ "// }\n" +
|
|
402
|
+ "// );\n" +
|
|
403
|
+ "// };\n" +
|
|
404
|
+ "// vm.cancel = function() {\n" +
|
|
405
|
+ "// $mdDialog.hide();\n" +
|
|
406
|
+ "// };\n" +
|
|
407
|
+ "// \n" +
|
|
408
|
+ "// \n" +
|
|
409
|
+ "// function saveEntityPromise() {\n" +
|
|
410
|
+ "// var entity = {\n" +
|
|
411
|
+ "// name: vm.entityName,\n" +
|
|
412
|
+ "// type: vm.type\n" +
|
|
413
|
+ "// };\n" +
|
|
414
|
+ "// if (vm.entityType == types.entityType.asset) {\n" +
|
|
415
|
+ "// return assetService.saveAsset(entity);\n" +
|
|
416
|
+ "// } else if (vm.entityType == types.entityType.device) {\n" +
|
|
417
|
+ "// return deviceService.saveDevice(entity);\n" +
|
|
418
|
+ "// }\n" +
|
|
419
|
+ "// }\n" +
|
|
420
|
+ "// \n" +
|
|
421
|
+ "// function saveAttributes(entityId) {\n" +
|
|
422
|
+ "// var attributesArray = [];\n" +
|
|
423
|
+ "// for (var key in vm.attributes) {\n" +
|
|
424
|
+ "// attributesArray.push({key: key, value: vm.attributes[key]});\n" +
|
|
425
|
+ "// }\n" +
|
|
426
|
+ "// if (attributesArray.length > 0) {\n" +
|
|
427
|
+ "// attributeService.saveEntityAttributes(entityId.entityType, entityId.id, \"SERVER_SCOPE\", attributesArray);\n" +
|
|
428
|
+ "// } \n" +
|
|
429
|
+ "// }\n" +
|
|
430
|
+ "// \n" +
|
|
431
|
+ "// function saveRelations(entityId) {\n" +
|
|
432
|
+ "// var tasks = [];\n" +
|
|
433
|
+ "// for (var i=0; i < vm.relations.length; i++) {\n" +
|
|
434
|
+ "// var relation = {\n" +
|
|
435
|
+ "// type: vm.relations[i].relationType\n" +
|
|
436
|
+ "// };\n" +
|
|
437
|
+ "// if (vm.relations[i].direction == types.entitySearchDirection.from) {\n" +
|
|
438
|
+ "// relation.to = vm.relations[i].relatedEntity;\n" +
|
|
439
|
+ "// relation.from = entityId;\n" +
|
|
440
|
+ "// } else {\n" +
|
|
441
|
+ "// relation.to = entityId;\n" +
|
|
442
|
+ "// relation.from = vm.relations[i].relatedEntity;\n" +
|
|
443
|
+ "// }\n" +
|
|
444
|
+ "// tasks.push(entityRelationService.saveRelation(relation));\n" +
|
|
445
|
+ "// }\n" +
|
|
446
|
+ "// $q.all(tasks).then(function(){\n" +
|
|
447
|
+ "// updateAliasData();\n" +
|
|
448
|
+ "// });\n" +
|
|
449
|
+ "// }\n" +
|
|
450
|
+ "// \n" +
|
|
451
|
+ "// function updateAliasData() {\n" +
|
|
452
|
+ "// var aliasIds = [];\n" +
|
|
453
|
+ "// for (var id in widgetContext.aliasController.resolvedAliases) {\n" +
|
|
454
|
+ "// aliasIds.push(id);\n" +
|
|
455
|
+ "// }\n" +
|
|
456
|
+ "// var tasks = [];\n" +
|
|
457
|
+ "// aliasIds.forEach(function(aliasId) {\n" +
|
|
458
|
+ "// widgetContext.aliasController.setAliasUnresolved(aliasId);\n" +
|
|
459
|
+ "// tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" +
|
|
460
|
+ "// });\n" +
|
|
461
|
+ "// $q.all(tasks).then(function() {\n" +
|
|
462
|
+ "// $rootScope.$broadcast('entityAliasesChanged', aliasIds);\n" +
|
|
463
|
+ "// });\n" +
|
|
464
|
+ "// }\n" +
|
|
465
|
+ "//}\n" +
|
|
466
|
+ "\n" +
|
|
467
|
+ "\n";
|
|
468
|
+
|
|
469
|
+ var sampleHtmlTemplate = '<!-- There are two example templates: for edit and add entity -->\n' +
|
|
470
|
+ '<!-- Edit entity example -->\n' +
|
|
471
|
+ '<!-- -->\n' +
|
|
472
|
+ '<!--<md-dialog aria-label="Edit entity">-->\n' +
|
|
473
|
+ '<!-- <form name="editEntityForm" class="edit-entity-form" ng-submit="vm.save()">-->\n' +
|
|
474
|
+ '<!-- <md-toolbar>-->\n' +
|
|
475
|
+ '<!-- <div class="md-toolbar-tools">-->\n' +
|
|
476
|
+ '<!-- <h2>Edit {{vm.entityType.toLowerCase()}} {{vm.entityName}}</h2>-->\n' +
|
|
477
|
+ '<!-- <span flex></span>-->\n' +
|
|
478
|
+ '<!-- <md-button class="md-icon-button" ng-click="vm.cancel()">-->\n' +
|
|
479
|
+ '<!-- <ng-md-icon icon="close" aria-label="Close"></ng-md-icon>-->\n' +
|
|
480
|
+ '<!-- </md-button>-->\n' +
|
|
481
|
+ '<!-- </div>-->\n' +
|
|
482
|
+ '<!-- </md-toolbar>-->\n' +
|
|
483
|
+ '<!-- <md-dialog-content>-->\n' +
|
|
484
|
+ '<!-- <div class="md-dialog-content">-->\n' +
|
|
485
|
+ '<!-- <div layout="row">-->\n' +
|
|
486
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
487
|
+ '<!-- <label>Entity Name</label>-->\n' +
|
|
488
|
+ '<!-- <input ng-model="vm.entityName" readonly>-->\n' +
|
|
489
|
+ '<!-- </md-input-container>-->\n' +
|
|
490
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
491
|
+ '<!-- <label>Entity Type</label>-->\n' +
|
|
492
|
+ '<!-- <input ng-model="vm.entityType" readonly>-->\n' +
|
|
493
|
+ '<!-- </md-input-container>-->\n' +
|
|
494
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
495
|
+ '<!-- <label>Type</label>-->\n' +
|
|
496
|
+ '<!-- <input ng-model="vm.type" readonly>-->\n' +
|
|
497
|
+ '<!-- </md-input-container>-->\n' +
|
|
498
|
+ '<!-- </div>-->\n' +
|
|
499
|
+ '<!-- <div layout="row">-->\n' +
|
|
500
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
501
|
+ '<!-- <label>Latitude</label>-->\n' +
|
|
502
|
+ '<!-- <input name="latitude" type="number" step="any" ng-model="vm.attributes.latitude">-->\n' +
|
|
503
|
+ '<!-- </md-input-container>-->\n' +
|
|
504
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
505
|
+ '<!-- <label>Longitude</label>-->\n' +
|
|
506
|
+ '<!-- <input name="longitude" type="number" step="any" ng-model="vm.attributes.longitude">-->\n' +
|
|
507
|
+ '<!-- </md-input-container>-->\n' +
|
|
508
|
+ '<!-- </div>-->\n' +
|
|
509
|
+ '<!-- <div layout="row">-->\n' +
|
|
510
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
511
|
+ '<!-- <label>Address</label>-->\n' +
|
|
512
|
+ '<!-- <input ng-model="vm.attributes.address">-->\n' +
|
|
513
|
+ '<!-- </md-input-container>-->\n' +
|
|
514
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
515
|
+ '<!-- <label>Owner</label>-->\n' +
|
|
516
|
+ '<!-- <input ng-model="vm.attributes.owner">-->\n' +
|
|
517
|
+ '<!-- </md-input-container>-->\n' +
|
|
518
|
+ '<!-- </div>-->\n' +
|
|
519
|
+ '<!-- <div layout="row">-->\n' +
|
|
520
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
521
|
+ '<!-- <label>Integer Value</label>-->\n' +
|
|
522
|
+ '<!-- <input name="integerNumber" type="number" step="1" ng-pattern="/^-?[0-9]+$/" ng-model="vm.attributes.number">-->\n' +
|
|
523
|
+ '<!-- <div ng-messages="editEntityForm.integerNumber.$error">-->\n' +
|
|
524
|
+ '<!-- <div ng-message="pattern">Invalid integer value.</div>-->\n' +
|
|
525
|
+ '<!-- </div>-->\n' +
|
|
526
|
+ '<!-- </md-input-container>-->\n' +
|
|
527
|
+ '<!-- <div class="boolean-value-input" layout="column" layout-align="center start" flex>-->\n' +
|
|
528
|
+ '<!-- <label class="checkbox-label">Boolean Value</label>-->\n' +
|
|
529
|
+ '<!-- <md-checkbox ng-model="vm.attributes.booleanValue" style="margin-bottom: 40px;">-->\n' +
|
|
530
|
+ '<!-- {{ (vm.attributes.booleanValue ? "value.true" : "value.false") | translate }}-->\n' +
|
|
531
|
+ '<!-- </md-checkbox>-->\n' +
|
|
532
|
+ '<!-- </div>-->\n' +
|
|
533
|
+ '<!-- </div>-->\n' +
|
|
534
|
+ '<!-- <div class="relations-list old-relations">-->\n' +
|
|
535
|
+ '<!-- <div class="md-body-1" style="padding-bottom: 10px; color: rgba(0,0,0,0.57);">Relations</div>-->\n' +
|
|
536
|
+ '<!-- <div class="body" ng-show="vm.relations.length">-->\n' +
|
|
537
|
+ '<!-- <div class="row" layout="row" layout-align="start center" ng-repeat="relation in vm.relations track by $index">-->\n' +
|
|
538
|
+ '<!-- <div class="md-whiteframe-1dp" flex layout="row" style="padding-left: 5px; margin-bottom: 3px;">-->\n' +
|
|
539
|
+ '<!-- <div flex layout="column">-->\n' +
|
|
540
|
+ '<!-- <div layout="row">-->\n' +
|
|
541
|
+ '<!-- <md-input-container class="md-block" style="min-width: 100px;">-->\n' +
|
|
542
|
+ '<!-- <label>Direction</label>-->\n' +
|
|
543
|
+ '<!-- <md-select ng-disabled="true" required ng-model="relation.direction">-->\n' +
|
|
544
|
+ '<!-- <md-option ng-repeat="direction in vm.entitySearchDirection" ng-value="direction">-->\n' +
|
|
545
|
+ '<!-- {{ ("relation.search-direction." + direction) | translate}}-->\n' +
|
|
546
|
+ '<!-- </md-option>-->\n' +
|
|
547
|
+ '<!-- </md-select>-->\n' +
|
|
548
|
+ '<!-- </md-input-container>-->\n' +
|
|
549
|
+ '<!-- <tb-relation-type-autocomplete ng-disabled="true" flex class="md-block"-->\n' +
|
|
550
|
+ '<!-- the-form="editEntityForm"-->\n' +
|
|
551
|
+ '<!-- ng-model="relation.relationType"-->\n' +
|
|
552
|
+ '<!-- tb-required="true">-->\n' +
|
|
553
|
+ '<!-- </tb-relation-type-autocomplete>-->\n' +
|
|
554
|
+ '<!-- </div>-->\n' +
|
|
555
|
+ '<!-- <div layout="row">-->\n' +
|
|
556
|
+ '<!-- <tb-entity-select flex class="md-block"-->\n' +
|
|
557
|
+ '<!-- the-form="editEntityForm"-->\n' +
|
|
558
|
+ '<!-- ng-disabled="true"-->\n' +
|
|
559
|
+ '<!-- tb-required="true"-->\n' +
|
|
560
|
+ '<!-- ng-model="relation.relatedEntity">-->\n' +
|
|
561
|
+ '<!-- </tb-entity-select>-->\n' +
|
|
562
|
+ '<!-- </div>-->\n' +
|
|
563
|
+ '<!-- </div>-->\n' +
|
|
564
|
+ '<!-- <div layout="column" layout-align="center center">-->\n' +
|
|
565
|
+ '<!-- <md-button class="md-icon-button md-primary" style="width: 40px; min-width: 40px;"-->\n' +
|
|
566
|
+ '<!-- ng-click="vm.removeOldRelation($index,relation)" aria-label="Remove">-->\n' +
|
|
567
|
+ '<!-- <md-tooltip md-direction="top">Remove relation</md-tooltip>-->\n' +
|
|
568
|
+ '<!-- <md-icon aria-label="Remove" class="material-icons">-->\n' +
|
|
569
|
+ '<!-- close-->\n' +
|
|
570
|
+ '<!-- </md-icon>-->\n' +
|
|
571
|
+ '<!-- </md-button>-->\n' +
|
|
572
|
+ '<!-- </div>-->\n' +
|
|
573
|
+ '<!-- </div>-->\n' +
|
|
574
|
+ '<!-- </div>-->\n' +
|
|
575
|
+ '<!-- </div>-->\n' +
|
|
576
|
+ '<!-- </div>-->\n' +
|
|
577
|
+ '<!-- <div class="relations-list">-->\n' +
|
|
578
|
+ '<!-- <div class="md-body-1" style="padding-bottom: 10px; color: rgba(0,0,0,0.57);">New Relations</div>-->\n' +
|
|
579
|
+ '<!-- <div class="body" ng-show="vm.newRelations.length">-->\n' +
|
|
580
|
+ '<!-- <div class="row" layout="row" layout-align="start center" ng-repeat="relation in vm.newRelations track by $index">-->\n' +
|
|
581
|
+ '<!-- <div class="md-whiteframe-1dp" flex layout="row" style="padding-left: 5px; margin-bottom: 3px;">-->\n' +
|
|
582
|
+ '<!-- <div flex layout="column">-->\n' +
|
|
583
|
+ '<!-- <div layout="row">-->\n' +
|
|
584
|
+ '<!-- <md-input-container class="md-block" style="min-width: 100px;">-->\n' +
|
|
585
|
+ '<!-- <label>Direction</label>-->\n' +
|
|
586
|
+ '<!-- <md-select name="direction" required ng-model="relation.direction">-->\n' +
|
|
587
|
+ '<!-- <md-option ng-repeat="direction in vm.entitySearchDirection" ng-value="direction">-->\n' +
|
|
588
|
+ '<!-- {{ ("relation.search-direction." + direction) | translate}}-->\n' +
|
|
589
|
+ '<!-- </md-option>-->\n' +
|
|
590
|
+ '<!-- </md-select>-->\n' +
|
|
591
|
+ '<!-- <div ng-messages="editEntityForm.direction.$error">-->\n' +
|
|
592
|
+ '<!-- <div ng-message="required">Relation direction is required.</div>-->\n' +
|
|
593
|
+ '<!-- </div>-->\n' +
|
|
594
|
+ '<!-- </md-input-container>-->\n' +
|
|
595
|
+ '<!-- <tb-relation-type-autocomplete flex class="md-block"-->\n' +
|
|
596
|
+ '<!-- the-form="editEntityForm"-->\n' +
|
|
597
|
+ '<!-- ng-model="relation.relationType"-->\n' +
|
|
598
|
+ '<!-- tb-required="true">-->\n' +
|
|
599
|
+ '<!-- </tb-relation-type-autocomplete>-->\n' +
|
|
600
|
+ '<!-- </div>-->\n' +
|
|
601
|
+ '<!-- <div layout="row">-->\n' +
|
|
602
|
+ '<!-- <tb-entity-select flex class="md-block"-->\n' +
|
|
603
|
+ '<!-- the-form="editEntityForm"-->\n' +
|
|
604
|
+ '<!-- tb-required="true"-->\n' +
|
|
605
|
+ '<!-- ng-model="relation.relatedEntity">-->\n' +
|
|
606
|
+ '<!-- </tb-entity-select>-->\n' +
|
|
607
|
+ '<!-- </div>-->\n' +
|
|
608
|
+ '<!-- </div>-->\n' +
|
|
609
|
+ '<!-- <div layout="column" layout-align="center center">-->\n' +
|
|
610
|
+ '<!-- <md-button class="md-icon-button md-primary" style="width: 40px; min-width: 40px;"-->\n' +
|
|
611
|
+ '<!-- ng-click="vm.removeRelation($index)" aria-label="Remove">-->\n' +
|
|
612
|
+ '<!-- <md-tooltip md-direction="top">Remove relation</md-tooltip>-->\n' +
|
|
613
|
+ '<!-- <md-icon aria-label="Remove" class="material-icons">-->\n' +
|
|
614
|
+ '<!-- close-->\n' +
|
|
615
|
+ '<!-- </md-icon>-->\n' +
|
|
616
|
+ '<!-- </md-button>-->\n' +
|
|
617
|
+ '<!-- </div>-->\n' +
|
|
618
|
+ '<!-- </div>-->\n' +
|
|
619
|
+ '<!-- </div>-->\n' +
|
|
620
|
+ '<!-- </div>-->\n' +
|
|
621
|
+ '<!-- <div>-->\n' +
|
|
622
|
+ '<!-- <md-button class="md-primary md-raised" ng-click="vm.addRelation()" aria-label="Add">-->\n' +
|
|
623
|
+ '<!-- <md-tooltip md-direction="top">Add Relation</md-tooltip>-->\n' +
|
|
624
|
+ '<!-- Add-->\n' +
|
|
625
|
+ '<!-- </md-button>-->\n' +
|
|
626
|
+ '<!-- </div> -->\n' +
|
|
627
|
+ '<!-- </div>-->\n' +
|
|
628
|
+ '<!-- </div>-->\n' +
|
|
629
|
+ '<!-- </md-dialog-content>-->\n' +
|
|
630
|
+ '<!-- <md-dialog-actions>-->\n' +
|
|
631
|
+ '<!-- <md-button type="submit" ng-disabled="editEntityForm.$invalid || !editEntityForm.$dirty" class="md-raised md-primary">Save</md-button>-->\n' +
|
|
632
|
+ '<!-- <md-button ng-click="vm.cancel()" class="md-primary">Cancel</md-button>-->\n' +
|
|
633
|
+ '<!-- </md-dialog-actions>-->\n' +
|
|
634
|
+ '<!-- </form>-->\n' +
|
|
635
|
+ '<!--</md-dialog>-->\n' +
|
|
636
|
+ '<!-- -->\n' +
|
|
637
|
+ '<!-- Add entity example -->\n' +
|
|
638
|
+ '<!-- -->\n' +
|
|
639
|
+ '<!--<md-dialog aria-label="Add entity">-->\n' +
|
|
640
|
+ '<!-- <form name="addEntityForm" class="add-entity-form" ng-submit="vm.save()">-->\n' +
|
|
641
|
+ '<!-- <md-toolbar>-->\n' +
|
|
642
|
+ '<!-- <div class="md-toolbar-tools">-->\n' +
|
|
643
|
+ '<!-- <h2>Add entity</h2>-->\n' +
|
|
644
|
+ '<!-- <span flex></span>-->\n' +
|
|
645
|
+ '<!-- <md-button class="md-icon-button" ng-click="vm.cancel()">-->\n' +
|
|
646
|
+ '<!-- <ng-md-icon icon="close" aria-label="Close"></ng-md-icon>-->\n' +
|
|
647
|
+ '<!-- </md-button>-->\n' +
|
|
648
|
+ '<!-- </div>-->\n' +
|
|
649
|
+ '<!-- </md-toolbar>-->\n' +
|
|
650
|
+ '<!-- <md-dialog-content>-->\n' +
|
|
651
|
+ '<!-- <div class="md-dialog-content">-->\n' +
|
|
652
|
+ '<!-- <div layout="row">-->\n' +
|
|
653
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
654
|
+ '<!-- <label>Entity Name</label>-->\n' +
|
|
655
|
+ '<!-- <input ng-model="vm.entityName" name=entityName required>-->\n' +
|
|
656
|
+ '<!-- <div ng-messages="addEntityForm.entityName.$error">-->\n' +
|
|
657
|
+ '<!-- <div ng-message="required">Entity name is required.</div>-->\n' +
|
|
658
|
+ '<!-- </div>-->\n' +
|
|
659
|
+ '<!-- </md-input-container>-->\n' +
|
|
660
|
+ '<!-- <tb-entity-type-select class="md-block" style="min-width: 100px; width: 100px;"-->\n' +
|
|
661
|
+ '<!-- the-form="addEntityForm"-->\n' +
|
|
662
|
+ '<!-- tb-required="true"-->\n' +
|
|
663
|
+ '<!-- allowed-entity-types="vm.allowedEntityTypes"-->\n' +
|
|
664
|
+ '<!-- ng-model="vm.entityType">-->\n' +
|
|
665
|
+ '<!-- </tb-entity-type-select>-->\n' +
|
|
666
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
667
|
+ '<!-- <label>Entity Subtype</label>-->\n' +
|
|
668
|
+ '<!-- <input ng-model="vm.type" name=type required>-->\n' +
|
|
669
|
+ '<!-- <div ng-messages="addEntityForm.type.$error">-->\n' +
|
|
670
|
+ '<!-- <div ng-message="required">Entity subtype is required.</div>-->\n' +
|
|
671
|
+ '<!-- </div>-->\n' +
|
|
672
|
+ '<!-- </md-input-container>-->\n' +
|
|
673
|
+ '<!-- </div>-->\n' +
|
|
674
|
+ '<!-- <div layout="row">-->\n' +
|
|
675
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
676
|
+ '<!-- <label>Latitude</label>-->\n' +
|
|
677
|
+ '<!-- <input name="latitude" type="number" step="any" ng-model="vm.attributes.latitude">-->\n' +
|
|
678
|
+ '<!-- </md-input-container>-->\n' +
|
|
679
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
680
|
+ '<!-- <label>Longitude</label>-->\n' +
|
|
681
|
+ '<!-- <input name="longitude" type="number" step="any" ng-model="vm.attributes.longitude">-->\n' +
|
|
682
|
+ '<!-- </md-input-container>-->\n' +
|
|
683
|
+ '<!-- </div>-->\n' +
|
|
684
|
+ '<!-- <div layout="row">-->\n' +
|
|
685
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
686
|
+ '<!-- <label>Address</label>-->\n' +
|
|
687
|
+ '<!-- <input ng-model="vm.attributes.address">-->\n' +
|
|
688
|
+ '<!-- </md-input-container>-->\n' +
|
|
689
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
690
|
+ '<!-- <label>Owner</label>-->\n' +
|
|
691
|
+ '<!-- <input ng-model="vm.attributes.owner">-->\n' +
|
|
692
|
+ '<!-- </md-input-container>-->\n' +
|
|
693
|
+ '<!-- </div>-->\n' +
|
|
694
|
+ '<!-- <div layout="row">-->\n' +
|
|
695
|
+ '<!-- <md-input-container flex class="md-block">-->\n' +
|
|
696
|
+ '<!-- <label>Integer Value</label>-->\n' +
|
|
697
|
+ '<!-- <input name="integerNumber" type="number" step="1" ng-pattern="/^-?[0-9]+$/" ng-model="vm.attributes.number">-->\n' +
|
|
698
|
+ '<!-- <div ng-messages="addEntityForm.integerNumber.$error">-->\n' +
|
|
699
|
+ '<!-- <div ng-message="pattern">Invalid integer value.</div>-->\n' +
|
|
700
|
+ '<!-- </div>-->\n' +
|
|
701
|
+ '<!-- </md-input-container>-->\n' +
|
|
702
|
+ '<!-- <div class="boolean-value-input" layout="column" layout-align="center start" flex>-->\n' +
|
|
703
|
+ '<!-- <label class="checkbox-label">Boolean Value</label>-->\n' +
|
|
704
|
+ '<!-- <md-checkbox ng-model="vm.attributes.booleanValue" style="margin-bottom: 40px;">-->\n' +
|
|
705
|
+ '<!-- {{ (vm.attributes.booleanValue ? "value.true" : "value.false") | translate }}-->\n' +
|
|
706
|
+ '<!-- </md-checkbox>-->\n' +
|
|
707
|
+ '<!-- </div>-->\n' +
|
|
708
|
+ '<!-- </div>-->\n' +
|
|
709
|
+ '<!-- <div class="relations-list">-->\n' +
|
|
710
|
+ '<!-- <div class="md-body-1" style="padding-bottom: 10px; color: rgba(0,0,0,0.57);">Relations</div>-->\n' +
|
|
711
|
+ '<!-- <div class="body" ng-show="vm.relations.length">-->\n' +
|
|
712
|
+ '<!-- <div class="row" layout="row" layout-align="start center" ng-repeat="relation in vm.relations track by $index">-->\n' +
|
|
713
|
+ '<!-- <div class="md-whiteframe-1dp" flex layout="row" style="padding-left: 5px;">-->\n' +
|
|
714
|
+ '<!-- <div flex layout="column">-->\n' +
|
|
715
|
+ '<!-- <div layout="row">-->\n' +
|
|
716
|
+ '<!-- <md-input-container class="md-block" style="min-width: 100px;">-->\n' +
|
|
717
|
+ '<!-- <label>Direction</label>-->\n' +
|
|
718
|
+ '<!-- <md-select name="direction" required ng-model="relation.direction">-->\n' +
|
|
719
|
+ '<!-- <md-option ng-repeat="direction in vm.entitySearchDirection" ng-value="direction">-->\n' +
|
|
720
|
+ '<!-- {{ ("relation.search-direction." + direction) | translate}}-->\n' +
|
|
721
|
+ '<!-- </md-option>-->\n' +
|
|
722
|
+ '<!-- </md-select>-->\n' +
|
|
723
|
+ '<!-- <div ng-messages="addEntityForm.direction.$error">-->\n' +
|
|
724
|
+ '<!-- <div ng-message="required">Relation direction is required.</div>-->\n' +
|
|
725
|
+ '<!-- </div>-->\n' +
|
|
726
|
+ '<!-- </md-input-container>-->\n' +
|
|
727
|
+ '<!-- <tb-relation-type-autocomplete flex class="md-block"-->\n' +
|
|
728
|
+ '<!-- the-form="addEntityForm"-->\n' +
|
|
729
|
+ '<!-- ng-model="relation.relationType"-->\n' +
|
|
730
|
+ '<!-- tb-required="true">-->\n' +
|
|
731
|
+ '<!-- </tb-relation-type-autocomplete>-->\n' +
|
|
732
|
+ '<!-- </div>-->\n' +
|
|
733
|
+ '<!-- <div layout="row">-->\n' +
|
|
734
|
+ '<!-- <tb-entity-select flex class="md-block"-->\n' +
|
|
735
|
+ '<!-- the-form="addEntityForm"-->\n' +
|
|
736
|
+ '<!-- tb-required="true"-->\n' +
|
|
737
|
+ '<!-- ng-model="relation.relatedEntity">-->\n' +
|
|
738
|
+ '<!-- </tb-entity-select>-->\n' +
|
|
739
|
+ '<!-- </div>-->\n' +
|
|
740
|
+ '<!-- </div>-->\n' +
|
|
741
|
+ '<!-- <div layout="column" layout-align="center center">-->\n' +
|
|
742
|
+ '<!-- <md-button class="md-icon-button md-primary" style="width: 40px; min-width: 40px;"-->\n' +
|
|
743
|
+ '<!-- ng-click="vm.removeRelation($index)" aria-label="Remove">-->\n' +
|
|
744
|
+ '<!-- <md-tooltip md-direction="top">Remove relation</md-tooltip>-->\n' +
|
|
745
|
+ '<!-- <md-icon aria-label="Remove" class="material-icons">-->\n' +
|
|
746
|
+ '<!-- close-->\n' +
|
|
747
|
+ '<!-- </md-icon>-->\n' +
|
|
748
|
+ '<!-- </md-button>-->\n' +
|
|
749
|
+ '<!-- </div>-->\n' +
|
|
750
|
+ '<!-- </div>-->\n' +
|
|
751
|
+ '<!-- </div>-->\n' +
|
|
752
|
+ '<!-- </div>-->\n' +
|
|
753
|
+ '<!-- <div>-->\n' +
|
|
754
|
+ '<!-- <md-button class="md-primary md-raised" ng-click="vm.addRelation()" aria-label="Add">-->\n' +
|
|
755
|
+ '<!-- <md-tooltip md-direction="top">Add Relation</md-tooltip>-->\n' +
|
|
756
|
+ '<!-- Add-->\n' +
|
|
757
|
+ '<!-- </md-button>-->\n' +
|
|
758
|
+ '<!-- </div> -->\n' +
|
|
759
|
+ '<!-- </div>-->\n' +
|
|
760
|
+ '<!-- </div>-->\n' +
|
|
761
|
+ '<!-- </md-dialog-content>-->\n' +
|
|
762
|
+ '<!-- <md-dialog-actions>-->\n' +
|
|
763
|
+ '<!-- <md-button type="submit" ng-disabled="addEntityForm.$invalid || !addEntityForm.$dirty" class="md-raised md-primary">Create</md-button>-->\n' +
|
|
764
|
+ '<!-- <md-button ng-click="vm.cancel()" class="md-primary">Cancel</md-button>-->\n' +
|
|
765
|
+ '<!-- </md-dialog-actions>-->\n' +
|
|
766
|
+ '<!-- </form>-->\n' +
|
|
767
|
+ '<!--</md-dialog>-->\n';
|
|
768
|
+
|
|
769
|
+ var sampleCss = '/* There are two examples: for edit and add entity */\n' +
|
|
770
|
+ '/* Edit entity example */\n' +
|
|
771
|
+ '/*\n' +
|
|
772
|
+ '.edit-entity-form md-input-container {\n' +
|
|
773
|
+ ' padding-right: 10px;\n' +
|
|
774
|
+ '}\n' +
|
|
775
|
+ '\n' +
|
|
776
|
+ '.edit-entity-form .boolean-value-input {\n' +
|
|
777
|
+ ' padding-left: 5px;\n' +
|
|
778
|
+ '}\n' +
|
|
779
|
+ '\n' +
|
|
780
|
+ '.edit-entity-form .boolean-value-input .checkbox-label {\n' +
|
|
781
|
+ ' margin-bottom: 8px;\n' +
|
|
782
|
+ ' color: rgba(0,0,0,0.54);\n' +
|
|
783
|
+ ' font-size: 12px;\n' +
|
|
784
|
+ '}\n' +
|
|
785
|
+ '\n' +
|
|
786
|
+ '.relations-list .header {\n' +
|
|
787
|
+ ' padding-right: 5px;\n' +
|
|
788
|
+ ' padding-bottom: 5px;\n' +
|
|
789
|
+ ' padding-left: 5px;\n' +
|
|
790
|
+ '}\n' +
|
|
791
|
+ '\n' +
|
|
792
|
+ '.relations-list .header .cell {\n' +
|
|
793
|
+ ' padding-right: 5px;\n' +
|
|
794
|
+ ' padding-left: 5px;\n' +
|
|
795
|
+ ' font-size: 12px;\n' +
|
|
796
|
+ ' font-weight: 700;\n' +
|
|
797
|
+ ' color: rgba(0, 0, 0, .54);\n' +
|
|
798
|
+ ' white-space: nowrap;\n' +
|
|
799
|
+ '}\n' +
|
|
800
|
+ '\n' +
|
|
801
|
+ '.relations-list .body {\n' +
|
|
802
|
+ ' padding-right: 5px;\n' +
|
|
803
|
+ ' padding-bottom: 15px;\n' +
|
|
804
|
+ ' padding-left: 5px;\n' +
|
|
805
|
+ '}\n' +
|
|
806
|
+ '\n' +
|
|
807
|
+ '.relations-list .body .row {\n' +
|
|
808
|
+ ' padding-top: 5px;\n' +
|
|
809
|
+ '}\n' +
|
|
810
|
+ '\n' +
|
|
811
|
+ '.relations-list .body .cell {\n' +
|
|
812
|
+ ' padding-right: 5px;\n' +
|
|
813
|
+ ' padding-left: 5px;\n' +
|
|
814
|
+ '}\n' +
|
|
815
|
+ '\n' +
|
|
816
|
+ '.relations-list .body md-autocomplete-wrap md-input-container {\n' +
|
|
817
|
+ ' height: 30px;\n' +
|
|
818
|
+ '}\n' +
|
|
819
|
+ '\n' +
|
|
820
|
+ '.relations-list .body .md-button {\n' +
|
|
821
|
+ ' margin: 0;\n' +
|
|
822
|
+ '}\n' +
|
|
823
|
+ '\n' +
|
|
824
|
+ '.relations-list.old-relations tb-entity-select tb-entity-autocomplete button {\n' +
|
|
825
|
+ ' display: none;\n' +
|
|
826
|
+ '} \n' +
|
|
827
|
+ '*/\n' +
|
|
828
|
+ '/* Add entity example */\n' +
|
|
829
|
+ '/*\n' +
|
|
830
|
+ '.add-entity-form md-input-container {\n' +
|
|
831
|
+ ' padding-right: 10px;\n' +
|
|
832
|
+ '}\n' +
|
|
833
|
+ '\n' +
|
|
834
|
+ '.add-entity-form .boolean-value-input {\n' +
|
|
835
|
+ ' padding-left: 5px;\n' +
|
|
836
|
+ '}\n' +
|
|
837
|
+ '\n' +
|
|
838
|
+ '.add-entity-form .boolean-value-input .checkbox-label {\n' +
|
|
839
|
+ ' margin-bottom: 8px;\n' +
|
|
840
|
+ ' color: rgba(0,0,0,0.54);\n' +
|
|
841
|
+ ' font-size: 12px;\n' +
|
|
842
|
+ '}\n' +
|
|
843
|
+ '\n' +
|
|
844
|
+ '.relations-list .header {\n' +
|
|
845
|
+ ' padding-right: 5px;\n' +
|
|
846
|
+ ' padding-bottom: 5px;\n' +
|
|
847
|
+ ' padding-left: 5px;\n' +
|
|
848
|
+ '}\n' +
|
|
849
|
+ '\n' +
|
|
850
|
+ '.relations-list .header .cell {\n' +
|
|
851
|
+ ' padding-right: 5px;\n' +
|
|
852
|
+ ' padding-left: 5px;\n' +
|
|
853
|
+ ' font-size: 12px;\n' +
|
|
854
|
+ ' font-weight: 700;\n' +
|
|
855
|
+ ' color: rgba(0, 0, 0, .54);\n' +
|
|
856
|
+ ' white-space: nowrap;\n' +
|
|
857
|
+ '}\n' +
|
|
858
|
+ '\n' +
|
|
859
|
+ '.relations-list .body {\n' +
|
|
860
|
+ ' padding-right: 5px;\n' +
|
|
861
|
+ ' padding-bottom: 15px;\n' +
|
|
862
|
+ ' padding-left: 5px;\n' +
|
|
863
|
+ '}\n' +
|
|
864
|
+ '\n' +
|
|
865
|
+ '.relations-list .body .row {\n' +
|
|
866
|
+ ' padding-top: 5px;\n' +
|
|
867
|
+ '}\n' +
|
|
868
|
+ '\n' +
|
|
869
|
+ '.relations-list .body .cell {\n' +
|
|
870
|
+ ' padding-right: 5px;\n' +
|
|
871
|
+ ' padding-left: 5px;\n' +
|
|
872
|
+ '}\n' +
|
|
873
|
+ '\n' +
|
|
874
|
+ '.relations-list .body md-autocomplete-wrap md-input-container {\n' +
|
|
875
|
+ ' height: 30px;\n' +
|
|
876
|
+ '}\n' +
|
|
877
|
+ '\n' +
|
|
878
|
+ '.relations-list .body .md-button {\n' +
|
|
879
|
+ ' margin: 0;\n' +
|
|
880
|
+ '}\n' +
|
|
881
|
+ '*/\n' +
|
|
882
|
+ '\n' +
|
|
883
|
+ '\n';
|
|
884
|
+
|
|
885
|
+ scope.$watch('action', function () {
|
|
886
|
+ ngModelCtrl.$setViewValue(scope.action);
|
|
887
|
+ });
|
|
888
|
+
|
|
889
|
+ ngModelCtrl.$render = function () {
|
|
890
|
+ scope.action = ngModelCtrl.$viewValue;
|
|
891
|
+ if (angular.isUndefined(scope.action.customHtml) && angular.isUndefined(scope.action.customCss) && angular.isUndefined(scope.action.customFunction)) {
|
|
892
|
+ scope.action.customFunction = sampleJsFunction;
|
|
893
|
+ scope.action.customHtml = sampleHtmlTemplate;
|
|
894
|
+ scope.action.customCss = sampleCss;
|
|
895
|
+ }
|
|
896
|
+ };
|
|
897
|
+
|
|
898
|
+ function removeResource(index) {
|
|
899
|
+ if (index > -1) {
|
|
900
|
+ scope.action.customResources.splice(index, 1);
|
|
901
|
+ scope.theForm.$setDirty();
|
|
902
|
+ }
|
|
903
|
+ }
|
|
904
|
+
|
|
905
|
+ function addResource() {
|
|
906
|
+ if (!scope.action.customResources) {
|
|
907
|
+ scope.action.customResources = [];
|
|
908
|
+ }
|
|
909
|
+ scope.action.customResources.push({url: ''});
|
|
910
|
+ scope.theForm.$setDirty();
|
|
911
|
+ }
|
|
912
|
+
|
|
913
|
+ function beautifyHtml() {
|
|
914
|
+ var res = html_beautify(scope.action.customHtml, {indent_size: 4, wrap_line_length: 60});
|
|
915
|
+ scope.action.customHtml = res;
|
|
916
|
+ }
|
|
917
|
+
|
|
918
|
+ function beautifyCss() {
|
|
919
|
+ var res = css_beautify(scope.action.customCss, {indent_size: 4});
|
|
920
|
+ scope.action.customCss = res;
|
|
921
|
+ }
|
|
922
|
+
|
|
923
|
+ function toggleFullscreen() {
|
|
924
|
+ scope.fullscreen = !scope.fullscreen;
|
|
925
|
+ if (scope.fullscreen) {
|
|
926
|
+ scope.customActionEditorElement = angular.element('.tb-custom-action-editor');
|
|
927
|
+ angular.element(scope.customActionEditorElement[0]).ready(function () {
|
|
928
|
+ var w = scope.customActionEditorElement.width();
|
|
929
|
+ if (w > 0) {
|
|
930
|
+ initSplitLayout();
|
|
931
|
+ } else {
|
|
932
|
+ scope.$watch(
|
|
933
|
+ function () {
|
|
934
|
+ return scope.customActionEditorElement[0].offsetWidth || parseInt(scope.customActionEditorElement.css('width'), 10);
|
|
935
|
+ },
|
|
936
|
+ function (newSize) {
|
|
937
|
+ if (newSize > 0) {
|
|
938
|
+ initSplitLayout();
|
|
939
|
+ }
|
|
940
|
+ }
|
|
941
|
+ );
|
|
942
|
+ }
|
|
943
|
+ });
|
|
944
|
+ } else {
|
|
945
|
+ scope.layoutInited = false;
|
|
946
|
+ }
|
|
947
|
+ }
|
|
948
|
+
|
|
949
|
+ function onDividerDrag() {
|
|
950
|
+ scope.$broadcast('update-ace-editor-size');
|
|
951
|
+ for (var i = 0; i < ace_editors.length; i++) {
|
|
952
|
+ var ace = ace_editors[i];
|
|
953
|
+ ace.resize();
|
|
954
|
+ ace.renderer.updateFull();
|
|
955
|
+ }
|
|
956
|
+ }
|
|
957
|
+
|
|
958
|
+ function initSplitLayout() {
|
|
959
|
+ if (!scope.layoutInited) {
|
|
960
|
+ Split([angular.element('#left-panel', scope.customActionEditorElement)[0], angular.element('#right-panel', scope.customActionEditorElement)[0]], {
|
|
961
|
+ sizes: [50, 50],
|
|
962
|
+ gutterSize: 8,
|
|
963
|
+ cursor: 'col-resize',
|
|
964
|
+ onDrag: function () {
|
|
965
|
+ onDividerDrag()
|
|
966
|
+ }
|
|
967
|
+ });
|
|
968
|
+
|
|
969
|
+ onDividerDrag();
|
|
970
|
+
|
|
971
|
+ scope.$applyAsync(function () {
|
|
972
|
+ scope.layoutInited = true;
|
|
973
|
+ var w = angular.element($window);
|
|
974
|
+ $timeout(function () {
|
|
975
|
+ w.triggerHandler('resize')
|
|
976
|
+ });
|
|
977
|
+ });
|
|
978
|
+
|
|
979
|
+ }
|
|
980
|
+ }
|
|
981
|
+
|
|
982
|
+ $compile(element.contents())(scope);
|
|
983
|
+ };
|
|
984
|
+
|
|
985
|
+ return {
|
|
986
|
+ restrict: "E",
|
|
987
|
+ require: "^ngModel",
|
|
988
|
+ scope: {
|
|
989
|
+ theForm: '=?',
|
|
990
|
+ },
|
|
991
|
+ link: linker
|
|
992
|
+ };
|
|
993
|
+} |
...
|
...
|
|