-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
dom.js
144 lines (121 loc) · 4.52 KB
/
dom.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"use strict";
function dom(moduleId, config, translate) {
const showGraphs = config.showPrice || config.showConsumption;
const showPower = config.showPowerGauge;
const showVoltage = config.showVoltageGauge;
const showCurrent = config.showCurrentGauge;
const showTable = config.showTable;
const gaugeStyle =
"width:" +
config.gaugesWidth +
"px; height:" +
config.gaugesHeight +
"px;" +
(config.gaugesVertical ? "" : "display:inline-block;");
const wrapper = document.createElement("div");
const name = moduleId.substr(moduleId.indexOf("MMM"));
Log.info("Translating CURRENT in dom() to " + translate("CURRENT"));
// Tibber chart
const graphs = document.createElement("div");
graphs.align = "center";
graphs.setAttribute("id", "tibberdata-" + moduleId);
graphs.setAttribute(
"style",
"width:" + config.graphWidth + "px; height:" + config.graphHeight + "px;"
);
const defaultTextGraphs = document.createElement("p");
defaultTextGraphs.innerHTML = "No Tibber data";
graphs.appendChild(defaultTextGraphs);
// Power
const spanPower = document.createElement("span");
const power = document.createElement("div");
power.setAttribute("id", "power-" + moduleId);
power.setAttribute("style", gaugeStyle);
const defaultTextPower = document.createElement("p");
defaultTextPower.innerHTML = name + "<br/>Power Gauge";
power.appendChild(defaultTextPower);
spanPower.appendChild(power);
// Voltage
const spanVoltage = document.createElement("span");
const voltage = document.createElement("div");
voltage.setAttribute("id", "voltage-" + moduleId);
voltage.setAttribute("style", gaugeStyle);
const defaultTextVoltage = document.createElement("p");
defaultTextVoltage.innerHTML = name + "<br/>Voltage Gauge";
voltage.appendChild(defaultTextVoltage);
spanVoltage.appendChild(voltage);
// Current
const spanCurrent = document.createElement("span");
const current = document.createElement("div");
current.setAttribute("id", "current-" + moduleId);
current.setAttribute("style", gaugeStyle);
const defaultTextCurrent = document.createElement("p");
defaultTextCurrent.innerHTML = name + "<br/>Current Gauge";
current.appendChild(defaultTextCurrent);
spanCurrent.appendChild(current);
// Table
const table = document.createElement("div");
table.setAttribute("id", "table-" + moduleId);
table.setAttribute(
"style",
"width: " + config.tableWidth + "px; padding-above: 30px;"
);
const tTable = document.createElement("table");
tTable.className = "small";
const tRow = document.createElement("tr");
const columnElementType = config.tableVertical ? "tr" : "td";
const tCol1 = document.createElement(columnElementType);
addTable(tCol1, translate("POWER TODAY"), "acc-power-" + moduleId, config);
tRow.appendChild(tCol1);
// const tCol2 = document.createElement(columnElementType);
// addTable(tCol2, "Current price", "current-price-" + moduleId, config);
// tRow.appendChild(tCol2);
const tCol3 = document.createElement(columnElementType);
addTable(tCol3, translate("COST TODAY"), "acc-cost-" + moduleId, config);
tRow.appendChild(tCol3);
tTable.appendChild(tRow);
table.appendChild(tTable);
// Build
showGraphs && !config.gaugesAbove && wrapper.appendChild(graphs);
showPower && wrapper.appendChild(spanPower);
showVoltage && wrapper.appendChild(spanVoltage);
showCurrent && wrapper.appendChild(spanCurrent);
showGraphs && config.gaugesAbove && wrapper.appendChild(graphs);
showTable && wrapper.appendChild(table);
return wrapper;
}
function addTable(tRow, labelText, id, config) {
// Label
const label = document.createElement("td");
label.innerHTML = labelText + ": ";
label.className = "align-left small-dimmed";
label.setAttribute(
"style",
"white-space: nowrap; padding-left: 20px; color: " +
config.tableLabelColor +
";"
);
tRow.appendChild(label);
// Value
const value = document.createElement("td");
value.id = id + "-value";
value.innerHTML = "";
value.className = "align-left";
value.style.color = config.tableValueColor;
value.setAttribute(
"style",
"white-space: nowrap; padding-left: 5px; padding-right: 5px; color: " +
config.tableValueColor +
";"
);
tRow.appendChild(value);
// Unit
const unit = document.createElement("td");
unit.id = id + "-unit";
unit.innerHTML = "";
unit.className = "align-left small-dimmed";
unit.style.color = config.tableLabelColor;
unit.style.whiteSpace = "nowrap";
unit.style.width = "99%";
tRow.appendChild(unit);
}