-
Notifications
You must be signed in to change notification settings - Fork 72
/
change_dashboard_state.json
18 lines (18 loc) · 5.67 KB
/
change_dashboard_state.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"alias": "static",
"name": "Change Dashboard State",
"descriptor": {
"type": "static",
"sizeX": 7.5,
"sizeY": 2.5,
"resources": [],
"templateHtml": "<div id=\"changeDashboardState\">\n<span id=\"dashboardStateLabel\">Change Dashboard State</span>\n<select id=\"dashboardState\" name=\"dashboardState\">\n \n </select>\n </div>",
"templateCss": "#changeDashboardState {\n\nwidth: 100%;\n top: 50%;\n text-align: center;\n position: absolute;\n}\n\n#dashboardState\n{\n margin-left: 5px;\n}",
"controllerScript": "self.onInit = function() {\n \n var settings = self.ctx.settings;\n //set Font size of select\n $('#dashboardState', self.ctx.$container)[0].style.fontSize = settings.fontSize + \"px\";\n //set Font size of label\n $('#dashboardStateLabel', self.ctx.$container)[0].style.fontSize = settings.fontSize + \"px\";\n \n //set Font color of Select\n $('#dashboardState', self.ctx.$container)[0].style.color = settings.fontColor;\n //set Font color of Label\n $('#dashboardStateLabel', self.ctx.$container)[0].style.color = settings.fontColor;\n \n //set Label Text according to settings\n $('#dashboardStateLabel', self.ctx.$container)[0].innerHTML = settings.labelText;\n \n \n //Add Options to the Select\n for (var i = 0; i < settings.dashboardStateList.length; i++)\n {\n $('#dashboardState', self.ctx.$container).append($('<option>', {\n text: settings.dashboardStateList[i].listEntry\n }));\n }\n \n \n //Select changed\n $('#dashboardState', self.ctx.$container).change(function() {\n var listEntry = ('#dashboardState', self.ctx.$container).find(\":selected\").text()\n console.log(\"list Entry:\" + listEntry)\n \n //Get Alias for the given name\n var alias = settings.dashboardStateList[0].dashboardAlias;\n for (var i = 0; i < settings.dashboardStateList.length; i++)\n {\n if (settings.dashboardStateList[i].listEntry == listEntry)\n {\n alias = settings.dashboardStateList[i].dashboardAlias;\n break;\n }\n }\n \n var selection = alias;\n\n var stateController = self.ctx.stateController;\n var stateID = stateController.getStateId();\n var params = stateController.getStateParams();\n\n var entityId = (getEntityID(selection));\n \n params.entityName = selection;\n params.entityId.id = entityId;\n \n \nstateController.resetState();\n stateController.updateState(stateID=stateID, params=params, true);\n \n \n});\n\n\nfunction getEntityID (alias)\n{\n var aliases = self.ctx.dashboard.aliasController.entityAliases;\n for (let element in aliases)\n {\n \n if (aliases[element].alias == alias)\n return aliases[element].filter.singleEntity.id;\n }\n \n}\n \n\n}\n\nself.actionSources = function() {\n return {\n 'elementClick': {\n name: 'widget-action.element-click',\n multiple: true\n }\n };\n}\n\nself.onDestroy = function() {\n}\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"Settings\",\n \"properties\": {\n \n \"fontSize\": {\n \"title\": \"Font size\",\n \"type\": \"number\",\n \"default\": 16\n },\n \"fontColor\": {\n \"title\": \"Font color\",\n \"type\": \"string\",\n \"default\": \"#008a00\"\n },\n \"labelText\": {\n \"title\": \"Label Text\",\n \"type\": \"string\",\n \"default\": \"Change Dashboard State\"\n },\n \"dashboardStateList\": {\n \"title\": \"Dashboard State list\",\n \"type\": \"array\",\n \"minItems\" : 1,\n \"items\": {\n \"title\": \"Dashboard State\",\n \"type\": \"object\",\n \"properties\": {\n \"dashboardAlias\": {\n \"title\": \"Dashboard Alias\",\n \"type\": \"string\"\n },\n \"listEntry\": {\n \"title\": \"List Entry\",\n \"type\": \"string\"\n }\n },\n \"required\": [\"dashboardAlias\", \"listEntry\"]\n }\n }\n },\n \"required\": [\"dashboardStateList\"]\n },\n \"form\": [\n \"fontSize\",\n \"fontColor\",\n \"labelText\",\n \"dashboardStateList\"\n ]\n}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"datasources\":[{\"type\":\"static\",\"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\":false,\"backgroundColor\":\"rgb(255, 255, 255)\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"dashboardStateList\":[{\"name\":\"test\",\"dashboardAlias\":\"CAG1D1\",\"listEntry\":\"Device 1\"}],\"fontSize\":16,\"fontColor\":\"#008a00\",\"labelText\":\"Change Dashboard State\"},\"title\":\"Change Dashboard State\",\"dropShadow\":true}"
},
"image": null,
"description": null
}