Thingsboard源码分析-用户表设计 - 图1

tenant

属性

字段 类型 描述
id varchar(31) 租户编号
created_time bigint 创建时间
additional_info varchar 额外信息
address varchar 第一地址
address2 varchar(255) 第二地址
city varchar(255) 城市
country varchar(255) 国家
email varchar(255) 邮箱
phone varchar(255) 电话号码
region varchar(255) 区域
search_text varchar(255) 搜索关键字
state varchar(255) 省份
title varchar(255) 租户名称
zip varchar(255) 邮政编码
isolated_tb_core boolean 单独tb容器服务
isolated_tb_rule_engine boolean 单独tb规则引擎服务

数据

id created_time additional_info address address2 city country email phone region search_text state title zip isolated_tb_core isolated_tb_rule_engine
e102f1b0-fcb8-11ea-82f8-9b35f0369853 1600768156747 {“description”:”测试租户相关的数据库字段”} 杭州西湖区 杭州余杭区 HangZhou China lovewsic@gmail.com 18036142209 Global 租户测试 ZheJiang 租户测试 310000 true true

DDL

  1. CREATE TABLE IF NOT EXISTS tenant (
  2. id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. additional_info varchar,
  5. address varchar,
  6. address2 varchar,
  7. city varchar(255),
  8. country varchar(255),
  9. email varchar(255),
  10. phone varchar(255),
  11. region varchar(255),
  12. search_text varchar(255),
  13. state varchar(255),
  14. title varchar(255),
  15. zip varchar(255),
  16. isolated_tb_core boolean,
  17. isolated_tb_rule_engine boolean
  18. );Copy to clipboardErrorCopied

页面显示

Thingsboard源码分析-用户表设计 - 图2

customer

属性

字段 类型 描述
id uuid 客户编号
created_time bigint 创建时间
additional_info varchar 额外信息
address varchar 第一地址
address2 varchar 第二地址
city varchar(255) 城市
country varchar(255) 国家
email varchar(255) 邮箱
phone varchar(255) 电话号码
search_text varchar(255) 搜索关键字
state varchar(255) 省份
tenant_id uuid 租户编号
title varchar(255) 客户名称
zip varchar(255) 邮政编码

数据

id created_time additional_info address address2 city country email phone search_text state tenant_id title zip
49b23e10-fd3a-11ea-bd9b-65a3fbb30788 1600823737457 {“description”:”Customer A”} 杭州西湖区 杭州余杭区 HangZhou China 18036142209 租户测试-customer a 浙江 e102f1b0-fcb8-11ea-82f8-9b35f0369853 租户测试-Customer A 310000

DDL

  1. CREATE TABLE IF NOT EXISTS customer (
  2. id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. additional_info varchar,
  5. address varchar,
  6. address2 varchar,
  7. city varchar(255),
  8. country varchar(255),
  9. email varchar(255),
  10. phone varchar(255),
  11. search_text varchar(255),
  12. state varchar(255),
  13. tenant_id uuid,
  14. title varchar(255),
  15. zip varchar(255)
  16. );Copy to clipboardErrorCopied

页面显示

Thingsboard源码分析-用户表设计 - 图3

tb_user

属性

字段 类型 描述
id uuid 用户编号
created_time bigint 创建时间
additional_info varchar 额外信息
authority varchar(255) 权限
customer_id uuid 客户编号
email varchar(255) 邮箱
first_name varchar(255)
last_name varchar(255)
search_text varchar(255) 搜索关键字
tenant_id uuid 租户编号

数据

id created_time additional_info authority customer_id email first_name last_name search_text tenant_id
d96bfe60-e881-11ea-a452-0bb049e7ba49 1598545498438 {“userPasswordHistory”:{“1598545498857”:”$2a$10$DGTJezh/ctB/NYK0JrxhyuFe7IxnCLlnb6x8/mezr8wFU5WT.vvyK”},”lastLoginTs”:1600823576876,”failedLoginAttempts”:0} SYS_ADMIN 13814000-1dd2-11b2-8080-808080808080 sysadmin@thingsboard.org sysadmin@thingsboard.org 13814000-1dd2-11b2-8080-808080808080
bfd211c0-fd39-11ea-bd9b-65a3fbb30788 1600823506140 {“description”:”admin manager”,”defaultDashboardId”:null,”defaultDashboardFullscreen”:false,”userPasswordHistory”:{“1600823540675”:”$2a$10$FgfcK3tItxsyxLjd1uiAze0smb4srCbf4Kbx6EIXez16F/GOMqsSq”},”lastLoginTs”:1600823673157,”failedLoginAttempts”:0} TENANT_ADMIN 13814000-1dd2-11b2-8080-808080808080 lovewsic@gmail.com 书伟 lovewsic@gmail.com e102f1b0-fcb8-11ea-82f8-9b35f0369853

DDL

  1. CREATE TABLE IF NOT EXISTS tb_user (
  2. id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. additional_info varchar,
  5. authority varchar(255),
  6. customer_id uuid,
  7. email varchar(255) UNIQUE,
  8. first_name varchar(255),
  9. last_name varchar(255),
  10. search_text varchar(255),
  11. tenant_id uuid
  12. );Copy to clipboardErrorCopied

页面显示

Thingsboard源码分析-用户表设计 - 图4

user_credentials

属性

字段 类型 描述
id uuid 用户认证编号
created_time bigint 创建时间
activate_token varchar(255) 激活令牌
enabled boolean 是否开启
password varchar(255) 密码
reset_token varchar(255) 重置令牌
user_id uuid 用户编号

数据

id created_time activate_token enabled password reset_token user_id
d9924b10-e881-11ea-a452-0bb049e7ba49 1598545498689 true $2a$10$DGTJezh/ctB/NYK0JrxhyuFe7IxnCLlnb6x8/mezr8wFU5WT.vvyK d96bfe60-e881-11ea-a452-0bb049e7ba49
bfe0b7c0-fd39-11ea-bd9b-65a3fbb30788 1600823506236 true $2a$10$FgfcK3tItxsyxLjd1uiAze0smb4srCbf4Kbx6EIXez16F/GOMqsSq bfd211c0-fd39-11ea-bd9b-65a3fbb30788

DDL

  1. CREATE TABLE IF NOT EXISTS user_credentials (
  2. id uuid NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. activate_token varchar(255) UNIQUE,
  5. enabled boolean,
  6. password varchar(255),
  7. reset_token varchar(255) UNIQUE,
  8. user_id uuid UNIQUE
  9. );Copy to clipboardErrorCopied

admin_settings

属性

字段 类型 描述
id uuid 系统设置编号
created_time bigint 创建时间
json_value varchar 系统设置JSON字符串
key varchar(255) 设置关键字

数据

