Repository navigation
Expand file tree
/
Copy pathota_widgets.json
More file actions
25 lines (25 loc) · 6.27 KB
/
Copy pathota_widgets.json
File metadata and controls
25 lines (25 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"widgetsBundle": {
"alias": "ota_for_esp32_widget22",
"title": "OTA widgets",
"image": null
},
"widgetTypes": [
{
"alias": "esp32",
"name": "ESP32_OTA_widget",
"descriptor": {
"type": "latest",
"sizeX": 7,
"sizeY": 4,
"resources": [],
"templateHtml": "<form class=\"ota-config-form\"\r\n name=\"esp32OtaUpdateConfigForm\"\r\n ng-submit=\"updateOtaConfig()\">\r\n <div style=\"margin: 15px 0;\">\r\n <div class=\"shared-attr-container\">\r\n <md-input-container ng-class=\"{'show-label': settings.showLabel}\" class=\"attr-input\">\r\n <label>Target firmware version</label>\r\n <input name=\"targetFwVer\"\r\n ng-model=\"targetFwVer\">\r\n </md-input-container>\r\n <md-input-container ng-class=\"{'show-label': settings.showLabel}\" class=\"attr-input\">\r\n <label>Firmware server URL</label>\r\n <input name=\"targetFwUrl\"\r\n ng-model=\"targetFwUrl\">\r\n </md-input-container>\r\n </div>\r\n\r\n <div class=\"start-ota\">\r\n <md-button type=\"submit\"\r\n class=\"md-primary md-raised\"\r\n ng-disabled=\"!targetFwUrl || !targetFwVer\">\r\n <span style=\"font-size: 13px;\">Start OTA</span>\r\n </md-button>\r\n </div>\r\n </div>\r\n</form>",
"templateCss": ".ota-config-form {\r\n overflow: hidden; \r\n height: 100%;\r\n display: flex;\r\n flex-direction: column;\r\n}\r\n\r\n.shared-attr-container {\r\n margin-top: 20px;\r\n display: flex;\r\n flex-direction: column;\r\n}\r\n\r\n.attr-input {\r\n font-size: 13px;\r\n margin: 0 15px;\r\n}\r\n\r\ninput {\r\n font-size: 13px;\r\n}\r\n\r\n.start-ota {\r\n font-size: 13px;\r\n margin: 0 15px;\r\n display: flex;\r\n justify-content: flex-start;\r\n}\r\n\r\nmd-toast{\r\n min-width: 0;\r\n}\r\nmd-toast .md-toast-content {\r\n font-size: 13px!important;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"controllerScript": "let attributeService;\nlet toast;\nlet types;\nlet utils;\nlet settings;\nlet datasource;\nlet subscription;\n\nself.onInit = function () {\n $scope = self.ctx.$scope;\n toast = $scope.$injector.get('toast');\n types = $scope.$injector.get('types');\n utils = $scope.$injector.get('utils');\n settings = angular.copy(self.ctx.settings) || {};\n datasource = self.ctx.datasources[0];\n subscription = self.ctx.defaultSubscription;\n $scope.settings = settings;\n \n attributeService = $scope.$injector.get('attributeService');\n $scope.updateOtaConfig = updateOtaConfig;\n\n $scope.activeVal = false;\n $scope.fwStateVal = undefined;\n $scope.currentFwVal = undefined;\n $scope.lastTargetFwVer = undefined;\n $scope.lastTargetFwUrl = undefined;\n $scope.lastOtaStartedOn = undefined;\n};\n\nself.onDataUpdated = function () {\n for (let i=0;i<subscription.data.length;i++) {\n let attributeValue = subscription.data[i].data[0][1];\n let dataKey = subscription.data[i].dataKey.name;\n console.log(`${dataKey} : ${attributeValue}`);\n if (dataKey === 'active') {\n $scope.activeVal = (attributeValue === 'true');\n }\n }\n};\n\nself.onResize = function () {\n};\n\nself.onDestroy = function () {\n};\n\nfunction updateOtaConfig() {\n $scope.lastTargetFwVer = $scope.targetFwVer;\n $scope.lastTargetFwUrl = $scope.targetFwUrl;\n saveShareAttributes();\n saveServerAttributes();\n}\n\nfunction saveShareAttributes() {\n attributeService.saveEntityAttributes(\n datasource.entityType,\n datasource.entityId,\n types.attributesScope.shared.value,\n [\n {\n key: \"targetFwVer\",\n value: $scope.targetFwVer\n },\n {\n key: \"targetFwUrl\",\n value: $scope.targetFwUrl\n }\n ]\n ).then(\n function success() {\n $scope.targetFwVer = undefined;\n $scope.targetFwUrl = undefined;\n\n if ($scope.activeVal) {\n toast.showSuccess('OTA configuration saved', 2000, angular.element(self.ctx.$container), 'bottom right');\n } else {\n toast.showError('OTA configuration saved,\\nbut will be sent when device become connected', angular.element(self.ctx.$container), 'bottom right');\n }\n },\n function fail() {\n console.log();\n toast.showError('OTA configuration can not be saved', angular.element(self.ctx.$container), 'bottom right');\n }\n );\n}\n\nfunction saveServerAttributes() {\n $scope.lastOtaStartedOn = Date.now();\n \n attributeService.saveEntityAttributes(\n datasource.entityType,\n datasource.entityId,\n types.attributesScope.server.value,\n [\n {\n key: \"lastTargetFwVer\",\n value: $scope.lastTargetFwVer\n },\n {\n key: \"lastTargetFwUrl\",\n value: $scope.lastTargetFwUrl\n },\n {\n key: \"lastOtaStartedOn\",\n value: $scope.lastOtaStartedOn\n }\n ]\n );\n}\n\nself.typeParameters = function () {\n return {\n dataKeysOptional: true,\n maxDatasources: 1\n };\n};\n",
"settingsSchema": "{}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Random\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.15479322438769105,\"funcBody\":\"var value = prevValue + Math.random() * 100 - 50;\\nvar multiplier = Math.pow(10, 2 || 0);\\nvar value = Math.round(value * multiplier) / multiplier;\\nif (value < -1000) {\\n\\tvalue = -1000;\\n} else if (value > 1000) {\\n\\tvalue = 1000;\\n}\\nreturn value;\"}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{},\"title\":\"ESP32_OTA_widget\"}"
}
}
]
}