Files
HomeAssistantVS/custom_components/maintenance_supporter/frontend/strategy/maintenance-dashboard-strategy.js
T

24 lines
15 KiB
JavaScript

/*! maintenance_supporter frontend 2.95.0 */
import{j as O}from"./chunks/chunk-4JW6SHXP.js";import{c as j,d as p,g as A,i as L}from"./chunks/chunk-3MSNNIFG.js";var Y={maintenance:"Maintenance",overview:"Overview",overdue:"Overdue",triggered:"Triggered",due_soon:"Due Soon",ok:"OK",today:"Today",today_this_week:"This week",unassigned:"Unassigned",tasks:"Tasks",strat_this_month:"This Month",strat_later:"Later",strat_week:"Week",strat_fortnight:"Fortnight",strat_month:"Month",strat_year:"Year",strat_other:"Other",strat_status:"Status",strat_empty_title:"No maintenance objects yet",strat_empty_content:"Open the Maintenance panel to add your first object \u2014 pool pump, HVAC filter, vehicle, anything that needs scheduled care.",strat_open_panel:"Open Maintenance panel",strat_add_object:"Add object",strat_not_loaded:"**Maintenance Supporter** is not loaded. Install/enable the integration first.",strat_group_by:"Group views by",strat_group_area:"By area (default)",strat_group_status:"By status (Overdue / Triggered / Due Soon / OK)",strat_group_floor:"By floor (uses HA floors)",strat_group_due_date:"By due date (Overdue / Today / Week / Month / Later)",strat_group_calendar:"Rolling calendar (Week / Fortnight / Month / Year)",strat_editor_help:'The "Overview" view is always first. Empty groups are skipped.'},h="en",c=t=>A(t,h,Y[t]);async function $(t){h=t?.language||"en",await L(h)}var V="maintenance-supporter",W=`ll-strategy-dashboard-${V}`,B="hui-maintenance-supporter-strategy-editor",F="NOT_RUNNING",q=[{status:"overdue",title:"overdue",icon:p.overdue,path:"overdue"},{status:"triggered",title:"triggered",icon:p.triggered,path:"triggered"},{status:"due_soon",title:"due_soon",icon:p.due_soon,path:"due-soon"},{status:"ok",title:"ok",icon:p.ok,path:"ok"}],x=[{title:"overdue",icon:p.overdue,path:"overdue",filter:{filter_due_max_days:-1},matches:t=>t<=-1},{title:"today",icon:"mdi:calendar-today",path:"today",filter:{filter_due_min_days:0,filter_due_max_days:0},matches:t=>t===0},{title:"today_this_week",icon:"mdi:calendar-week",path:"this-week",filter:{filter_due_min_days:1,filter_due_max_days:7},matches:t=>t>=1&&t<=7},{title:"strat_this_month",icon:"mdi:calendar-month",path:"this-month",filter:{filter_due_min_days:8,filter_due_max_days:30},matches:t=>t>=8&&t<=30},{title:"strat_later",icon:"mdi:calendar-clock",path:"later",filter:{filter_due_min_days:31},matches:t=>t>=31}];function l(t){return{type:"grid",cards:[t]}}var z={condition:"view_columns",min:2};function _(t,r,e){let s=r[t];if(s)return`{{ states('${s}') }}`;let n=e[t];return n==null?"\u2014":String(n)}function Q(t={},r={}){return{type:"markdown",text_only:!0,content:[`\u{1F534} **${_("overdue",t,r)}** ${c("overdue")}`,`\u26A1 **${_("triggered",t,r)}** ${c("triggered")}`,`\u{1F7E1} **${_("due_soon",t,r)}** ${c("due_soon")}`,`\u{1F7E2} **${_("ok",t,r)}** ${c("ok")}`].join(" \xB7 ")}}function X(){return{title:c("maintenance"),type:"panel",cards:[{type:"empty-state",icon:"mdi:wrench-clock",icon_color:"primary",content_only:!0,title:c("strat_empty_title"),content:c("strat_empty_content"),buttons:[{icon:"mdi:wrench",text:c("strat_open_panel"),appearance:"filled",variant:"brand",tap_action:{action:"navigate",navigation_path:"/maintenance-supporter"}},{icon:"mdi:plus",text:c("strat_add_object"),appearance:"outlined",variant:"brand",tap_action:{action:"fire-dom-event",ll_custom:{type:"maintenance-supporter:add-object"}}}]}]}}function J(t={},r={}){let e=Q(t,r);return{title:c("overview"),icon:"mdi:wrench-clock",path:"overview",type:"sections",header:{layout:"responsive",card:e},sidebar:{sections:[{type:"grid",cards:[{type:"heading",heading:c("strat_status"),heading_style:"title"},e]}],visibility:[z],content_label:c("tasks"),sidebar_label:c("strat_status")},sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[...j]})]}}function Z(t,r){let e=new Map;for(let i of t){let a=i.object.area_id||null;e.has(a)||e.set(a,[]),e.get(a).push(i)}let s=Array.from(e.keys()).filter(i=>i!==null);s.sort((i,a)=>{let d=r[i]?.name||i,u=r[a]?.name||a;return d.localeCompare(u)});let n=[];for(let i of s){let a=e.get(i);if(a.length===0)continue;let d=r[i];n.push({title:d?.name||i,icon:d?.icon||"mdi:floor-plan",path:`area-${i}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:a.map(u=>u.object.name)})]})}let o=e.get(null);return o&&o.length>0&&n.push({title:c("unassigned"),icon:"mdi:help-circle-outline",path:"unassigned",type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:o.map(i=>i.object.name)})]}),n}function ee(t){let r=new Set;for(let s of t)for(let n of s.tasks||[])n.status&&r.add(n.status);let e=[];for(let s of q)r.has(s.status)&&e.push({title:c(s.title),icon:s.icon,path:s.path,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[s.status]})]});return e}function te(t,r,e){let s=new Map;for(let a of t){let d=a.object.area_id,u=d&&r[d]?.floor_id||null;s.has(u)||s.set(u,[]),s.get(u).push(a)}let n=Array.from(s.keys()).filter(a=>a!==null);n.sort((a,d)=>{let u=e[a],y=e[d],M=u?.level??0,R=y?.level??0;return M!==R?M-R:(u?.name||a).localeCompare(y?.name||d)});let o=[];for(let a of n){let d=s.get(a);if(d.length===0)continue;let u=e[a];o.push({title:u?.name||a,icon:u?.icon||"mdi:home-floor-1",path:`floor-${a}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:d.map(y=>y.object.name)})]})}let i=s.get(null);return i&&i.length>0&&o.push({title:c("strat_other"),icon:"mdi:help-circle-outline",path:"other",type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:i.map(a=>a.object.name)})]}),o}function ne(t){return[{title:"strat_week",icon:"mdi:calendar-week",path:"cal-7",window_days:7},{title:"strat_fortnight",icon:"mdi:calendar-week-begin",path:"cal-14",window_days:14},{title:"strat_month",icon:"mdi:calendar-month",path:"cal-30",window_days:30},{title:"strat_year",icon:"mdi:calendar-clock",path:"cal-365",window_days:365}].map(e=>({title:c(e.title),icon:e.icon,path:e.path,type:"panel",cards:[{type:"custom:maintenance-supporter-calendar-card",window_days:e.window_days,show_window_chips:!1,show_user_filter:!0}]}))}function re(t){let r=new Set;for(let s of t)for(let n of s.tasks||[]){let o=n.days_until_due;o!=null&&x.forEach((i,a)=>{i.matches(o)&&r.add(a)})}let e=[];return x.forEach((s,n)=>{r.has(n)&&e.push({title:c(s.title),icon:s.icon,path:s.path,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,...s.filter})]})}),e}var I=class extends HTMLElement{static getCreateSuggestions(r){return{title:"Maintenance Supporter",icon:"mdi:wrench-clock"}}static async getConfigElement(){return document.createElement(B)}static async generate(r,e){if(e.config?.state===F)return{views:[{type:"sections",sections:[{cards:[{type:"starting"}]}]}]};if(e.config?.recovery_mode)return{views:[{type:"sections",sections:[{cards:[{type:"recovery-mode"}]}]}]};await $(e);let s;try{s=await e.connection.sendMessagePromise({type:"maintenance_supporter/objects"})}catch{return{title:c("maintenance"),views:[{title:c("maintenance"),cards:[{type:"markdown",content:c("strat_not_loaded")}]}]}}let n=s.objects||[];if(n.length===0)return{title:c("maintenance"),views:[X()]};let o=r?.group_by??"area",i={area:()=>Z(n,e.areas||{}),status:()=>ee(n),floor:()=>te(n,e.areas||{},e.floors||{}),due_date:()=>re(n),calendar:()=>ne(n)},a={},d={};try{let u=await e.connection.sendMessagePromise({type:"maintenance_supporter/statistics"});a=u.summary_entity_ids||{},d={overdue:u.overdue,triggered:u.triggered,due_soon:u.due_soon,ok:u.ok}}catch{}return{title:c("maintenance"),views:[J(a,d),...(i[o]??i.area)()]}}},se=[{value:"area",label:"strat_group_area"},{value:"status",label:"strat_group_status"},{value:"floor",label:"strat_group_floor"},{value:"due_date",label:"strat_group_due_date"},{value:"calendar",label:"strat_group_calendar"}];function k(t){return t.replace(/[&<>"']/g,r=>`&#${r.charCodeAt(0)};`)}var T=class extends HTMLElement{constructor(){super(...arguments);this._config={type:"custom:maintenance-supporter"}}set hass(e){let s=(e?.language||"en")!==h;this._hass=e,s&&$(e).then(()=>this._render())}setConfig(e){this._config=e,this._render()}connectedCallback(){this._render()}_render(){let e=this._config.group_by??"area",s=se.map(o=>`<option value="${o.value}"${o.value===e?" selected":""}>${k(c(o.label))}</option>`).join("");this.innerHTML=`
<style>
:host, .editor { display: block; padding: 16px 0; }
label { display: block; font-weight: 500; margin-bottom: 8px; }
select {
width: 100%; padding: 8px; font-size: 14px;
background: var(--card-background-color, white);
color: var(--primary-text-color, black);
border: 1px solid var(--divider-color, #e0e0e0);
border-radius: 4px;
}
.help {
margin-top: 8px; font-size: 12px;
color: var(--secondary-text-color, #666);
}
</style>
<div class="editor">
<label for="group-by">${k(c("strat_group_by"))}</label>
<select id="group-by">${s}</select>
<div class="help">${k(c("strat_editor_help"))}</div>
</div>
`;let n=this.querySelector("#group-by");n?.addEventListener("change",()=>{let o={...this._config,group_by:n.value};this._config=o,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:o},bubbles:!0,composed:!0}))})}},E="maintenance-supporter-section",ae=`ll-strategy-section-${E}`,b=class extends HTMLElement{static async generate(r,e){let s={type:"custom:maintenance-supporter-card",show_header:!1};r?.filter_status?.length&&(s.filter_status=r.filter_status),r?.max_items&&(s.max_items=r.max_items),r?.filter_due_min_days!==void 0&&(s.filter_due_min_days=r.filter_due_min_days),r?.filter_due_max_days!==void 0&&(s.filter_due_max_days=r.filter_due_max_days);let n=r?.filter_objects;if(r?.area_id&&!n)try{n=((await e.connection.sendMessagePromise({type:"maintenance_supporter/objects"})).objects||[]).filter(a=>a.object.area_id===r.area_id).map(a=>a.object.name)}catch{}n&&n.length>0&&(s.filter_objects=n);let o=[];return r?.title&&o.push({type:"heading",heading:r.title,heading_style:"title"}),o.push(s),{type:"grid",cards:o}}},U="2.3.6",ie="[maintenance-supporter]";function D(t,r){try{return customElements.get(t)?"skipped":(customElements.define(t,r),"ok")}catch(e){return`ERROR: ${String(e)}`}}var K={editor:D(B,T),section:D(ae,b)};console.log(`${ie} strategy bundle v${U} loaded \u2014 registrations:`,K,"\u2014 run maintenanceSupporterDiagnose() in console for full state");window.maintenanceSupporterDiagnose=async()=>{let t=W,r=[];try{let e=document.querySelector("home-assistant");e?.hass&&(r=(await e.hass.connection.sendMessagePromise({type:"lovelace/resources"})).resources||[])}catch(e){r=[{url:`<error: ${String(e)}>`}]}return{version:U,el_registered:!!customElements.get(t),el_class_excerpt:customElements.get(t)?.toString().slice(0,100)||null,customStrategies_dashboard:window.customStrategies?.filter(e=>e.strategyType==="dashboard").map(e=>e.type)||[],scriptTagsInPage:Array.from(document.querySelectorAll("script[type=module]")).map(e=>e.src).filter(e=>/maint|strateg/i.test(e)),lovelaceResources_matching:r.filter(e=>/maint|strateg/i.test(e.url||"")).map(e=>e.url),registrations:K}};var w=class extends HTMLElement{static async generate(r,e){return await import("./chunks/vacation-section-card-R3FY4AUU.js"),{type:"grid",cards:[{type:"custom:maintenance-vacation-section-card",title:r?.title}]}}},v=class extends HTMLElement{static async generate(r,e){return await import("./chunks/budget-section-card-FYYZR3LV.js"),{type:"grid",cards:[{type:"custom:maintenance-budget-section-card",title:r?.title}]}}},S=class extends HTMLElement{static async generate(r,e){return await import("./chunks/groups-section-card-DLDUVDMS.js"),{type:"grid",cards:[{type:"custom:maintenance-groups-section-card",title:r?.title}]}}},G="ll-strategy-section-maintenance-supporter-vacation",P="ll-strategy-section-maintenance-supporter-budget",N="ll-strategy-section-maintenance-supporter-groups";customElements.get(G)||customElements.define(G,w);customElements.get(P)||customElements.define(P,v);customElements.get(N)||customElements.define(N,S);var pe={[E]:b,"maintenance-supporter-vacation":w,"maintenance-supporter-budget":v,"maintenance-supporter-groups":S},f=null;function oe(){return f||(f=import("./chunks/dialog-mount-BY7EKQPS.js").catch(t=>{throw f=null,t})),f}var H="_msSupporterLlCustomBound";function m(t){history.pushState(null,"",t),window.dispatchEvent(new CustomEvent("location-changed"))}function ce(){let t=window;t[H]||(t[H]=!0,document.addEventListener("ll-custom",r=>{let e=r.detail;if(!e||typeof e!="object")return;let s=e.ll_custom,n=s&&typeof s=="object"?s:e;if(!n||typeof n.type!="string"||!n.type.startsWith("maintenance-supporter:"))return;let o=n.type.slice(22);if(o==="deep-link"&&typeof n.path=="string"){m(n.path);return}(async()=>{let i;try{i=await oe()}catch{m("/maintenance-supporter");return}if(o==="add-object"){if(i.openCreateObjectDialog())return;m("/maintenance-supporter?ms_action=add_object");return}if(o==="open-task"&&typeof n.entry_id=="string"&&typeof n.task_id=="string"){if(i.openTaskQuickActions(n.entry_id,n.task_id)||i.openEditTaskDialog(n.entry_id,n.task_id))return;m(`/maintenance-supporter?entry_id=${encodeURIComponent(n.entry_id)}&task_id=${encodeURIComponent(n.task_id)}`);return}if(o==="open-object"&&typeof n.entry_id=="string"){if(i.openObjectQuickActions(n.entry_id))return;m(`/maintenance-supporter?entry_id=${encodeURIComponent(n.entry_id)}`);return}if(o==="edit-history"&&typeof n.entry_id=="string"&&typeof n.task_id=="string"&&typeof n.original_timestamp=="string"){let d=document.querySelector("home-assistant")?.hass;if(!d)return;try{let u=await O(d,n.entry_id,n.task_id,n.original_timestamp);if(!u)return;i.openHistoryEditDialog(u)}catch{m("/maintenance-supporter")}}})()}))}ce();var C=window;C.customStrategies=C.customStrategies||[];function g(t){C.customStrategies.some(e=>e.type===t.type&&e.strategyType===t.strategyType)||C.customStrategies.push(t)}g({type:V,strategyType:"dashboard",name:"Maintenance Supporter",description:"Auto-generated dashboard. Group views by area, status, floor, or due date \u2014 picked from the strategy editor or YAML.",documentationURL:"https://github.com/iluebbe/maintenance_supporter#dashboard-strategy"});g({type:E,strategyType:"section",name:"Maintenance Supporter \u2014 Section",description:"Embed maintenance tasks (filterable by area, status, due date) as a section in any dashboard view.",documentationURL:"https://github.com/iluebbe/maintenance_supporter#section-strategy"});g({type:"maintenance-supporter-vacation",strategyType:"section",name:"Maintenance Supporter \u2014 Vacation Status",description:"Compact vacation-mode status banner. Tap to open settings in the panel."});g({type:"maintenance-supporter-budget",strategyType:"section",name:"Maintenance Supporter \u2014 Budget Status",description:"Monthly + yearly maintenance budget overview. Tap for details."});g({type:"maintenance-supporter-groups",strategyType:"section",name:"Maintenance Supporter \u2014 Groups",description:"List of configured task groups with member counts."});export{I as MaintenanceDashboardStrategy,pe as SECTION_STRATEGIES,Q as kpiMarkdownCard};