@datarailsshared/dr_renderer 1.2.41-beta → 1.2.41

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.
@@ -0,0 +1,308 @@
1
+ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
2
+
3
+ publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
4
+ event.stopPropagation();
5
+ event.preventDefault();
6
+ try {
7
+ const td = event.currentTarget;
8
+ const a = td.querySelector('a');
9
+ const locationId = a.getAttribute('location_id');
10
+ scope.callFromPublishItem(event, options.widgetId, options.dashboardId, locationId, window.published_item_sheetname);
11
+ } catch (e) {
12
+ }
13
+ return false;
14
+ }
15
+
16
+ publishedItemsRenderer.resizeTable = function (options, window) {
17
+ options.alreadySetTimeout = null;
18
+ const publish_item_image = window.document.getElementById('publish_item_image');
19
+ const table = window.document.getElementsByTagName("table")[0];
20
+ const body = window.document.getElementsByTagName("body")[0];
21
+ let body_zoom = body.style.zoom;
22
+ body_zoom = parseFloat(body_zoom);
23
+
24
+ if (!body_zoom) {
25
+ body_zoom = 1;
26
+ }
27
+
28
+ if (table && options.autoResize) {
29
+ let zoom = table.style.zoom;
30
+ zoom = parseFloat(zoom);
31
+
32
+ if (!zoom) {
33
+ zoom = 1;
34
+ }
35
+
36
+ const positionInfo = table.getBoundingClientRect();
37
+ let height = (positionInfo.height + positionInfo.y * 2) * zoom * body_zoom;
38
+ let width = (positionInfo.width + positionInfo.x * 2) * zoom * body_zoom;
39
+
40
+ if (height < window.innerHeight && width < window.innerWidth) {
41
+ zoom += 0.05;
42
+ height = (positionInfo.height + positionInfo.y * 2) * zoom * body_zoom;
43
+ width = (positionInfo.width + positionInfo.x * 2) * zoom * body_zoom;
44
+ if (height < window.innerHeight && width < window.innerWidth) {
45
+ table.style.zoom = zoom;
46
+ setTimeout(function () {
47
+ publishedItemsRenderer.resizeTable(options, window);
48
+ }, 10);
49
+ }
50
+ } else if (height >= window.innerHeight || width >= window.innerWidth) {
51
+ zoom -= 0.05;
52
+ height = (positionInfo.height + positionInfo.y * 2) * zoom * body_zoom;
53
+ width = (positionInfo.width + positionInfo.x * 2) * zoom * body_zoom;
54
+ table.style.zoom = zoom;
55
+ if (height >= window.innerHeight || width >= window.innerWidth) {
56
+ setTimeout(function () {
57
+ publishedItemsRenderer.resizeTable(options, window);
58
+ }, 10);
59
+ }
60
+ }
61
+ }
62
+ if (publish_item_image) {
63
+ if (publish_item_image.style.height === '100%') {
64
+ publish_item_image.style.height = 'auto';
65
+ publish_item_image.style.width = '100%';
66
+ publish_item_image.style.marginTop = "";
67
+ setTimeout(function () {
68
+ publishedItemsRenderer.resizeTable(options, window);
69
+ }, 10);
70
+ }
71
+
72
+ const imgPositionInfo = publish_item_image.getBoundingClientRect();
73
+ const height = (imgPositionInfo.height + imgPositionInfo.y * 2) * body_zoom;
74
+ if (height > window.innerHeight) {
75
+ publish_item_image.style.height = '100%';
76
+ publish_item_image.style.width = 'auto';
77
+ } else if (height < window.innerHeight) {
78
+ const temp = (window.innerHeight - height) / 2;
79
+ publish_item_image.style.marginTop = (temp / body_zoom + imgPositionInfo.y) + "px";
80
+ }
81
+ }
82
+ }
83
+
84
+ publishedItemsRenderer.resetTableZoom = function (document) {
85
+ const table = document.getElementsByTagName("table")[0];
86
+ if (table) {
87
+ table.style.zoom = 1;
88
+ }
89
+ }
90
+
91
+ publishedItemsRenderer.changedAutoResize = function (new_auto_resize, options, window, document) {
92
+ if (options.autoResize !== new_auto_resize) {
93
+ options.autoResize = new_auto_resize;
94
+ if (!options.autoResize) {
95
+ publishedItemsRenderer.resetTableZoom(document);
96
+ } else {
97
+ if (!options.alreadySetTimeout) {
98
+ options.alreadySetTimeout = setTimeout(function () {
99
+ publishedItemsRenderer.resizeTable(options, window);
100
+ }, 100);
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ publishedItemsRenderer.changedInputValue = function (firstTime, scope, options) {
107
+ const input_values = [];
108
+ if (options.inputValuesData) {
109
+ for (let key in options.inputValuesData) {
110
+ input_values.push(options.inputValuesData[key]);
111
+ }
112
+ }
113
+
114
+ try {
115
+ scope.changedInputValues(input_values, options.widgetId, options.dashboardId, firstTime);
116
+ } catch (e) {
117
+ console.error(e);
118
+ }
119
+ }
120
+
121
+ publishedItemsRenderer.changedInputElement = function (event, scope, options) {
122
+ const inputElement = event.currentTarget;
123
+ const name = inputElement.getAttribute('name');
124
+ const metaData = options.inputValuesData ? options.inputValuesData[name] : null;
125
+ let newValue = inputElement.value;
126
+ if (metaData) {
127
+ if (metaData.type === 'editInput')
128
+ newValue = parseFloat(newValue);
129
+
130
+ if (metaData.value !== newValue) {
131
+ metaData.value = newValue;
132
+ publishedItemsRenderer.changedInputValue(false, scope, options);
133
+ }
134
+ }
135
+ }
136
+
137
+ publishedItemsRenderer.createInputElement = function (tdElement, inputMetaData, formatValue, scope, options, document) {
138
+ tdElement.innerHTML = '';
139
+ if (inputMetaData) {
140
+ switch (inputMetaData.type) {
141
+ case "editInput":
142
+ case "editInputPercent":
143
+ let inEl = document.createElement("INPUT");
144
+ let labelEl = document.createElement("LABEL");
145
+
146
+ if (inputMetaData.value === 'DR_INPUT') {
147
+ labelEl.innerText = null;
148
+ } else {
149
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inputMetaData.value).value : inputMetaData.value;
150
+ }
151
+ labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
152
+ labelEl.addEventListener("click", function (event) {
153
+ event.stopPropagation();
154
+ labelEl.style.display = 'none';
155
+ inEl.style.display = 'block';
156
+ setTimeout(function () {
157
+ inEl.focus();
158
+ }, 1)
159
+ });
160
+
161
+ if (inputMetaData.type === 'editInputPercent')
162
+ inEl.setAttribute("type", "text");
163
+ else if (inputMetaData.type === 'editInput')
164
+ inEl.setAttribute("type", "number");
165
+
166
+ inEl.setAttribute("name", inputMetaData.name);
167
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
168
+ inEl.value = inputMetaData.value;
169
+ inEl.addEventListener("focusout", function (event) {
170
+ event.preventDefault();
171
+ publishedItemsRenderer.changedInputElement(event, scope, options);
172
+ inEl.style.display = 'none';
173
+ labelEl.innerText = inEl.value;
174
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
175
+ labelEl.style.display = 'block';
176
+ });
177
+ inEl.addEventListener("keyup", function (event) {
178
+ // Number 13 is the "Enter" key on the keyboard
179
+ if (event.keyCode === 13) {
180
+ // Cancel the default action, if needed
181
+ event.preventDefault();
182
+ publishedItemsRenderer.changedInputElement(event, scope, options);
183
+ inEl.style.display = 'none';
184
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
185
+ labelEl.style.display = 'block';
186
+ }
187
+ });
188
+ tdElement.appendChild(inEl);
189
+ tdElement.appendChild(labelEl);
190
+ break;
191
+ case "dateInput":
192
+ let dateEl = document.createElement("DIV");
193
+ const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
194
+ const formattedDate = formatValue('d', format, inputMetaData.value).value
195
+ dateEl.innerHTML = '<label class="value" style="cursor: pointer;">' + formattedDate + '</label>';
196
+ tdElement.appendChild(dateEl);
197
+ tdElement.classList.toggle("input-filter-list-td");
198
+ tdElement.setAttribute("name", inputMetaData.name);
199
+ tdElement.addEventListener("click", function (event) {
200
+ try {
201
+ scope.openDatePickerFromPublishedItem(event, options.widgetId, options.dashboardId, inputMetaData, format);
202
+ } catch (e) {
203
+ console.error(e);
204
+ }
205
+ })
206
+ break;
207
+ case "excelList":
208
+ let selectEl = document.createElement("SELECT");
209
+ selectEl.setAttribute("name", inputMetaData.name);
210
+ selectEl.setAttribute("class", "dr_input");
211
+ for (let i = 0; i < inputMetaData.values.length; i++) {
212
+ let option = document.createElement("option");
213
+ option.setAttribute("value", inputMetaData.values[i]);
214
+ option.innerText = inputMetaData.values[i];
215
+ if (inputMetaData.values[i] === inputMetaData.value) {
216
+ option.setAttribute("selected", "");
217
+ }
218
+ selectEl.appendChild(option);
219
+ }
220
+ selectEl.addEventListener("change", function (event) {
221
+ publishedItemsRenderer.changedInputElement(event, scope, options)
222
+ });
223
+ tdElement.appendChild(selectEl);
224
+ break;
225
+ case "filterList":
226
+ let listHolderEl = document.createElement("DIV");
227
+ listHolderEl.setAttribute("class", "filter_list_holder");
228
+ listHolderEl.innerHTML = '<label class="value">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
229
+ tdElement.appendChild(listHolderEl);
230
+ tdElement.classList.toggle("input-filter-list-td");
231
+ tdElement.setAttribute("name", inputMetaData.name);
232
+ tdElement.addEventListener("click", function (event) {
233
+ let inputElement = event.currentTarget;
234
+ let name = inputElement.getAttribute('name');
235
+ let metaData = options.inputValuesData ? options.inputValuesData[name] : null;
236
+ if (metaData) {
237
+ try {
238
+ scope.openFilterListFromPublishedItem(event, options.widgetId, options.dashboardId, metaData);
239
+ } catch (e) {
240
+ console.error(e);
241
+ }
242
+ }
243
+ });
244
+ break;
245
+ }
246
+ }
247
+ }
248
+
249
+ publishedItemsRenderer.changedInputFilterValue = function (metaData, newValue, document) {
250
+ let tdLabelElement = document.querySelector('td[name="' + metaData.name + '"]>div>label[class="value"]');
251
+ if (tdLabelElement) {
252
+ tdLabelElement.innerText = newValue;
253
+ }
254
+ console.log(tdLabelElement, newValue);
255
+ }
256
+
257
+ publishedItemsRenderer.prepareInputCells = function (document, scope, options) {
258
+ let inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
259
+ if (!options.inputValuesData) {
260
+ options.inputValuesData = {};
261
+ }
262
+ if (inputCells.length > 0) {
263
+ for (let i = 0; i < inputCells.length; i++) {
264
+ let tdElement = inputCells[i].parentElement;
265
+ let inputId = inputCells[i].getAttribute('name') || 'no_attribute';
266
+ publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document);
267
+ }
268
+ }
269
+ }
270
+
271
+ publishedItemsRenderer.addEventListeners = function (document, window, scope, options) {
272
+ document.addEventListener("DOMContentLoaded", function () {
273
+ if (!options.alreadySetTimeout) {
274
+ options.alreadySetTimeout = setTimeout(function () {
275
+ publishedItemsRenderer.resizeTable(options, window);
276
+ }, 50);
277
+ }
278
+ });
279
+ window.addEventListener("resize", function () {
280
+ if (!options.alreadySetTimeout) {
281
+ options.alreadySetTimeout = setTimeout(function () {
282
+ publishedItemsRenderer.resizeTable(options, window);
283
+ }, 100);
284
+ }
285
+ });
286
+
287
+ // Add click event to cell with formula
288
+ let all_a_hrefs = document.querySelectorAll('td a[location_id]');
289
+ for (let i = 0; i < all_a_hrefs.length; i++) {
290
+ let td_elem = all_a_hrefs[i].closest('td');
291
+ td_elem.classList.add("apply_hover");
292
+ td_elem.addEventListener('click', function (event) {
293
+ publishedItemsRenderer.formulaCellClicked(event, scope, options, window)
294
+ });
295
+ }
296
+ }
297
+
298
+ publishedItemsRenderer.initPublishedItem = function (document, window, scope, options) {
299
+ publishedItemsRenderer.prepareInputCells(document, scope, options);
300
+ publishedItemsRenderer.addEventListeners(document, window, scope, options);
301
+
302
+ setTimeout(function () {
303
+ publishedItemsRenderer.changedInputValue(true, scope, options);
304
+ }, 500);
305
+ }
306
+ }
307
+
308
+ module.exports = getPublishedItemsRenderer;
package/start_run.sh CHANGED
@@ -1,3 +1,3 @@
1
- #!/bin/bash
2
- source ~/.nvm/nvm.sh
3
- nvm use 14.15.1
1
+ #!/bin/bash
2
+ source ~/.nvm/nvm.sh
3
+ nvm use 14.15.1