-
Notifications
You must be signed in to change notification settings - Fork 72
/
switch_1.json
26 lines (26 loc) · 13.5 KB
/
switch_1.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
{
"alias": "switch_1",
"name": "Switch 1",
"descriptor": {
"type": "rpc",
"sizeX": 9,
"sizeY": 7.5,
"resources": [
{
"url": "//sre-solutions.com/static/tb-widget/on-off-switch.css"
},
{
"url": "//sre-solutions.com/static/tb-widget/on-off-switch.js"
},
{
"url": "//sre-solutions.com/static/tb-widget/on-off-switch-onload.js"
}
],
"templateHtml": "<div class=\"checkbox-container\">\r\n\r\n\r\n <input type=\"checkbox\" name=\"on-off-switch\" id=\"on-off-switch\" checked=\"\">\r\n</div>",
"templateCss": ".on-off-switch\n{\n \n top: 50%;\n transform:translate(-50%, -50%);\n \n position: absolute;\n left: 50%;\n \n}",
"controllerScript": "var namespace;\nvar cssParser = new cssjs();\nvar dg;\n\nself.onInit = function() {\n\n\n\n console.log(self.ctx);\n var settings = self.ctx.settings;\n dg = new DG.OnOffSwitch({\n el: $('#on-off-switch', self.ctx.$container),\n height: settings.height || 150,\n trackColorOn:settings.backgroundcolorOn || \"#F57C00\",\n trackColorOff:settings.backgroundcolorOff || \"#666\",\n trackBorderColor:'#555',\n textColorOff:settings.textColorOff || \"#fff\",\n textColorOn:settings.textColorOn || \"#fff\",\n textOn:settings.textOn || \"ON\",\n textOff:settings.textOff || \"OFF\",\n listener:function(name, checked){\n\n \n\n var method = settings.changeRequestMethod || 'setValue';\n var paramsBody = convertStatus(checked);\n \n \n self.ctx.controlApi.sendOneWayCommand(method, \n paramsBody, settings.requestTimeout)\n }\n\n \n \n \n });\n \n \n\n \n //Set Value Mathod\n var convertStatusChangeMethod = settings.convertStatusChangeMethod || \"return value;\";\n \n var convertStatus = new Function(\"value\", convertStatusChangeMethod);\n\n //Get Value Method\n var convertGetValueMethod = settings.convertStatusRequestMethod || \"return data ? true : false;\";\n \n var convertGetValue = new Function(\"data\", convertGetValueMethod);\n \n function requestStatus() {\n \n method = settings.statusRequestMethod;\n paramsBody = \"\";\n self.ctx.controlApi.sendTwoWayCommand(method, \n paramsBody, \n settings.requestTimeout)\n .subscribe(\n function success(responseBody) {\n \n let value = (convertGetValue(responseBody)); \n dg.listener = undefined;\n if (value)\n {\n //$('#on-off-switch', self.ctx.$container).checked = true;\n //$('#on-off-switch', self.ctx.$container).value = true;\n dg.check();\n \n }\n else\n {\n dg.uncheck();\n //$('#on-off-switch', self.ctx.$container).checked = false;\n //$('#on-off-switch', self.ctx.$container).click();\n }\n dg.listener = function(name, checked){\n\n \n\n var method = settings.changeRequestMethod || 'setValue';\n var paramsBody = convertStatus(checked);\n \n \n self.ctx.controlApi.sendOneWayCommand(method, \n paramsBody, settings.requestTimeout)\n }\n }\n );\n \n }\n \nconsole.log(self.ctx.defaultSubscription);\n\nif ((settings.retrieveValueMethod == \"Subscribe for attribute\") || (settings.retrieveValueMethod == \"Subscribe for timeseries\"))\n{\nvar type = 'timeseries'\nif (settings.retrieveValueMethod == \"Subscribe for attribute\")\n type = 'attribute'\ndatasources = [\n { // datasource\n type: 'entity',// type of the datasource. Can be \"function\" or \"entity\"\n name: 'name', // name of the datasource (in case of \"entity\" usually Entity name)\n aliasName: self.ctx.defaultSubscription.targetDeviceName, // name of the alias used to resolve this particular datasource Entity\n entityName: self.ctx.defaultSubscription.targetDeviceName, // name of the Entity used as datasource\n entityType: 'DEVICE', // datasource Entity type (for ex. \"DEVICE\", \"ASSET\", \"TENANT\", etc.)\n entityId: self.ctx.defaultSubscription.targetDeviceId, // entity identificator presented as string uuid. \n dataKeys: [ // array of keys (Array<DataKey>) (attributes or timeseries) of the entity used to fetch data \n { // dataKey\n name: settings.updateValueKey, // the name of the particular entity attribute/timeseries \n type: type, // type of the dataKey. Can be \"timeseries\", \"attribute\" or \"function\" \n label: settings.updateValueKey, // label of the dataKey. Used as display value (for ex. in the widget legend section) \n color: '#ffffff', // color of the key. Can be used by widget to set color of the key data (for ex. lines in line chart or segments in the pie chart). \n funcBody: \"\", // only applicable for datasource with type \"function\" and \"function\" key type. Defines body of the function to generate simulated data.\n settings: {} // dataKey specific settings with structure according to the defined Data key settings json schema. See \"Settings schema section\".\n },\n //...\n ]\n },\n //...\n ]\n function subscribeForLabelPatternsSources(datasources) {\n const labelPatternsSourcesSubscriptionOptions = {\n datasources,\n useDashboardTimewindow: false,\n type: 'latest',\n callbacks: {\n onDataUpdated: (subscription) => {\n console.log(subscription.data[0].data[0][1]);\n let data = subscription.data[0].data[0][1];\n \n dg.listener = undefined;\n let value = (convertGetValue(data)); \n \n if (value === true)\n {\n console.log (\"check\");\n dg.check()\n \n }\n else\n {\n dg.uncheck();\n console.log (\"uncheck\");\n \n }\n \n dg.listener = function(name, checked){\n\n \n\n var method = settings.changeRequestMethod || 'setValue';\n var paramsBody = convertStatus(checked);\n \n \n self.ctx.controlApi.sendOneWayCommand(method, \n paramsBody, settings.requestTimeout)\n }\n }\n }\n };\n \n self.ctx.subscriptionApi.createSubscription(labelPatternsSourcesSubscriptionOptions, true).subscribe(\n (subscription) => {\n //this.labelPatternsSourcesSubscription = subscription;\n }\n );\n }\nsubscribeForLabelPatternsSources(datasources);\n}\n\n if (settings.retrieveValueMethod == 'Call RPC get value method')\n {\n requestStatus()\n }\n self.onResize();\n}\n \n\n\n\nself.onResize = function() {\n\n $('.on-off-switch', self.ctx.$container)[0].style.zoom = self.ctx.width/500;\n\n\n if (parseInt($('.on-off-switch', self.ctx.$container)[0].style.height) > self.ctx.height)\n $('.on-off-switch', self.ctx.$container)[0].style.zoom = self.ctx.height/180;\n \n // $('#on-off-switch', self.ctx.$container)[0].style.marginLeft = self.ctx.width - $('.checkbox-container', self.ctx.$container)[0].offsetWidth + \"px\";\n \n}\n\nself.onDestroy = function() {\n}\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"Settings\",\n \"properties\": {\n \"retrieveValueMethod\":\n {\n \"title\": \"Retrieve on/off value using method\",\n \"type\": \"string\",\n \"enum\": [\n \"Don't retrieve\",\n \"Call RPC get value method\",\n \"Subscribe for attribute\",\n \"Subscribe for timeseries\"],\n \"default\": \"Call RPC get value method\"\n },\n \"updateValueKey\": {\n \"title\": \"Attribute/Timeseries value key (only when subscribe for attribute/timeseries method)\",\n \"type\": \"string\",\n \"default\": \"value\"\n },\n \"requestTimeout\": {\n \"title\": \"RPC request timeout\",\n \"type\": \"number\",\n \"default\": 500\n },\n \"changeRequestMethod\": {\n \"title\": \"RPC set value method\",\n \"type\": \"string\",\n \"default\": \"setValue\"\n },\n \"statusRequestMethod\": {\n \"title\": \"RPC get value method\",\n \"type\": \"string\",\n \"default\": \"getValue\"\n },\n \"backgroundcolorOn\": {\n \"title\": \"Background Color On\",\n \"type\": \"string\",\n \"default\": \"#F57C00\"\n },\n \"backgroundcolorOff\": {\n \"title\": \"Background Color Off\",\n \"type\": \"string\",\n \"default\": \"#666\"\n },\n \"textColorOn\": {\n \"title\": \"Text Color On\",\n \"type\": \"string\",\n \"default\": \"#fff\"\n },\n \"textColorOff\": {\n \"title\": \"Text Color Off\",\n \"type\": \"string\",\n \"default\": \"#fff\"\n },\n \"height\": {\n \"title\": \"Height in px\",\n \"type\": \"number\",\n \"default\": 150\n },\n \"textOn\": {\n \"title\": \"Text ON\",\n \"type\": \"string\",\n \"default\": \"ON\"\n },\n \"textOff\": {\n \"title\": \"Text OFF\",\n \"type\": \"string\",\n \"default\": \"OFF\"\n },\n \"convertStatusChangeMethod\": {\n \"title\": \"Convert value function, f(value), returns payload used by RPC set value method\",\n \"type\": \"string\",\n \"default\": \"return value;\"\n },\n \"convertStatusRequestMethod\": {\n \"title\": \"Parse value function, f(data), returns boolean\",\n \"type\": \"string\",\n \"default\": \"return data ? true : false;\"\n } \n \n },\n \"required\": [ \n \"retrieveValueMethod\",\n \"statusRequestMethod\",\n \"changeRequestMethod\",\n \"convertStatusRequestMethod\",\n \"convertStatusChangeMethod\",\n \"requestTimeout\",\n \"backgroundcolorOn\",\n \"backgroundcolorOff\",\n \"textColorOn\",\n \"textColorOff\",\n \"height\",\n \"textOn\",\n \"textOn\"]\n },\n \"form\": [\n \"retrieveValueMethod\",\n \"updateValueKey\",\n \"statusRequestMethod\",\n \"changeRequestMethod\",\n {\n \"key\": \"convertStatusRequestMethod\",\n \"type\": \"javascript\"\n },\n {\n \"key\": \"convertStatusChangeMethod\",\n \"type\": \"javascript\"\n },\n \"requestTimeout\",\n {\n \"key\": \"backgroundcolorOn\",\n \"type\": \"color\"\n },{\n \"key\": \"backgroundcolorOff\",\n \"type\": \"color\"\n },{\n \"key\": \"textColorOn\",\n \"type\": \"color\"\n },{\n \"key\": \"textColorOff\",\n \"type\": \"color\"\n },\n \"height\",\n \"textOn\",\n \"textOff\"\n ]\n \n \n}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"targetDeviceAliases\":[],\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"0px\",\"settings\":{\"parseGpioStatusFunction\":\"return body[pin] === true;\",\"gpioStatusChangeRequest\":{\"method\":\"setGpioStatus\",\"paramsBody\":\"{\\n \\\"pin\\\": \\\"{$pin}\\\",\\n \\\"enabled\\\": \\\"{$enabled}\\\"\\n}\"},\"requestTimeout\":500,\"switchPanelBackgroundColor\":\"#b71c1c\",\"gpioStatusRequest\":{\"method\":\"getGpioStatus\",\"paramsBody\":\"{}\"},\"gpioList\":[{\"pin\":1,\"label\":\"GPIO 1\",\"row\":0,\"col\":0,\"_uniqueKey\":0},{\"pin\":2,\"label\":\"GPIO 2\",\"row\":0,\"col\":1,\"_uniqueKey\":1},{\"pin\":3,\"label\":\"GPIO 3\",\"row\":1,\"col\":0,\"_uniqueKey\":2}]},\"title\":\"Switch 1\"}"
}
}