From e1e1314f1f9179744dc9f44af7abe02c53ee41d6 Mon Sep 17 00:00:00 2001 From: Nico Melone Date: Tue, 17 Jan 2023 23:06:23 -0600 Subject: [PATCH] added code for note widget --- .DS_Store | Bin 10244 -> 10244 bytes Widgets/.DS_Store | Bin 6148 -> 6148 bytes Widgets/notes/addNote.html | 31 +++++ Widgets/notes/addNote.js | 90 +++++++++++++ Widgets/notes/editNote.html | 187 ++++++++++++++++++++++++++ Widgets/notes/editNote.js | 216 +++++++++++++++++++++++++++++++ meshifyDrivers/.DS_Store | Bin 6148 -> 6148 bytes meshifyDrivers/mainHPRPI/main.py | 4 +- uplink_converter.js | 74 +++++++++++ 9 files changed, 600 insertions(+), 2 deletions(-) create mode 100644 Widgets/notes/addNote.html create mode 100644 Widgets/notes/addNote.js create mode 100644 Widgets/notes/editNote.html create mode 100644 Widgets/notes/editNote.js create mode 100644 uplink_converter.js diff --git a/.DS_Store b/.DS_Store index 7a5db0b25aa1b1077ae3d3b4f4fa0b26c8ec957a..eaaefa95d6879a0e139bab0352fbaba352d34791 100644 GIT binary patch delta 63 zcmV-F0Kor*P=rvhc@qJ+lgt%y3mAKQHZnIXATl;GlSvjE0g97u5g!4IlfV=pvr`n| V1pxuGH5$?dvj!mh1hWDa0|S?p6Mz5! delta 49 zcmZn(XbIR*DLnaela!yI!?-z+c?F{iNQRXmk0GC-gdr747Fl@m zc_z_7Bt^OTE-pzq`AI-E9CLZow{>hk;)txCp*S}`g@B5JjLAw&N|P0s<}osC-p{m= KWiva+Uw#0Qoh + +

New Note

+ + +
+ +
+
+
+ +
+
+
+ + +
+ + + \ No newline at end of file diff --git a/Widgets/notes/addNote.js b/Widgets/notes/addNote.js new file mode 100644 index 0000000..8860ad7 --- /dev/null +++ b/Widgets/notes/addNote.js @@ -0,0 +1,90 @@ +let $injector = widgetContext.$scope.$injector; +let customDialog = $injector.get(widgetContext.servicesMap.get('customDialog')); +let assetService = $injector.get(widgetContext.servicesMap.get('assetService')); +let attributeService = $injector.get(widgetContext.servicesMap.get('attributeService')); +let entityService = $injector.get(widgetContext.servicesMap.get('entityService')); +console.log(widgetContext); +openAddEntityDialog(); + +function openAddEntityDialog() { + customDialog.customDialog(htmlTemplate, AddEntityDialogController).subscribe(() => {}); +} + +function AddEntityDialogController(instance) { + let vm = instance; + + vm.entityName = entityName; + + vm.attributes = {}; + vm.timeseries = {}; + + vm.editEntity = vm.fb.group({ + attributes: vm.fb.group({ + note: "" + }) + }); + + getEntityInfo(); + + vm.cancel = function() { + vm.dialogRef.close(null); + }; + + vm.save = function() { + vm.loading = true; + saveAttributes(entityId).subscribe( + () => { + vm.dialogRef.close(null); + }, () =>{ + vm.loading = false; + } + ); + }; + + function getEntityAttributes(attributes) { + for (var i = 0; i < attributes.length; i++) { + vm.attributes[attributes[i].key] = attributes[i].value; + } + } + + function getEntityInfo() { + vm.loading = true; + attributeService.getEntityAttributes(entityId, 'SERVER_SCOPE').subscribe( + function (data) { + console.log(data); + getEntityAttributes(data); + + vm.editEntity.patchValue({ + attributes: vm.attributes + }, {emitEvent: false}); + vm.loading = false; + } + ); + /*attributeService.getEntityTimeseries(entityId, ["LOGS"],Date.now() - 24*60*60*1000, Date.now() ).subscribe( + function (data) { + console.log(data); + //getEntityTimeseries(data); + + vm.editEntity.patchValue({ + timeseries: vm.timeseries + }, {emitEvent: false}); + vm.loading = false; + } + );*/ + } + + function saveAttributes(entityId) { + let attributes = vm.editEntity.get('attributes').value; + let attributesArray = []; + for (let key in attributes) { + if (attributes[key] !== vm.attributes[key]) { + attributesArray.push({key: key, value: attributes[key]}); + } + } + /*if (attributesArray.length > 0) { + return attributeService.saveEntityAttributes(entityId, "SERVER_SCOPE", attributesArray); + }*/ + return attributeService.saveEntityTimeseries(entityId,"ANY", [{"lastUpdateTs": Date.now(), "key": widgetContext.datasources[0].dataKeys[0].name, "value": attributes.note}] ); + //return widgetContext.rxjs.of([]); + } +} diff --git a/Widgets/notes/editNote.html b/Widgets/notes/editNote.html new file mode 100644 index 0000000..1818c92 --- /dev/null +++ b/Widgets/notes/editNote.html @@ -0,0 +1,187 @@ +
+ +

Edit {{entityType.toLowerCase()}} {{entityName}}

+ + +
+ + +
+
+
+ + Entity Name + + + + Entity Label + + +
+
+ + Entity Type + + + + Type + + +
+
+
+ + Latitude + + + + Longitude + + +
+
+ + Address + + + + Owner + + +
+
+ + Integer Value + + + Invalid integer value. + + +
+ + + {{ (editEntityFormGroup.get('attributes.booleanValue').value ? "value.true" : "value.false") | translate }} + +
+
+
+
+
Relations
+
+
+
+
+
+ + Direction + + + {{ ("relation.search-direction." + direction.value) | translate}} + + + + Relation direction is required. + + + + +
+
+ + +
+
+
+ +
+
+
+
+
+
+
New Relations
+
+
+
+
+
+ + Direction + + + {{ ("relation.search-direction." + direction.value) | translate}} + + + + Relation direction is required. + + + + +
+
+ + +
+
+
+ +
+
+
+
+
+ +
+
+
+
+ + +
+
diff --git a/Widgets/notes/editNote.js b/Widgets/notes/editNote.js new file mode 100644 index 0000000..b2a2d89 --- /dev/null +++ b/Widgets/notes/editNote.js @@ -0,0 +1,216 @@ +let $injector = widgetContext.$scope.$injector; +let customDialog = $injector.get(widgetContext.servicesMap.get('customDialog')); +let entityService = $injector.get(widgetContext.servicesMap.get('entityService')); +let assetService = $injector.get(widgetContext.servicesMap.get('assetService')); +let deviceService = $injector.get(widgetContext.servicesMap.get('deviceService')); +let attributeService = $injector.get(widgetContext.servicesMap.get('attributeService')); +let entityRelationService = $injector.get(widgetContext.servicesMap.get('entityRelationService')); + +openEditEntityDialog(); + +function openEditEntityDialog() { + customDialog.customDialog(htmlTemplate, EditEntityDialogController).subscribe(); +} + +function EditEntityDialogController(instance) { + let vm = instance; + + vm.entityName = entityName; + vm.entityType = entityId.entityType; + vm.entitySearchDirection = { + from: "FROM", + to: "TO" + }; + vm.attributes = {}; + vm.oldRelationsData = []; + vm.relationsToDelete = []; + vm.entity = {}; + + vm.editEntityFormGroup = vm.fb.group({ + entityName: ['', [vm.validators.required]], + entityType: [null], + entityLabel: [null], + type: ['', [vm.validators.required]], + attributes: vm.fb.group({ + latitude: [null], + longitude: [null], + address: [null], + owner: [null], + number: [null, [vm.validators.pattern(/^-?[0-9]+$/)]], + booleanValue: [false] + }), + oldRelations: vm.fb.array([]), + relations: vm.fb.array([]) + }); + + getEntityInfo(); + + vm.cancel = function() { + vm.dialogRef.close(null); + }; + + vm.relations = function() { + return vm.editEntityFormGroup.get('relations'); + }; + + vm.oldRelations = function() { + return vm.editEntityFormGroup.get('oldRelations'); + }; + + vm.addRelation = function() { + vm.relations().push(vm.fb.group({ + relatedEntity: [null, [vm.validators.required]], + relationType: [null, [vm.validators.required]], + direction: [null, [vm.validators.required]] + })); + }; + + function addOldRelation() { + vm.oldRelations().push(vm.fb.group({ + relatedEntity: [{value: null, disabled: true}, [vm.validators.required]], + relationType: [{value: null, disabled: true}, [vm.validators.required]], + direction: [{value: null, disabled: true}, [vm.validators.required]] + })); + } + + vm.removeRelation = function(index) { + vm.relations().removeAt(index); + vm.relations().markAsDirty(); + }; + + vm.removeOldRelation = function(index) { + vm.oldRelations().removeAt(index); + vm.relationsToDelete.push(vm.oldRelationsData[index]); + vm.oldRelations().markAsDirty(); + }; + + vm.save = function() { + vm.editEntityFormGroup.markAsPristine(); + widgetContext.rxjs.forkJoin([ + saveAttributes(entityId), + saveRelations(entityId), + saveEntity() + ]).subscribe( + function () { + widgetContext.updateAliases(); + vm.dialogRef.close(null); + } + ); + }; + + function getEntityAttributes(attributes) { + for (var i = 0; i < attributes.length; i++) { + vm.attributes[attributes[i].key] = attributes[i].value; + } + } + + function getEntityRelations(relations) { + let relationsFrom = relations[0]; + let relationsTo = relations[1]; + for (let i=0; i < relationsFrom.length; i++) { + let relation = { + direction: 'FROM', + relationType: relationsFrom[i].type, + relatedEntity: relationsFrom[i].to + }; + vm.oldRelationsData.push(relation); + addOldRelation(); + } + for (let i=0; i < relationsTo.length; i++) { + let relation = { + direction: 'TO', + relationType: relationsTo[i].type, + relatedEntity: relationsTo[i].from + }; + vm.oldRelationsData.push(relation); + addOldRelation(); + } + } + + function getEntityInfo() { + widgetContext.rxjs.forkJoin([ + entityRelationService.findInfoByFrom(entityId), + entityRelationService.findInfoByTo(entityId), + attributeService.getEntityAttributes(entityId, 'SERVER_SCOPE'), + entityService.getEntity(entityId.entityType, entityId.id) + ]).subscribe( + function (data) { + getEntityRelations(data.slice(0,2)); + getEntityAttributes(data[2]); + vm.entity = data[3]; + vm.editEntityFormGroup.patchValue({ + entityName: vm.entity.name, + entityType: vm.entityType, + entityLabel: vm.entity.label, + type: vm.entity.type, + attributes: vm.attributes, + oldRelations: vm.oldRelationsData + }, {emitEvent: false}); + } + ); + } + + function saveEntity() { + const formValues = vm.editEntityFormGroup.value; + if (vm.entity.label !== formValues.entityLabel){ + vm.entity.label = formValues.entityLabel; + if (formValues.entityType == 'ASSET') { + return assetService.saveAsset(vm.entity); + } else if (formValues.entityType == 'DEVICE') { + return deviceService.saveDevice(vm.entity); + } + } + return widgetContext.rxjs.of([]); + } + + function saveAttributes(entityId) { + let attributes = vm.editEntityFormGroup.get('attributes').value; + let attributesArray = []; + for (let key in attributes) { + if (attributes[key] !== vm.attributes[key]) { + attributesArray.push({key: key, value: attributes[key]}); + } + } + if (attributesArray.length > 0) { + return attributeService.saveEntityAttributes(entityId, "SERVER_SCOPE", attributesArray); + } + return widgetContext.rxjs.of([]); + } + + function saveRelations(entityId) { + let relations = vm.editEntityFormGroup.get('relations').value; + let tasks = []; + for(let i=0; i < relations.length; i++) { + let relation = { + type: relations[i].relationType, + typeGroup: 'COMMON' + }; + if (relations[i].direction == 'FROM') { + relation.to = relations[i].relatedEntity; + relation.from = entityId; + } else { + relation.to = entityId; + relation.from = relations[i].relatedEntity; + } + tasks.push(entityRelationService.saveRelation(relation)); + } + for (let i=0; i < vm.relationsToDelete.length; i++) { + let relation = { + type: vm.relationsToDelete[i].relationType + }; + if (vm.relationsToDelete[i].direction == 'FROM') { + relation.to = vm.relationsToDelete[i].relatedEntity; + relation.from = entityId; + } else { + relation.to = entityId; + relation.from = vm.relationsToDelete[i].relatedEntity; + } + tasks.push(entityRelationService.deleteRelation(relation.from, relation.type, relation.to)); + } + if (tasks.length > 0) { + return widgetContext.rxjs.forkJoin(tasks); + } + return widgetContext.rxjs.of([]); + } +} + diff --git a/meshifyDrivers/.DS_Store b/meshifyDrivers/.DS_Store index ff2a3e1f52a81bc0b078f41447e9535e056b1598..5fc03d6265ebeaac0e49cdd1f4fa3ecc74558322 100644 GIT binary patch delta 181 zcmZoMXfc@J&nU1lU^g?Pz+@hl?L0~4#RW+@`AG~63_B(tVJ%dbsIE3MGS^WsGBc{x zQK+^wGSE>lF*d8M<>U}m*0&Cd&(6us%kP>T%O=m*J$WsQ93$i8Gc1cIZ(tGTDGM&j i%gN762O7pWc>$}$7B|}zL}llFFybgB{k&$ delta 109 zcmV-z0FwWNFoZCWPXP|GP`d*G4wDQ7x09U(2mt_-AO;qbyakPup9U3^fCfJSxs$*K zaVQykdowaKEFdvCIejc3doeLKIV>PIFgSgE2?!M