@openremote/or-dashboard-builder 1.6.0-snapshot.20250514095754 → 1.6.0-snapshot.20250515141253

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/umd/index.js CHANGED
@@ -2690,7 +2690,7 @@
2690
2690
  .hidescroll::-webkit-scrollbar {
2691
2691
  display: none; /* for Chrome, Safari, and Opera */
2692
2692
  }
2693
- `,Ld=1e6;function Ed(t){return null!=t?qn.i18next.t("dashboard.presets."+t.toLowerCase()):"undefined"}function Sd(t){return qn.i18next.t("dashboard.access."+t.toLowerCase())}function Cd(t,e=!1){return t.sort(((t,i)=>{if(null!=t.breakpoint&&null!=i.breakpoint){if(t.breakpoint>i.breakpoint)return e?1:-1;if(t.breakpoint<i.breakpoint)return e?1:-1}return 0}))}function Ad(t,e){let i;return Cd(e,!0).forEach((e=>{null!=e.breakpoint&&t<=e.breakpoint&&(i=e)})),i}const Dd=new Map;function Id(){Dd.set("linechart",Cs.getManifest()),Dd.set("gauge",Os.getManifest()),Dd.set("image",Hs.getManifest()),Dd.set("kpi",Us.getManifest()),Dd.set("map",ul.getManifest()),Dd.set("attributeinput",_l.getManifest()),Dd.set("table",Wl.getManifest()),Dd.set("gateway",kd.getManifest())}let Rd=class extends Lt{static get styles(){return[Md,Sr]}constructor(){super(),this.editMode=!1,this.fullscreen=!0,this.realm=Wn().displayRealm,this.readonly=!0,this.refreshInterval="OFF",this.keyEmitter=new es,this.sidebarMenuIndex=0,this.showDashboardTree=!0,this.menuItems=[{icon:"content-copy",text:qn.i18next.t("copy")+" URL",value:"copy"},{icon:"open-in-new",text:qn.i18next.t("dashboard.openInNewTab"),value:"tab"}],this.tabItems=[{name:qn.i18next.t("dashboard.widgets")},{name:qn.i18next.t("settings")}],this.isInitializing=!0,this.isLoading=!0,this.hasChanged=!1,Id(),this.updateComplete.then((()=>{this.loadAllDashboards(this.realm)}))}connectedCallback(){super.connectedCallback(),this.keyEmitter.addListener("delete",(t=>{var e,i,n;if(this.selectedWidgetId){const t=null===(n=null===(i=null===(e=this.selectedDashboard)||void 0===e?void 0:e.template)||void 0===i?void 0:i.widgets)||void 0===n?void 0:n.find((t=>t.id==this.selectedWidgetId));t&&Kr(qn.i18next.t("areYouSure"),qn.i18next.t("dashboard.deleteWidgetWarning"),qn.i18next.t("delete")).then((e=>{e&&this.deleteWidget(t)}))}})),this.keyEmitter.addListener("deselect",(t=>{this.deselectWidget()})),this.keyEmitter.addListener("save",(t=>{this.saveDashboard()}))}disconnectedCallback(){super.disconnectedCallback(),this.keyEmitter.removeAllListeners()}willUpdate(t){var e,i,n;if(super.willUpdate(t),this.isLoading=null==this.dashboards,this.isInitializing=null==this.dashboards,1!==t.size||!t.has("selectedWidget")){const t=this.initialDashboardJSON?JSON.parse(this.initialDashboardJSON):void 0,e=Vn.Util.difference(this.selectedDashboard,t);if(Object.keys(e).length>0)this.hasChanged=!0,console.debug("Dashboard has detected changes! Diff:",e);else{const t=this.initialTemplateJSON?JSON.parse(this.initialTemplateJSON):void 0,e=Vn.Util.difference(this.currentTemplate,t);Object.keys(e).length>0?(this.hasChanged=!0,console.debug("Template has detected changes! Diff:",e)):this.hasChanged=!1}}t.has("realm")&&void 0!==t.get("realm")&&this.realm&&this.loadAllDashboards(this.realm),t.has("selectedDashboard")&&(this.deselectWidget(),this.currentTemplate=null===(e=this.selectedDashboard)||void 0===e?void 0:e.template,this.editMode||(this.refreshInterval=(null===(i=this.currentTemplate)||void 0===i?void 0:i.refreshInterval)||"OFF",t.set("refreshInterval",this.refreshInterval)),this.dispatchEvent(new CustomEvent("selected",{detail:this.selectedDashboard}))),t.has("editMode")&&(this.deselectWidget(),this.refreshInterval="OFF",this.showDashboardTree=!0,this.editMode?this.refreshInterval="OFF":this.refreshInterval=(null===(n=this.currentTemplate)||void 0===n?void 0:n.refreshInterval)||"OFF",t.set("refreshInterval",this.refreshInterval)),t.has("refreshInterval")&&this.refreshInterval&&this.setRefreshTimer(function(t){switch(t){case"OFF":default:return;case"ONE_MIN":return 6e4;case"FIVE_MIN":return 3e5;case"QUARTER":return 9e5;case"ONE_HOUR":return 36e5}}(this.refreshInterval))}setRefreshTimer(t){this.clearRefreshTimer(),void 0!==t&&(this.refreshTimer=setInterval((()=>{var t;this.deselectWidget(),null===(t=this.dashboardPreview)||void 0===t||t.refreshWidgets()}),t))}clearRefreshTimer(){this.refreshTimer&&(clearInterval(this.refreshTimer),this.refreshTimer=void 0)}loadAllDashboards(t){var e;return function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function o(t){try{l(n.next(t))}catch(t){a(t)}}function s(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,s)}l((n=n.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){yield Wn().rest.api.DashboardResource.getAllRealmDashboards(t).then((t=>{this.dashboards=t.data})).catch((t=>{Ma(void 0,"errorOccurred"),console.error(t)})),void 0!==this.selectedId&&(this.selectedDashboard=null===(e=this.dashboards)||void 0===e?void 0:e.find((t=>t.id==this.selectedId)))}))}updated(t){super.updated(t),t.has("currentTemplate")&&null!=this.selectedDashboard&&(this.selectedDashboard.template=this.currentTemplate)}onWidgetCreation(t){const e=JSON.parse(JSON.stringify(this.currentTemplate));e.widgets||(e.widgets=[]),e.widgets.push(t),this.currentTemplate=e}deleteWidget(t){var e;if(null!=this.currentTemplate&&null!=this.currentTemplate.widgets){const i=this.currentTemplate;i.widgets=null===(e=i.widgets)||void 0===e?void 0:e.filter((e=>e.id!=t.id)),this.currentTemplate=i}this.selectedWidgetId===t.id&&this.deselectWidget()}selectWidget(t){var e,i;const n=null===(i=null===(e=this.currentTemplate)||void 0===e?void 0:e.widgets)||void 0===i?void 0:i.find((e=>{var i,n;return(null===(i=e.gridItem)||void 0===i?void 0:i.id)==(null===(n=t.gridItem)||void 0===n?void 0:n.id)}));null!=n?this.selectedWidgetId=n.id:console.error("The selected widget does not exist!")}deselectWidget(){this.selectedWidgetId=void 0}selectDashboard(t){var e;if(null!=this.dashboards){if(this.selectedDashboard&&this.initialDashboardJSON){const t=this.dashboards.indexOf(this.selectedDashboard);t&&JSON.stringify(this.selectedDashboard)!==this.initialDashboardJSON&&(this.dashboards[t]=JSON.parse(this.initialDashboardJSON))}this.selectedDashboard=t?this.dashboards.find((e=>e.id==t.id)):void 0,this.initialDashboardJSON=JSON.stringify(this.selectedDashboard),this.initialTemplateJSON=JSON.stringify(null===(e=this.selectedDashboard)||void 0===e?void 0:e.template)}}changeDashboardName(t){null!=this.selectedDashboard&&(this.selectedDashboard.displayName=t,this.requestUpdate("selectedDashboard"))}openDashboardInInsights(){var t;if(null!=this.selectedDashboard){const e=window.location.origin+"/insights/?realm="+Wn().displayRealm+"#/view/"+this.selectedDashboard.id+"/true/";null===(t=window.open(e))||void 0===t||t.focus()}}shareUrl(t){var e;let i=window.location.href.replace("true","false");"copy"==t?navigator.clipboard.writeText(i):"tab"==t&&(null===(e=window.open(i,"_blank"))||void 0===e||e.focus())}saveDashboard(){null!=this.selectedDashboard&&!this._isReadonly()&&this._hasEditAccess()?(this.isLoading=!0,Wn().rest.api.DashboardResource.update(this.selectedDashboard).then((()=>{var t;null!=this.dashboards&&null!=this.selectedDashboard&&(this.initialDashboardJSON=JSON.stringify(this.selectedDashboard),this.initialTemplateJSON=JSON.stringify(this.selectedDashboard.template),this.dashboards[null===(t=this.dashboards)||void 0===t?void 0:t.indexOf(this.selectedDashboard)]=this.selectedDashboard,this.currentTemplate=Object.assign({},this.selectedDashboard.template),Ma(void 0,"dashboard.saveSuccessful"))})).catch((t=>{console.error(t),Ma(void 0,"errorOccurred")})).finally((()=>{this.isLoading=!1}))):(console.error("The selected dashboard could not be found.."),Ma(void 0,"errorOccurred"))}_isReadonly(){return this.readonly}_hasEditAccess(){return Wn().hasRole("write:insights")}_hasViewAccess(){var t,e;return Wn().hasRole("read:insights")&&null!=this.userId&&("PRIVATE"!=(null===(t=this.selectedDashboard)||void 0===t?void 0:t.access)||(null===(e=this.selectedDashboard)||void 0===e?void 0:e.ownerId)==this.userId)}render(){var t,e,i,n;window.matchMedia("(max-width: 600px)").matches&&this.editMode&&(this.dispatchEvent(new CustomEvent("editToggle",{detail:!1})),this.showDashboardTree=!0);const r={display:!this.editMode||!this._isReadonly()&&this._hasEditAccess()?void 0:"none",maxHeight:this.editMode?"calc(100vh - 77px - 50px)":"inherit"};return!this.isInitializing||null!=this.dashboards&&0==this.dashboards.length?F`
2693
+ `,Ld=1e6;function Ed(t){return null!=t?qn.i18next.t("dashboard.presets."+t.toLowerCase()):"undefined"}function Sd(t){return qn.i18next.t("dashboard.access."+t.toLowerCase())}function Cd(t,e=!1){return t.sort(((t,i)=>{if(null!=t.breakpoint&&null!=i.breakpoint){if(t.breakpoint>i.breakpoint)return e?1:-1;if(t.breakpoint<i.breakpoint)return e?1:-1}return 0}))}function Ad(t,e){let i;return Cd(e,!0).forEach((e=>{null!=e.breakpoint&&t<=e.breakpoint&&(i=e)})),i}const Dd=new Map;function Id(){Dd.set("linechart",Cs.getManifest()),Dd.set("gauge",Os.getManifest()),Dd.set("image",Hs.getManifest()),Dd.set("kpi",Us.getManifest()),Dd.set("map",ul.getManifest()),Dd.set("attributeinput",_l.getManifest()),Dd.set("table",Wl.getManifest()),Dd.set("gateway",kd.getManifest())}let Rd=class extends Lt{static get styles(){return[Md,Sr]}constructor(){super(),this.editMode=!1,this.fullscreen=!0,this.realm=Wn().displayRealm,this.readonly=!0,this.refreshInterval="OFF",this.keyEmitter=new es,this.sidebarMenuIndex=0,this.showDashboardTree=!0,this.menuItems=[{icon:"content-copy",text:qn.i18next.t("copy")+" URL",value:"copy"},{icon:"open-in-new",text:qn.i18next.t("dashboard.openInNewTab"),value:"tab"}],this.tabItems=[{name:qn.i18next.t("dashboard.widgets")},{name:qn.i18next.t("settings")}],this.isInitializing=!0,this.isLoading=!0,this.hasChanged=!1,Id(),this.updateComplete.then((()=>{this.loadAllDashboards(this.realm)}))}connectedCallback(){super.connectedCallback(),this.keyEmitter.addListener("delete",(t=>{var e,i,n;if(this.selectedWidgetId){const t=null===(n=null===(i=null===(e=this.selectedDashboard)||void 0===e?void 0:e.template)||void 0===i?void 0:i.widgets)||void 0===n?void 0:n.find((t=>t.id==this.selectedWidgetId));t&&Kr(qn.i18next.t("areYouSure"),qn.i18next.t("dashboard.deleteWidgetWarning"),qn.i18next.t("delete")).then((e=>{e&&this.deleteWidget(t)}))}})),this.keyEmitter.addListener("deselect",(t=>{this.deselectWidget()})),this.keyEmitter.addListener("save",(t=>{this.saveDashboard()}))}disconnectedCallback(){super.disconnectedCallback(),this.keyEmitter.removeAllListeners()}willUpdate(t){var e,i,n;if(super.willUpdate(t),this.isLoading=null==this.dashboards,this.isInitializing=null==this.dashboards,1!==t.size||!t.has("selectedWidget")){const t=this.initialDashboardJSON?JSON.parse(this.initialDashboardJSON):void 0,e=Vn.Util.difference(this.selectedDashboard,t);if(Object.keys(e).length>0)this.hasChanged=!0,console.debug("Dashboard has detected changes! Diff:",e);else{const t=this.initialTemplateJSON?JSON.parse(this.initialTemplateJSON):void 0,e=Vn.Util.difference(this.currentTemplate,t);Object.keys(e).length>0?(this.hasChanged=!0,console.debug("Template has detected changes! Diff:",e)):this.hasChanged=!1}}t.has("realm")&&void 0!==t.get("realm")&&this.realm&&this.loadAllDashboards(this.realm),t.has("selectedDashboard")&&(this.deselectWidget(),this.currentTemplate=null===(e=this.selectedDashboard)||void 0===e?void 0:e.template,this.editMode||(this.refreshInterval=(null===(i=this.currentTemplate)||void 0===i?void 0:i.refreshInterval)||"OFF",t.set("refreshInterval",this.refreshInterval)),this.dispatchEvent(new CustomEvent("selected",{detail:this.selectedDashboard}))),t.has("editMode")&&(this.deselectWidget(),this.refreshInterval="OFF",this.showDashboardTree=!0,this.editMode?this.refreshInterval="OFF":this.refreshInterval=(null===(n=this.currentTemplate)||void 0===n?void 0:n.refreshInterval)||"OFF",t.set("refreshInterval",this.refreshInterval)),t.has("refreshInterval")&&this.refreshInterval&&this.setRefreshTimer(function(t){switch(t){case"OFF":default:return;case"ONE_MIN":return 6e4;case"FIVE_MIN":return 3e5;case"QUARTER":return 9e5;case"ONE_HOUR":return 36e5}}(this.refreshInterval))}setRefreshTimer(t){this.clearRefreshTimer(),void 0!==t&&(this.refreshTimer=setInterval((()=>{var t;this.deselectWidget(),null===(t=this.dashboardPreview)||void 0===t||t.refreshWidgets()}),t))}clearRefreshTimer(){this.refreshTimer&&(clearInterval(this.refreshTimer),this.refreshTimer=void 0)}loadAllDashboards(t){var e;return function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function o(t){try{l(n.next(t))}catch(t){a(t)}}function s(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,s)}l((n=n.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){yield Wn().rest.api.DashboardResource.getAllRealmDashboards(t).then((t=>{this.dashboards=t.data})).catch((t=>{Ma(void 0,"errorOccurred"),console.error(t)})),void 0!==this.selectedId&&(this.selectedDashboard=null===(e=this.dashboards)||void 0===e?void 0:e.find((t=>t.id==this.selectedId)))}))}updated(t){super.updated(t),t.has("currentTemplate")&&null!=this.selectedDashboard&&(this.selectedDashboard.template=this.currentTemplate)}onWidgetCreation(t){const e=JSON.parse(JSON.stringify(this.currentTemplate));e.widgets||(e.widgets=[]),e.widgets.push(t),this.currentTemplate=e}deleteWidget(t){var e;if(null!=this.currentTemplate&&null!=this.currentTemplate.widgets){const i=this.currentTemplate;i.widgets=null===(e=i.widgets)||void 0===e?void 0:e.filter((e=>e.id!=t.id)),this.currentTemplate=i}this.selectedWidgetId===t.id&&this.deselectWidget()}selectWidget(t){var e,i;const n=null===(i=null===(e=this.currentTemplate)||void 0===e?void 0:e.widgets)||void 0===i?void 0:i.find((e=>{var i,n;return(null===(i=e.gridItem)||void 0===i?void 0:i.id)==(null===(n=t.gridItem)||void 0===n?void 0:n.id)}));null!=n?this.selectedWidgetId=n.id:console.error("The selected widget does not exist!")}deselectWidget(){this.selectedWidgetId=void 0}selectDashboard(t){var e;if(null!=this.dashboards){if(this.selectedDashboard&&this.initialDashboardJSON){const t=this.dashboards.indexOf(this.selectedDashboard);t&&JSON.stringify(this.selectedDashboard)!==this.initialDashboardJSON&&(this.dashboards[t]=JSON.parse(this.initialDashboardJSON))}this.selectedDashboard=t?this.dashboards.find((e=>e.id==t.id)):void 0,this.initialDashboardJSON=JSON.stringify(this.selectedDashboard),this.initialTemplateJSON=JSON.stringify(null===(e=this.selectedDashboard)||void 0===e?void 0:e.template)}}changeDashboardName(t){null!=this.selectedDashboard&&(this.selectedDashboard.displayName=t,this.requestUpdate("selectedDashboard"))}openDashboardInInsights(){var t;if(null!=this.selectedDashboard){const e=window.location.origin+"/insights/?realm="+Wn().displayRealm+"#/view/"+this.selectedDashboard.id+"/true/";null===(t=window.open(e))||void 0===t||t.focus()}}shareUrl(t){var e;let i=window.location.href.replace("true","false");"copy"==t?navigator.clipboard.writeText(i):"tab"==t&&(null===(e=window.open(i,"_blank"))||void 0===e||e.focus())}saveDashboard(){null!=this.selectedDashboard&&!this._isReadonly()&&this._hasEditAccess()?(this.isLoading=!0,Wn().rest.api.DashboardResource.update(this.selectedDashboard).then((t=>{var e,i;this.selectedDashboard=t.data,this.dashboards=[this.selectedDashboard,...null===(e=this.dashboards)||void 0===e?void 0:e.filter((t=>t.id!==this.selectedDashboard.id))],this.initialDashboardJSON=JSON.stringify(this.selectedDashboard),this.initialTemplateJSON=JSON.stringify(this.selectedDashboard.template),this.dashboards[null===(i=this.dashboards)||void 0===i?void 0:i.indexOf(this.selectedDashboard)]=this.selectedDashboard,this.currentTemplate=Object.assign({},this.selectedDashboard.template),Ma(void 0,"dashboard.saveSuccessful")})).catch((t=>{console.error(t),Ma(void 0,"errorOccurred")})).finally((()=>{this.isLoading=!1}))):(console.error("The selected dashboard could not be found.."),Ma(void 0,"errorOccurred"))}_isReadonly(){return this.readonly}_hasEditAccess(){return Wn().hasRole("write:insights")}_hasViewAccess(){var t,e;return Wn().hasRole("read:insights")&&null!=this.userId&&("PRIVATE"!=(null===(t=this.selectedDashboard)||void 0===t?void 0:t.access)||(null===(e=this.selectedDashboard)||void 0===e?void 0:e.ownerId)==this.userId)}render(){var t,e,i,n;window.matchMedia("(max-width: 600px)").matches&&this.editMode&&(this.dispatchEvent(new CustomEvent("editToggle",{detail:!1})),this.showDashboardTree=!0);const r={display:!this.editMode||!this._isReadonly()&&this._hasEditAccess()?void 0:"none",maxHeight:this.editMode?"calc(100vh - 77px - 50px)":"inherit"};return!this.isInitializing||null!=this.dashboards&&0==this.dashboards.length?F`
2694
2694
  <div id="container">
2695
2695
  ${this.showDashboardTree?F`
2696
2696
  <or-dashboard-tree id="tree" class="${this.selectedDashboard?"hideMobile":void 0}"