id created_time json_value key
d9af48f0-e881-11ea-a452-0bb049e7ba49 1598545498879 {“baseUrl”:”http://localhost:8080”} general
d9b25630-e881-11ea-a452-0bb049e7ba49 1598545498899 {“mailFrom”:”ThingsBoard sysadmin@localhost.localdomain“,”smtpProtocol”:”smtp”,”smtpHost”:”localhost”,”smtpPort”:”25”,”timeout”:”10000”,”enableTls”:false,”username”:””,”password”:””,”tlsVersion”:”TLSv1.2”,”enableProxy”:false} mail

DDL

  1. CREATE TABLE IF NOT EXISTS admin_settings (
  2. id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. json_value varchar,
  5. key varchar(255)
  6. );Copy to clipboardErrorCopied

数据显示

Thingsboard源码分析-用户表设计 - 图5

tb_schema_settings

属性

字段 类型 描述
schema_version bigint 数据模式版本

数据

schema_version
3001000

DDL

  1. CREATE TABLE IF NOT EXISTS tb_schema_settings
  2. (
  3. schema_version bigint NOT NULL,
  4. CONSTRAINT tb_schema_settings_pkey PRIMARY KEY (schema_version)
  5. );Copy to clipboardErrorCopied

widget_type

属性

字段 类型 描述
id
created_time
alias
bundle_alias
descriptor
name
tenant_id

数据

id created_time alias bundle_alias descriptor name tenant_id
da4631c0-e881-11ea-a452-0bb049e7ba49 1598545499868 raspberry_pi_gpio_panel gpio_widgets {“type”:”latest”,”sizeX”:7,”sizeY”:10.5,”resources”:[],”templateHtml”:”
\n
\n
\n
\n {{ cell.label }}\n
\n {{cell.pin}}\n \n \n \n \n {{cell.pin}}\n \n {{ cell.label }}\n \n
\n \n \n \n \n \n \n”,”templateCss”:”.error {\n font-size: 14px !important;\n color: maroon;/rgb(250,250,250);/\n background-color: transparent;\n padding: 6px;\n}\n\n.error span {\n margin: auto;\n}\n\n.gpio-panel {\n padding-top: 10px;\n white-space: nowrap;\n}\n\n.gpio-panel section[fxflex] {\n min-width: 0px;\n}\n\n.gpio-panel tb-led-light > div {\n margin: auto;\n}\n\n.led-panel {\n margin: 0;\n width: 66px;\n min-width: 66px;\n}\n\n.led-container {\n width: 48px;\n min-width: 48px;\n}\n\n.pin {\n margin-top: auto;\n margin-bottom: auto;\n color: white;\n font-size: 12px;\n width: 16px;\n min-width: 16px;\n}\n\n.led-panel.col-0 .pin {\n margin-left: auto;\n padding-left: 2px;\n text-align: right;\n}\n\n.led-panel.col-1 .pin {\n margin-right: auto;\n \n text-align: left;\n}\n\n.gpio-left-label {\n margin-right: 8px;\n}\n\n.gpio-right-label {\n margin-left: 8px;\n}”,”controllerScript”:”var namespace;\nvar cssParser = new cssjs();\n\nself.onInit = function() {\n var utils = self.ctx.$injector.get(self.ctx.servicesMap.get(‘utils’));\n namespace = ‘gpio-panel-‘ + utils.guid();\n cssParser.testMode = false;\n cssParser.cssPreviewNamespace = namespace;\n self.ctx.$container.addClass(namespace);\n self.ctx.ngZone.run(function() {\n init(); \n });\n}\n\nfunction init() {\n var i, gpio;\n \n var scope = self.ctx.$scope;\n var settings = self.ctx.settings;\n \n scope.gpioList = [];\n scope.gpioByPin = {};\n for (var g = 0; g < settings.gpioList.length; g++) {\n gpio = settings.gpioList[g];\n scope.gpioList.push(\n {\n row: gpio.row,\n col: gpio.col,\n pin: gpio.pin,\n label: gpio.label,\n enabled: false,\n colorOn: tinycolor(gpio.color).lighten(20).toHexString(),\n colorOff: tinycolor(gpio.color).darken().toHexString()\n }\n );\n scope.gpioByPin[gpio.pin] = scope.gpioList[scope.gpioList.length-1];\n }\n\n scope.ledPanelBackgroundColor = settings.ledPanelBackgroundColor || tinycolor(‘green’).lighten(2).toRgbString();\n\n scope.gpioCells = {};\n var rowCount = 0;\n for (i = 0; i < scope.gpioList.length; i++) {\n gpio = scope.gpioList[i];\n scope.gpioCells[gpio.row+’‘+gpio.col] = gpio;\n rowCount = Math.max(rowCount, gpio.row+1);\n }\n \n scope.prefferedRowHeight = 32;\n scope.rows = [];\n for (i = 0; i < rowCount; i++) {\n var row = [];\n for (var c =0; c<2;c++) {\n if (scope.gpioCells[i+’‘+c]) {\n row[c] = scope.gpioCells[i+’_’+c];\n } else {\n row[c] = null;\n }\n }\n scope.rows.push(row);\n } \n \n self.onResize();\n}\n\nself.onDataUpdated = function() {\n var changed = false;\n for (var d = 0; d < self.ctx.data.length; d++) {\n var cellData = self.ctx.data[d];\n var dataKey = cellData.dataKey;\n var gpio = self.ctx.$scope.gpioByPin[dataKey.label];\n if (gpio) {\n var enabled = false;\n if (cellData.data.length > 0) {\n var tvPair = cellData.data[cellData.data.length - 1];\n enabled = (tvPair[1] === true || tvPair[1] === ‘true’);\n }\n if (gpio.enabled != enabled) {\n changed = true;\n gpio.enabled = enabled;\n }\n }\n }\n if (changed) {\n self.ctx.detectChanges();\n } \n}\n\nself.onResize = function() {\n var rowCount = self.ctx.$scope.rows.length;\n var prefferedRowHeight = (self.ctx.height - 35)/rowCount;\n prefferedRowHeight = Math.min(32, prefferedRowHeight);\n prefferedRowHeight = Math.max(12, prefferedRowHeight);\n self.ctx.$scope.prefferedRowHeight = prefferedRowHeight;\n \n var ratio = prefferedRowHeight/32;\n \n var css = ‘.gpio-left-label, .gpio-right-label {\n’ +\n ‘ font-size: ‘ + 16_ratio+’px;\n’+\n ‘}\n’;\n var pinsFontSize = Math.max(9, 12_ratio);\n css += ‘.pin {\n’ +\n ‘ font-size: ‘ + pinsFontSize+’px;\n’+\n ‘}\n’;\n \n cssParser.createStyleElement(namespace, css); \n \n self.ctx.detectChanges();\n}\n\nself.onDestroy = function() {\n}\n”,”settingsSchema”:”{\n “schema”: {\n “type”: “object”,\n “title”: “Settings”,\n “properties”: {\n “gpioList”: {\n “title”: “Gpio leds”,\n “type”: “array”,\n “minItems” : 1,\n “items”: {\n “title”: “Gpio led”,\n “type”: “object”,\n “properties”: {\n “pin”: {\n “title”: “Pin”,\n “type”: “number”\n },\n “label”: {\n “title”: “Label”,\n “type”: “string”\n },\n “row”: {\n “title”: “Row”,\n “type”: “number”\n },\n “col”: {\n “title”: “Column”,\n “type”: “number”\n },\n “color”: {\n “title”: “Color”,\n “type”: “string”,\n “default”: “red”\n }\n },\n “required”: [“pin”, “label”, “row”, “col”, “color”]\n }\n },\n “ledPanelBackgroundColor”: {\n “title”: “LED panel background color”,\n “type”: “string”,\n “default”: “#008a00”\n } \n },\n “required”: [“gpioList”, \n “ledPanelBackgroundColor”]\n },\n “form”: [\n {\n “key”: “gpioList”,\n “items”: [\n “gpioList[].pin”,\n “gpioList[].label”,\n “gpioList[].row”,\n “gpioList[].col”,\n {\n “key”: “gpioList[].color”,\n “type”: “color”\n }\n ]\n },\n {\n “key”: “ledPanelBackgroundColor”,\n “type”: “color”\n }\n ]\n}”,”dataKeySettingsSchema”:”{}\n”,”defaultConfig”:”{“showTitle”:true,”backgroundColor”:”#fff”,”color”:”rgba(0, 0, 0, 0.87)”,”padding”:”0px”,”settings”:{“gpioList”:[{“pin”:1,”label”:”3.3V”,”row”:0,”col”:0,”color”:”#fc9700”,”_uniqueKey”:0},{“pin”:2,”label”:”5V”,”row”:0,”col”:1,”color”:”#fb0000”,”_uniqueKey”:1},{“pin”:3,”label”:”GPIO 2 (I2C1_SDA)”,”row”:1,”col”:0,”color”:”#02fefb”,”_uniqueKey”:2},{“color”:”#fb0000”,”pin”:4,”label”:”5V”,”row”:1,”col”:1},{“color”:”#02fefb”,”pin”:5,”label”:”GPIO 3 (I2C1_SCL)”,”row”:2,”col”:0},{“color”:”#000000”,”pin”:6,”label”:”GND”,”row”:2,”col”:1},{“color”:”#00fd00”,”pin”:7,”label”:”GPIO 4 (GPCLK0)”,”row”:3,”col”:0},{“color”:”#fdfb00”,”pin”:8,”label”:”GPIO 14 (UART_TXD)”,”row”:3,”col”:1},{“color”:”#000000”,”pin”:9,”label”:”GND”,”row”:4,”col”:0},{“color”:”#fdfb00”,”pin”:10,”label”:”GPIO 15 (UART_RXD)”,”row”:4,”col”:1},{“color”:”#00fd00”,”pin”:11,”label”:”GPIO 17”,”row”:5,”col”:0},{“color”:”#00fd00”,”pin”:12,”label”:”GPIO 18”,”row”:5,”col”:1},{“color”:”#00fd00”,”pin”:13,”label”:”GPIO 27”,”row”:6,”col”:0},{“color”:”#000000”,”pin”:14,”label”:”GND”,”row”:6,”col”:1},{“color”:”#00fd00”,”pin”:15,”label”:”GPIO 22”,”row”:7,”col”:0},{“color”:”#00fd00”,”pin”:16,”label”:”GPIO 23”,”row”:7,”col”:1},{“color”:”#fc9700”,”pin”:17,”label”:”3.3V”,”row”:8,”col”:0},{“color”:”#00fd00”,”pin”:18,”label”:”GPIO 24”,”row”:8,”col”:1},{“color”:”#fd01fd”,”pin”:19,”label”:”GPIO 10 (SPI_MOSI)”,”row”:9,”col”:0},{“color”:”#000000”,”pin”:20,”label”:”GND”,”row”:9,”col”:1},{“color”:”#fd01fd”,”pin”:21,”label”:”GPIO 9 (SPI_MISO)”,”row”:10,”col”:0},{“color”:”#00fd00”,”pin”:22,”label”:”GPIO 25”,”row”:10,”col”:1},{“color”:”#fd01fd”,”pin”:23,”label”:”GPIO 11 (SPI_SCLK)”,”row”:11,”col”:0},{“color”:”#fd01fd”,”pin”:24,”label”:”GPIO 8 (SPI_CE0)”,”row”:11,”col”:1},{“color”:”#000000”,”pin”:25,”label”:”GND”,”row”:12,”col”:0},{“color”:”#fd01fd”,”pin”:26,”label”:”GPIO 7 (SPI_CE1)”,”row”:12,”col”:1},{“color”:”#ffffff”,”pin”:27,”label”:”ID_SD”,”row”:13,”col”:0},{“color”:”#ffffff”,”pin”:28,”label”:”ID_SC”,”row”:13,”col”:1},{“color”:”#00fd00”,”pin”:29,”label”:”GPIO 5”,”row”:14,”col”:0},{“color”:”#000000”,”pin”:30,”label”:”GND”,”row”:14,”col”:1},{“color”:”#00fd00”,”pin”:31,”label”:”GPIO 6”,”row”:15,”col”:0},{“color”:”#00fd00”,”pin”:32,”label”:”GPIO 12”,”row”:15,”col”:1},{“color”:”#00fd00”,”pin”:33,”label”:”GPIO 13”,”row”:16,”col”:0},{“color”:”#000000”,”pin”:34,”label”:”GND”,”row”:16,”col”:1},{“color”:”#00fd00”,”pin”:35,”label”:”GPIO 19”,”row”:17,”col”:0},{“color”:”#00fd00”,”pin”:36,”label”:”GPIO 16”,”row”:17,”col”:1},{“color”:”#00fd00”,”pin”:37,”label”:”GPIO 26”,”row”:18,”col”:0},{“color”:”#00fd00”,”pin”:38,”label”:”GPIO 20”,”row”:18,”col”:1},{“color”:”#000000”,”pin”:39,”label”:”GND”,”row”:19,”col”:0},{“color”:”#00fd00”,”pin”:40,”label”:”GPIO 21”,”row”:19,”col”:1}],”ledPanelBackgroundColor”:”#008a00”},”title”:”Raspberry Pi GPIO Panel”,”datasources”:[{“type”:”function”,”name”:”function”,”dataKeys”:[{“name”:”f(x)”,”type”:”function”,”label”:”7”,”color”:”#2196f3”,”settings”:{},”_hash”:0.22518255793320163,”funcBody”:”var period = time % 1500;\nreturn period < 500;”},{“name”:”f(x)”,”type”:”function”,”label”:”11”,”color”:”#4caf50”,”settings”:{},”_hash”:0.7008206860666621,”funcBody”:”var period = time % 1500;\nreturn period >= 500 && period < 1000;”},{“name”:”f(x)”,”type”:”function”,”label”:”12”,”color”:”#f44336”,”settings”:{},”_hash”:0.42600325102193426,”funcBody”:”var period = time % 1500;\nreturn period >= 1000;”},{“name”:”f(x)”,”type”:”function”,”label”:”13”,”color”:”#ffc107”,”settings”:{},”_hash”:0.48362241571415243,”funcBody”:”var period = time % 1500;\nreturn period < 500;”},{“name”:”f(x)”,”type”:”function”,”label”:”29”,”color”:”#607d8b”,”settings”:{},”_hash”:0.7217670147518815,”funcBody”:”var period = time % 1500;\nreturn period >= 500 && period < 1000;”}]}],”timewindow”:{“realtime”:{“timewindowMs”:60000}}}”}
Raspberry Pi GPIO Panel 13814000-1dd2-11b2-8080-808080808080
da47b860-e881-11ea-a452-0bb049e7ba49 1598545499878 raspberry_pi_gpio_control gpio_widgets {“type”:”rpc”,”sizeX”:6,”sizeY”:10.5,”resources”:[],”templateHtml”:”
\n
\n
\n
\n {{ cell.label }}\n
\n {{cell.pin}}\n \n \n \n \n {{cell.pin}}\n \n {{ cell.label }}\n \n
\n \n \n \n \n \n \n {{rpcErrorText}}\n \n”,”templateCss”:”.error {\n font-size: 14px !important;\n color: maroon;/rgb(250,250,250);/\n background-color: transparent;\n padding: 6px;\n}\n\n.error span {\n margin: auto;\n}\n\n.gpio-panel {\n padding-top: 10px;\n white-space: nowrap;\n}\n\n.gpio-panel section[fxflex] {\n min-width: 0px;\n}\n\n.switch-panel {\n margin: 0;\n height: 32px;\n width: 66px;\n min-width: 66px;\n}\n\n.switch-panel mat-slide-toggle {\n margin: 0;\n width: 36px;\n min-width: 36px;\n}\n\n.switch-panel.col-0 mat-slide-toggle {\n margin-left: 8px;\n margin-right: 4px;\n}\n\n.switch-panel.col-1 mat-slide-toggle {\n margin-left: 4px;\n margin-right: 8px;\n}\n\n.gpio-row {\n height: 32px;\n}\n\n.pin {\n margin-top: auto;\n margin-bottom: auto;\n color: white;\n font-size: 12px;\n width: 16px;\n min-width: 16px;\n}\n\n.switch-panel.col-0 .pin {\n margin-left: auto;\n padding-left: 2px;\n text-align: right;\n}\n\n.switch-panel.col-1 .pin {\n margin-right: auto;\n \n text-align: left;\n}\n\n.gpio-left-label {\n margin-right: 8px;\n}\n\n.gpio-right-label {\n margin-left: 8px;\n}”,”controllerScript”:”var namespace;\nvar cssParser = new cssjs();\n\nself.onInit = function() {\n var utils = self.ctx.$injector.get(self.ctx.servicesMap.get(‘utils’));\n namespace = ‘gpio-control-‘ + utils.guid();\n cssParser.testMode = false;\n cssParser.cssPreviewNamespace = namespace;\n self.ctx.$container.addClass(namespace);\n self.ctx.ngZone.run(function() {\n init(); \n });\n}\n\nfunction init() {\n \n var i, gpio;\n var scope = self.ctx.$scope;\n var settings = self.ctx.settings;\n scope.gpioList = [];\n for (var g = 0; g < settings.gpioList.length; g++) {\n gpio = settings.gpioList[g];\n scope.gpioList.push(\n {\n row: gpio.row,\n col: gpio.col,\n pin: gpio.pin,\n label: gpio.label,\n enabled: false\n }\n );\n }\n\n scope.requestTimeout = settings.requestTimeout || 1000;\n\n scope.switchPanelBackgroundColor = settings.switchPanelBackgroundColor || tinycolor(‘green’).lighten(2).toRgbString();\n\n scope.gpioStatusRequest = {\n method: “getGpioStatus”,\n paramsBody: “{}”\n };\n \n if (settings.gpioStatusRequest) {\n scope.gpioStatusRequest.method = settings.gpioStatusRequest.method || scope.gpioStatusRequest.method;\n scope.gpioStatusRequest.paramsBody = settings.gpioStatusRequest.paramsBody || scope.gpioStatusRequest.paramsBody;\n }\n \n scope.gpioStatusChangeRequest = {\n method: “setGpioStatus”,\n paramsBody: “{\n \“pin\“: \“{$pin}\“,\n \“enabled\“: \“{$enabled}\“\n}”\n };\n \n if (settings.gpioStatusChangeRequest) {\n scope.gpioStatusChangeRequest.method = settings.gpioStatusChangeRequest.method || scope.gpioStatusChangeRequest.method;\n scope.gpioStatusChangeRequest.paramsBody = settings.gpioStatusChangeRequest.paramsBody || scope.gpioStatusChangeRequest.paramsBody;\n }\n \n scope.parseGpioStatusFunction = “return body[pin] === true;”;\n \n if (settings.parseGpioStatusFunction && settings.parseGpioStatusFunction.length > 0) {\n scope.parseGpioStatusFunction = settings.parseGpioStatusFunction;\n }\n \n scope.parseGpioStatusFunction = new Function(“body, pin”, scope.parseGpioStatusFunction);\n \n function requestGpioStatus() {\n self.ctx.controlApi.sendTwoWayCommand(scope.gpioStatusRequest.method, \n scope.gpioStatusRequest.paramsBody, \n scope.requestTimeout)\n .subscribe(\n function success(responseBody) {\n for (var g = 0; g < scope.gpioList.length; g++) {\n var gpio = scope.gpioList[g];\n var enabled = scope.parseGpioStatusFunction.apply(this, [responseBody, gpio.pin]);\n gpio.enabled = enabled; \n self.ctx.detectChanges();\n }\n }\n );\n }\n \n function changeGpioStatus(gpio) {\n var pin = gpio.pin + ‘’;\n var enabled = !gpio.enabled;\n enabled = enabled === true ? ‘true’ : ‘false’;\n var paramsBody = scope.gpioStatusChangeRequest.paramsBody;\n var requestBody = JSON.parse(paramsBody.replace(“\“{$pin}\“”, pin).replace(“\“{$enabled}\“”, enabled));\n self.ctx.controlApi.sendTwoWayCommand(scope.gpioStatusChangeRequest.method, \n requestBody, scope.requestTimeout)\n .subscribe(\n function success(responseBody) {\n var enabled = scope.parseGpioStatusFunction.apply(this, [responseBody, gpio.pin]);\n gpio.enabled = enabled;\n self.ctx.detectChanges();\n }\n );\n }\n \n scope.gpioCells = {};\n var rowCount = 0;\n for (i = 0; i < scope.gpioList.length; i++) {\n gpio = scope.gpioList[i];\n scope.gpioCells[gpio.row+’‘+gpio.col] = gpio;\n rowCount = Math.max(rowCount, gpio.row+1);\n }\n \n scope.prefferedRowHeight = 32;\n scope.rows = [];\n for (i = 0; i < rowCount; i++) {\n var row = [];\n for (var c =0; c<2;c++) {\n if (scope.gpioCells[i+’‘+c]) {\n row[c] = scope.gpioCells[i+’_’+c];\n } else {\n row[c] = null;\n }\n }\n scope.rows.push(row);\n }\n\n scope.gpioClick = function($event, gpio) {\n if (scope.rpcEnabled && !scope.executingRpcRequest) {\n changeGpioStatus(gpio);\n }\n };\n \n scope.gpioToggleChange = function($event, gpio) {\n gpio.enabled = !$event.checked;\n $event.source.toggle();\n self.ctx.detectChanges();\n }\n \n if (scope.rpcEnabled) {\n requestGpioStatus(); \n }\n \n self.onResize();\n}\n\nself.onResize = function() {\n var scope = self.ctx.$scope;\n var rowCount = scope.rows.length;\n var prefferedRowHeight = (self.ctx.height - 35)/rowCount;\n prefferedRowHeight = Math.min(32, prefferedRowHeight);\n prefferedRowHeight = Math.max(12, prefferedRowHeight);\n scope.prefferedRowHeight = prefferedRowHeight;\n var ratio = prefferedRowHeight/32;\n \n var css = ‘.mat-slide-toggle .mat-slide-toggle-bar {\n’ +\n ‘ height: ‘ + 14_ratio+’px;\n’+\n ‘ width: ‘ + 36_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-thumb-container {\n’ +\n ‘ height: ‘ + 20_ratio+’px;\n’+\n ‘ width: ‘ + 20_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-thumb {\n’ +\n ‘ height: ‘ + 20_ratio+’px;\n’+\n ‘ width: ‘ + 20_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-ripple {\n’ +\n ‘ height: ‘ + 40_ratio+’px;\n’+\n ‘ width: ‘ + 40_ratio+’px;\n’+\n ‘ top: calc(50% - ‘+20_ratio+’px);\n’+\n ‘ left: calc(50% - ‘+20_ratio+’px);\n’+\n ‘}\n’;\n css += ‘.gpio-left-label, .gpio-right-label {\n’ +\n ‘ font-size: ‘ + 16_ratio+’px;\n’+\n ‘}\n’;\n var pinsFontSize = Math.max(9, 12_ratio);\n css += ‘.pin {\n’ +\n ‘ font-size: ‘ + pinsFontSize+’px;\n’+\n ‘}\n’;\n\n cssParser.createStyleElement(namespace, css);\n \n self.ctx.detectChanges();\n}\n\nself.onDestroy = function() {\n}\n”,”settingsSchema”:”{\n “schema”: {\n “type”: “object”,\n “title”: “Settings”,\n “properties”: {\n “gpioList”: {\n “title”: “Gpio switches”,\n “type”: “array”,\n “minItems” : 1,\n “items”: {\n “title”: “Gpio switch”,\n “type”: “object”,\n “properties”: {\n “pin”: {\n “title”: “Pin”,\n “type”: “number”\n },\n “label”: {\n “title”: “Label”,\n “type”: “string”\n },\n “row”: {\n “title”: “Row”,\n “type”: “number”\n },\n “col”: {\n “title”: “Column”,\n “type”: “number”\n }\n },\n “required”: [“pin”, “label”, “row”, “col”]\n }\n },\n “requestTimeout”: {\n “title”: “RPC request timeout”,\n “type”: “number”,\n “default”: 500\n },\n “switchPanelBackgroundColor”: {\n “title”: “Switches panel background color”,\n “type”: “string”,\n “default”: “#008a00”\n },\n “gpioStatusRequest”: {\n “title”: “GPIO status request”,\n “type”: “object”,\n “properties”: {\n “method”: {\n “title”: “Method name”,\n “type”: “string”,\n “default”: “getGpioStatus”\n },\n “paramsBody”: {\n “title”: “Method body”,\n “type”: “string”,\n “default”: “{}”\n }\n },\n “required”: [“method”, “paramsBody”]\n },\n “gpioStatusChangeRequest”: {\n “title”: “GPIO status change request”,\n “type”: “object”,\n “properties”: {\n “method”: {\n “title”: “Method name”,\n “type”: “string”,\n “default”: “setGpioStatus”\n },\n “paramsBody”: {\n “title”: “Method body”,\n “type”: “string”,\n “default”: “{\n \“pin\“: \“{$pin}\“,\n \“enabled\“: \“{$enabled}\“\n}”\n }\n },\n “required”: [“method”, “paramsBody”]\n },\n “parseGpioStatusFunction”: {\n “title”: “Parse gpio status function”,\n “type”: “string”,\n “default”: “return body[pin] === true;”\n } \n },\n “required”: [“gpioList”, \n “requestTimeout”,\n “switchPanelBackgroundColor”,\n “gpioStatusRequest”,\n “gpioStatusChangeRequest”,\n “parseGpioStatusFunction”]\n },\n “form”: [\n “gpioList”,\n “requestTimeout”,\n {\n “key”: “switchPanelBackgroundColor”,\n “type”: “color”\n },\n {\n “key”: “gpioStatusRequest”,\n “items”: [\n “gpioStatusRequest.method”,\n {\n “key”: “gpioStatusRequest.paramsBody”,\n “type”: “json”\n }\n ]\n },\n {\n “key”: “gpioStatusChangeRequest”,\n “items”: [\n “gpioStatusChangeRequest.method”,\n {\n “key”: “gpioStatusChangeRequest.paramsBody”,\n “type”: “json”\n }\n ]\n },\n {\n “key”: “parseGpioStatusFunction”,\n “type”: “javascript”\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”:”#008a00”,”gpioStatusRequest”:{“method”:”getGpioStatus”,”paramsBody”:”{}”},”gpioList”:[{“pin”:7,”label”:”GPIO 4 (GPCLK0)”,”row”:3,”col”:0,”_uniqueKey”:0},{“pin”:11,”label”:”GPIO 17”,”row”:5,”col”:0,”_uniqueKey”:1},{“pin”:12,”label”:”GPIO 18”,”row”:5,”col”:1,”_uniqueKey”:2},{“_uniqueKey”:3,”pin”:13,”label”:”GPIO 27”,”row”:6,”col”:0},{“_uniqueKey”:4,”pin”:15,”label”:”GPIO 22”,”row”:7,”col”:0},{“_uniqueKey”:5,”pin”:16,”label”:”GPIO 23”,”row”:7,”col”:1},{“_uniqueKey”:6,”pin”:18,”label”:”GPIO 24”,”row”:8,”col”:1},{“_uniqueKey”:7,”pin”:22,”label”:”GPIO 25”,”row”:10,”col”:1},{“_uniqueKey”:8,”pin”:29,”label”:”GPIO 5”,”row”:14,”col”:0},{“_uniqueKey”:9,”pin”:31,”label”:”GPIO 6”,”row”:15,”col”:0},{“_uniqueKey”:10,”pin”:32,”label”:”GPIO 12”,”row”:15,”col”:1},{“_uniqueKey”:11,”pin”:33,”label”:”GPIO 13”,”row”:16,”col”:0},{“_uniqueKey”:12,”pin”:35,”label”:”GPIO 19”,”row”:17,”col”:0},{“_uniqueKey”:13,”pin”:36,”label”:”GPIO 16”,”row”:17,”col”:1},{“_uniqueKey”:14,”pin”:37,”label”:”GPIO 26”,”row”:18,”col”:0},{“_uniqueKey”:15,”pin”:38,”label”:”GPIO 20”,”row”:18,”col”:1},{“_uniqueKey”:16,”pin”:40,”label”:”GPIO 21”,”row”:19,”col”:1}]},”title”:”Raspberry Pi GPIO Control”}”}
Raspberry Pi GPIO Control 13814000-1dd2-11b2-8080-808080808080
da434b90-e881-11ea-a452-0bb049e7ba49 1598545499849 basic_gpio_control gpio_widgets {“type”:”rpc”,”sizeX”:4,”sizeY”:2,”resources”:[],”templateHtml”:”
\n
\n
\n
\n {{ cell.label }}\n
\n {{cell.pin}}\n \n \n \n \n {{cell.pin}}\n \n {{ cell.label }}\n \n
\n \n \n \n \n \n \n {{rpcErrorText}}\n \n”,”templateCss”:”.error {\n font-size: 14px !important;\n color: maroon;/rgb(250,250,250);/\n background-color: transparent;\n padding: 6px;\n}\n\n.error span {\n margin: auto;\n}\n\n.gpio-panel {\n padding-top: 10px;\n white-space: nowrap;\n}\n\n.gpio-panel section[fxflex] {\n min-width: 0px;\n}\n\n\n.switch-panel {\n margin: 0;\n height: 32px;\n width: 66px;\n min-width: 66px;\n}\n\n.switch-panel mat-slide-toggle {\n margin: 0;\n width: 36px;\n min-width: 36px;\n}\n\n.switch-panel.col-0 mat-slide-toggle {\n margin-left: 8px;\n margin-right: 4px;\n}\n\n.switch-panel.col-1 mat-slide-toggle {\n margin-left: 4px;\n margin-right: 8px;\n}\n\n.gpio-row {\n height: 32px;\n}\n\n.pin {\n margin-top: auto;\n margin-bottom: auto;\n color: white;\n font-size: 12px;\n width: 16px;\n min-width: 16px;\n}\n\n.switch-panel.col-0 .pin {\n margin-left: auto;\n padding-left: 2px;\n text-align: right;\n}\n\n.switch-panel.col-1 .pin {\n margin-right: auto;\n \n text-align: left;\n}\n\n.gpio-left-label {\n margin-right: 8px;\n}\n\n.gpio-right-label {\n margin-left: 8px;\n}”,”controllerScript”:”var namespace;\nvar cssParser = new cssjs();\n\nself.onInit = function() {\n var utils = self.ctx.$injector.get(self.ctx.servicesMap.get(‘utils’));\n namespace = ‘gpio-control-‘ + utils.guid();\n cssParser.testMode = false;\n cssParser.cssPreviewNamespace = namespace;\n self.ctx.$container.addClass(namespace);\n self.ctx.ngZone.run(function() {\n init(); \n });\n}\n\nfunction init() {\n \n var i, gpio;\n var scope = self.ctx.$scope;\n var settings = self.ctx.settings;\n scope.gpioList = [];\n for (var g = 0; g < settings.gpioList.length; g++) {\n gpio = settings.gpioList[g];\n scope.gpioList.push(\n {\n row: gpio.row,\n col: gpio.col,\n pin: gpio.pin,\n label: gpio.label,\n enabled: false\n }\n );\n }\n\n scope.requestTimeout = settings.requestTimeout || 1000;\n\n scope.switchPanelBackgroundColor = settings.switchPanelBackgroundColor || tinycolor(‘green’).lighten(2).toRgbString();\n\n scope.gpioStatusRequest = {\n method: “getGpioStatus”,\n paramsBody: “{}”\n };\n \n if (settings.gpioStatusRequest) {\n scope.gpioStatusRequest.method = settings.gpioStatusRequest.method || scope.gpioStatusRequest.method;\n scope.gpioStatusRequest.paramsBody = settings.gpioStatusRequest.paramsBody || scope.gpioStatusRequest.paramsBody;\n }\n \n scope.gpioStatusChangeRequest = {\n method: “setGpioStatus”,\n paramsBody: “{\n \“pin\“: \“{$pin}\“,\n \“enabled\“: \“{$enabled}\“\n}”\n };\n \n if (settings.gpioStatusChangeRequest) {\n scope.gpioStatusChangeRequest.method = settings.gpioStatusChangeRequest.method || scope.gpioStatusChangeRequest.method;\n scope.gpioStatusChangeRequest.paramsBody = settings.gpioStatusChangeRequest.paramsBody || scope.gpioStatusChangeRequest.paramsBody;\n }\n \n scope.parseGpioStatusFunction = “return body[pin] === true;”;\n \n if (settings.parseGpioStatusFunction && settings.parseGpioStatusFunction.length > 0) {\n scope.parseGpioStatusFunction = settings.parseGpioStatusFunction;\n }\n \n scope.parseGpioStatusFunction = new Function(“body, pin”, scope.parseGpioStatusFunction);\n \n function requestGpioStatus() {\n self.ctx.controlApi.sendTwoWayCommand(scope.gpioStatusRequest.method, \n scope.gpioStatusRequest.paramsBody, \n scope.requestTimeout)\n .subscribe(\n function success(responseBody) {\n for (var g = 0; g < scope.gpioList.length; g++) {\n var gpio = scope.gpioList[g];\n var enabled = scope.parseGpioStatusFunction.apply(this, [responseBody, gpio.pin]);\n gpio.enabled = enabled; \n self.ctx.detectChanges();\n }\n }\n );\n }\n \n function changeGpioStatus(gpio) {\n var pin = gpio.pin + ‘’;\n var enabled = !gpio.enabled;\n enabled = enabled === true ? ‘true’ : ‘false’;\n var paramsBody = scope.gpioStatusChangeRequest.paramsBody;\n var requestBody = JSON.parse(paramsBody.replace(“\“{$pin}\“”, pin).replace(“\“{$enabled}\“”, enabled));\n self.ctx.controlApi.sendTwoWayCommand(scope.gpioStatusChangeRequest.method, \n requestBody, scope.requestTimeout)\n .subscribe(\n function success(responseBody) {\n var enabled = scope.parseGpioStatusFunction.apply(this, [responseBody, gpio.pin]);\n gpio.enabled = enabled;\n self.ctx.detectChanges();\n }\n );\n }\n \n scope.gpioCells = {};\n var rowCount = 0;\n for (i = 0; i < scope.gpioList.length; i++) {\n gpio = scope.gpioList[i];\n scope.gpioCells[gpio.row+’‘+gpio.col] = gpio;\n rowCount = Math.max(rowCount, gpio.row+1);\n }\n \n scope.prefferedRowHeight = 32;\n scope.rows = [];\n for (i = 0; i < rowCount; i++) {\n var row = [];\n for (var c =0; c<2;c++) {\n if (scope.gpioCells[i+’‘+c]) {\n row[c] = scope.gpioCells[i+’_’+c];\n } else {\n row[c] = null;\n }\n }\n scope.rows.push(row);\n }\n\n scope.gpioClick = function($event, gpio) {\n if (scope.rpcEnabled && !scope.executingRpcRequest) {\n changeGpioStatus(gpio);\n }\n };\n \n scope.gpioToggleChange = function($event, gpio) {\n gpio.enabled = !$event.checked;\n $event.source.toggle();\n self.ctx.detectChanges();\n }\n \n if (scope.rpcEnabled) {\n requestGpioStatus(); \n }\n \n self.onResize();\n}\n\nself.onResize = function() {\n var scope = self.ctx.$scope;\n var rowCount = scope.rows.length;\n var prefferedRowHeight = (self.ctx.height - 35)/rowCount;\n prefferedRowHeight = Math.min(32, prefferedRowHeight);\n prefferedRowHeight = Math.max(12, prefferedRowHeight);\n scope.prefferedRowHeight = prefferedRowHeight;\n var ratio = prefferedRowHeight/32;\n \n var css = ‘.mat-slide-toggle .mat-slide-toggle-bar {\n’ +\n ‘ height: ‘ + 14_ratio+’px;\n’+\n ‘ width: ‘ + 36_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-thumb-container {\n’ +\n ‘ height: ‘ + 20_ratio+’px;\n’+\n ‘ width: ‘ + 20_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-thumb {\n’ +\n ‘ height: ‘ + 20_ratio+’px;\n’+\n ‘ width: ‘ + 20_ratio+’px;\n’+\n ‘}\n’;\n css += ‘.mat-slide-toggle .mat-slide-toggle-ripple {\n’ +\n ‘ height: ‘ + 40_ratio+’px;\n’+\n ‘ width: ‘ + 40_ratio+’px;\n’+\n ‘ top: calc(50% - ‘+20_ratio+’px);\n’+\n ‘ left: calc(50% - ‘+20_ratio+’px);\n’+\n ‘}\n’;\n css += ‘.gpio-left-label, .gpio-right-label {\n’ +\n ‘ font-size: ‘ + 16_ratio+’px;\n’+\n ‘}\n’;\n var pinsFontSize = Math.max(9, 12_ratio);\n css += ‘.pin {\n’ +\n ‘ font-size: ‘ + pinsFontSize+’px;\n’+\n ‘}\n’;\n\n cssParser.createStyleElement(namespace, css);\n \n self.ctx.detectChanges();\n}\n\nself.onDestroy = function() {\n}\n”,”settingsSchema”:”{\n “schema”: {\n “type”: “object”,\n “title”: “Settings”,\n “properties”: {\n “gpioList”: {\n “title”: “Gpio switches”,\n “type”: “array”,\n “minItems” : 1,\n “items”: {\n “title”: “Gpio switch”,\n “type”: “object”,\n “properties”: {\n “pin”: {\n “title”: “Pin”,\n “type”: “number”\n },\n “label”: {\n “title”: “Label”,\n “type”: “string”\n },\n “row”: {\n “title”: “Row”,\n “type”: “number”\n },\n “col”: {\n “title”: “Column”,\n “type”: “number”\n }\n },\n “required”: [“pin”, “label”, “row”, “col”]\n }\n },\n “requestTimeout”: {\n “title”: “RPC request timeout”,\n “type”: “number”,\n “default”: 500\n },\n “switchPanelBackgroundColor”: {\n “title”: “Switches panel background color”,\n “type”: “string”,\n “default”: “#008a00”\n },\n “gpioStatusRequest”: {\n “title”: “GPIO status request”,\n “type”: “object”,\n “properties”: {\n “method”: {\n “title”: “Method name”,\n “type”: “string”,\n “default”: “getGpioStatus”\n },\n “paramsBody”: {\n “title”: “Method body”,\n “type”: “string”,\n “default”: “{}”\n }\n },\n “required”: [“method”, “paramsBody”]\n },\n “gpioStatusChangeRequest”: {\n “title”: “GPIO status change request”,\n “type”: “object”,\n “properties”: {\n “method”: {\n “title”: “Method name”,\n “type”: “string”,\n “default”: “setGpioStatus”\n },\n “paramsBody”: {\n “title”: “Method body”,\n “type”: “string”,\n “default”: “{\n \“pin\“: \“{$pin}\“,\n \“enabled\“: \“{$enabled}\“\n}”\n }\n },\n “required”: [“method”, “paramsBody”]\n },\n “parseGpioStatusFunction”: {\n “title”: “Parse gpio status function”,\n “type”: “string”,\n “default”: “return body[pin] === true;”\n } \n },\n “required”: [“gpioList”, \n “requestTimeout”,\n “switchPanelBackgroundColor”,\n “gpioStatusRequest”,\n “gpioStatusChangeRequest”,\n “parseGpioStatusFunction”]\n },\n “form”: [\n “gpioList”,\n “requestTimeout”,\n {\n “key”: “switchPanelBackgroundColor”,\n “type”: “color”\n },\n {\n “key”: “gpioStatusRequest”,\n “items”: [\n “gpioStatusRequest.method”,\n {\n “key”: “gpioStatusRequest.paramsBody”,\n “type”: “json”\n }\n ]\n },\n {\n “key”: “gpioStatusChangeRequest”,\n “items”: [\n “gpioStatusChangeRequest.method”,\n {\n “key”: “gpioStatusChangeRequest.paramsBody”,\n “type”: “json”\n }\n ]\n },\n {\n “key”: “parseGpioStatusFunction”,\n “type”: “javascript”\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”:”Basic GPIO Control”}”}
Basic GPIO Control 13814000-1dd2-11b2-8080-808080808080
da44f940-e881-11ea-a452-0bb049e7ba49 1598545499860 gpio_panel gpio_widgets {“type”:”latest”,”sizeX”:5,”sizeY”:2,”resources”:[],”templateHtml”:”
\n
\n
\n
\n {{ cell.label }}\n
\n {{cell.pin}}\n \n \n \n \n {{cell.pin}}\n \n {{ cell.label }}\n \n
\n \n \n \n \n \n \n”,”templateCss”:”.error {\n font-size: 14px !important;\n color: maroon;/rgb(250,250,250);/\n background-color: transparent;\n padding: 6px;\n}\n\n.error span {\n margin: auto;\n}\n\n.gpio-panel {\n padding-top: 10px;\n white-space: nowrap;\n}\n\n.gpio-panel section[fxflex] {\n min-width: 0px;\n}\n\n\n.gpio-panel tb-led-light > div {\n margin: auto;\n}\n\n.led-panel {\n margin: 0;\n width: 66px;\n min-width: 66px;\n}\n\n.led-container {\n width: 48px;\n min-width: 48px;\n}\n\n.pin {\n margin-top: auto;\n margin-bottom: auto;\n color: white;\n font-size: 12px;\n width: 16px;\n min-width: 16px;\n}\n\n.led-panel.col-0 .pin {\n margin-left: auto;\n padding-left: 2px;\n text-align: right;\n}\n\n.led-panel.col-1 .pin {\n margin-right: auto;\n \n text-align: left;\n}\n\n.gpio-left-label {\n margin-right: 8px;\n}\n\n.gpio-right-label {\n margin-left: 8px;\n}”,”controllerScript”:”var namespace;\nvar cssParser = new cssjs();\n\nself.onInit = function() {\n var utils = self.ctx.$injector.get(self.ctx.servicesMap.get(‘utils’));\n namespace = ‘gpio-panel-‘ + utils.guid();\n cssParser.testMode = false;\n cssParser.cssPreviewNamespace = namespace;\n self.ctx.$container.addClass(namespace);\n self.ctx.ngZone.run(function() {\n init(); \n });\n}\n\nfunction init() {\n var i, gpio;\n \n var scope = self.ctx.$scope;\n var settings = self.ctx.settings;\n \n scope.gpioList = [];\n scope.gpioByPin = {};\n for (var g = 0; g < settings.gpioList.length; g++) {\n gpio = settings.gpioList[g];\n scope.gpioList.push(\n {\n row: gpio.row,\n col: gpio.col,\n pin: gpio.pin,\n label: gpio.label,\n enabled: false,\n colorOn: tinycolor(gpio.color).lighten(20).toHexString(),\n colorOff: tinycolor(gpio.color).darken().toHexString()\n }\n );\n scope.gpioByPin[gpio.pin] = scope.gpioList[scope.gpioList.length-1];\n }\n\n scope.ledPanelBackgroundColor = settings.ledPanelBackgroundColor || tinycolor(‘green’).lighten(2).toRgbString();\n\n scope.gpioCells = {};\n var rowCount = 0;\n for (i = 0; i < scope.gpioList.length; i++) {\n gpio = scope.gpioList[i];\n scope.gpioCells[gpio.row+’‘+gpio.col] = gpio;\n rowCount = Math.max(rowCount, gpio.row+1);\n }\n \n scope.prefferedRowHeight = 32;\n scope.rows = [];\n for (i = 0; i < rowCount; i++) {\n var row = [];\n for (var c =0; c<2;c++) {\n if (scope.gpioCells[i+’‘+c]) {\n row[c] = scope.gpioCells[i+’_’+c];\n } else {\n row[c] = null;\n }\n }\n scope.rows.push(row);\n } \n \n self.onResize();\n}\n\nself.onDataUpdated = function() {\n var changed = false;\n for (var d = 0; d < self.ctx.data.length; d++) {\n var cellData = self.ctx.data[d];\n var dataKey = cellData.dataKey;\n var gpio = self.ctx.$scope.gpioByPin[dataKey.label];\n if (gpio) {\n var enabled = false;\n if (cellData.data.length > 0) {\n var tvPair = cellData.data[cellData.data.length - 1];\n enabled = (tvPair[1] === true || tvPair[1] === ‘true’);\n }\n if (gpio.enabled != enabled) {\n changed = true;\n gpio.enabled = enabled;\n }\n }\n }\n if (changed) {\n self.ctx.detectChanges();\n } \n}\n\nself.onResize = function() {\n var rowCount = self.ctx.$scope.rows.length;\n var prefferedRowHeight = (self.ctx.height - 35)/rowCount;\n prefferedRowHeight = Math.min(32, prefferedRowHeight);\n prefferedRowHeight = Math.max(12, prefferedRowHeight);\n self.ctx.$scope.prefferedRowHeight = prefferedRowHeight;\n \n var ratio = prefferedRowHeight/32;\n \n var css = ‘.gpio-left-label, .gpio-right-label {\n’ +\n ‘ font-size: ‘ + 16_ratio+’px;\n’+\n ‘}\n’;\n var pinsFontSize = Math.max(9, 12_ratio);\n css += ‘.pin {\n’ +\n ‘ font-size: ‘ + pinsFontSize+’px;\n’+\n ‘}\n’;\n \n cssParser.createStyleElement(namespace, css); \n \n self.ctx.detectChanges();\n}\n\nself.onDestroy = function() {\n}\n”,”settingsSchema”:”{\n “schema”: {\n “type”: “object”,\n “title”: “Settings”,\n “properties”: {\n “gpioList”: {\n “title”: “Gpio leds”,\n “type”: “array”,\n “minItems” : 1,\n “items”: {\n “title”: “Gpio led”,\n “type”: “object”,\n “properties”: {\n “pin”: {\n “title”: “Pin”,\n “type”: “number”\n },\n “label”: {\n “title”: “Label”,\n “type”: “string”\n },\n “row”: {\n “title”: “Row”,\n “type”: “number”\n },\n “col”: {\n “title”: “Column”,\n “type”: “number”\n },\n “color”: {\n “title”: “Color”,\n “type”: “string”,\n “default”: “red”\n }\n },\n “required”: [“pin”, “label”, “row”, “col”, “color”]\n }\n },\n “ledPanelBackgroundColor”: {\n “title”: “LED panel background color”,\n “type”: “string”,\n “default”: “#008a00”\n } \n },\n “required”: [“gpioList”, \n “ledPanelBackgroundColor”]\n },\n “form”: [\n {\n “key”: “gpioList”,\n “items”: [\n “gpioList[].pin”,\n “gpioList[].label”,\n “gpioList[].row”,\n “gpioList[].col”,\n {\n “key”: “gpioList[].color”,\n “type”: “color”\n }\n ]\n },\n {\n “key”: “ledPanelBackgroundColor”,\n “type”: “color”\n }\n ]\n}”,”dataKeySettingsSchema”:”{}\n”,”defaultConfig”:”{“showTitle”:true,”backgroundColor”:”#fff”,”color”:”rgba(0, 0, 0, 0.87)”,”padding”:”0px”,”settings”:{“gpioList”:[{“pin”:1,”label”:”GPIO 1”,”row”:0,”col”:0,”color”:”#008000”,”_uniqueKey”:0},{“pin”:2,”label”:”GPIO 2”,”row”:0,”col”:1,”color”:”#ffff00”,”_uniqueKey”:1},{“pin”:3,”label”:”GPIO 3”,”row”:1,”col”:0,”color”:”#cf006f”,”_uniqueKey”:2}],”ledPanelBackgroundColor”:”#b71c1c”},”title”:”Basic GPIO Panel”,”datasources”:[{“type”:”function”,”name”:”function”,”dataKeys”:[{“name”:”f(x)”,”type”:”function”,”label”:”1”,”color”:”#2196f3”,”settings”:{},”_hash”:0.22518255793320163,”funcBody”:”var period = time % 1500;\nreturn period < 500;”},{“name”:”f(x)”,”type”:”function”,”label”:”2”,”color”:”#4caf50”,”settings”:{},”_hash”:0.7008206860666621,”funcBody”:”var period = time % 1500;\nreturn period >= 500 && period < 1000;”},{“name”:”f(x)”,”type”:”function”,”label”:”3”,”color”:”#f44336”,”settings”:{},”_hash”:0.42600325102193426,”funcBody”:”var period = time % 1500;\nreturn period >= 1000;”}]}],”timewindow”:{“realtime”:{“timewindowMs”:60000}}}”}
Basic GPIO Panel 13814000-1dd2-11b2-8080-808080808080

DDL

  1. CREATE TABLE IF NOT EXISTS widget_type (
  2. id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. alias varchar(255),
  5. bundle_alias varchar(255),
  6. descriptor varchar(1000000),
  7. name varchar(255),
  8. tenant_id uuid
  9. );Copy to clipboardErrorCopied

数据显示

Thingsboard源码分析-用户表设计 - 图6

widget_bundle

属性

字段 类型 描述
id uuid 编号
created_time bigint 创建时间
alias varchar(255) 别名
search_text varchar(255) 搜索关键字
tenant_id uuid 租户编号
title varchar(255) 名称

数据

id created_time alias search_text tenant_id title
da2da0b0-e881-11ea-a452-0bb049e7ba49 1598545499707 charts charts 13814000-1dd2-11b2-8080-808080808080 Charts
da41ec00-e881-11ea-a452-0bb049e7ba49 1598545499840 gpio_widgets gpio widgets 13814000-1dd2-11b2-8080-808080808080 GPIO widgets
da49b430-e881-11ea-a452-0bb049e7ba49 1598545499891 maps_v2 maps 13814000-1dd2-11b2-8080-808080808080 Maps

DDL

  1. CREATE TABLE IF NOT EXISTS widgets_bundle (
  2. id uuid NOT NULL CONSTRAINT widgets_bundle_pkey PRIMARY KEY,
  3. created_time bigint NOT NULL,
  4. alias varchar(255),
  5. search_text varchar(255),
  6. tenant_id uuid,
  7. title varchar(255)
  8. );Copy to clipboardErrorCopied

数据显示

Thingsboard源码分析-用户表设计 - 图7