-
Notifications
You must be signed in to change notification settings - Fork 2
/
advanced_thingsboard_attribute_widget__ataw_.json
29 lines (29 loc) · 13.2 KB
/
advanced_thingsboard_attribute_widget__ataw_.json
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
26
27
28
29
{
"alias": "update_attributes2",
"name": "Advanced Thingsboard Attribute Widget (ATAW)",
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAACgCAAAAABslHx1AAAAAmJLR0QA/4ePzL8AAAWhSURBVHja7dv7b1NVHADw/T/fW/dk3SM6B3NTBkoGQ+kkBFeRiVHDL4jxARghZERmcEzqYBMqk+sCyTaUoQQhcwJFBUaZUBDHxmNjK+vWtbf30a/fc2/LY8JCNoy5zff7w93t6bnfnk/POe3N2WkaiojbOkxCmskwbB0mJU0wdF3TVJuGpum6oBDE0LWYEo1GIzYMarYS00iCaeRQlahuDTQbRlyPKipJCKIpEdsyTEpE0Qhi6LGJGNo6CKAbadQhIcPeECNEXUKQaBBtHsGogKipAFFNyIjdISMWJGJ/SIQhDGEIQxjCEIYwhCEMYchUcaHx5lRPDzRenFSiX3n85OM3cKjx3BOHPOemw7n8nQ8UtoDv7vqFf+Bf13RD66SSb+HUFI247qcVg96+xKN3s9UeaHqgguq/NWOI00WHP6D+URAV3nsMyMC28Ska8RGEEXNXJq/24mTITah9cpDDx3o9+yP04Kyn3SsgvoamSzjUAq4DiKF9O35JXHBlp/yTgAx7PadRkakn+uWrl+Uheuabr3qogtK2vTOxZnO75Qs67VwK3h45a4FsHO8IeILdrQTZdchzErFPvo7YcaS/Edw/JDLOHFKRlzMbKlVsd+QWOgmyGSpLHEfPlcKsCuwrzpkLG836vuysIidB/AXOMvgS589H3CINiC488lRhieTF8UXp8xzVpsTvfNol1cTfyIXSpjJHdplek+WEwDvpBMnLy4dm7IAjiHOqjpeAsxr9hWbGJwC5gfXQpj37/Fh8DfgU9zaM5q2whtZbzutY5/hL1HflDlC1VlxSHMQPM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MYQhDGMIQhjCEIQxhCEMYwhCGMIQh/0v8A7Y7NXI35bvdAAAAAElFTkSuQmCC",
"description": "Allows to send shared attribute update when user press the button.",
"descriptor": {
"type": "rpc",
"sizeX": 9,
"sizeY": 7,
"resources": [
{
"url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
},
{
"url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
},
{
"url": "https://cdn.jsdelivr.net/gh/SchweizerischeBundesbahnen/thingsboard-advanced-attribute-widget/src/class.inputfield.js",
"isModule": false
}
],
"templateHtml": "<div class=\"tb-rpc-button\" fxLayout=\"column\">\n <div fxFlex=\"20\" class=\"title-container\" fxLayout=\"row\"\n fxLayoutAlign=\"center center\" [fxShow]=\"showTitle\">\n <span class=\"button-title\">{{title}}</span>\n </div>\n <div fxFlex=\"{{showTitle ? 80 : 100}}\" [ngStyle]=\"{paddingTop: showTitle ? '5px': '10px'}\" style=\"align-items: normal;\"\n class=\"button-container\" fxLayout=\"column\" fxLayoutAlign=\"center center\" id=\"cstmWidgetContainer\">\n <div style=\"margin-top: -10px; overflow-y: auto\">\n <form id=\"cstmFrm1-{{ command }}\" style=\"margin-top: -2px;\"></form>\n </div>\n </div>\n <div class=\"error-container\" [ngStyle]=\"{'background': error?.length ? 'rgba(255,255,255,0.25)' : 'none'}\"\n fxLayout=\"row\" fxLayoutAlign=\"center center\">\n <span class=\"button-error\">{{ error }}</span>\n </div>\n</div>",
"templateCss": ".tb-rpc-button {\n width: 100%;\n height: 100%;\n}\n\nform {\n margin: 50px;\n}\n\n.tb-rpc-button .title-container {\n font-weight: 500;\n white-space: nowrap;\n margin: 10px 0;\n}\n\n.tb-rpc-button .button-container div{\n min-width: 80%\n}\n\n.tb-rpc-button .button-container .mat-button{\n width: 100%;\n margin: 0;\n}\n\n.tb-rpc-button .error-container {\n position: absolute;\n top: 2%;\n right: 0;\n left: 0;\n z-index: 4;\n height: 14px;\n}\n\n.tb-rpc-button .error-container .button-error {\n color: #ff3315;\n white-space: nowrap;\n}\n\n\n.tb-cstm-button-add {\n margin-left: 0px;\n padding: 2px 20px;\n width: 100%;\n margin-top: 10px;\n padding: 1px 16px;\n font-size: 12px;\n}\n\n\n.tb-cstm-row-container {\n padding-top: 10px;\n padding-bottom: 5px;\n border-bottom: 1px solid #dbdbdb;\n}\n\n@keyframes shake {\n 0% { transform: translate(1px, 1px) rotate(0deg); }\n 10% { transform: translate(-1px, -2px) rotate(-1deg); }\n 20% { transform: translate(-3px, 0px) rotate(1deg); }\n 30% { transform: translate(3px, 2px) rotate(0deg); }\n 40% { transform: translate(1px, -1px) rotate(1deg); }\n 50% { transform: translate(-1px, 2px) rotate(-1deg); }\n 60% { transform: translate(-3px, 1px) rotate(0deg); }\n 70% { transform: translate(3px, 1px) rotate(-1deg); }\n 80% { transform: translate(-1px, -1px) rotate(1deg); }\n 90% { transform: translate(1px, 2px) rotate(0deg); }\n 100% { transform: translate(1px, -2px) rotate(-1deg); }\n}\n\n.shake {\n animation: shake 0.3s;\n animation-iteration-count: infinite;\n}\n\n.button-container {\n font-size: 12px;\n}\n\n",
"controllerScript": "/*\n global self, $, classInputField\n*/\n\n\n\nself.onInit = function() {\n self.ctx.ngZone.run(function() {\n init();\n self.ctx.detectChanges();\n });\n};\n\nfunction init() {\n\n // load input fields from widget advanced settings JSON\n let cstmFields = self.ctx.settings.entityParameters;\n if (cstmFields && typeof cstmFields !== 'object') {\n cstmFields = JSON.parse(cstmFields);\n }\n\n // so angular can use it in html code\n self.ctx.$scope.command = self.ctx.settings.command;\n\n\n\n $(document).ready(function() {\n\n // parent DOM\n const frm = document.getElementById('cstmFrm1-' + self.ctx.settings.command);\n\n self.ctx.$scope.fields = [];\n\n // iterate input fields\n for (let i = 0; i < cstmFields.length; i++) {\n const field = cstmFields[i];\n\n // create new field and add to scope array under \"field\"\n let clField = new classInputField(frm, field, self);\n self.ctx.$scope.fields.push(clField);\n }\n\n frm.appendChild(document.createElement('br'));\n\n // send button\n let button = document.createElement('button');\n button.className = 'btn btn-primary';\n button.innerHTML = self.ctx.settings.buttonText;\n $(button).click(self.ctx.$scope.sendUpdate);\n frm.appendChild(button);\n self.ctx.$scope.btnSend = button;\n\n });\n\n\n // angular DOM elements\n self.ctx.$scope.showTitle = self.ctx.settings.title && self.ctx.settings.title.length ? true : false;\n self.ctx.$scope.title = self.ctx.settings.title;\n self.ctx.$scope.styleButton = self.ctx.settings.styleButton;\n\n\n if (self.ctx.settings.styleButton.isPrimary === false) {\n self.ctx.$scope.customStyle = {\n 'background-color': self.ctx.$scope.styleButton.bgColor,\n 'color': self.ctx.$scope.styleButton.textColor\n };\n }\n\n\n // gets called when button is pushed\n // saves attributes and triggers rule chain \"attributes updated\"\n // must be inside init() to access $scope\n self.ctx.$scope.sendUpdate = function(event) {\n\n\n let entityId = {\n entityType: \"DEVICE\",\n id: self.ctx.defaultSubscription.targetDeviceId\n };\n\n const entityAttributeType = self.ctx.settings.entityAttributeType;\n\n\n // holds all attributes that will be written to device\n let attributes = [];\n\n\n // take command from widget Settings\n attributes.push({\n key: 'command',\n value: self.ctx.settings.command\n });\n // loop input forms and get values\n self.ctx.$scope.fields.forEach(item => attributes.push(item.getValue()));\n\n\n const attributeService = self.ctx.$scope.$injector.get(self.ctx.servicesMap.get('attributeService'));\n // save attributes\n attributeService.saveEntityAttributes(entityId, entityAttributeType, attributes).subscribe(\n function success() {\n self.ctx.$scope.error = '';\n self.ctx.detectChanges();\n },\n function fail(rejection) {\n if (self.ctx.settings.showError) {\n self.ctx.$scope.error =\n rejection.status + \": \" +\n rejection.statusText;\n self.ctx.detectChanges();\n }\n }\n\n );\n\n // to prevent boostrap from sending formular for <button>\n event.preventDefault();\n };\n\n\n\n}\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"Settings\",\n \"properties\": {\n \"title\": {\n \"title\": \"Widget title\",\n \"type\": \"string\",\n \"default\": \"\"\n },\n \"buttonText\": {\n \"title\": \"Button label\",\n \"type\": \"string\",\n \"default\": \"Update device attribute\"\n },\n \"command\": {\n \"title\": \"Device Command\",\n \"type\": \"string\",\n \"default\": \"startMission\"\n },\n \"entityAttributeType\": {\n \"title\": \"Device attribute scope\",\n \"type\": \"string\",\n \"default\": \"SERVER_SCOPE\"\n },\n \"entityParameters\": {\n \"title\": \"Device attribute parameters\",\n \"type\": \"string\",\n \"default\": \"[\\n {\\n \\\"title\\\": \\\"Some Label:\\\",\\n \\\"key\\\": \\\"someKey\\\",\\n \\\"type\\\": \\\"text|range|checkbox\\\",\\n \\\"default\\\": \\\"someValue\\\",\\n \\\"multi\\\": false,\\n \\\"multitype\\\": \\\"array|none\\\",\\n \\\"pattern\\\":\\\"^[+-]?([0-9]+\\\\.?[0-9]*|\\\\.[0-9]+)$\\\"\\n }\\n]\"\n },\n \"styleButton\": {\n \"type\": \"object\",\n \"title\": \"Button Style\",\n \"properties\": {\n \"isRaised\": {\n \"type\": \"boolean\",\n \"title\": \"Raised\",\n \"default\": true\n },\n \"isPrimary\": {\n \"type\": \"boolean\",\n \"title\": \"Primary color\",\n \"default\": false\n },\n \"bgColor\": {\n \"type\": \"string\",\n \"title\": \"Button background color\",\n \"default\": null\n },\n \"textColor\": {\n \"type\": \"string\",\n \"title\": \"Button text color\",\n \"default\": null\n }\n }\n },\n \"required\": []\n }\n },\n \"form\": [\n \"title\",\n \"buttonText\",\n \"command\",\n {\n \"key\": \"entityAttributeType\",\n \"type\": \"rc-select\",\n \"multiple\": false,\n \"items\": [{\n \"value\": \"SERVER_SCOPE\",\n \"label\": \"Server attribute\"\n }, {\n \"value\": \"SHARED_SCOPE\",\n \"label\": \"Shared attribute\"\n }]\n }, {\n \"key\": \"entityParameters\",\n \"type\": \"json\"\n },\n {\n \"key\": \"styleButton\",\n \"items\": [\n \"styleButton.isRaised\",\n \"styleButton.isPrimary\",\n {\n \"key\": \"styleButton.bgColor\",\n \"type\": \"color\"\n },\n {\n \"key\": \"styleButton.textColor\",\n \"type\": \"color\"\n }\n ]\n }\n ]\n\n}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"showTitle\":false,\"backgroundColor\":\"#e6e7e8\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"0px\",\"settings\":{\"styleButton\":{\"isRaised\":true,\"isPrimary\":false},\"entityParameters\":\"{}\",\"entityAttributeType\":\"SERVER_SCOPE\",\"buttonText\":\"Update device attribute\"},\"title\":\"Advanced Thingsboard Attribute Widget (ATAW)\",\"dropShadow\":true,\"enableFullscreen\":false,\"widgetStyle\":{},\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400},\"useDashboardTimewindow\":true,\"showLegend\":false,\"actions\":{},\"targetDeviceAliases\":[]}"
}
}