capibara 1.3.69 → 1.3.71
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/dist/index.js +315 -315
- package/docs/valvulas-planilla/PLAN_ARBOL_ANIDADO_E_INDICADORES.md +188 -0
- package/docs/valvulas-planilla/README.md +9 -0
- package/package.json +5 -3
- package/src/lib/capibara.js +24 -16
- package/src/scss/layout/_nav.scss +23 -0
- package/src/util/tableElements.js +50 -49
- package/src/util/utils.js +44 -60
- package/test/utils.test.js +29 -0
package/src/util/utils.js
CHANGED
|
@@ -85,7 +85,7 @@ export default {
|
|
|
85
85
|
indexSelectedDay(list, props) {
|
|
86
86
|
let index = -1;
|
|
87
87
|
list.forEach((l, i) => {
|
|
88
|
-
if (l.date == props.date && l.item
|
|
88
|
+
if (l.date == props.date && this.getNodeKey(l.item) == this.getNodeKey(props.item)) {
|
|
89
89
|
index = i;
|
|
90
90
|
}
|
|
91
91
|
})
|
|
@@ -107,29 +107,42 @@ export default {
|
|
|
107
107
|
* @param {item} item - Item a buscar en Array
|
|
108
108
|
* @return {Integer} Posicion, default -1
|
|
109
109
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
110
|
+
getNodeKey(item) {
|
|
111
|
+
return String((item && item.type) || "node") + ":" + String(item && item.id);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Lista canónica de filas del árbol. Mantiene la compatibilidad con los
|
|
116
|
+
* árboles parent -> child y permite consumidores con más profundidad.
|
|
117
|
+
*/
|
|
118
|
+
flattenTree(data, options = {}) {
|
|
119
|
+
const rows = [];
|
|
120
|
+
const tabKey = options.tabKey;
|
|
121
|
+
const visibleOnly = options.visibleOnly !== false;
|
|
122
|
+
|
|
123
|
+
const isVisibleInTab = (item) => {
|
|
124
|
+
if (!tabKey || !item || !item.visibleInTabs) return true;
|
|
125
|
+
return item.visibleInTabs.indexOf(tabKey) !== -1;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const walk = (items, parent, ancestors, depth) => {
|
|
129
|
+
(items || []).forEach((item) => {
|
|
130
|
+
if (!item || item.isHidden || !isVisibleInTab(item)) return;
|
|
131
|
+
rows.push({ item, parent, ancestors, depth, key: this.getNodeKey(item) });
|
|
132
|
+
if (item.children && item.children.length && (!visibleOnly || !item.isClosed)) {
|
|
133
|
+
walk(item.children, item, ancestors.concat([item]), depth + 1);
|
|
127
134
|
}
|
|
128
135
|
});
|
|
136
|
+
};
|
|
129
137
|
|
|
130
|
-
|
|
138
|
+
walk(data || [], null, [], 0);
|
|
139
|
+
return rows;
|
|
140
|
+
},
|
|
131
141
|
|
|
132
|
-
|
|
142
|
+
getPositionByItem(config, item, typeNode = "child") {
|
|
143
|
+
const rows = this.flattenTree(config.data);
|
|
144
|
+
const key = this.getNodeKey(item);
|
|
145
|
+
return rows.findIndex((row) => row.key === key && (typeNode === "child" || row.depth === 0));
|
|
133
146
|
},
|
|
134
147
|
|
|
135
148
|
|
|
@@ -147,27 +160,9 @@ export default {
|
|
|
147
160
|
* @return {Object} Item encontrado
|
|
148
161
|
*/
|
|
149
162
|
getItemByEvent(config, evt, $table) {
|
|
150
|
-
let item = null;
|
|
151
|
-
let actualPosition = 0;
|
|
152
163
|
let pos = this.eventToPosition(config, evt, $table);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (d.isHidden) return;
|
|
156
|
-
if (actualPosition == position ) {
|
|
157
|
-
item = d;
|
|
158
|
-
}
|
|
159
|
-
actualPosition++;
|
|
160
|
-
if (!d.isClosed) {
|
|
161
|
-
d.children.forEach(c => {
|
|
162
|
-
if (c.isHidden) return;
|
|
163
|
-
if (actualPosition == position ) {
|
|
164
|
-
item = c;
|
|
165
|
-
}
|
|
166
|
-
actualPosition++;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
return item;
|
|
164
|
+
const rows = this.flattenTree(config.data);
|
|
165
|
+
return rows[pos.y] ? rows[pos.y].item : null;
|
|
171
166
|
},
|
|
172
167
|
|
|
173
168
|
|
|
@@ -197,20 +192,15 @@ export default {
|
|
|
197
192
|
* @return {Object} item o {item, parent}
|
|
198
193
|
*/
|
|
199
194
|
getItemById(config, id, typeNode = "child", withParent = false) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
d.children.forEach(c => {
|
|
208
|
-
if (c.id == id && typeNode == "child") {
|
|
209
|
-
item = c;
|
|
210
|
-
parent = d;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
195
|
+
const rows = this.flattenTree(config.data, { visibleOnly: false });
|
|
196
|
+
const isStructuralType = typeNode === "child" || typeNode === "parent";
|
|
197
|
+
let found = rows.find((row) => {
|
|
198
|
+
if (row.item.id != id) return false;
|
|
199
|
+
if (!isStructuralType) return row.item.type === typeNode;
|
|
200
|
+
return typeNode === "child" || row.depth === 0;
|
|
213
201
|
});
|
|
202
|
+
let item = found ? found.item : null;
|
|
203
|
+
let parent = found ? found.parent : null;
|
|
214
204
|
|
|
215
205
|
if (withParent) {
|
|
216
206
|
return { item, parent }
|
|
@@ -476,13 +466,7 @@ export default {
|
|
|
476
466
|
let diff_time = end.getTime() - start.getTime();
|
|
477
467
|
let days = diff_time / dateUtils.dayInMilliseconds;
|
|
478
468
|
|
|
479
|
-
config.data.
|
|
480
|
-
if (d.isHidden) return;
|
|
481
|
-
rows++;
|
|
482
|
-
if (d.children && !d.isClosed) {
|
|
483
|
-
rows += d.children.filter(c => !c.isHidden).length;
|
|
484
|
-
}
|
|
485
|
-
});
|
|
469
|
+
rows = this.flattenTree(config.data).length;
|
|
486
470
|
|
|
487
471
|
let height = rows * h;
|
|
488
472
|
let width = days * w;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import utils from "../src/util/utils";
|
|
3
|
+
|
|
4
|
+
describe("árbol de Capibara", () => {
|
|
5
|
+
const valve = { id: 7, type: "valvula", label: "Válvula 7" };
|
|
6
|
+
const sector = { id: 7, type: "sector", label: "Sector 7", children: [valve] };
|
|
7
|
+
const equipo = { id: 1, type: "equipo", label: "Equipo", children: [sector] };
|
|
8
|
+
const config = { data: [equipo] };
|
|
9
|
+
|
|
10
|
+
it("distingue nodos de distinto tipo aunque compartan ID", () => {
|
|
11
|
+
expect(utils.getNodeKey(sector)).toBe("sector:7");
|
|
12
|
+
expect(utils.getNodeKey(valve)).toBe("valvula:7");
|
|
13
|
+
expect(utils.indexSelectedDay([{ date: "2026-09-14", item: sector }], { date: "2026-09-14", item: valve })).toBe(-1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("aplana todos los niveles y respeta el colapso", () => {
|
|
17
|
+
expect(utils.flattenTree(config.data).map((row) => row.key)).toEqual(["equipo:1", "sector:7", "valvula:7"]);
|
|
18
|
+
sector.isClosed = true;
|
|
19
|
+
expect(utils.flattenTree(config.data).map((row) => row.key)).toEqual(["equipo:1", "sector:7"]);
|
|
20
|
+
expect(utils.flattenTree(config.data, { visibleOnly: false }).map((row) => row.key)).toEqual(["equipo:1", "sector:7", "valvula:7"]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("encuentra una válvula anidada y conserva su padre inmediato", () => {
|
|
24
|
+
const found = utils.getItemById(config, 7, "valvula", true);
|
|
25
|
+
expect(found.item).toBe(valve);
|
|
26
|
+
expect(found.parent).toBe(sector);
|
|
27
|
+
expect(utils.getItemById(config, 7, "sector")).toBe(sector);
|
|
28
|
+
});
|
|
29
|
+
});
|