Files
HomeAssistantVS/custom_components/maintenance_supporter/frontend/panel-chunks/chunk-C7OGYVZI.js
T

3 lines
5.5 KiB
JavaScript

/*! maintenance_supporter frontend 2.90.0 */
import{b as S}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-XB4BHMUS.js";async function x(n,t,s=300){return(await n.connection.sendMessagePromise({type:"auth/sign_path",path:t,expires:s})).path}async function C(n,t,s=300){return x(n,`/api/maintenance_supporter/document/${t}`,s)}async function N(n,t,s=""){let e=window.open("about:blank","_blank");try{let o=await C(n,t);e&&(e.location.href=new URL(o+s,window.location.origin).href)}catch(o){throw e&&e.close(),o}}async function B(n,t,s){S(await C(n,t,30),s)}function O(n){let t=URL.createObjectURL(new Blob([n],{type:"text/html"}));window.open(t,"_blank"),setTimeout(()=>URL.revokeObjectURL(t),6e4)}var E={days:1,weeks:7,months:30.4368,years:365.25};function b(n,t){return!n||n<=0?0:n*(E[t||"days"]??1)}function L(n,t,s){let e=b(n,s);if(e<=0||t==null)return{pct:0,overflow:!1};let o=(e-t)/e*100;return{pct:Math.max(0,Math.min(100,o)),overflow:o>100}}var D=5;function h(n){let t=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),e=String(n.getDate()).padStart(2,"0");return`${t}-${s}-${e}`}function P(n,t){let s=[];for(let e=0;e<t;e++){let o=new Date(n);o.setDate(o.getDate()+e),o.setHours(0,0,0,0),s.push(h(o))}return s}function y(n,t){let[s,e,o]=n.split("-").map(Number),g=new Date(s,e-1,o);return g.setDate(g.getDate()+t),h(g)}function R(n){if(!n||n.length===0)return null;let t=n.map(s=>s.cost).filter(s=>typeof s=="number");return t.length===0?null:t.reduce((s,e)=>s+e,0)/t.length}function T(n){let{windowStart:t,windowEnd:s,task:e,entryId:o,objectName:g}=n,u=[],d=(a,c)=>({date:a,entry_id:o,task_id:e.id,task_name:e.name,object_name:g,status:c&&(e.status==="overdue"||e.status==="triggered")?"ok":e.status,days_until_due:c?null:e.days_until_due??null,projected:c,schedule_type:e.schedule_type,interval_days:e.interval_days??null,interval_unit:e.interval_unit??null,responsible_user_id:e.responsible_user_id??null,avg_cost:R(e.history),adaptive_enabled:!!e.adaptive_config?.enabled,prediction_confidence:e.threshold_prediction_confidence??null}),p=Math.max(1,Math.round(b(e.interval_days,e.interval_unit)));if(e.status==="overdue"||e.status==="triggered"){if(u.push(d(t,!1)),e.schedule_type==="time_based"&&e.interval_days&&e.interval_days>0){let a=y(t,p),c=1;for(;a<=s&&c<D;)u.push(d(a,!0)),c++,a=y(a,p)}return u}let r=e.next_due;if(typeof r!="string"||!r)return u;let i=r.slice(0,10);if(i>=t&&i<=s)u.push(d(i,!1));else if(i>s)return u;if(e.schedule_type==="time_based"&&e.interval_days&&e.interval_days>0){let a=y(i,p),c=u.length;for(;a<=s&&c<D;)a>=t&&(u.push(d(a,!0)),c++),a=y(a,p)}return u}var j={overdue:0,triggered:1,due_soon:2,ok:3};function Y(n,t,s,e=null){let o=P(t,s),g=o[0],u=o[o.length-1],d=[];for(let r of n){let i=r.object?.name||"",a=r.entry_id,c=r.tasks||[];for(let l of c){if(e&&l.responsible_user_id!==e||l.enabled===!1)continue;let _=T({windowStart:g,windowEnd:u,task:l,entryId:a,objectName:i});d.push(..._)}}let p=new Map;for(let r of o)p.set(r,[]);for(let r of d){let i=p.get(r.date);i&&i.push(r)}for(let[,r]of p)r.sort((i,a)=>{let c=j[i.status]??99,l=j[a.status]??99;if(c!==l)return c-l;if(i.projected!==a.projected)return i.projected?1:-1;let _=i.object_name.localeCompare(a.object_name);return _!==0?_:i.task_name.localeCompare(a.task_name)});return o.map(r=>({date:r,events:p.get(r)??[]}))}var H={completed:"ok",reset:"ok",skipped:"due_soon",missed:"overdue",triggered:"triggered",trigger_replaced:"triggered",trigger_removed:"ok"};function M(n,t){let s=[];for(let e=t-1;e>=0;e--){let o=new Date(n);o.setDate(o.getDate()-e),o.setHours(0,0,0,0),s.push(h(o))}return s}function $(n,t,s,e=null){let o=M(t,s),g=o[0],u=o[o.length-1],d=new Map;for(let r of o)d.set(r,[]);for(let r of n){let i=r.object?.name||"",a=r.entry_id,c=r.tasks||[];for(let l of c){if(e&&l.responsible_user_id!==e)continue;let _=l.history||[];for(let m of _){if(typeof m?.timestamp!="string")continue;let f=m.timestamp.slice(0,10);if(f<g||f>u)continue;let w=d.get(f);if(!w)continue;let k=m.type??"completed";w.push({date:f,entry_id:a,task_id:l.id,task_name:l.name,object_name:i,status:H[k]??"ok",days_until_due:null,projected:!1,schedule_type:l.schedule_type,interval_days:l.interval_days??null,responsible_user_id:l.responsible_user_id??null,avg_cost:typeof m.cost=="number"?m.cost:null,adaptive_enabled:!!l.adaptive_config?.enabled,prediction_confidence:null,history_timestamp:m.timestamp,history_type:k,history_cost:typeof m.cost=="number"?m.cost:null,history_notes:typeof m.notes=="string"?m.notes:null,history_duration:typeof m.duration=="number"?m.duration:null})}}}let p={completed:0,reset:1,skipped:2,triggered:3,trigger_replaced:4};for(let[,r]of d)r.sort((i,a)=>{let c=p[i.history_type??""]??99,l=p[a.history_type??""]??99;if(c!==l)return c-l;let _=i.object_name.localeCompare(a.object_name);return _!==0?_:i.task_name.localeCompare(a.task_name)});return o.map(r=>({date:r,events:d.get(r)??[]}))}var v={features:{adaptive:!1,predictions:!1,seasonal:!1,environmental:!1,budget:!1,groups:!1,checklists:!1,schedule_time:!1,completion_actions:!1},defaultWarningDays:7,rowActionStyle:"buttons_compact"};function A(){let n=window;return n.__msSettingsCache??={promise:null}}function X(n){let t=A();if(t.promise)return t.promise;let s=n.connection.sendMessagePromise({type:"maintenance_supporter/settings"}).then(e=>({features:e.features??v.features,defaultWarningDays:e.general?.default_warning_days??7,rowActionStyle:e.general?.row_action_style??v.rowActionStyle})).catch(()=>(t.promise===s&&(t.promise=null),v));return t.promise=s,s}function q(){A().promise=null}export{x as a,C as b,N as c,B as d,O as e,L as f,h as g,Y as h,$ as i,X as j,q as k};