myio-js-library 0.1.570 → 0.1.572
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.cjs +238 -29
- package/dist/index.d.cts +69 -1
- package/dist/index.d.ts +69 -1
- package/dist/index.js +237 -29
- package/dist/myio-js-library.umd.js +237 -29
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -890,6 +890,7 @@ __export(src_exports, {
|
|
|
890
890
|
resolveClassification: () => resolveClassification,
|
|
891
891
|
resolveGoalAmount: () => resolveGoalAmount,
|
|
892
892
|
resolveGroup: () => resolveGroup,
|
|
893
|
+
resolveManualDeviceName: () => resolveManualDeviceName,
|
|
893
894
|
resolveMoneyRollout: () => resolveMoneyRollout,
|
|
894
895
|
resolveMoneyRowValues: () => resolveMoneyRowValues,
|
|
895
896
|
resolvePercentDecimals: () => resolvePercentDecimals,
|
|
@@ -953,7 +954,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
953
954
|
// package.json
|
|
954
955
|
var package_default = {
|
|
955
956
|
name: "myio-js-library",
|
|
956
|
-
version: "0.1.
|
|
957
|
+
version: "0.1.572",
|
|
957
958
|
description: "A clean, standalone JS SDK for MYIO projects",
|
|
958
959
|
license: "MIT",
|
|
959
960
|
repository: "github:gh-myio/myio-js-library",
|
|
@@ -101143,7 +101144,7 @@ function createGoalsBarTooltip(opts) {
|
|
|
101143
101144
|
function render3(data) {
|
|
101144
101145
|
const accent = resolveAccent3(data.accentColor ?? opts?.accentColor, doc);
|
|
101145
101146
|
el2.style.setProperty("--myio-gbt-accent", accent);
|
|
101146
|
-
const
|
|
101147
|
+
const rowsHtml2 = data.rows && data.rows.length > 0 ? data.rows.map((r) => renderRow(r, 0)).join("") : `<div class="myio-gbt__empty">Sem dados para este per\xEDodo</div>`;
|
|
101147
101148
|
el2.innerHTML = `
|
|
101148
101149
|
<div class="myio-gbt__card">
|
|
101149
101150
|
<div class="myio-gbt__header">
|
|
@@ -101154,7 +101155,7 @@ function createGoalsBarTooltip(opts) {
|
|
|
101154
101155
|
<button class="myio-gbt__btn myio-gbt__btn--pin${pinned ? " is-pinned" : ""}" data-action="pin" title="${pinned ? "Desafixar" : "Fixar na tela"}">\u{1F4CC}</button>
|
|
101155
101156
|
<button class="myio-gbt__btn myio-gbt__btn--close" data-action="close" title="Fechar">\u2715</button>
|
|
101156
101157
|
</div>
|
|
101157
|
-
<div class="myio-gbt__body">${
|
|
101158
|
+
<div class="myio-gbt__body">${rowsHtml2}</div>
|
|
101158
101159
|
</div>`;
|
|
101159
101160
|
if (pinned) el2.classList.add("myio-gbt--pinned");
|
|
101160
101161
|
wireInteractions();
|
|
@@ -112148,7 +112149,7 @@ async function openClearGcdrIdsModal(state6) {
|
|
|
112148
112149
|
opacity:${disabled ? "0.5" : "1"};
|
|
112149
112150
|
" ${disabled ? "disabled" : ""}>${label}</button>`;
|
|
112150
112151
|
}
|
|
112151
|
-
function
|
|
112152
|
+
function progressHtml2(phase, done, total) {
|
|
112152
112153
|
const pct = total > 0 ? Math.round(done / total * 100) : 0;
|
|
112153
112154
|
return `
|
|
112154
112155
|
<div style="padding:8px 0;">
|
|
@@ -112204,7 +112205,7 @@ async function openClearGcdrIdsModal(state6) {
|
|
|
112204
112205
|
${tableHtml(assetToClear, GCDR_CLEAR_ASSET_KEYS)}
|
|
112205
112206
|
${devToClear.length + assetToClear.length === 0 ? '<div style="text-align:center; color:#6b7280; padding:16px 0; font-size:13px;">\u2705 Nenhum device ou asset possui essas chaves. Nada a limpar.</div>' : ""}`;
|
|
112206
112207
|
}
|
|
112207
|
-
renderShell(
|
|
112208
|
+
renderShell(progressHtml2("Buscando devices e assets\u2026", 0, 0), "");
|
|
112208
112209
|
try {
|
|
112209
112210
|
const [devicesResp, assetsResp] = await Promise.all([
|
|
112210
112211
|
tbFetch(state6, `/api/customer/${customerId}/devices?pageSize=1000&page=0`),
|
|
@@ -112233,7 +112234,7 @@ async function openClearGcdrIdsModal(state6) {
|
|
|
112233
112234
|
}));
|
|
112234
112235
|
const done = deviceRows.length + assetRows.length;
|
|
112235
112236
|
const bodyEl = overlay.querySelector("#gcdr-clear-body");
|
|
112236
|
-
if (bodyEl) bodyEl.innerHTML =
|
|
112237
|
+
if (bodyEl) bodyEl.innerHTML = progressHtml2(`Lendo SERVER_SCOPE (${entityType})\u2026`, done, total);
|
|
112237
112238
|
}
|
|
112238
112239
|
}
|
|
112239
112240
|
const fetchDeviceAttrs = async (id) => {
|
|
@@ -112263,7 +112264,7 @@ async function openClearGcdrIdsModal(state6) {
|
|
|
112263
112264
|
overlay.querySelector("#gcdr-clear-apply")?.addEventListener("click", async () => {
|
|
112264
112265
|
let done3 = 0;
|
|
112265
112266
|
overlay.querySelector("#gcdr-clear-footer").innerHTML = "";
|
|
112266
|
-
overlay.querySelector("#gcdr-clear-body").innerHTML =
|
|
112267
|
+
overlay.querySelector("#gcdr-clear-body").innerHTML = progressHtml2("Removendo atributos GCDR\u2026", 0, totalToClear);
|
|
112267
112268
|
async function execClear(rows, keys, entityType) {
|
|
112268
112269
|
const results = [];
|
|
112269
112270
|
const chunks = [];
|
|
@@ -112280,7 +112281,7 @@ async function openClearGcdrIdsModal(state6) {
|
|
|
112280
112281
|
}
|
|
112281
112282
|
done3++;
|
|
112282
112283
|
const progEl = overlay.querySelector("#gcdr-clear-body");
|
|
112283
|
-
if (progEl) progEl.innerHTML =
|
|
112284
|
+
if (progEl) progEl.innerHTML = progressHtml2("Removendo atributos GCDR\u2026", done3, totalToClear);
|
|
112284
112285
|
}));
|
|
112285
112286
|
}
|
|
112286
112287
|
return results;
|
|
@@ -115267,7 +115268,7 @@ function splitImportableDevices(devices) {
|
|
|
115267
115268
|
const missingKey = [];
|
|
115268
115269
|
for (const d of devices || []) {
|
|
115269
115270
|
const slave = Number(d?.slaveId);
|
|
115270
|
-
if (d?.centralId && UUID_RE.test(String(d.centralId)) && Number.isInteger(slave) && slave >= 1
|
|
115271
|
+
if (d?.centralId && UUID_RE.test(String(d.centralId)) && Number.isInteger(slave) && slave >= 1) ok.push(d);
|
|
115271
115272
|
else missingKey.push(d);
|
|
115272
115273
|
}
|
|
115273
115274
|
return { ok, missingKey };
|
|
@@ -115402,7 +115403,7 @@ function rowsFromTable(domain, table) {
|
|
|
115402
115403
|
}
|
|
115403
115404
|
const lineErrors = [];
|
|
115404
115405
|
if (!UUID_RE.test(gw)) lineErrors.push("gateway_id inv\xE1lido");
|
|
115405
|
-
if (!Number.isInteger(slave) || slave < 1
|
|
115406
|
+
if (!Number.isInteger(slave) || slave < 1) lineErrors.push("slave_id deve ser inteiro maior ou igual a 1");
|
|
115406
115407
|
if (!date) lineErrors.push("data inv\xE1lida (use AAAA-MM-DD)");
|
|
115407
115408
|
if (!hour) lineErrors.push("hora inv\xE1lida (use HH:00)");
|
|
115408
115409
|
if (Number.isNaN(value) || value < 0) lineErrors.push("valor deve ser n\xFAmero \u2265 0");
|
|
@@ -115963,20 +115964,12 @@ function nextManualSeq(domain, sigla, existingNames) {
|
|
|
115963
115964
|
}, 0);
|
|
115964
115965
|
return max + 1;
|
|
115965
115966
|
}
|
|
115966
|
-
async function
|
|
115967
|
-
const domain = params.domain;
|
|
115968
|
-
const profile = MANUAL_DEVICE_PROFILES[domain];
|
|
115969
|
-
if (!profile) throw new ManualDeviceError(`Dom\xEDnio inv\xE1lido: ${domain}`);
|
|
115970
|
-
const label = String(params.label || "").trim();
|
|
115971
|
-
const identifier = String(params.identifier || "").trim();
|
|
115972
|
-
if (!label) throw new ManualDeviceError("Informe a etiqueta.");
|
|
115973
|
-
if (!identifier) throw new ManualDeviceError("Informe o identificador.");
|
|
115974
|
-
if (!params.customerId) throw new ManualDeviceError("Cliente n\xE3o identificado.");
|
|
115967
|
+
async function buildTbApi(params) {
|
|
115975
115968
|
const base = params.baseUrl ?? "";
|
|
115976
115969
|
const doFetch = params.fetchImpl ?? fetch.bind(window);
|
|
115977
115970
|
const tokenValue = typeof params.token === "function" ? await params.token() : params.token;
|
|
115978
115971
|
const headers = { "X-Authorization": `Bearer ${tokenValue}`, "Content-Type": "application/json" };
|
|
115979
|
-
|
|
115972
|
+
return async (method, path, body, okStatuses = []) => {
|
|
115980
115973
|
const res = await doFetch(`${base}${path}`, {
|
|
115981
115974
|
method,
|
|
115982
115975
|
headers,
|
|
@@ -115989,7 +115982,9 @@ async function createManualDevice(params) {
|
|
|
115989
115982
|
const text2 = await res.text().catch(() => "");
|
|
115990
115983
|
return text2 ? JSON.parse(text2) : null;
|
|
115991
115984
|
};
|
|
115992
|
-
|
|
115985
|
+
}
|
|
115986
|
+
async function findManualAsset(api, customerId) {
|
|
115987
|
+
const cid = encodeURIComponent(customerId);
|
|
115993
115988
|
const assets = await api("GET", `/api/customer/${cid}/assets?pageSize=100&page=0&textSearch=MANUAIS`);
|
|
115994
115989
|
const asset = (assets?.data || []).find(
|
|
115995
115990
|
(a) => String(a?.name || "").toUpperCase().endsWith(MANUAL_ASSET_SUFFIX)
|
|
@@ -116007,12 +116002,45 @@ async function createManualDevice(params) {
|
|
|
116007
116002
|
`n\xE3o foi poss\xEDvel extrair a sigla de "${asset.name}"`
|
|
116008
116003
|
);
|
|
116009
116004
|
}
|
|
116005
|
+
return { asset, sigla };
|
|
116006
|
+
}
|
|
116007
|
+
async function existingManualNames(api, customerId, sigla) {
|
|
116010
116008
|
const existing = await api(
|
|
116011
116009
|
"GET",
|
|
116012
|
-
`/api/customer/${
|
|
116010
|
+
`/api/customer/${encodeURIComponent(customerId)}/devices?pageSize=1000&page=0&textSearch=${encodeURIComponent(`${sigla}_LOJA_`)}`
|
|
116013
116011
|
);
|
|
116014
|
-
|
|
116015
|
-
|
|
116012
|
+
return (existing?.data || []).map((d) => String(d?.name || ""));
|
|
116013
|
+
}
|
|
116014
|
+
async function resolveManualDeviceName(params) {
|
|
116015
|
+
const profile = MANUAL_DEVICE_PROFILES[params.domain];
|
|
116016
|
+
if (!profile) throw new ManualDeviceError(`Dom\xEDnio inv\xE1lido: ${params.domain}`);
|
|
116017
|
+
if (!params.customerId) throw new ManualDeviceError("Cliente n\xE3o identificado.");
|
|
116018
|
+
const api = await buildTbApi(params);
|
|
116019
|
+
const { asset, sigla } = await findManualAsset(api, params.customerId);
|
|
116020
|
+
const seq = nextManualSeq(params.domain, sigla, await existingManualNames(api, params.customerId, sigla));
|
|
116021
|
+
return {
|
|
116022
|
+
name: manualDeviceName(params.domain, sigla, seq),
|
|
116023
|
+
sigla,
|
|
116024
|
+
seq,
|
|
116025
|
+
assetId: asset.id.id,
|
|
116026
|
+
assetName: asset.name,
|
|
116027
|
+
deviceProfile: profile
|
|
116028
|
+
};
|
|
116029
|
+
}
|
|
116030
|
+
async function createManualDevice(params) {
|
|
116031
|
+
const domain = params.domain;
|
|
116032
|
+
const profile = MANUAL_DEVICE_PROFILES[domain];
|
|
116033
|
+
if (!profile) throw new ManualDeviceError(`Dom\xEDnio inv\xE1lido: ${domain}`);
|
|
116034
|
+
const label = String(params.label || "").trim();
|
|
116035
|
+
const identifier = String(params.identifier || "").trim();
|
|
116036
|
+
if (!label) throw new ManualDeviceError("Informe a etiqueta.");
|
|
116037
|
+
if (!identifier) throw new ManualDeviceError("Informe o identificador.");
|
|
116038
|
+
if (!params.customerId) throw new ManualDeviceError("Cliente n\xE3o identificado.");
|
|
116039
|
+
const api = await buildTbApi(params);
|
|
116040
|
+
const cid = encodeURIComponent(params.customerId);
|
|
116041
|
+
const { asset, sigla } = await findManualAsset(api, params.customerId);
|
|
116042
|
+
const fixedName = String(params.name || "").trim();
|
|
116043
|
+
let seq = fixedName ? 0 : nextManualSeq(domain, sigla, await existingManualNames(api, params.customerId, sigla));
|
|
116016
116044
|
let deviceProfileId;
|
|
116017
116045
|
try {
|
|
116018
116046
|
const profiles = await api("GET", `/api/deviceProfileInfos?pageSize=50&page=0&textSearch=${encodeURIComponent(profile)}`);
|
|
@@ -116020,7 +116048,7 @@ async function createManualDevice(params) {
|
|
|
116020
116048
|
if (p?.id?.id) deviceProfileId = { id: p.id.id, entityType: "DEVICE_PROFILE" };
|
|
116021
116049
|
} catch {
|
|
116022
116050
|
}
|
|
116023
|
-
let name = manualDeviceName(domain, sigla, seq);
|
|
116051
|
+
let name = fixedName || manualDeviceName(domain, sigla, seq);
|
|
116024
116052
|
let created = null;
|
|
116025
116053
|
for (let attempt = 0; ; attempt++) {
|
|
116026
116054
|
try {
|
|
@@ -116033,6 +116061,9 @@ async function createManualDevice(params) {
|
|
|
116033
116061
|
break;
|
|
116034
116062
|
} catch (err) {
|
|
116035
116063
|
const dup = /already exists|já existe/i.test(err?.detail || "");
|
|
116064
|
+
if (fixedName && dup) {
|
|
116065
|
+
throw new ManualDeviceError(`J\xE1 existe um dispositivo chamado ${fixedName} no ThingsBoard.`, err?.detail);
|
|
116066
|
+
}
|
|
116036
116067
|
if (!dup || attempt >= 4) throw err;
|
|
116037
116068
|
seq += 1;
|
|
116038
116069
|
name = manualDeviceName(domain, sigla, seq);
|
|
@@ -116055,6 +116086,7 @@ async function createManualDevice(params) {
|
|
|
116055
116086
|
typeGroup: "COMMON"
|
|
116056
116087
|
});
|
|
116057
116088
|
await api("POST", `/api/plugins/telemetry/DEVICE/${deviceId}/attributes/SERVER_SCOPE`, {
|
|
116089
|
+
...params.extraAttributes || {},
|
|
116058
116090
|
deviceProfile: profile,
|
|
116059
116091
|
identifier
|
|
116060
116092
|
});
|
|
@@ -116108,6 +116140,22 @@ function injectStyles15() {
|
|
|
116108
116140
|
border: 1px dashed #e5e7eb; border-radius: 6px; padding: 8px 10px; line-height: 1.6;
|
|
116109
116141
|
}
|
|
116110
116142
|
.myio-manualdev__tech code { font-size: 11.5px; color: #374151; }
|
|
116143
|
+
.myio-manualdev__summary { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
116144
|
+
.myio-manualdev__summary th { text-align: left; font-weight: 500; color: #6b7280; padding: 4px 8px 4px 0; width: 42%; vertical-align: top; }
|
|
116145
|
+
.myio-manualdev__summary td { color: #111827; padding: 4px 0; word-break: break-word; }
|
|
116146
|
+
.myio-manualdev__steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
|
|
116147
|
+
.myio-manualdev__step { display: grid; grid-template-columns: 22px 92px 1fr; gap: 8px; align-items: start; font-size: 13px; }
|
|
116148
|
+
.myio-manualdev__step-sys { font-weight: 600; color: #3e1a7d; }
|
|
116149
|
+
.myio-manualdev__step-msg { display: block; font-size: 11.5px; color: #6b7280; word-break: break-word; }
|
|
116150
|
+
.myio-manualdev__step[data-status="error"] .myio-manualdev__step-msg { color: #991b1b; }
|
|
116151
|
+
.myio-manualdev__step[data-status="warn"] .myio-manualdev__step-msg { color: #92400e; }
|
|
116152
|
+
.myio-manualdev__more { font-size: 13px; }
|
|
116153
|
+
.myio-manualdev__more > summary { cursor: pointer; color: #3e1a7d; font-weight: 500; font-size: 13px; }
|
|
116154
|
+
.myio-manualdev__more[open] > summary { margin-bottom: 10px; }
|
|
116155
|
+
.myio-manualdev__more > .myio-manualdev__summary { margin-bottom: 10px; }
|
|
116156
|
+
.myio-manualdev__note { margin: 0; font-size: 12.5px; border-radius: 6px; padding: 8px 10px; }
|
|
116157
|
+
.myio-manualdev__note--warn { color: #92400e; background: #fef3c7; }
|
|
116158
|
+
.myio-manualdev__note--block { color: #991b1b; background: #fee2e2; }
|
|
116111
116159
|
`;
|
|
116112
116160
|
document.head.appendChild(style);
|
|
116113
116161
|
}
|
|
@@ -116145,10 +116193,61 @@ function successHtml(domain, r, tech) {
|
|
|
116145
116193
|
</div>` : ""}
|
|
116146
116194
|
</div>`;
|
|
116147
116195
|
}
|
|
116196
|
+
var STEP_ICON = {
|
|
116197
|
+
pending: "\u25CB",
|
|
116198
|
+
running: "\u23F3",
|
|
116199
|
+
ok: "\u2705",
|
|
116200
|
+
warn: "\u26A0\uFE0F",
|
|
116201
|
+
error: "\u274C",
|
|
116202
|
+
skipped: "\u23ED\uFE0F",
|
|
116203
|
+
rolledback: "\u21A9\uFE0F"
|
|
116204
|
+
};
|
|
116205
|
+
function stepsHtml(steps) {
|
|
116206
|
+
return `<ol class="myio-manualdev__steps">${steps.map(
|
|
116207
|
+
(s) => `<li class="myio-manualdev__step" data-status="${escapeHtml14(s.status)}">
|
|
116208
|
+
<span aria-hidden="true">${STEP_ICON[s.status] || "\u25CB"}</span>
|
|
116209
|
+
<span class="myio-manualdev__step-sys">${escapeHtml14(s.system)}</span>
|
|
116210
|
+
<span>${escapeHtml14(s.title)}${s.message ? `<small class="myio-manualdev__step-msg">${escapeHtml14(s.message)}</small>` : ""}</span>
|
|
116211
|
+
</li>`
|
|
116212
|
+
).join("")}</ol>`;
|
|
116213
|
+
}
|
|
116214
|
+
function notesHtml(plan) {
|
|
116215
|
+
const block = (plan.blockers || []).map((b) => `<p class="myio-manualdev__note myio-manualdev__note--block" role="alert">\u26D4 ${escapeHtml14(b)}</p>`);
|
|
116216
|
+
const warn = (plan.warnings || []).map((w) => `<p class="myio-manualdev__note myio-manualdev__note--warn">\u26A0\uFE0F ${escapeHtml14(w)}</p>`);
|
|
116217
|
+
return [...block, ...warn].join("");
|
|
116218
|
+
}
|
|
116219
|
+
function rowsHtml(rows) {
|
|
116220
|
+
return `<table class="myio-manualdev__summary"><tbody>${rows.map((r) => `<tr><th>${escapeHtml14(r.label)}</th><td>${escapeHtml14(r.value)}</td></tr>`).join("")}</tbody></table>`;
|
|
116221
|
+
}
|
|
116222
|
+
function moreHtml(inner, open = false) {
|
|
116223
|
+
return `<details class="myio-manualdev__more"${open ? " open" : ""}>
|
|
116224
|
+
<summary>Ver mais detalhes</summary>
|
|
116225
|
+
${inner}
|
|
116226
|
+
</details>`;
|
|
116227
|
+
}
|
|
116228
|
+
function planHtml(plan) {
|
|
116229
|
+
return `
|
|
116230
|
+
<div class="myio-manualdev">
|
|
116231
|
+
<p class="myio-manualdev__hint">Revise o que ser\xE1 criado. Nada foi gravado ainda.</p>
|
|
116232
|
+
${rowsHtml(plan.summary)}
|
|
116233
|
+
${notesHtml(plan)}
|
|
116234
|
+
${moreHtml(`${plan.details?.length ? rowsHtml(plan.details) : ""}${stepsHtml(plan.steps)}`)}
|
|
116235
|
+
</div>`;
|
|
116236
|
+
}
|
|
116237
|
+
function progressHtml(steps, message, ok, open = false) {
|
|
116238
|
+
return `
|
|
116239
|
+
<div class="myio-manualdev">
|
|
116240
|
+
${ok === void 0 ? '<p class="myio-manualdev__hint">Criando o dispositivo\u2026 n\xE3o feche esta janela.</p>' : `<p class="myio-manualdev__note ${ok ? "myio-manualdev__note--warn" : "myio-manualdev__note--block"}" role="status">${escapeHtml14(
|
|
116241
|
+
message || (ok ? "Conclu\xEDdo com avisos." : "N\xE3o foi poss\xEDvel concluir.")
|
|
116242
|
+
)}</p>`}
|
|
116243
|
+
${moreHtml(stepsHtml(steps), open)}
|
|
116244
|
+
</div>`;
|
|
116245
|
+
}
|
|
116148
116246
|
function openManualDeviceModal(params) {
|
|
116149
116247
|
const domain = params.domain;
|
|
116150
116248
|
if (!MANUAL_DEVICE_PROFILES[domain]) throw new Error(`[openManualDeviceModal] dom\xEDnio inv\xE1lido: ${domain}`);
|
|
116151
116249
|
injectStyles15();
|
|
116250
|
+
if (params.provisioner) return openProvisionedModal(params, params.provisioner);
|
|
116152
116251
|
const values = { label: "", identifier: "" };
|
|
116153
116252
|
let busy = false;
|
|
116154
116253
|
let created = null;
|
|
@@ -116218,6 +116317,115 @@ function openManualDeviceModal(params) {
|
|
|
116218
116317
|
}
|
|
116219
116318
|
return modal;
|
|
116220
116319
|
}
|
|
116320
|
+
function openProvisionedModal(params, provisioner) {
|
|
116321
|
+
const domain = params.domain;
|
|
116322
|
+
const values = { label: "", identifier: "" };
|
|
116323
|
+
let phase = "form";
|
|
116324
|
+
let plan = null;
|
|
116325
|
+
let outcome = null;
|
|
116326
|
+
const modal = openStandardModal({
|
|
116327
|
+
title: DOMAIN_TEXT2[domain].title,
|
|
116328
|
+
icon: DOMAIN_TEXT2[domain].icon,
|
|
116329
|
+
bodyHtml: formHtml(domain, values),
|
|
116330
|
+
width: 560,
|
|
116331
|
+
container: params.container,
|
|
116332
|
+
buttons: [
|
|
116333
|
+
{ label: "Cancelar", value: "cancel", variant: "secondary" },
|
|
116334
|
+
{ label: "Voltar", value: "back", variant: "secondary", closeOnClick: false },
|
|
116335
|
+
{ label: "Revisar", value: "next", variant: "primary", closeOnClick: false }
|
|
116336
|
+
],
|
|
116337
|
+
onButton: (v) => {
|
|
116338
|
+
if (v === "back" && phase === "plan") return showForm();
|
|
116339
|
+
if (v !== "next") return;
|
|
116340
|
+
if (phase === "form") return void review();
|
|
116341
|
+
if (phase === "plan") return void apply();
|
|
116342
|
+
if (phase === "done") {
|
|
116343
|
+
modal.close();
|
|
116344
|
+
if (outcome?.result) params.onCreated?.(outcome.result);
|
|
116345
|
+
}
|
|
116346
|
+
}
|
|
116347
|
+
});
|
|
116348
|
+
modal.setButton("back", { hidden: true });
|
|
116349
|
+
const bindForm = (focus = true) => {
|
|
116350
|
+
const form = modal.getBodyEl().querySelector("form");
|
|
116351
|
+
form?.addEventListener("submit", (e) => {
|
|
116352
|
+
e.preventDefault();
|
|
116353
|
+
void review();
|
|
116354
|
+
});
|
|
116355
|
+
if (focus) form?.querySelector('input[name="label"]')?.focus();
|
|
116356
|
+
};
|
|
116357
|
+
bindForm();
|
|
116358
|
+
function showForm(error, detail) {
|
|
116359
|
+
phase = "form";
|
|
116360
|
+
modal.setBodyHtml(formHtml(domain, values, error, detail));
|
|
116361
|
+
bindForm();
|
|
116362
|
+
modal.setButton("back", { hidden: true });
|
|
116363
|
+
modal.setButton("cancel", { disabled: false, hidden: false });
|
|
116364
|
+
modal.setButton("next", { disabled: false, label: "Revisar" });
|
|
116365
|
+
}
|
|
116366
|
+
const errorText = (err) => {
|
|
116367
|
+
const msg = err instanceof ManualDeviceError ? err.message : "N\xE3o foi poss\xEDvel montar o plano.";
|
|
116368
|
+
const detail = params.showTechnicalDetails ? (err instanceof ManualDeviceError ? err.detail : String(err?.message || err)) || void 0 : void 0;
|
|
116369
|
+
return { msg, detail };
|
|
116370
|
+
};
|
|
116371
|
+
async function review() {
|
|
116372
|
+
if (phase !== "form") return;
|
|
116373
|
+
const body = modal.getBodyEl();
|
|
116374
|
+
values.label = (body.querySelector('input[name="label"]')?.value || "").trim();
|
|
116375
|
+
values.identifier = (body.querySelector('input[name="identifier"]')?.value || "").trim();
|
|
116376
|
+
const missing = !values.label ? "label" : !values.identifier ? "identifier" : null;
|
|
116377
|
+
if (missing) {
|
|
116378
|
+
showForm(missing === "label" ? "Informe a etiqueta." : "Informe o identificador.");
|
|
116379
|
+
const input = modal.getBodyEl().querySelector(`input[name="${missing}"]`);
|
|
116380
|
+
input?.setAttribute("aria-invalid", "true");
|
|
116381
|
+
input?.focus();
|
|
116382
|
+
return;
|
|
116383
|
+
}
|
|
116384
|
+
phase = "planning";
|
|
116385
|
+
modal.setButton("next", { disabled: true, label: "Revisando\u2026" });
|
|
116386
|
+
body.querySelectorAll("input").forEach((i) => i.disabled = true);
|
|
116387
|
+
try {
|
|
116388
|
+
plan = await provisioner.plan({ domain, label: values.label, identifier: values.identifier });
|
|
116389
|
+
phase = "plan";
|
|
116390
|
+
modal.setBodyHtml(planHtml(plan));
|
|
116391
|
+
modal.setButton("back", { hidden: false, disabled: false });
|
|
116392
|
+
modal.setButton("next", { disabled: !!plan.blockers?.length, label: "Criar" });
|
|
116393
|
+
} catch (err) {
|
|
116394
|
+
const { msg, detail } = errorText(err);
|
|
116395
|
+
showForm(msg, detail);
|
|
116396
|
+
}
|
|
116397
|
+
}
|
|
116398
|
+
async function apply() {
|
|
116399
|
+
if (phase !== "plan" || !plan || plan.blockers?.length) return;
|
|
116400
|
+
phase = "applying";
|
|
116401
|
+
const steps = plan.steps.map((s) => ({ ...s }));
|
|
116402
|
+
modal.setBodyHtml(progressHtml(steps));
|
|
116403
|
+
modal.setButton("back", { hidden: true });
|
|
116404
|
+
modal.setButton("cancel", { hidden: true });
|
|
116405
|
+
modal.setButton("next", { disabled: true, label: "Criando\u2026" });
|
|
116406
|
+
const moreOpen = () => !!modal.getBodyEl().querySelector(".myio-manualdev__more")?.open;
|
|
116407
|
+
const onStep = (step) => {
|
|
116408
|
+
const i = steps.findIndex((s) => s.key === step.key);
|
|
116409
|
+
if (i >= 0) steps[i] = { ...steps[i], ...step };
|
|
116410
|
+
else steps.push(step);
|
|
116411
|
+
modal.setBodyHtml(progressHtml(steps, void 0, void 0, moreOpen()));
|
|
116412
|
+
};
|
|
116413
|
+
try {
|
|
116414
|
+
outcome = await provisioner.apply(plan, onStep);
|
|
116415
|
+
} catch (err) {
|
|
116416
|
+
outcome = { ok: false, steps, message: errorText(err).msg };
|
|
116417
|
+
}
|
|
116418
|
+
phase = "done";
|
|
116419
|
+
const finalSteps = outcome.steps?.length ? outcome.steps : steps;
|
|
116420
|
+
const clean = outcome.ok && finalSteps.every((s) => s.status === "ok");
|
|
116421
|
+
modal.setBodyHtml(
|
|
116422
|
+
clean && outcome.result ? successHtml(domain, outcome.result, !!params.showTechnicalDetails) + (params.showTechnicalDetails ? moreHtml(stepsHtml(finalSteps)) : "") : progressHtml(finalSteps, outcome.message, outcome.ok, true)
|
|
116423
|
+
// algo deu errado: já mostra os passos
|
|
116424
|
+
);
|
|
116425
|
+
modal.setButton("next", { disabled: false, label: outcome.ok ? "Concluir" : "Fechar" });
|
|
116426
|
+
}
|
|
116427
|
+
return modal;
|
|
116428
|
+
}
|
|
116221
116429
|
|
|
116222
116430
|
// src/components/myio-gcdr-login/dom.ts
|
|
116223
116431
|
function h2(doc, tag, attrs = {}, ...children) {
|
|
@@ -151259,7 +151467,7 @@ var AlarmsNotificationsPanelView = class {
|
|
|
151259
151467
|
const selected = this.groupedAlarms.filter((a) => this.selectedIds.has(a.id));
|
|
151260
151468
|
const count = selected.length;
|
|
151261
151469
|
const listHtml = selected.slice(0, 5).map((a) => `<li class="abm-alarm-item">${this.esc(a.title)}</li>`).join("");
|
|
151262
|
-
const
|
|
151470
|
+
const moreHtml2 = count > 5 ? `<li class="abm-alarm-item abm-alarm-more">+${count - 5} mais...</li>` : "";
|
|
151263
151471
|
const overlay = document.createElement("div");
|
|
151264
151472
|
overlay.className = "abm-overlay";
|
|
151265
151473
|
overlay.innerHTML = `
|
|
@@ -151270,7 +151478,7 @@ var AlarmsNotificationsPanelView = class {
|
|
|
151270
151478
|
</div>
|
|
151271
151479
|
<div class="abm-body">
|
|
151272
151480
|
<div class="abm-count">${count} alarme${count !== 1 ? "s" : ""} selecionado${count !== 1 ? "s" : ""}</div>
|
|
151273
|
-
<ul class="abm-alarm-list">${listHtml}${
|
|
151481
|
+
<ul class="abm-alarm-list">${listHtml}${moreHtml2}</ul>
|
|
151274
151482
|
<div class="abm-action-label">Escolha a a\xE7\xE3o:</div>
|
|
151275
151483
|
<div class="abm-actions">
|
|
151276
151484
|
${this.isAlarmActionAllowed("acknowledge") ? `<button class="abm-action-btn abm-action-btn--ack" data-bulk-action="acknowledge">
|
|
@@ -151360,7 +151568,7 @@ var AlarmsNotificationsPanelView = class {
|
|
|
151360
151568
|
const sev = SEVERITY_CONFIG[a.severity];
|
|
151361
151569
|
return `<div class="aam-alarm-item"><span class="aam-alarm-sev" style="background:${sev.bg};color:${sev.text}">${sev.icon}</span><span>${this.esc(a.title)}</span></div>`;
|
|
151362
151570
|
}).join("");
|
|
151363
|
-
const
|
|
151571
|
+
const moreHtml2 = count > 5 ? `<div class="aam-alarm-more">+${count - 5} alarmes</div>` : "";
|
|
151364
151572
|
const durationHtml = cfg.showDuration ? `<div class="aam-field-group">
|
|
151365
151573
|
<label class="alarm-action-modal__label">Dura\xE7\xE3o do adiamento</label>
|
|
151366
151574
|
<select class="alarm-action-modal__select" id="aamDuration">
|
|
@@ -151382,7 +151590,7 @@ var AlarmsNotificationsPanelView = class {
|
|
|
151382
151590
|
</div>
|
|
151383
151591
|
<div class="aam-summary">
|
|
151384
151592
|
<div class="aam-summary-header-label">${count} alarme${count !== 1 ? "s" : ""} selecionado${count !== 1 ? "s" : ""}</div>
|
|
151385
|
-
<div class="aam-alarm-list-bulk">${listHtml}${
|
|
151593
|
+
<div class="aam-alarm-list-bulk">${listHtml}${moreHtml2}</div>
|
|
151386
151594
|
</div>
|
|
151387
151595
|
<div class="alarm-action-modal__body">
|
|
151388
151596
|
${durationHtml}
|
|
@@ -179107,6 +179315,7 @@ var version = package_default.version || "0.0.0";
|
|
|
179107
179315
|
resolveClassification,
|
|
179108
179316
|
resolveGoalAmount,
|
|
179109
179317
|
resolveGroup,
|
|
179318
|
+
resolveManualDeviceName,
|
|
179110
179319
|
resolveMoneyRollout,
|
|
179111
179320
|
resolveMoneyRowValues,
|
|
179112
179321
|
resolvePercentDecimals,
|