2 lines
3 KiB
JavaScript
2 lines
3 KiB
JavaScript
|
import{s as d}from"./service.541fc1e6.js";import{_ as h,G as f,r as y,o as t,c as _,w as p,a,t as i,b as s,F as c,d as m,e as r,n as g,p as k,f as T}from"./index.868de8fa.js";const b={name:"OctoPrint",mixins:[d],props:{item:Object},components:{Generic:f},data:()=>({printTime:null,printTimeLeft:null,completion:null,state:null,printer:null,error:null}),computed:{statusClass:function(){switch(this.state){case"Operational":return"ready";case"Offline":return"offline";case"Printing":return"in-progress";default:return"pending"}}},created(){this.display=this.item.display=="bar"?this.item.display:"text",this.fetchPrinterStatus(),this.fetchStatus()},methods:{fetchStatus:async function(){try{const e=await this.fetch(`api/job?apikey=${this.item.apikey}`);this.printTime=e.progress.printTime,this.printTimeLeft=e.progress.printTimeLeft,this.completion=e.progress.completion,this.state=e.state,this.error=e.error}catch(e){this.error=`Fail to fetch octoprint data (${e.message})`,console.error(e)}},fetchPrinterStatus:async function(){try{const e=await this.fetch(`api/printer?apikey=${this.item.apikey}`);this.printer=e,this.error=e.error}catch(e){this.error=`Fail to fetch octoprint data (${e.message})`,console.error(e)}},toTime:function(e){return new Date(e*1e3).toTimeString().substring(0,5)}}},n=e=>(k("data-v-a18dcc40"),e=e(),T(),e),C={class:"title is-4"},S={class:"subtitle is-6"},v=n(()=>a("i",{class:"fa-solid fa-gear mr-1"},null,-1)),w={key:0},F=n(()=>a("span",{class:"separator mx-1"}," | ",-1)),O=["title"],P=n(()=>a("i",{class:"fa-solid fa-stopwatch mr-1"},null,-1)),L=n(()=>a("i",{class:"fa-solid fa-temperature-half mr-1"},null,-1)),B={key:0},G=n(()=>a("span",{class:"separator mx-1"}," | ",-1)),I={key:1},N=["value","title"],V=["title"],j=["title"];function D(e,$,l,z,E,o){const u=y("Generic");return t(),_(u,{item:l.item,title:e.state},{content:p(()=>[a("p",C,i(l.item.name),1),a("p",S,[l.item.subtitle&&!e.state?(t(),s(c,{key:0},[m(i(l.item.subtitle),1)],64)):r("",!0),!e.error&&e.display=="text"&&o.statusClass=="in-progress"?(t(),s(c,{key:1},[v,e.completion?(t(),s("b",w,i(e.completion.toFixed())+"%",1)):r("",!0),F,e.printTime?(t(),s("span",{key:1,title:`${o.toTime(e.printTimeLeft)} left`},[P,m(" "+i(o.toTime(e.printTime)),1)],8,O)):r("",!0)],64)):r("",!0),!e.error&&e.display=="text"&&o.statusClass=="ready"?(t(),s(c,{key:2},[L,e.printer.temperature.bed?(t(),s("b",B,i(e.printer.temperature.bed.actual.toFixed())+" C",1)):r("",!0),G,e.printer.temperature.tool0?(t(),s("b",I,i(e.printer.temperature.tool0.actual.toFixed())+" C",1)):r("",!0)],64)):r("",!0),!e.error&&e.display=="bar"?(t(),s(c,{key:3},[e.completion?(t(),s("progress",{key:0,class:"progress is-primary",value:e.completion,max:"100",title:`${e.state} - ${e.completion.toFixed()}%, ${o.toTime(e.printTimeLeft)} left`},i(e.completion)+"% ",9,N)):r("",!0)],64)):r("",!0),e.error?(t(),s("span",{key:4,title:e.error},i(e.error),9,V)):r("",!0)])]),indicator:p(()=>[a("i",{class:g(["status",o.statusClass]),title:e.state},null,10,j)]),_:1},8,["item","title"])}const H=h(b,[["render",D],["__scopeId","data-v-a18dcc40"]]);export{H as default};
|