iobroker.vis-jsontemplate 4.4.0 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -278
- package/io-package.json +27 -1
- package/package.json +2 -2
- package/widgets/vis-jsontemplate/dist/jsontemplate-dist.js +3 -3
- package/widgets/vis-jsontemplate/dist/jsontemplate-dist.js.map +2 -2
- package/widgets/vis-jsontemplate/js/ejs.js +2 -2
- package/widgets/vis2vis-jsontemplate/assets/{JSONTemplateWidget-CuodcMVh.js → JSONTemplateWidget-C4epIyqD.js} +69 -69
- package/widgets/vis2vis-jsontemplate/assets/{createSvgIcon-Cq4e8ujY.js → createSvgIcon-DA3KcVqi.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{defaultTheme-B-lAEsPt.js → defaultTheme-kiJLTqpM.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/index-B4g3Uqrp.js +934 -0
- package/widgets/vis2vis-jsontemplate/assets/{index-D88unquR.js → index-DYF2SjKE.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{index-B5Pbv5OS.js → index-KHkCh06t.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{index-BSv2jlm7.js → index-wgINFdb3.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{jsx-runtime-CTyvUz-w.js → jsx-runtime-EJ1eazSQ.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{localSharedImportMap-BRXKLd38.js → localSharedImportMap-DDM89DWG.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/useTheme-Dnh4pjiM.js +1 -0
- package/widgets/vis2vis-jsontemplate/assets/virtualExposes-DZUl9izO.js +1 -0
- package/widgets/vis2vis-jsontemplate/assets/{vis2visjsonTemplateWidgets__loadShare__react__loadShare__.js-Dt3Fjk3e.js → vis2visjsonTemplateWidgets__loadShare__react__loadShare__.js-vfrWv2rD.js} +1 -1
- package/widgets/vis2vis-jsontemplate/assets/{vis2visjsonTemplateWidgets__loadShare__react__loadShare__.js_commonjs-proxy-C8eFn1vH.js → vis2visjsonTemplateWidgets__loadShare__react__loadShare__.js_commonjs-proxy-Q0lGMY-Q.js} +1 -1
- package/widgets/vis2vis-jsontemplate/customWidgets.js +5 -5
- package/widgets/vis2vis-jsontemplate/assets/index-DB7EX0gZ.js +0 -934
- package/widgets/vis2vis-jsontemplate/assets/useTheme-DTFsYD9R.js +0 -1
- package/widgets/vis2vis-jsontemplate/assets/virtualExposes-BOppGhLO.js +0 -1
- /package/widgets/vis2vis-jsontemplate/assets/{index-DWi86O0N.js → index-CgtArtd6.js} +0 -0
- /package/widgets/vis2vis-jsontemplate/assets/{index-DyH-k3Gm.js → index-DPgSwWJY.js} +0 -0
package/README.md
CHANGED
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
Adapter to visualize JSON data and other data in Vis/Vis2.
|
|
17
17
|
You can customize the output of the data with a template system.
|
|
18
18
|
In the templates you can include HTML, CSS and Javascript.
|
|
19
|
+
The template system used was `ejs`.
|
|
20
|
+
You can try out the basic features here in the online playground.
|
|
21
|
+
<https://ionicabizau.github.io/ejs-playground>
|
|
19
22
|
|
|
20
23
|
The jsontemplate widget was previously available in the rssfeed (for vis1) and
|
|
21
24
|
vis-2-widgets-ovarious adapters. The widgets will be removed from these
|
|
@@ -139,285 +142,11 @@ a specific layout. Here is an example:
|
|
|
139
142
|
|
|
140
143
|
(In Markdown colors aren't visible)
|
|
141
144
|
|
|
142
|
-
#### Use
|
|
145
|
+
#### More Use Cases
|
|
143
146
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
in the admin adapter.
|
|
148
|
-
|
|
149
|
-
**Block 2:**
|
|
150
|
-
|
|
151
|
-
stringify the result and output to html
|
|
152
|
-
|
|
153
|
-
**Block 3:**
|
|
154
|
-
|
|
155
|
-
definition of the sendToAsync function
|
|
156
|
-
|
|
157
|
-
```ejs
|
|
158
|
-
<% req = await sendToAsync("admin.0","selectSendTo",{test:"test"}); %>
|
|
159
|
-
<%- JSON.stringify(req) %>
|
|
160
|
-
<% async function sendToAsync(instance, command, sendData) {
|
|
161
|
-
console.log(`sendToAsync ${command} ${sendData}`);
|
|
162
|
-
return new Promise((resolve, reject) => {
|
|
163
|
-
try {
|
|
164
|
-
vis.conn.sendTo(instance, command, sendData, function (receiveData) {
|
|
165
|
-
resolve(receiveData);
|
|
166
|
-
});
|
|
167
|
-
} catch (error) {
|
|
168
|
-
reject(error);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
} %>
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
**Result:**
|
|
175
|
-
|
|
176
|
-
```text
|
|
177
|
-
[{"label":"Afghanistan","value":"AF"},{"label":"Åland Islands","value":"AX"},{"label":"Albania","value":"AL"}]
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
#### Use case for loading additional scripts
|
|
181
|
-
|
|
182
|
-
Additional fields allow you to load JavaScript libraries (e.g., from CDNs
|
|
183
|
-
like jsDelivr or cdnjs). The following example demonstrates this
|
|
184
|
-
for the chartJS library.
|
|
185
|
-
|
|
186
|
-
**Step 1:**
|
|
187
|
-
|
|
188
|
-
Create a new Datapoint with type string or json named `0_userdata.0.chartData`
|
|
189
|
-
and the following content
|
|
190
|
-
|
|
191
|
-
```json
|
|
192
|
-
[12, 19, 3, 5, 2, 3]
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**Step 2:**
|
|
196
|
-
|
|
197
|
-
Enter the following url in the json_script[1] field:
|
|
198
|
-
|
|
199
|
-
```text
|
|
200
|
-
https://cdn.jsdelivr.net/npm/chart.js
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**Step 3:**
|
|
204
|
-
|
|
205
|
-
Enter the created data point name in the JSON Datapoint field.
|
|
206
|
-
Enter the following template in the JSON Template field.
|
|
207
|
-
|
|
208
|
-
Except for one line, this is standard HTML + JavaScript.
|
|
209
|
-
|
|
210
|
-
```html
|
|
211
|
-
data: <%- JSON.stringify(data) %>,
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
The data read from the data point is available in the JavaScript
|
|
215
|
-
variable `data` and is output within the template instructions <%- ... %>.
|
|
216
|
-
Once the template is compiled and included in the HTML document,
|
|
217
|
-
it is executed by the browser, so that the chart is displayed via JavaScript.
|
|
218
|
-
|
|
219
|
-
```ejs
|
|
220
|
-
<div>
|
|
221
|
-
<canvas id="myChart"></canvas>
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
|
-
<script>
|
|
225
|
-
const ctx = document.getElementById('myChart');
|
|
226
|
-
|
|
227
|
-
new Chart(ctx, {
|
|
228
|
-
type: 'bar',
|
|
229
|
-
data: {
|
|
230
|
-
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
|
|
231
|
-
datasets: [{
|
|
232
|
-
label: '# of Votes',
|
|
233
|
-
data: <%- JSON.stringify(data) %>,
|
|
234
|
-
borderWidth: 1
|
|
235
|
-
}]
|
|
236
|
-
},
|
|
237
|
-
options: {
|
|
238
|
-
scales: {
|
|
239
|
-
y: {
|
|
240
|
-
beginAtZero: true
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
</script>
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-

|
|
249
|
-
|
|
250
|
-
#### Use case for a database-supported task list
|
|
251
|
-
|
|
252
|
-
##### **Introduction**
|
|
253
|
-
|
|
254
|
-
This use case describes how to visualize and interactively modify
|
|
255
|
-
a to-do list from a MySQL database in `ioBroker`.
|
|
256
|
-
The focus is on implementing a simple
|
|
257
|
-
status change via a button click. This concept serves as
|
|
258
|
-
a **Proof of Concept (PoC)** and can be included in future documentation.
|
|
259
|
-
|
|
260
|
-
---
|
|
261
|
-
|
|
262
|
-
##### **Database Structure (MySQL)**
|
|
263
|
-
|
|
264
|
-
First, a MySQL database named `test` is created.
|
|
265
|
-
It contains a table `test` with the following fields:
|
|
266
|
-
|
|
267
|
-
- `id`: Unique ID for each entry
|
|
268
|
-
- `todo`: Title of the to-do entry
|
|
269
|
-
- `action`: Status of the entry (0 = in progress, 1 = completed)
|
|
270
|
-
|
|
271
|
-
###### **SQL Code for Table Creation**
|
|
272
|
-
|
|
273
|
-
<details>
|
|
274
|
-
<summary>Details</summary>
|
|
275
|
-
<pre><code>
|
|
276
|
-
|
|
277
|
-
```sql
|
|
278
|
-
|
|
279
|
-
CREATE TABLE `test` (
|
|
280
|
-
`id` int(11) NOT NULL,
|
|
281
|
-
`todo` varchar(100) NOT NULL,
|
|
282
|
-
`action` int(11) NOT NULL
|
|
283
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
284
|
-
|
|
285
|
-
INSERT INTO `test` (`id`, `todo`, `action`) VALUES
|
|
286
|
-
(1, 'Todo 1', 0),
|
|
287
|
-
(2, 'Todo 2', 1),
|
|
288
|
-
(3, 'Todo 3', 1),
|
|
289
|
-
(4, 'Todo 4', 0);
|
|
290
|
-
|
|
291
|
-
ALTER TABLE `test`
|
|
292
|
-
ADD PRIMARY KEY (`id`),
|
|
293
|
-
ADD UNIQUE KEY `id` (`id`),
|
|
294
|
-
ADD KEY `idx` (`id`);
|
|
295
|
-
|
|
296
|
-
ALTER TABLE `test`
|
|
297
|
-
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
|
|
298
|
-
COMMIT;
|
|
299
|
-
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
</code></pre>
|
|
303
|
-
|
|
304
|
-
</details>
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
##### **Integration into ioBroker**
|
|
309
|
-
|
|
310
|
-
###### **SQL Adapter**
|
|
311
|
-
|
|
312
|
-
To interact with the database, the `ioBroker.sql` adapter is required.
|
|
313
|
-
It is configured accordingly to connect to the MySQL database `test`.
|
|
314
|
-
Note that `ioBroker` automatically creates its own structures in the
|
|
315
|
-
database to store history data points.
|
|
316
|
-
|
|
317
|
-
###### **JSONTemplate Widget**
|
|
318
|
-
|
|
319
|
-
For visualization, we use the `JSONTemplate` widget.
|
|
320
|
-
|
|
321
|
-
##### **Integration into VIS**
|
|
322
|
-
|
|
323
|
-
We place the `JSONTemplate` widget and fill in the following fields:
|
|
324
|
-
|
|
325
|
-
###### **Template Code**
|
|
326
|
-
|
|
327
|
-
<details>
|
|
328
|
-
<summary>Details</summary>
|
|
329
|
-
<pre><code>
|
|
330
|
-
|
|
331
|
-
```html
|
|
332
|
-
<style>
|
|
333
|
-
.btn {
|
|
334
|
-
width: 100%;
|
|
335
|
-
}
|
|
336
|
-
</style>
|
|
337
|
-
<table>
|
|
338
|
-
<tr>
|
|
339
|
-
<th>ID</th>
|
|
340
|
-
<th>Todo</th>
|
|
341
|
-
<th>Action</th>
|
|
342
|
-
</tr>
|
|
343
|
-
<% let todos = await getTodo(); for (let i = 0; i < todos.length; i++) { let todo = todos[i]; %>
|
|
344
|
-
<tr>
|
|
345
|
-
<td><%- todo.id %></td>
|
|
346
|
-
<td><%- todo.todo %></td>
|
|
347
|
-
<td><%- getButton(todo.id, todo.action) %></td>
|
|
348
|
-
</tr>
|
|
349
|
-
<% } %>
|
|
350
|
-
</table>
|
|
351
|
-
|
|
352
|
-
<script>
|
|
353
|
-
window.vis-jsontemplate = { clicktodo: clicktodo };
|
|
354
|
-
|
|
355
|
-
function getButton(id, action) {
|
|
356
|
-
let text = action === 0 ? 'In Progress' : 'Completed';
|
|
357
|
-
return `<button class="btn" onclick="window.vis-jsontemplate.clicktodo(this)" data-id="${id}" data-action="${action}">${text}</button>`;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function clicktodo(el) {
|
|
361
|
-
let id = el.dataset.id;
|
|
362
|
-
let action = el.dataset.action;
|
|
363
|
-
let nextAction = action == 0 ? 1 : 0;
|
|
364
|
-
setAction(id, nextAction);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
async function getTodo() {
|
|
368
|
-
let req = await sendToAsync('sql.0', 'query', 'SELECT * FROM test.test');
|
|
369
|
-
return req.result;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
async function setAction(id, action) {
|
|
373
|
-
await sendToAsync('sql.0', 'query', `UPDATE test.test SET action = ${action} WHERE id = ${id}`);
|
|
374
|
-
vis.setValue('local_trigger', Math.random());
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
async function sendToAsync(instance, command, sendData) {
|
|
378
|
-
return new Promise((resolve, reject) => {
|
|
379
|
-
try {
|
|
380
|
-
vis.conn.sendTo(instance, command, sendData, receiveData => resolve(receiveData));
|
|
381
|
-
} catch (error) {
|
|
382
|
-
reject(error);
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
</script>
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
</code></pre>
|
|
390
|
-
|
|
391
|
-
</details>
|
|
392
|
-
|
|
393
|
-
###### **Data Point for Refreshing Content**
|
|
394
|
-
|
|
395
|
-
To ensure updates are reflected after a status change,
|
|
396
|
-
we add the following local data point:
|
|
397
|
-
|
|
398
|
-
```text
|
|
399
|
-
local_trigger
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
This data point **does not need to be explicitly created**,
|
|
403
|
-
as `local_?` data points are processed internally within VIS (see `vis` documentation).
|
|
404
|
-
|
|
405
|
-
##### **Code Explanation**
|
|
406
|
-
|
|
407
|
-
###### **Template Structure**
|
|
408
|
-
|
|
409
|
-
| Line | Content |
|
|
410
|
-
| ----- | ---------------------------------------------------------------------- |
|
|
411
|
-
| 1-5 | CSS styles for button appearance |
|
|
412
|
-
| 6-11 | Table header with columns ID, Todo, Action |
|
|
413
|
-
| 12-16 | Fetching data from the MySQL database using `getTodo()` |
|
|
414
|
-
| 17-21 | Loop to display to-do entries with buttons |
|
|
415
|
-
| 23-28 | Global reference of the `clicktodo()` function |
|
|
416
|
-
| 30-37 | `getButton()` function to create a button with the current status |
|
|
417
|
-
| 38-44 | `clicktodo()` function to change the status via button click |
|
|
418
|
-
| 45-48 | `getTodo()` function to fetch data via the SQL adapter |
|
|
419
|
-
| 49-52 | `setAction()` function to update the database entry |
|
|
420
|
-
| 53-58 | `sendToAsync()` function to use `async/await` with `vis.conn.sendTo()` |
|
|
147
|
+
- [Use Case Async calls](documentation/usecase-asynccall.md)
|
|
148
|
+
- [Use Case loading scripts](documentation/usecase-loadingscripts.md)
|
|
149
|
+
- [Use Case Tasklist](documentation/usecase-tasklist.md)
|
|
421
150
|
|
|
422
151
|
## Templatesystem
|
|
423
152
|
|
|
@@ -634,6 +363,15 @@ Loop over the attributes of an object
|
|
|
634
363
|
Placeholder for the next version (at the beginning of the line):
|
|
635
364
|
### **WORK IN PROGRESS**
|
|
636
365
|
-->
|
|
366
|
+
### 4.4.2 (2026-04-13)
|
|
367
|
+
|
|
368
|
+
- fix runtime
|
|
369
|
+
|
|
370
|
+
### 4.4.1 (2026-04-13)
|
|
371
|
+
|
|
372
|
+
- fix regression
|
|
373
|
+
- update packages
|
|
374
|
+
|
|
637
375
|
### 4.4.0 (2026-03-24)
|
|
638
376
|
|
|
639
377
|
- optimize lib size
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "vis-jsontemplate",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.2",
|
|
5
5
|
"news": {
|
|
6
|
+
"4.4.2": {
|
|
7
|
+
"en": "fix runtime",
|
|
8
|
+
"de": "die laufzeit",
|
|
9
|
+
"ru": "исправить runtime",
|
|
10
|
+
"pt": "corrigir o tempo de execução",
|
|
11
|
+
"nl": "fix runtime",
|
|
12
|
+
"fr": "fixer l'exécution",
|
|
13
|
+
"it": "correzione di runtime",
|
|
14
|
+
"es": "corrección",
|
|
15
|
+
"pl": "fix runtime",
|
|
16
|
+
"uk": "фіксувати runtime",
|
|
17
|
+
"zh-cn": "固定运行时间"
|
|
18
|
+
},
|
|
19
|
+
"4.4.1": {
|
|
20
|
+
"en": "fix regression\nupdate packages",
|
|
21
|
+
"de": "regression\nupdate-pakete",
|
|
22
|
+
"ru": "фиксировать регрессию\nобновление пакетов",
|
|
23
|
+
"pt": "corrigir regressão\natualizar pacotes",
|
|
24
|
+
"nl": "repareren regressie\npakketten bijwerken",
|
|
25
|
+
"fr": "fixer la régression\nmettre à jour les paquets",
|
|
26
|
+
"it": "correzione della regressione\npacchetti di aggiornamento",
|
|
27
|
+
"es": "regreso\nactualizar paquetes",
|
|
28
|
+
"pl": "naprawić regresję\naktualizacja pakietów",
|
|
29
|
+
"uk": "фіксація регресія\nоновлення пакетів",
|
|
30
|
+
"zh-cn": "修复回归\n更新软件包"
|
|
31
|
+
},
|
|
6
32
|
"4.4.0": {
|
|
7
33
|
"en": "- optimize lib size\n- The ability to load additional JavaScript and CSS files\n has been added (also for vis2).\n- Improve react components\n- align translation for vis2 widget",
|
|
8
34
|
"de": "- optimierung der lib-größe\n- Die Möglichkeit, zusätzliche JavaScript- und CSS-Dateien zu laden\nwurde hinzugefügt (auch für vis2).\n- Reaktionskomponenten verbessern\n- übersetzung ausrichten für vis2 widget",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.vis-jsontemplate",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "vis-jsontemplate",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "oweitman",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@iobroker/build-tools": "^3.0.1",
|
|
32
32
|
"@iobroker/vis-2-widgets-react-dev": "^4.0.4",
|
|
33
33
|
"@iobroker/vis-2-widgets-testing": "^1.0.6",
|
|
34
|
-
"@types/node": "^25.5.
|
|
34
|
+
"@types/node": "^25.5.2"
|
|
35
35
|
},
|
|
36
36
|
"main": "widgets/vis2jsontemplate/customWidgets.js",
|
|
37
37
|
"files": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
var version;
|
|
59
59
|
var init_package = __esm({
|
|
60
60
|
"../package.json"() {
|
|
61
|
-
version = "4.4.
|
|
61
|
+
version = "4.4.2";
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
|
|
@@ -571,8 +571,8 @@
|
|
|
571
571
|
return e;
|
|
572
572
|
})())({ 1: [function(require2, module3, exports3) {
|
|
573
573
|
"use strict";
|
|
574
|
-
var fs = require2("fs");
|
|
575
|
-
var path = require2("path");
|
|
574
|
+
var fs = require2("node:fs");
|
|
575
|
+
var path = require2("node:path");
|
|
576
576
|
var utils = require2("./utils");
|
|
577
577
|
var scopeOptionWarned = false;
|
|
578
578
|
var _VERSION_STRING = require2("../package.json").version;
|