24 lines
15 KiB
JavaScript
24 lines
15 KiB
JavaScript
/*! maintenance_supporter frontend 2.96.0 */
|
|
import{j as O}from"./chunks/chunk-XOYZSKDM.js";import{c as A,d as p,g as j,i as L}from"./chunks/chunk-RGIYRWN4.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=>j(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 X={condition:"view_columns",min:2};function _(t,n,e){let s=n[t];if(s)return`{{ states('${s}') }}`;let r=e[t];return r==null?"\u2014":String(r)}function z(t={},n={}){return{type:"markdown",text_only:!0,content:[`\u{1F534} **${_("overdue",t,n)}** ${c("overdue")}`,`\u26A1 **${_("triggered",t,n)}** ${c("triggered")}`,`\u{1F7E1} **${_("due_soon",t,n)}** ${c("due_soon")}`,`\u{1F7E2} **${_("ok",t,n)}** ${c("ok")}`].join(" \xB7 ")}}function Q(){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={},n={}){let e=z(t,n);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:[X],content_label:c("tasks"),sidebar_label:c("strat_status")},sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_status:[...A]})]}}function Z(t,n){let e=new Map;for(let a of t){let i=a.object.area_id||null;e.has(i)||e.set(i,[]),e.get(i).push(a)}let s=Array.from(e.keys()).filter(a=>a!==null);s.sort((a,i)=>{let u=n[a]?.name||a,d=n[i]?.name||i;return u.localeCompare(d)});let r=[];for(let a of s){let i=e.get(a);if(i.length===0)continue;let u=n[a];r.push({title:u?.name||a,icon:u?.icon||"mdi:floor-plan",path:`area-${a}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:i.map(d=>d.object.name)})]})}let o=e.get(null);return o&&o.length>0&&r.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(a=>a.object.name)})]}),r}function ee(t){let n=new Set;for(let s of t)for(let r of s.tasks||[])r.status&&n.add(r.status);let e=[];for(let s of q)n.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,n,e){let s=new Map;for(let i of t){let u=i.object.area_id,d=u&&n[u]?.floor_id||null;s.has(d)||s.set(d,[]),s.get(d).push(i)}let r=Array.from(s.keys()).filter(i=>i!==null);r.sort((i,u)=>{let d=e[i],y=e[u],M=d?.level??0,R=y?.level??0;return M!==R?M-R:(d?.name||i).localeCompare(y?.name||u)});let o=[];for(let i of r){let u=s.get(i);if(u.length===0)continue;let d=e[i];o.push({title:d?.name||i,icon:d?.icon||"mdi:home-floor-1",path:`floor-${i}`,type:"sections",sections:[l({type:"custom:maintenance-supporter-card",show_header:!1,filter_objects:u.map(y=>y.object.name)})]})}let a=s.get(null);return a&&a.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:a.map(i=>i.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 n=new Set;for(let s of t)for(let r of s.tasks||[]){let o=r.days_until_due;o!=null&&x.forEach((a,i)=>{a.matches(o)&&n.add(i)})}let e=[];return x.forEach((s,r)=>{n.has(r)&&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(n){return{title:"Maintenance Supporter",icon:"mdi:wrench-clock"}}static async getConfigElement(){return document.createElement(B)}static async generate(n,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 r=s.objects||[];if(r.length===0)return{title:c("maintenance"),views:[Q()]};let o=n?.group_by??"area",a={area:()=>Z(r,e.areas||{}),status:()=>ee(r),floor:()=>te(r,e.areas||{},e.floors||{}),due_date:()=>re(r),calendar:()=>ne(r)},i={},u={};try{let d=await e.connection.sendMessagePromise({type:"maintenance_supporter/statistics"});i=d.summary_entity_ids||{},u={overdue:d.overdue,triggered:d.triggered,due_soon:d.due_soon,ok:d.ok}}catch{}return{title:c("maintenance"),views:[J(i,u),...(a[o]??a.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,n=>`&#${n.charCodeAt(0)};`)}var E=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 r=this.querySelector("#group-by");r?.addEventListener("change",()=>{let o={...this._config,group_by:r.value};this._config=o,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:o},bubbles:!0,composed:!0}))})}},T="maintenance-supporter-section",ae=`ll-strategy-section-${T}`,b=class extends HTMLElement{static async generate(n,e){let s={type:"custom:maintenance-supporter-card",show_header:!1};n?.filter_status?.length&&(s.filter_status=n.filter_status),n?.max_items&&(s.max_items=n.max_items),n?.filter_due_min_days!==void 0&&(s.filter_due_min_days=n.filter_due_min_days),n?.filter_due_max_days!==void 0&&(s.filter_due_max_days=n.filter_due_max_days),n?.filter_objects?.length?s.filter_objects=n.filter_objects:n?.area_id&&(s.filter_areas=[n.area_id]);let r=[];return n?.title&&r.push({type:"heading",heading:n.title,heading_style:"title"}),r.push(s),{type:"grid",cards:r}}},U="2.3.6",ie="[maintenance-supporter]";function D(t,n){try{return customElements.get(t)?"skipped":(customElements.define(t,n),"ok")}catch(e){return`ERROR: ${String(e)}`}}var K={editor:D(B,E),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,n=[];try{let e=document.querySelector("home-assistant");e?.hass&&(n=(await e.hass.connection.sendMessagePromise({type:"lovelace/resources"})).resources||[])}catch(e){n=[{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:n.filter(e=>/maint|strateg/i.test(e.url||"")).map(e=>e.url),registrations:K}};var w=class extends HTMLElement{static async generate(n,e){return await import("./chunks/vacation-section-card-KBV2JPSC.js"),{type:"grid",cards:[{type:"custom:maintenance-vacation-section-card",title:n?.title}]}}},v=class extends HTMLElement{static async generate(n,e){return await import("./chunks/budget-section-card-3BHOHMGQ.js"),{type:"grid",cards:[{type:"custom:maintenance-budget-section-card",title:n?.title}]}}},S=class extends HTMLElement{static async generate(n,e){return await import("./chunks/groups-section-card-N72HOEE7.js"),{type:"grid",cards:[{type:"custom:maintenance-groups-section-card",title:n?.title}]}}},P="ll-strategy-section-maintenance-supporter-vacation",G="ll-strategy-section-maintenance-supporter-budget",N="ll-strategy-section-maintenance-supporter-groups";customElements.get(P)||customElements.define(P,w);customElements.get(G)||customElements.define(G,v);customElements.get(N)||customElements.define(N,S);var pe={[T]:b,"maintenance-supporter-vacation":w,"maintenance-supporter-budget":v,"maintenance-supporter-groups":S},f=null;function oe(){return f||(f=import("./chunks/dialog-mount-ZNHSIDHE.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",n=>{let e=n.detail;if(!e||typeof e!="object")return;let s=e.ll_custom,r=s&&typeof s=="object"?s:e;if(!r||typeof r.type!="string"||!r.type.startsWith("maintenance-supporter:"))return;let o=r.type.slice(22);if(o==="deep-link"&&typeof r.path=="string"){m(r.path);return}(async()=>{let a;try{a=await oe()}catch{m("/maintenance-supporter");return}if(o==="add-object"){if(a.openCreateObjectDialog())return;m("/maintenance-supporter?ms_action=add_object");return}if(o==="open-task"&&typeof r.entry_id=="string"&&typeof r.task_id=="string"){if(a.openTaskQuickActions(r.entry_id,r.task_id)||a.openEditTaskDialog(r.entry_id,r.task_id))return;m(`/maintenance-supporter?entry_id=${encodeURIComponent(r.entry_id)}&task_id=${encodeURIComponent(r.task_id)}`);return}if(o==="open-object"&&typeof r.entry_id=="string"){if(a.openObjectQuickActions(r.entry_id))return;m(`/maintenance-supporter?entry_id=${encodeURIComponent(r.entry_id)}`);return}if(o==="edit-history"&&typeof r.entry_id=="string"&&typeof r.task_id=="string"&&typeof r.original_timestamp=="string"){let u=document.querySelector("home-assistant")?.hass;if(!u)return;try{let d=await O(u,r.entry_id,r.task_id,r.original_timestamp);if(!d)return;a.openHistoryEditDialog(d)}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/blob/master/docs/EXAMPLES.md#dashboard-strategy"});g({type:T,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/blob/master/docs/EXAMPLES.md#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,z as kpiMarkdownCard};
|