import{S,Q as v,a as n,b as g,C as y}from"./ScraperIdeComponent.c3392f54.js";import{a as _,b as d,g as p,i as b}from"./QPage.1ebdd4ad.js";import{_ as V,H as C,I as c,J as u,K as l,L as s,O as P,t as k,S as f,R as Q}from"./index.f9c30c55.js";import{t as w,v as L,x as q,p as x}from"./api.7efe3d3e.js";const{capitalize:h}=x,D={name:"ScraperIde",components:{ScraperIdeComponent:S},data(){return{loading:!1,error:!1,showSaveDialog:!1,draftScraper:{name:"",schedule:"inactive",priority:0,handler:"dynamic_scraper",config:{}},schedules:[],priorities:[],saveLoading:!1}},created(){this.loading=!0,Promise.all([w().then(e=>this.schedules=e.map(this.makeScheduleOption)),L().then(e=>this.priorities=e.map(this.makePriorityOption))]).then(this.prettifyScraperParamsLabels).catch(e=>this.$q.notify({message:`Error occured, plese refresh the page: ${e}`,color:"negative"})).finally(()=>this.loading=!1)},methods:{makeScheduleOption(e){return{label:e.split("_").map(h).join(" "),value:e}},makePriorityOption(e){return{label:h(e.name),value:e.value}},onSave(e){this.draftScraper.config=e,this.prettifyScraperParamsLabels(),this.showSaveDialog=!0},prettifyScraperParamsLabels(){const e=this.schedules.filter(o=>o.value===this.draftScraper.schedule)[0];this.draftScraper.schedule=e||this.draftScraper.schedule;const r=this.priorities.filter(o=>o.value===this.draftScraper.priority)[0];this.draftScraper.priority=r||this.draftScraper.priority},saveScraper(){const e={name:this.draftScraper.name,handler:this.draftScraper.handler,schedule:this.draftScraper.schedule.value||this.draftScraper.schedule,priority:this.draftScraper.priority.value==0?0:this.draftScraper.priority.value||this.draftScraper.priority,schedule_crontab:this.draftScraper.schedule_crontab,config:this.draftScraper.config};this.saveLoading=!0,q(e).then(r=>{this.$q.notify({message:"Successfully created new scraper",color:"positive"}),this.$router.push({name:"ScraperPage",params:{id:r.id}})}).catch(r=>this.$q.notify({message:`Failed to create new scraper: ${r}`,color:"negative"})).finally(()=>this.saveLoading=!1)}}},I=Q("div",{class:"text-h6"},"Save Scraper",-1);function U(e,r,o,O,a,i){const m=C("scraper-ide-component");return c(),u(_,null,{default:l(()=>[s(m,{modelValue:a.draftScraper.config,"onUpdate:modelValue":r[0]||(r[0]=t=>a.draftScraper.config=t),"enable-save-btn":!0,onSave:i.onSave},null,8,["modelValue","onSave"]),s(b,{modelValue:a.showSaveDialog,"onUpdate:modelValue":r[5]||(r[5]=t=>a.showSaveDialog=t)},{default:l(()=>[s(v,{class:"save-dialog"},{default:l(()=>[s(n,null,{default:l(()=>[I]),_:1}),s(n,{class:"q-pt-none"},{default:l(()=>[s(d,{modelValue:a.draftScraper.name,"onUpdate:modelValue":r[1]||(r[1]=t=>a.draftScraper.name=t),label:"Name",dense:""},null,8,["modelValue"]),s(p,{modelValue:a.draftScraper.schedule,"onUpdate:modelValue":r[2]||(r[2]=t=>a.draftScraper.schedule=t),label:"Schedule",options:a.schedules,dense:"",class:"q-pt-md"},null,8,["modelValue","options"]),a.draftScraper.schedule==="crontab"?(c(),u(d,{key:0,modelValue:a.draftScraper.schedule_crontab,"onUpdate:modelValue":r[3]||(r[3]=t=>a.draftScraper.schedule_crontab=t),label:"Crontab",dense:"",class:"q-pt-md"},null,8,["modelValue"])):P("",!0),s(p,{modelValue:a.draftScraper.priority,"onUpdate:modelValue":r[4]||(r[4]=t=>a.draftScraper.priority=t),label:"Priority",options:a.priorities,dense:"",class:"q-pt-md"},null,8,["modelValue","options"])]),_:1}),s(g,{align:"right"},{default:l(()=>[k(s(f,{flat:"",label:"Cancel"},null,512),[[y]]),s(f,{label:"Save",color:"positive",loading:a.saveLoading,onClick:i.saveScraper},null,8,["loading","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1})}var A=V(D,[["render",U]]);export{A as default};
