myio-js-library 0.1.341 → 0.1.342
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 +132 -4
- package/dist/index.js +132 -4
- package/dist/myio-js-library.umd.js +132 -4
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -971,7 +971,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
971
971
|
// package.json
|
|
972
972
|
var package_default = {
|
|
973
973
|
name: "myio-js-library",
|
|
974
|
-
version: "0.1.
|
|
974
|
+
version: "0.1.342",
|
|
975
975
|
description: "A clean, standalone JS SDK for MYIO projects",
|
|
976
976
|
license: "MIT",
|
|
977
977
|
repository: "github:gh-myio/myio-js-library",
|
|
@@ -2999,6 +2999,132 @@ function buildEntityObject(config, item, context) {
|
|
|
2999
2999
|
powerRanges: item.powerRanges || null
|
|
3000
3000
|
};
|
|
3001
3001
|
}
|
|
3002
|
+
function createDefaultActionHandlers(config, entityObject, item) {
|
|
3003
|
+
const MyIOLibrary2 = typeof window !== "undefined" && window.MyIOLibrary;
|
|
3004
|
+
const MyIOUtils = typeof window !== "undefined" && window.MyIOUtils;
|
|
3005
|
+
const MyIOAuth = MyIOUtils?.MyIOAuth;
|
|
3006
|
+
const CLIENT_ID = MyIOUtils?.CLIENT_ID;
|
|
3007
|
+
const CLIENT_SECRET = MyIOUtils?.CLIENT_SECRET;
|
|
3008
|
+
const getDataApiHost = MyIOUtils?.getDataApiHost || (() => "https://api.data.apps.myio-bas.com");
|
|
3009
|
+
return {
|
|
3010
|
+
handleActionDashboard: async () => {
|
|
3011
|
+
LogHelper2.log(`[${config.widgetName}] Opening dashboard for:`, entityObject.entityId);
|
|
3012
|
+
try {
|
|
3013
|
+
if (typeof MyIOLibrary2?.openDashboardPopupEnergy !== "function") {
|
|
3014
|
+
window.alert("Dashboard component n\xE3o dispon\xEDvel");
|
|
3015
|
+
return;
|
|
3016
|
+
}
|
|
3017
|
+
const startDate = window.STATE?.period?.startDateISO || MyIOUtils?.currentPeriod?.startDateISO;
|
|
3018
|
+
const endDate = window.STATE?.period?.endDateISO || MyIOUtils?.currentPeriod?.endDateISO;
|
|
3019
|
+
if (!startDate || !endDate) {
|
|
3020
|
+
window.alert("Per\xEDodo de datas n\xE3o definido.");
|
|
3021
|
+
return;
|
|
3022
|
+
}
|
|
3023
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
3024
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available`);
|
|
3025
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
const tokenIngestionDashBoard = await MyIOAuth.getToken();
|
|
3029
|
+
const myTbTokenDashBoard = localStorage.getItem("jwt_token");
|
|
3030
|
+
MyIOLibrary2.openDashboardPopupEnergy({
|
|
3031
|
+
deviceId: entityObject.entityId,
|
|
3032
|
+
readingType: config.domain,
|
|
3033
|
+
// 'water' or 'energy'
|
|
3034
|
+
startDate,
|
|
3035
|
+
endDate,
|
|
3036
|
+
tbJwtToken: myTbTokenDashBoard,
|
|
3037
|
+
ingestionToken: tokenIngestionDashBoard,
|
|
3038
|
+
clientId: CLIENT_ID,
|
|
3039
|
+
clientSecret: CLIENT_SECRET,
|
|
3040
|
+
onClose: () => {
|
|
3041
|
+
const o = document.querySelector(".myio-modal-overlay");
|
|
3042
|
+
if (o) o.remove();
|
|
3043
|
+
}
|
|
3044
|
+
});
|
|
3045
|
+
} catch (err) {
|
|
3046
|
+
LogHelper2.error(`[${config.widgetName}] Error opening dashboard:`, err);
|
|
3047
|
+
window.alert("Erro ao abrir dashboard");
|
|
3048
|
+
}
|
|
3049
|
+
},
|
|
3050
|
+
handleActionReport: async () => {
|
|
3051
|
+
LogHelper2.log(`[${config.widgetName}] Opening report for:`, item.ingestionId);
|
|
3052
|
+
try {
|
|
3053
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
3054
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available for report`);
|
|
3055
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
const ingestionToken2 = await MyIOAuth.getToken();
|
|
3059
|
+
await MyIOLibrary2?.openDashboardPopupReport?.({
|
|
3060
|
+
ingestionId: item.ingestionId,
|
|
3061
|
+
identifier: item.identifier,
|
|
3062
|
+
label: item.label,
|
|
3063
|
+
domain: config.domain,
|
|
3064
|
+
api: {
|
|
3065
|
+
dataApiBaseUrl: getDataApiHost(),
|
|
3066
|
+
clientId: CLIENT_ID,
|
|
3067
|
+
clientSecret: CLIENT_SECRET,
|
|
3068
|
+
ingestionToken: ingestionToken2
|
|
3069
|
+
}
|
|
3070
|
+
});
|
|
3071
|
+
} catch (err) {
|
|
3072
|
+
LogHelper2.error(`[${config.widgetName}] Error opening report:`, err);
|
|
3073
|
+
window.alert("Erro ao abrir relat\xF3rio");
|
|
3074
|
+
}
|
|
3075
|
+
},
|
|
3076
|
+
handleActionSettings: async () => {
|
|
3077
|
+
LogHelper2.log(`[${config.widgetName}] Opening settings for:`, entityObject.entityId);
|
|
3078
|
+
const jwt = localStorage.getItem("jwt_token");
|
|
3079
|
+
if (!jwt) {
|
|
3080
|
+
LogHelper2.error(`[${config.widgetName}] JWT token not found`);
|
|
3081
|
+
window.alert("Token de autentica\xE7\xE3o n\xE3o encontrado");
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
const tbId = entityObject.entityId;
|
|
3085
|
+
if (!tbId || tbId === item.ingestionId) {
|
|
3086
|
+
window.alert("ID inv\xE1lido");
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
3089
|
+
try {
|
|
3090
|
+
await MyIOLibrary2?.openDashboardPopupSettings?.({
|
|
3091
|
+
deviceId: tbId,
|
|
3092
|
+
label: item.label,
|
|
3093
|
+
jwtToken: jwt,
|
|
3094
|
+
domain: config.domain,
|
|
3095
|
+
deviceType: entityObject.deviceType,
|
|
3096
|
+
deviceProfile: entityObject.deviceProfile,
|
|
3097
|
+
customerName: entityObject.customerName,
|
|
3098
|
+
connectionData: {
|
|
3099
|
+
centralName: entityObject.centralName,
|
|
3100
|
+
connectionStatusTime: entityObject.connectionStatusTime,
|
|
3101
|
+
timeVal: entityObject.timeVal || (/* @__PURE__ */ new Date("1970-01-01")).getTime(),
|
|
3102
|
+
deviceStatus: entityObject.deviceStatus !== "power_off" && entityObject.deviceStatus !== "not_installed" ? "power_on" : "power_off",
|
|
3103
|
+
lastDisconnectTime: entityObject.lastDisconnectTime || 0
|
|
3104
|
+
},
|
|
3105
|
+
ui: { title: "Configura\xE7\xF5es", width: 900 },
|
|
3106
|
+
mapInstantaneousPower: entityObject.mapInstantaneousPower,
|
|
3107
|
+
onSaved: (payload) => {
|
|
3108
|
+
LogHelper2.log(`[${config.widgetName}] Settings saved:`, payload);
|
|
3109
|
+
if (typeof window.showGlobalSuccessModal === "function") {
|
|
3110
|
+
window.showGlobalSuccessModal(6);
|
|
3111
|
+
}
|
|
3112
|
+
},
|
|
3113
|
+
onClose: () => {
|
|
3114
|
+
const settingsOverlay = document.querySelector(".myio-settings-modal-overlay");
|
|
3115
|
+
if (settingsOverlay) settingsOverlay.remove();
|
|
3116
|
+
const overlay = document.querySelector(".myio-modal-overlay");
|
|
3117
|
+
if (overlay) overlay.remove();
|
|
3118
|
+
LogHelper2.log(`[${config.widgetName}] Settings modal closed`);
|
|
3119
|
+
}
|
|
3120
|
+
});
|
|
3121
|
+
} catch (e) {
|
|
3122
|
+
LogHelper2.error(`[${config.widgetName}] Error opening settings:`, e);
|
|
3123
|
+
window.alert("Erro ao abrir configura\xE7\xF5es");
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
};
|
|
3127
|
+
}
|
|
3002
3128
|
async function renderList(config, STATE, visible, context) {
|
|
3003
3129
|
const listElement = document.getElementById(config.listElementId);
|
|
3004
3130
|
if (!listElement) {
|
|
@@ -3011,6 +3137,7 @@ async function renderList(config, STATE, visible, context) {
|
|
|
3011
3137
|
const container = document.createElement("div");
|
|
3012
3138
|
listElement.appendChild(container);
|
|
3013
3139
|
const entityObject = buildEntityObject(config, item, context);
|
|
3140
|
+
const defaultHandlers = createDefaultActionHandlers(config, entityObject, item);
|
|
3014
3141
|
if (MyIOLibrary2?.renderCardComponentHeadOffice) {
|
|
3015
3142
|
MyIOLibrary2.renderCardComponentHeadOffice(container, {
|
|
3016
3143
|
entityObject,
|
|
@@ -3020,9 +3147,10 @@ async function renderList(config, STATE, visible, context) {
|
|
|
3020
3147
|
handleClickCard: (ev, entity) => {
|
|
3021
3148
|
LogHelper2.log(`[${config.widgetName}] Card clicked: ${entity.name}`);
|
|
3022
3149
|
},
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3150
|
+
// RFC-0144: Use context handlers if provided, otherwise use defaults
|
|
3151
|
+
handleActionDashboard: context?.handleActionDashboard ? () => context.handleActionDashboard(entityObject, item) : defaultHandlers.handleActionDashboard,
|
|
3152
|
+
handleActionReport: context?.handleActionReport ? () => context.handleActionReport(entityObject, item) : defaultHandlers.handleActionReport,
|
|
3153
|
+
handleActionSettings: context?.handleActionSettings ? () => context.handleActionSettings(entityObject, item) : defaultHandlers.handleActionSettings,
|
|
3026
3154
|
handleSelect: (checked, entity) => {
|
|
3027
3155
|
if (!STATE.selectedIds) STATE.selectedIds = /* @__PURE__ */ new Set();
|
|
3028
3156
|
const MyIOSelectionStore2 = typeof window !== "undefined" && window.MyIOLibrary?.MyIOSelectionStore || typeof window !== "undefined" && window.MyIOSelectionStore;
|
package/dist/index.js
CHANGED
|
@@ -546,7 +546,7 @@ var init_template_card = __esm({
|
|
|
546
546
|
// package.json
|
|
547
547
|
var package_default = {
|
|
548
548
|
name: "myio-js-library",
|
|
549
|
-
version: "0.1.
|
|
549
|
+
version: "0.1.342",
|
|
550
550
|
description: "A clean, standalone JS SDK for MYIO projects",
|
|
551
551
|
license: "MIT",
|
|
552
552
|
repository: "github:gh-myio/myio-js-library",
|
|
@@ -2574,6 +2574,132 @@ function buildEntityObject(config, item, context) {
|
|
|
2574
2574
|
powerRanges: item.powerRanges || null
|
|
2575
2575
|
};
|
|
2576
2576
|
}
|
|
2577
|
+
function createDefaultActionHandlers(config, entityObject, item) {
|
|
2578
|
+
const MyIOLibrary2 = typeof window !== "undefined" && window.MyIOLibrary;
|
|
2579
|
+
const MyIOUtils = typeof window !== "undefined" && window.MyIOUtils;
|
|
2580
|
+
const MyIOAuth = MyIOUtils?.MyIOAuth;
|
|
2581
|
+
const CLIENT_ID = MyIOUtils?.CLIENT_ID;
|
|
2582
|
+
const CLIENT_SECRET = MyIOUtils?.CLIENT_SECRET;
|
|
2583
|
+
const getDataApiHost = MyIOUtils?.getDataApiHost || (() => "https://api.data.apps.myio-bas.com");
|
|
2584
|
+
return {
|
|
2585
|
+
handleActionDashboard: async () => {
|
|
2586
|
+
LogHelper2.log(`[${config.widgetName}] Opening dashboard for:`, entityObject.entityId);
|
|
2587
|
+
try {
|
|
2588
|
+
if (typeof MyIOLibrary2?.openDashboardPopupEnergy !== "function") {
|
|
2589
|
+
window.alert("Dashboard component n\xE3o dispon\xEDvel");
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
const startDate = window.STATE?.period?.startDateISO || MyIOUtils?.currentPeriod?.startDateISO;
|
|
2593
|
+
const endDate = window.STATE?.period?.endDateISO || MyIOUtils?.currentPeriod?.endDateISO;
|
|
2594
|
+
if (!startDate || !endDate) {
|
|
2595
|
+
window.alert("Per\xEDodo de datas n\xE3o definido.");
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
2599
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available`);
|
|
2600
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
const tokenIngestionDashBoard = await MyIOAuth.getToken();
|
|
2604
|
+
const myTbTokenDashBoard = localStorage.getItem("jwt_token");
|
|
2605
|
+
MyIOLibrary2.openDashboardPopupEnergy({
|
|
2606
|
+
deviceId: entityObject.entityId,
|
|
2607
|
+
readingType: config.domain,
|
|
2608
|
+
// 'water' or 'energy'
|
|
2609
|
+
startDate,
|
|
2610
|
+
endDate,
|
|
2611
|
+
tbJwtToken: myTbTokenDashBoard,
|
|
2612
|
+
ingestionToken: tokenIngestionDashBoard,
|
|
2613
|
+
clientId: CLIENT_ID,
|
|
2614
|
+
clientSecret: CLIENT_SECRET,
|
|
2615
|
+
onClose: () => {
|
|
2616
|
+
const o = document.querySelector(".myio-modal-overlay");
|
|
2617
|
+
if (o) o.remove();
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
} catch (err) {
|
|
2621
|
+
LogHelper2.error(`[${config.widgetName}] Error opening dashboard:`, err);
|
|
2622
|
+
window.alert("Erro ao abrir dashboard");
|
|
2623
|
+
}
|
|
2624
|
+
},
|
|
2625
|
+
handleActionReport: async () => {
|
|
2626
|
+
LogHelper2.log(`[${config.widgetName}] Opening report for:`, item.ingestionId);
|
|
2627
|
+
try {
|
|
2628
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
2629
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available for report`);
|
|
2630
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
2631
|
+
return;
|
|
2632
|
+
}
|
|
2633
|
+
const ingestionToken2 = await MyIOAuth.getToken();
|
|
2634
|
+
await MyIOLibrary2?.openDashboardPopupReport?.({
|
|
2635
|
+
ingestionId: item.ingestionId,
|
|
2636
|
+
identifier: item.identifier,
|
|
2637
|
+
label: item.label,
|
|
2638
|
+
domain: config.domain,
|
|
2639
|
+
api: {
|
|
2640
|
+
dataApiBaseUrl: getDataApiHost(),
|
|
2641
|
+
clientId: CLIENT_ID,
|
|
2642
|
+
clientSecret: CLIENT_SECRET,
|
|
2643
|
+
ingestionToken: ingestionToken2
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
} catch (err) {
|
|
2647
|
+
LogHelper2.error(`[${config.widgetName}] Error opening report:`, err);
|
|
2648
|
+
window.alert("Erro ao abrir relat\xF3rio");
|
|
2649
|
+
}
|
|
2650
|
+
},
|
|
2651
|
+
handleActionSettings: async () => {
|
|
2652
|
+
LogHelper2.log(`[${config.widgetName}] Opening settings for:`, entityObject.entityId);
|
|
2653
|
+
const jwt = localStorage.getItem("jwt_token");
|
|
2654
|
+
if (!jwt) {
|
|
2655
|
+
LogHelper2.error(`[${config.widgetName}] JWT token not found`);
|
|
2656
|
+
window.alert("Token de autentica\xE7\xE3o n\xE3o encontrado");
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
const tbId = entityObject.entityId;
|
|
2660
|
+
if (!tbId || tbId === item.ingestionId) {
|
|
2661
|
+
window.alert("ID inv\xE1lido");
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
try {
|
|
2665
|
+
await MyIOLibrary2?.openDashboardPopupSettings?.({
|
|
2666
|
+
deviceId: tbId,
|
|
2667
|
+
label: item.label,
|
|
2668
|
+
jwtToken: jwt,
|
|
2669
|
+
domain: config.domain,
|
|
2670
|
+
deviceType: entityObject.deviceType,
|
|
2671
|
+
deviceProfile: entityObject.deviceProfile,
|
|
2672
|
+
customerName: entityObject.customerName,
|
|
2673
|
+
connectionData: {
|
|
2674
|
+
centralName: entityObject.centralName,
|
|
2675
|
+
connectionStatusTime: entityObject.connectionStatusTime,
|
|
2676
|
+
timeVal: entityObject.timeVal || (/* @__PURE__ */ new Date("1970-01-01")).getTime(),
|
|
2677
|
+
deviceStatus: entityObject.deviceStatus !== "power_off" && entityObject.deviceStatus !== "not_installed" ? "power_on" : "power_off",
|
|
2678
|
+
lastDisconnectTime: entityObject.lastDisconnectTime || 0
|
|
2679
|
+
},
|
|
2680
|
+
ui: { title: "Configura\xE7\xF5es", width: 900 },
|
|
2681
|
+
mapInstantaneousPower: entityObject.mapInstantaneousPower,
|
|
2682
|
+
onSaved: (payload) => {
|
|
2683
|
+
LogHelper2.log(`[${config.widgetName}] Settings saved:`, payload);
|
|
2684
|
+
if (typeof window.showGlobalSuccessModal === "function") {
|
|
2685
|
+
window.showGlobalSuccessModal(6);
|
|
2686
|
+
}
|
|
2687
|
+
},
|
|
2688
|
+
onClose: () => {
|
|
2689
|
+
const settingsOverlay = document.querySelector(".myio-settings-modal-overlay");
|
|
2690
|
+
if (settingsOverlay) settingsOverlay.remove();
|
|
2691
|
+
const overlay = document.querySelector(".myio-modal-overlay");
|
|
2692
|
+
if (overlay) overlay.remove();
|
|
2693
|
+
LogHelper2.log(`[${config.widgetName}] Settings modal closed`);
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2696
|
+
} catch (e) {
|
|
2697
|
+
LogHelper2.error(`[${config.widgetName}] Error opening settings:`, e);
|
|
2698
|
+
window.alert("Erro ao abrir configura\xE7\xF5es");
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2577
2703
|
async function renderList(config, STATE, visible, context) {
|
|
2578
2704
|
const listElement = document.getElementById(config.listElementId);
|
|
2579
2705
|
if (!listElement) {
|
|
@@ -2586,6 +2712,7 @@ async function renderList(config, STATE, visible, context) {
|
|
|
2586
2712
|
const container = document.createElement("div");
|
|
2587
2713
|
listElement.appendChild(container);
|
|
2588
2714
|
const entityObject = buildEntityObject(config, item, context);
|
|
2715
|
+
const defaultHandlers = createDefaultActionHandlers(config, entityObject, item);
|
|
2589
2716
|
if (MyIOLibrary2?.renderCardComponentHeadOffice) {
|
|
2590
2717
|
MyIOLibrary2.renderCardComponentHeadOffice(container, {
|
|
2591
2718
|
entityObject,
|
|
@@ -2595,9 +2722,10 @@ async function renderList(config, STATE, visible, context) {
|
|
|
2595
2722
|
handleClickCard: (ev, entity) => {
|
|
2596
2723
|
LogHelper2.log(`[${config.widgetName}] Card clicked: ${entity.name}`);
|
|
2597
2724
|
},
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2725
|
+
// RFC-0144: Use context handlers if provided, otherwise use defaults
|
|
2726
|
+
handleActionDashboard: context?.handleActionDashboard ? () => context.handleActionDashboard(entityObject, item) : defaultHandlers.handleActionDashboard,
|
|
2727
|
+
handleActionReport: context?.handleActionReport ? () => context.handleActionReport(entityObject, item) : defaultHandlers.handleActionReport,
|
|
2728
|
+
handleActionSettings: context?.handleActionSettings ? () => context.handleActionSettings(entityObject, item) : defaultHandlers.handleActionSettings,
|
|
2601
2729
|
handleSelect: (checked, entity) => {
|
|
2602
2730
|
if (!STATE.selectedIds) STATE.selectedIds = /* @__PURE__ */ new Set();
|
|
2603
2731
|
const MyIOSelectionStore2 = typeof window !== "undefined" && window.MyIOLibrary?.MyIOSelectionStore || typeof window !== "undefined" && window.MyIOSelectionStore;
|
|
@@ -551,7 +551,7 @@
|
|
|
551
551
|
|
|
552
552
|
// package.json
|
|
553
553
|
var package_default = {
|
|
554
|
-
version: "0.1.
|
|
554
|
+
version: "0.1.342"};
|
|
555
555
|
|
|
556
556
|
// src/format/energy.ts
|
|
557
557
|
function formatEnergy(value, unit, decimals = 3) {
|
|
@@ -2521,6 +2521,132 @@
|
|
|
2521
2521
|
powerRanges: item.powerRanges || null
|
|
2522
2522
|
};
|
|
2523
2523
|
}
|
|
2524
|
+
function createDefaultActionHandlers(config, entityObject, item) {
|
|
2525
|
+
const MyIOLibrary2 = typeof window !== "undefined" && window.MyIOLibrary;
|
|
2526
|
+
const MyIOUtils = typeof window !== "undefined" && window.MyIOUtils;
|
|
2527
|
+
const MyIOAuth = MyIOUtils?.MyIOAuth;
|
|
2528
|
+
const CLIENT_ID = MyIOUtils?.CLIENT_ID;
|
|
2529
|
+
const CLIENT_SECRET = MyIOUtils?.CLIENT_SECRET;
|
|
2530
|
+
const getDataApiHost = MyIOUtils?.getDataApiHost || (() => "https://api.data.apps.myio-bas.com");
|
|
2531
|
+
return {
|
|
2532
|
+
handleActionDashboard: async () => {
|
|
2533
|
+
LogHelper2.log(`[${config.widgetName}] Opening dashboard for:`, entityObject.entityId);
|
|
2534
|
+
try {
|
|
2535
|
+
if (typeof MyIOLibrary2?.openDashboardPopupEnergy !== "function") {
|
|
2536
|
+
window.alert("Dashboard component n\xE3o dispon\xEDvel");
|
|
2537
|
+
return;
|
|
2538
|
+
}
|
|
2539
|
+
const startDate = window.STATE?.period?.startDateISO || MyIOUtils?.currentPeriod?.startDateISO;
|
|
2540
|
+
const endDate = window.STATE?.period?.endDateISO || MyIOUtils?.currentPeriod?.endDateISO;
|
|
2541
|
+
if (!startDate || !endDate) {
|
|
2542
|
+
window.alert("Per\xEDodo de datas n\xE3o definido.");
|
|
2543
|
+
return;
|
|
2544
|
+
}
|
|
2545
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
2546
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available`);
|
|
2547
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
const tokenIngestionDashBoard = await MyIOAuth.getToken();
|
|
2551
|
+
const myTbTokenDashBoard = localStorage.getItem("jwt_token");
|
|
2552
|
+
MyIOLibrary2.openDashboardPopupEnergy({
|
|
2553
|
+
deviceId: entityObject.entityId,
|
|
2554
|
+
readingType: config.domain,
|
|
2555
|
+
// 'water' or 'energy'
|
|
2556
|
+
startDate,
|
|
2557
|
+
endDate,
|
|
2558
|
+
tbJwtToken: myTbTokenDashBoard,
|
|
2559
|
+
ingestionToken: tokenIngestionDashBoard,
|
|
2560
|
+
clientId: CLIENT_ID,
|
|
2561
|
+
clientSecret: CLIENT_SECRET,
|
|
2562
|
+
onClose: () => {
|
|
2563
|
+
const o = document.querySelector(".myio-modal-overlay");
|
|
2564
|
+
if (o) o.remove();
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
} catch (err) {
|
|
2568
|
+
LogHelper2.error(`[${config.widgetName}] Error opening dashboard:`, err);
|
|
2569
|
+
window.alert("Erro ao abrir dashboard");
|
|
2570
|
+
}
|
|
2571
|
+
},
|
|
2572
|
+
handleActionReport: async () => {
|
|
2573
|
+
LogHelper2.log(`[${config.widgetName}] Opening report for:`, item.ingestionId);
|
|
2574
|
+
try {
|
|
2575
|
+
if (!MyIOAuth || typeof MyIOAuth.getToken !== "function") {
|
|
2576
|
+
LogHelper2.error(`[${config.widgetName}] MyIOAuth not available for report`);
|
|
2577
|
+
window.alert("Autentica\xE7\xE3o n\xE3o dispon\xEDvel. Recarregue a p\xE1gina.");
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
const ingestionToken2 = await MyIOAuth.getToken();
|
|
2581
|
+
await MyIOLibrary2?.openDashboardPopupReport?.({
|
|
2582
|
+
ingestionId: item.ingestionId,
|
|
2583
|
+
identifier: item.identifier,
|
|
2584
|
+
label: item.label,
|
|
2585
|
+
domain: config.domain,
|
|
2586
|
+
api: {
|
|
2587
|
+
dataApiBaseUrl: getDataApiHost(),
|
|
2588
|
+
clientId: CLIENT_ID,
|
|
2589
|
+
clientSecret: CLIENT_SECRET,
|
|
2590
|
+
ingestionToken: ingestionToken2
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
} catch (err) {
|
|
2594
|
+
LogHelper2.error(`[${config.widgetName}] Error opening report:`, err);
|
|
2595
|
+
window.alert("Erro ao abrir relat\xF3rio");
|
|
2596
|
+
}
|
|
2597
|
+
},
|
|
2598
|
+
handleActionSettings: async () => {
|
|
2599
|
+
LogHelper2.log(`[${config.widgetName}] Opening settings for:`, entityObject.entityId);
|
|
2600
|
+
const jwt = localStorage.getItem("jwt_token");
|
|
2601
|
+
if (!jwt) {
|
|
2602
|
+
LogHelper2.error(`[${config.widgetName}] JWT token not found`);
|
|
2603
|
+
window.alert("Token de autentica\xE7\xE3o n\xE3o encontrado");
|
|
2604
|
+
return;
|
|
2605
|
+
}
|
|
2606
|
+
const tbId = entityObject.entityId;
|
|
2607
|
+
if (!tbId || tbId === item.ingestionId) {
|
|
2608
|
+
window.alert("ID inv\xE1lido");
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
try {
|
|
2612
|
+
await MyIOLibrary2?.openDashboardPopupSettings?.({
|
|
2613
|
+
deviceId: tbId,
|
|
2614
|
+
label: item.label,
|
|
2615
|
+
jwtToken: jwt,
|
|
2616
|
+
domain: config.domain,
|
|
2617
|
+
deviceType: entityObject.deviceType,
|
|
2618
|
+
deviceProfile: entityObject.deviceProfile,
|
|
2619
|
+
customerName: entityObject.customerName,
|
|
2620
|
+
connectionData: {
|
|
2621
|
+
centralName: entityObject.centralName,
|
|
2622
|
+
connectionStatusTime: entityObject.connectionStatusTime,
|
|
2623
|
+
timeVal: entityObject.timeVal || (/* @__PURE__ */ new Date("1970-01-01")).getTime(),
|
|
2624
|
+
deviceStatus: entityObject.deviceStatus !== "power_off" && entityObject.deviceStatus !== "not_installed" ? "power_on" : "power_off",
|
|
2625
|
+
lastDisconnectTime: entityObject.lastDisconnectTime || 0
|
|
2626
|
+
},
|
|
2627
|
+
ui: { title: "Configura\xE7\xF5es", width: 900 },
|
|
2628
|
+
mapInstantaneousPower: entityObject.mapInstantaneousPower,
|
|
2629
|
+
onSaved: (payload) => {
|
|
2630
|
+
LogHelper2.log(`[${config.widgetName}] Settings saved:`, payload);
|
|
2631
|
+
if (typeof window.showGlobalSuccessModal === "function") {
|
|
2632
|
+
window.showGlobalSuccessModal(6);
|
|
2633
|
+
}
|
|
2634
|
+
},
|
|
2635
|
+
onClose: () => {
|
|
2636
|
+
const settingsOverlay = document.querySelector(".myio-settings-modal-overlay");
|
|
2637
|
+
if (settingsOverlay) settingsOverlay.remove();
|
|
2638
|
+
const overlay = document.querySelector(".myio-modal-overlay");
|
|
2639
|
+
if (overlay) overlay.remove();
|
|
2640
|
+
LogHelper2.log(`[${config.widgetName}] Settings modal closed`);
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
} catch (e) {
|
|
2644
|
+
LogHelper2.error(`[${config.widgetName}] Error opening settings:`, e);
|
|
2645
|
+
window.alert("Erro ao abrir configura\xE7\xF5es");
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2524
2650
|
async function renderList(config, STATE, visible, context) {
|
|
2525
2651
|
const listElement = document.getElementById(config.listElementId);
|
|
2526
2652
|
if (!listElement) {
|
|
@@ -2533,6 +2659,7 @@
|
|
|
2533
2659
|
const container = document.createElement("div");
|
|
2534
2660
|
listElement.appendChild(container);
|
|
2535
2661
|
const entityObject = buildEntityObject(config, item, context);
|
|
2662
|
+
const defaultHandlers = createDefaultActionHandlers(config, entityObject, item);
|
|
2536
2663
|
if (MyIOLibrary2?.renderCardComponentHeadOffice) {
|
|
2537
2664
|
MyIOLibrary2.renderCardComponentHeadOffice(container, {
|
|
2538
2665
|
entityObject,
|
|
@@ -2542,9 +2669,10 @@
|
|
|
2542
2669
|
handleClickCard: (ev, entity) => {
|
|
2543
2670
|
LogHelper2.log(`[${config.widgetName}] Card clicked: ${entity.name}`);
|
|
2544
2671
|
},
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2672
|
+
// RFC-0144: Use context handlers if provided, otherwise use defaults
|
|
2673
|
+
handleActionDashboard: context?.handleActionDashboard ? () => context.handleActionDashboard(entityObject, item) : defaultHandlers.handleActionDashboard,
|
|
2674
|
+
handleActionReport: context?.handleActionReport ? () => context.handleActionReport(entityObject, item) : defaultHandlers.handleActionReport,
|
|
2675
|
+
handleActionSettings: context?.handleActionSettings ? () => context.handleActionSettings(entityObject, item) : defaultHandlers.handleActionSettings,
|
|
2548
2676
|
handleSelect: (checked, entity) => {
|
|
2549
2677
|
if (!STATE.selectedIds) STATE.selectedIds = /* @__PURE__ */ new Set();
|
|
2550
2678
|
const MyIOSelectionStore2 = typeof window !== "undefined" && window.MyIOLibrary?.MyIOSelectionStore || typeof window !== "undefined" && window.MyIOSelectionStore;
|