capibara 1.3.69 → 1.3.72
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/.claude/skills/capibara-publish/SKILL.md +38 -0
- package/dist/index.js +250 -238
- 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 +33 -17
- package/src/scss/components/_input_nav.scss +99 -0
- package/src/scss/layout/_nav.scss +53 -0
- package/src/scss/layout/_plotContainer.scss +4 -0
- package/src/util/tableElements.js +171 -59
- package/src/util/utils.js +44 -60
- package/test/utils.test.js +29 -0
|
@@ -135,7 +135,16 @@ export default {
|
|
|
135
135
|
let { width, itemHeight } = utils.getTableDimensions(config);
|
|
136
136
|
config.timeline.plots.horizontal.forEach((p) => {
|
|
137
137
|
let item = utils.getItemById(config, p.idNode, p.typeNode);
|
|
138
|
-
|
|
138
|
+
// Los plots de nivel superior conservan el comportamiento histórico;
|
|
139
|
+
// los de nodos anidados (por ejemplo válvulas) deben usar su posición
|
|
140
|
+
// real dentro del árbol visible.
|
|
141
|
+
if (!item) return;
|
|
142
|
+
let topPosition = utils.getPositionByItem(
|
|
143
|
+
config,
|
|
144
|
+
item,
|
|
145
|
+
p.typeNode === "parent" ? "parent" : "child"
|
|
146
|
+
);
|
|
147
|
+
if (topPosition < 0) return;
|
|
139
148
|
let plot = dom.createElement("div", {
|
|
140
149
|
classNames: ["plot-horizontal", p.className || ""],
|
|
141
150
|
style: {
|
|
@@ -1137,7 +1146,7 @@ export default {
|
|
|
1137
1146
|
navList += `
|
|
1138
1147
|
<div class="children-items ${
|
|
1139
1148
|
d.isClosed ? "hide" : ""
|
|
1140
|
-
} " child-list="${d.id || -1}">`;
|
|
1149
|
+
} " child-list="${d.id || -1}" child-type="${d.type || ""}">`;
|
|
1141
1150
|
|
|
1142
1151
|
d.children.forEach((c) => {
|
|
1143
1152
|
if (c.isHidden) return;
|
|
@@ -1201,6 +1210,7 @@ export default {
|
|
|
1201
1210
|
*/
|
|
1202
1211
|
|
|
1203
1212
|
navList += `
|
|
1213
|
+
${c.children && c.children.length ? `<button class="tree-icon nested-tree-icon ${c.isClosed ? "" : "cap-rotate"}" item-id="${c.id || -1}" type-node="${c.type || ""}">${icons.chevronDown}</button>` : ""}
|
|
1204
1214
|
${lightSpan}
|
|
1205
1215
|
${multiButtonsDetailTmpl}
|
|
1206
1216
|
<div
|
|
@@ -1216,6 +1226,15 @@ export default {
|
|
|
1216
1226
|
</div>
|
|
1217
1227
|
</div>
|
|
1218
1228
|
</div>`;
|
|
1229
|
+
|
|
1230
|
+
if (c.children && c.children.length) {
|
|
1231
|
+
navList += `<div class="children-items nested-children-items ${c.isClosed ? "hide" : ""}" child-list="${c.id || -1}" child-type="${c.type || ""}">`;
|
|
1232
|
+
c.children.forEach((gc) => {
|
|
1233
|
+
if (gc.isHidden) return;
|
|
1234
|
+
navList += `<div class="child-nav-item grandchild-nav-item ${gc.rowClass || ""}"><div class="nav-item-container"><div class="item-title ${gc.clickeable ? "clickeable" : ""} ${gc.navOver ? "hoverable" : ""}" item-id="${gc.id || -1}" type-node="${gc.type || ""}"><div class="truncate">${gc.label}</div></div></div></div>`;
|
|
1235
|
+
});
|
|
1236
|
+
navList += `</div>`;
|
|
1237
|
+
}
|
|
1219
1238
|
});
|
|
1220
1239
|
|
|
1221
1240
|
navList += `
|
|
@@ -1298,7 +1317,7 @@ export default {
|
|
|
1298
1317
|
if (c.isHidden) return;
|
|
1299
1318
|
initialNavList += `<div class="child-initial-nav-item ${
|
|
1300
1319
|
d.isClosed ? "hide" : ""
|
|
1301
|
-
}" child="${d.id || -1}">`;
|
|
1320
|
+
} ${c.rowClass || ""}" child="${d.id || -1}">`;
|
|
1302
1321
|
|
|
1303
1322
|
if (c.withNav !== false) {
|
|
1304
1323
|
config.timeline.nav.left.initial.vars.forEach((v) => {
|
|
@@ -1366,6 +1385,28 @@ export default {
|
|
|
1366
1385
|
}
|
|
1367
1386
|
initialNavList += `
|
|
1368
1387
|
</div>`;
|
|
1388
|
+
|
|
1389
|
+
// Reserva una fila para cada nieto en las columnas iniciales. Esto
|
|
1390
|
+
// mantiene alineados los valores del sector con sus válvulas y deja
|
|
1391
|
+
// que el color de contexto cubra todo el sidebar.
|
|
1392
|
+
if (c.children) {
|
|
1393
|
+
c.children.forEach((gc) => {
|
|
1394
|
+
if (gc.isHidden) return;
|
|
1395
|
+
initialNavList += `<div class="child-initial-nav-item grandchild-initial-nav-item ${
|
|
1396
|
+
d.isClosed || c.isClosed ? "hide" : ""
|
|
1397
|
+
} ${gc.rowClass || ""}" child="${c.id || -1}" child-type="${c.type || ""}">`;
|
|
1398
|
+
|
|
1399
|
+
if (gc.withNav !== false) {
|
|
1400
|
+
config.timeline.nav.left.initial.vars.forEach((v) => {
|
|
1401
|
+
if (v.onlyTab && tab && v.onlyTab !== tab.key) return;
|
|
1402
|
+
let value = utils.getVarByPath(gc.values, v.varName);
|
|
1403
|
+
if (v.round && !isNaN(value)) value = utils.round(value, v.round);
|
|
1404
|
+
initialNavList += `<div class="item-col">${value == null ? "" : value}</div>`;
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
initialNavList += `</div>`;
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1369
1410
|
});
|
|
1370
1411
|
}
|
|
1371
1412
|
|
|
@@ -1442,7 +1483,7 @@ export default {
|
|
|
1442
1483
|
if (c.isHidden) return;
|
|
1443
1484
|
exNavList += `<div class="child-ex-nav-item ${
|
|
1444
1485
|
d.isClosed ? "hide" : ""
|
|
1445
|
-
}" child="${d.id || -1}">`;
|
|
1486
|
+
} ${c.rowClass || ""}" child="${d.id || -1}">`;
|
|
1446
1487
|
|
|
1447
1488
|
if (c.withNav !== false) {
|
|
1448
1489
|
config.timeline.nav.left.extend.vars.forEach((v) => {
|
|
@@ -1511,6 +1552,28 @@ export default {
|
|
|
1511
1552
|
}
|
|
1512
1553
|
exNavList += `
|
|
1513
1554
|
</div>`;
|
|
1555
|
+
|
|
1556
|
+
// Los nodos anidados (por ejemplo, válvulas bajo un sector) también
|
|
1557
|
+
// necesitan una fila en el sidebar extendido. Sin ella, las columnas
|
|
1558
|
+
// laterales quedan desalineadas respecto de la planilla.
|
|
1559
|
+
if (c.children) {
|
|
1560
|
+
c.children.forEach((gc) => {
|
|
1561
|
+
if (gc.isHidden) return;
|
|
1562
|
+
exNavList += `<div class="child-ex-nav-item grandchild-ex-nav-item ${
|
|
1563
|
+
d.isClosed || c.isClosed ? "hide" : ""
|
|
1564
|
+
} ${gc.rowClass || ""}" child="${c.id || -1}" child-type="${c.type || ""}">`;
|
|
1565
|
+
|
|
1566
|
+
if (gc.withNav !== false) {
|
|
1567
|
+
config.timeline.nav.left.extend.vars.forEach((v) => {
|
|
1568
|
+
if (v.onlyTab && tab && v.onlyTab !== tab.key) return;
|
|
1569
|
+
let value = utils.getVarByPath(gc.values, v.varName);
|
|
1570
|
+
if (v.round && !isNaN(value)) value = utils.round(value, v.round);
|
|
1571
|
+
exNavList += `<div class="item-col">${value == null ? "" : value}</div>`;
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
exNavList += `</div>`;
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1514
1577
|
});
|
|
1515
1578
|
}
|
|
1516
1579
|
|
|
@@ -1569,7 +1632,7 @@ export default {
|
|
|
1569
1632
|
//buttons
|
|
1570
1633
|
btnNavList += `<div class="cap-btn-child-nav-item parent ${
|
|
1571
1634
|
d.isClosed ? "hide" : ""
|
|
1572
|
-
}" child="${d.id || -1}">
|
|
1635
|
+
} ${c.rowClass || ""}" child="${d.id || -1}">
|
|
1573
1636
|
<div class="cap-btn-nav-item-content">`;
|
|
1574
1637
|
|
|
1575
1638
|
if (
|
|
@@ -1655,7 +1718,7 @@ export default {
|
|
|
1655
1718
|
let typeNode = i.getAttribute("type-node");
|
|
1656
1719
|
let $container = i.closest(".nav-item-container");
|
|
1657
1720
|
let isParent = $container && $container.classList.contains("parent");
|
|
1658
|
-
let item = utils.getItemById(config, itemId, isParent ? "parent" : "child");
|
|
1721
|
+
let item = utils.getItemById(config, itemId, typeNode) || utils.getItemById(config, itemId, isParent ? "parent" : "child");
|
|
1659
1722
|
i.dispatchEvent(
|
|
1660
1723
|
new CustomEvent("overNavItem", {
|
|
1661
1724
|
bubbles: true,
|
|
@@ -1761,7 +1824,7 @@ export default {
|
|
|
1761
1824
|
let typeNode = i.getAttribute("type-node");
|
|
1762
1825
|
let $container = i.closest(".nav-item-container");
|
|
1763
1826
|
let isParent = $container && $container.classList.contains("parent");
|
|
1764
|
-
let item = utils.getItemById(config, itemId, isParent ? "parent" : "child");
|
|
1827
|
+
let item = utils.getItemById(config, itemId, typeNode) || utils.getItemById(config, itemId, isParent ? "parent" : "child");
|
|
1765
1828
|
let value = i.value;
|
|
1766
1829
|
if (inputType == "time") {
|
|
1767
1830
|
let hh_input = i.parentElement.querySelector("input.hh").value;
|
|
@@ -1811,7 +1874,7 @@ export default {
|
|
|
1811
1874
|
e.stopPropagation(); // evitar que también dispare el click de item-title
|
|
1812
1875
|
let itemId = i.getAttribute("item-id");
|
|
1813
1876
|
let typeNode = i.getAttribute("type-node");
|
|
1814
|
-
let item = utils.getItemById(config, itemId, "parent");
|
|
1877
|
+
let item = utils.getItemById(config, itemId, typeNode) || utils.getItemById(config, itemId, "parent");
|
|
1815
1878
|
|
|
1816
1879
|
if (item && item.onClickDetailButton) {
|
|
1817
1880
|
item.onClickDetailButton({
|
|
@@ -1849,25 +1912,29 @@ export default {
|
|
|
1849
1912
|
i.addEventListener("click", (e) => {
|
|
1850
1913
|
let itemId = i.getAttribute("item-id");
|
|
1851
1914
|
let typeNode = i.getAttribute("type-node");
|
|
1852
|
-
let dataConfig =
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
let $
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1915
|
+
let dataConfig = utils.getItemById(config, itemId, typeNode) || utils.getItemById(config, itemId, "child");
|
|
1916
|
+
if (!dataConfig) dataConfig = utils.getItemById(config, itemId, "parent");
|
|
1917
|
+
|
|
1918
|
+
let $navLeft = e.currentTarget.closest("nav.left");
|
|
1919
|
+
// Para nodos anidados el contenedor de hijos es hermano de la fila,
|
|
1920
|
+
// no descendiente de `.child-nav-item`.
|
|
1921
|
+
let childSelector = "[child-list='" + itemId + "'][child-type='" + typeNode + "']";
|
|
1922
|
+
let $children = $navLeft ? $navLeft.querySelector(childSelector) : null;
|
|
1923
|
+
let itemsToHide = $navLeft
|
|
1924
|
+
? $navLeft.querySelectorAll(
|
|
1925
|
+
"[child='" + itemId + "'][child-type='" + typeNode + "'], " + childSelector
|
|
1926
|
+
)
|
|
1927
|
+
: [];
|
|
1861
1928
|
|
|
1862
1929
|
if ($children) {
|
|
1863
1930
|
if ($children.classList.contains("hide")) {
|
|
1864
1931
|
e.currentTarget.classList.add("cap-rotate");
|
|
1865
1932
|
itemsToHide.forEach((i) => i.classList.remove("hide"));
|
|
1866
|
-
dataConfig.isClosed = false;
|
|
1933
|
+
if (dataConfig) dataConfig.isClosed = false;
|
|
1867
1934
|
} else {
|
|
1868
1935
|
e.currentTarget.classList.remove("cap-rotate");
|
|
1869
1936
|
itemsToHide.forEach((i) => i.classList.add("hide"));
|
|
1870
|
-
dataConfig.isClosed = true;
|
|
1937
|
+
if (dataConfig) dataConfig.isClosed = true;
|
|
1871
1938
|
}
|
|
1872
1939
|
}
|
|
1873
1940
|
|
|
@@ -1895,8 +1962,11 @@ export default {
|
|
|
1895
1962
|
* @param {Object} [item={}] - Configuracion de item
|
|
1896
1963
|
* @return {String} Html de ventana de detalle
|
|
1897
1964
|
*/
|
|
1898
|
-
getDetailNavItemContent(item = {}) {
|
|
1965
|
+
getDetailNavItemContent(item = {}, context = {}) {
|
|
1899
1966
|
if (item.navOver == undefined) item.navOver = {};
|
|
1967
|
+
const content = typeof item.navOver.content === "function"
|
|
1968
|
+
? item.navOver.content(context)
|
|
1969
|
+
: item.navOver.content || "";
|
|
1900
1970
|
|
|
1901
1971
|
return `
|
|
1902
1972
|
<div class="header-detail">
|
|
@@ -1914,7 +1984,7 @@ export default {
|
|
|
1914
1984
|
</div>
|
|
1915
1985
|
|
|
1916
1986
|
<div class="detail-container">
|
|
1917
|
-
${
|
|
1987
|
+
${content}
|
|
1918
1988
|
</div>`;
|
|
1919
1989
|
},
|
|
1920
1990
|
|
|
@@ -2292,36 +2362,17 @@ export default {
|
|
|
2292
2362
|
*/
|
|
2293
2363
|
redrawFloatBox(config, tab, $container) {
|
|
2294
2364
|
$container.innerHTML = "";
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
if (dataParent.isHidden) return;
|
|
2299
|
-
|
|
2300
|
-
(dataParent.data || []).forEach((data) => {
|
|
2365
|
+
const rows = utils.flattenTree(config.data, { tabKey: tab && tab.key });
|
|
2366
|
+
rows.forEach((row) => {
|
|
2367
|
+
(row.item.data || []).forEach((data) => {
|
|
2301
2368
|
this.createFloatBoxItem({
|
|
2302
2369
|
container: $container,
|
|
2303
2370
|
data,
|
|
2304
|
-
item:
|
|
2305
|
-
isClosed:
|
|
2371
|
+
item: row.item,
|
|
2372
|
+
isClosed: false,
|
|
2306
2373
|
tab,
|
|
2307
2374
|
config,
|
|
2308
|
-
typeNode: "parent",
|
|
2309
|
-
});
|
|
2310
|
-
});
|
|
2311
|
-
|
|
2312
|
-
dataParent.children.forEach((dataChild) => {
|
|
2313
|
-
if (dataChild.isHidden) return;
|
|
2314
|
-
|
|
2315
|
-
dataChild.data.forEach((data) => {
|
|
2316
|
-
this.createFloatBoxItem({
|
|
2317
|
-
container: $container,
|
|
2318
|
-
data,
|
|
2319
|
-
item: dataChild,
|
|
2320
|
-
isClosed: dataParent.isClosed,
|
|
2321
|
-
tab,
|
|
2322
|
-
config,
|
|
2323
|
-
typeNode: "child",
|
|
2324
|
-
});
|
|
2375
|
+
typeNode: row.depth === 0 ? "parent" : "child",
|
|
2325
2376
|
});
|
|
2326
2377
|
});
|
|
2327
2378
|
});
|
|
@@ -2351,7 +2402,7 @@ export default {
|
|
|
2351
2402
|
// Verificar si hay contenido visible en floatBox
|
|
2352
2403
|
let hasVisibleContent = false;
|
|
2353
2404
|
|
|
2354
|
-
if (hasMessage || hasErrors) {
|
|
2405
|
+
if (hasMessage || hasErrors || (data.indicators && data.indicators.length)) {
|
|
2355
2406
|
hasVisibleContent = true;
|
|
2356
2407
|
} else if (data.values && tab && tab.floatBox) {
|
|
2357
2408
|
// Verificar si hay contenido visible en nums, dots, plots, icons
|
|
@@ -2441,7 +2492,7 @@ export default {
|
|
|
2441
2492
|
//children Data
|
|
2442
2493
|
let position = this.getPositionFloatBox(config, data, item, typeNode);
|
|
2443
2494
|
|
|
2444
|
-
let className = "";
|
|
2495
|
+
let className = item.rowClass ? item.rowClass + " " : "";
|
|
2445
2496
|
|
|
2446
2497
|
if (data.errors && data.errors.length > 0) {
|
|
2447
2498
|
className += "has-errors ";
|
|
@@ -2474,6 +2525,12 @@ export default {
|
|
|
2474
2525
|
`;
|
|
2475
2526
|
}
|
|
2476
2527
|
|
|
2528
|
+
let strIndicators = "";
|
|
2529
|
+
(data.indicators || []).forEach((indicator) => {
|
|
2530
|
+
if (!indicator) return;
|
|
2531
|
+
strIndicators += `<span class="cell-indicator ${indicator.className || ""}" title="${indicator.label || ""}" aria-label="${indicator.label || ""}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="${indicator.icon || ""}" /></svg></span>`;
|
|
2532
|
+
});
|
|
2533
|
+
|
|
2477
2534
|
let str = `
|
|
2478
2535
|
<div class="float-box ${className} "
|
|
2479
2536
|
style="${position ? position : ""}"
|
|
@@ -2481,6 +2538,7 @@ export default {
|
|
|
2481
2538
|
type-node="${item.type || ""}">
|
|
2482
2539
|
|
|
2483
2540
|
${strMsg}
|
|
2541
|
+
${strIndicators}
|
|
2484
2542
|
<div class="float-box-content">`;
|
|
2485
2543
|
|
|
2486
2544
|
let strExt = `
|
|
@@ -3260,7 +3318,10 @@ export default {
|
|
|
3260
3318
|
r.setAttribute("input-key", props.key);
|
|
3261
3319
|
break;
|
|
3262
3320
|
case "select":
|
|
3263
|
-
r = this.createInputSelect(props, dataDay, daySelected);
|
|
3321
|
+
r = this.createInputSelect(props, dataDay, daySelected, selected);
|
|
3322
|
+
break;
|
|
3323
|
+
case "checkboxList":
|
|
3324
|
+
r = this.createInputCheckboxList(props, dataDay, daySelected, selected);
|
|
3264
3325
|
break;
|
|
3265
3326
|
case "file":
|
|
3266
3327
|
r = this.createInputFile(props, dataDay);
|
|
@@ -3483,6 +3544,11 @@ export default {
|
|
|
3483
3544
|
let hintStyle = hintLines
|
|
3484
3545
|
? ` style="min-height:${(hintLines * 1.3).toFixed(2)}em;line-height:1.3;"`
|
|
3485
3546
|
: "";
|
|
3547
|
+
const clearButton = props.clearable
|
|
3548
|
+
? `<button type="button" class="nav-input-clear" aria-label="Limpiar ${props.label}" title="Limpiar">
|
|
3549
|
+
${icons.closeIcon}
|
|
3550
|
+
</button>`
|
|
3551
|
+
: "";
|
|
3486
3552
|
|
|
3487
3553
|
let elem = dom.createElementFromHTML(`
|
|
3488
3554
|
<div class="input-section ${props.classNames || ""} ${
|
|
@@ -3497,9 +3563,12 @@ export default {
|
|
|
3497
3563
|
</span>
|
|
3498
3564
|
</div>
|
|
3499
3565
|
<div class="d-flex">
|
|
3500
|
-
<
|
|
3501
|
-
|
|
3502
|
-
|
|
3566
|
+
<div class="nav-input-clearable">
|
|
3567
|
+
<input type="number"
|
|
3568
|
+
class="nav-input"
|
|
3569
|
+
value="${value}">
|
|
3570
|
+
${clearButton}
|
|
3571
|
+
</div>
|
|
3503
3572
|
|
|
3504
3573
|
<span class="text-hint"${hintStyle}>
|
|
3505
3574
|
${props.textHint || ""}
|
|
@@ -3508,6 +3577,22 @@ export default {
|
|
|
3508
3577
|
</div>`);
|
|
3509
3578
|
|
|
3510
3579
|
let inputElem = elem.querySelector("input");
|
|
3580
|
+
let clearButtonElem = elem.querySelector(".nav-input-clear");
|
|
3581
|
+
|
|
3582
|
+
if (clearButtonElem) {
|
|
3583
|
+
const syncClearButton = () => {
|
|
3584
|
+
clearButtonElem.classList.toggle("is-hidden", inputElem.value === "");
|
|
3585
|
+
};
|
|
3586
|
+
clearButtonElem.addEventListener("click", (event) => {
|
|
3587
|
+
event.preventDefault();
|
|
3588
|
+
event.stopPropagation();
|
|
3589
|
+
inputElem.value = "";
|
|
3590
|
+
inputElem.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3591
|
+
inputElem.focus();
|
|
3592
|
+
});
|
|
3593
|
+
inputElem.addEventListener("input", syncClearButton);
|
|
3594
|
+
syncClearButton();
|
|
3595
|
+
}
|
|
3511
3596
|
|
|
3512
3597
|
this.addKeyDownInputEvents(inputElem, elem, props);
|
|
3513
3598
|
|
|
@@ -3704,9 +3789,10 @@ export default {
|
|
|
3704
3789
|
return elem;
|
|
3705
3790
|
},
|
|
3706
3791
|
|
|
3707
|
-
createInputSelect(props, dataDay, daySelected = null) {
|
|
3792
|
+
createInputSelect(props, dataDay, daySelected = null, selected = []) {
|
|
3708
3793
|
let value = null;
|
|
3709
|
-
let options = props.options;
|
|
3794
|
+
let options = typeof props.options === "function" ? props.options({ dataDay, daySelected, selected }) : props.options;
|
|
3795
|
+
options = options || [];
|
|
3710
3796
|
|
|
3711
3797
|
if (dataDay && dataDay.values) {
|
|
3712
3798
|
let val = utils.getVarByPath(dataDay, props.varName);
|
|
@@ -3721,18 +3807,16 @@ export default {
|
|
|
3721
3807
|
${props.label}
|
|
3722
3808
|
</span>
|
|
3723
3809
|
|
|
3724
|
-
<select class="input-select">
|
|
3810
|
+
<select class="input-select" ${props.multiple ? "multiple" : ""}>
|
|
3725
3811
|
|
|
3726
|
-
|
|
3727
|
-
${props.noDataLabel || "-- sin asignar --"}
|
|
3728
|
-
</option>
|
|
3812
|
+
${props.multiple ? "" : `<option value="" ${value == null ? "selected" : ""}>${props.noDataLabel || "-- sin asignar --"}</option>`}
|
|
3729
3813
|
|
|
3730
3814
|
`;
|
|
3731
3815
|
|
|
3732
3816
|
options.forEach((option) => {
|
|
3733
3817
|
str += `
|
|
3734
3818
|
<option value="${option.id}" ${
|
|
3735
|
-
option.id == value ? "selected" : ""
|
|
3819
|
+
props.multiple ? (Array.isArray(value) && value.indexOf(option.id) !== -1 ? "selected" : "") : option.id == value ? "selected" : ""
|
|
3736
3820
|
}>
|
|
3737
3821
|
${option.label}
|
|
3738
3822
|
</option>
|
|
@@ -3750,6 +3834,34 @@ export default {
|
|
|
3750
3834
|
return elem;
|
|
3751
3835
|
},
|
|
3752
3836
|
|
|
3837
|
+
createInputCheckboxList(props, dataDay, daySelected = null, selected = []) {
|
|
3838
|
+
let value = [];
|
|
3839
|
+
let options = typeof props.options === "function" ? props.options({ dataDay, daySelected, selected }) : props.options;
|
|
3840
|
+
options = options || [];
|
|
3841
|
+
|
|
3842
|
+
if (dataDay && dataDay.values) {
|
|
3843
|
+
const val = utils.getVarByPath(dataDay, props.varName);
|
|
3844
|
+
value = val && Array.isArray(val.value) ? val.value.map((item) => String(item)) : [];
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
let str = `<div input-key="${props.key || ""}" class="${props.isHidden ? "hide" : ""}">
|
|
3848
|
+
<div class="input-section cap-checkbox-list-section">
|
|
3849
|
+
<span class="text-subtitle">${props.label}</span>
|
|
3850
|
+
${props.helpText ? `<span class="cap-checkbox-list-help">${props.helpText}</span>` : ""}
|
|
3851
|
+
<div class="cap-checkbox-list" role="group" aria-label="${props.label}">`;
|
|
3852
|
+
|
|
3853
|
+
options.forEach((option) => {
|
|
3854
|
+
const checked = value.indexOf(String(option.id)) !== -1 ? "checked" : "";
|
|
3855
|
+
str += `<label class="cap-checkbox-list-option">
|
|
3856
|
+
<input class="input-checkbox-list" type="checkbox" value="${option.id}" ${checked}>
|
|
3857
|
+
<span>${option.label}</span>
|
|
3858
|
+
</label>`;
|
|
3859
|
+
});
|
|
3860
|
+
|
|
3861
|
+
str += `</div></div></div>`;
|
|
3862
|
+
return dom.createElementFromHTML(str);
|
|
3863
|
+
},
|
|
3864
|
+
|
|
3753
3865
|
/**
|
|
3754
3866
|
* Crea Input de texto TextArea como elemento Dom
|
|
3755
3867
|
*
|
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
|
+
});
|