farmdata2-1.3.0/tray_seeding/tray_seeding.js

tray_seeding/tray_seeding.js
import{_ as f,r as d,o as b,c as w,a,w as u,d as m,t as z,b as D,v as L,e as Q,f as P}from"../_plugin-vue_export-helper/_plugin-vue_export-helper.js";import{S as q,T as U,Q as Y,U as M,X as F,R as _,c as I,d as j,a as g,b as p,e as G,f as O,r as Z,D as X,L as H,N as J,C as K,j as W,k as v,s as S,l as C,m as $,Z as ee,p as te}from"../uiUtil/uiUtil.js";import{C as se}from"../CropSelector/CropSelector.js";const ne={name:"TraySizeSelector",components:{SelectorBase:q},emits:["error","ready","update:selected","valid"],props:{required:{type:Boolean,default:!1},selected:{type:String,default:null},showValidityStyling:{type:Boolean,default:!1}},data(){return{traySizeList:[],canCreateTraySize:!1}},computed:{},methods:{handleUpdateSelected(n){this.$emit("update:selected",n)},handleValid(n){this.$emit("valid",n)},handleAddClicked(){U(),window.location.href="/admin/structure/taxonomy/manage/tray_size/add"}},watch:{},created(){let n=Y("create-terms-in-tray_size"),e=M();Promise.all([n,e]).then(([r,l])=>{this.traySizeList=Array.from(l.keys()),this.canCreateTraySize=r,this.$emit("ready")}).catch(r=>{console.error("TraySizeSelector: Error fetching tray sizes."),console.error(r),this.$emit("error","Unable to fetch tray sizes.")})}};function ie(n,e,r,l,s,o){const y=d("SelectorBase");return b(),w("div",null,[a(y,{id:"tray-size-selector","data-cy":"tray-size-selector",label:"Tray Size",invalidFeedbackText:"A tray size is required",options:s.traySizeList,required:r.required,selected:r.selected,showValidityStyling:r.showValidityStyling,"onUpdate:selected":e[0]||(e[0]=i=>o.handleUpdateSelected(i)),onValid:e[1]||(e[1]=i=>o.handleValid(i)),onAddClicked:o.handleAddClicked,includeAddButton:s.canCreateTraySize},null,8,["options","required","selected","showValidityStyling","onAddClicked","includeAddButton"])])}const re=f(ne,[["render",ie]]),ae={name:"TextDisplay",components:{},emits:["ready"],props:{label:{type:String,required:!0},text:{type:String,required:!0}},data(){return{}},computed:{processedText(){return this.text==null||this.text=="NaN"?"":this.text}},methods:{},watch:{},created(){this.$emit("ready")}},oe={"data-cy":"text-label"};function le(n,e,r,l,s,o){const y=F,i=_;return b(),w("div",null,[a(i,{id:"text-group","data-cy":"text-group",label:r.label,"label-for":"text-text","label-cols":"auto"},{label:u(()=>[m("span",oe,z(r.label)+":",1)]),default:u(()=>[a(y,{id:"text-text","data-cy":"text-text",disabled:"",plaintext:"",modelValue:o.processedText,"onUpdate:modelValue":e[0]||(e[0]=c=>o.processedText=c)},null,8,["modelValue"])]),_:1},8,["label"])])}const de=f(ae,[["render",le]]);async function ye(n){try{return await Z([{name:"plantAsset",do:async()=>await I(n.seedingDate,n.cropName,n.comment),undo:async i=>{await j(i.plantAsset.id)}},{name:"traysQuantity",do:async i=>await g("count",n.trays,"Trays","TRAYS",i.plantAsset,"increment"),undo:async i=>{await p(i.traysQuantity.id)}},{name:"traySizeQuantity",do:async()=>await g("ratio",n.traySize,"Tray Size","CELLS/TRAY"),undo:async i=>{await p(i.traySizeQuantity.id)}},{name:"seedsQuantity",do:async()=>await g("count",n.seedsPerCell*n.trays*n.traySize,"Seeds","SEEDS"),undo:async i=>{await p(i.seedsQuantity.id)}},{name:"seedingLog",do:async i=>await G(n.seedingDate,n.locationName,[],["seeding","seeding_tray"],i.plantAsset,[i.traysQuantity,i.traySizeQuantity,i.seedsQuantity]),undo:async i=>{await O(i.seedingLog.id)}}])}catch(e){console.error(`TraySeeding: 
`+e.message),console.error(e);let r="Error creating tray seeding.";for(const l of Object.keys(e.results))e.results[l]&&(r+=`
  Result of operation `+l+" could not be cleaned up.",e.results[l].attributes&&e.results[l].attributes.name?(r+=`
   Manually delete log or asset with:`,r+=`
     name: `+e.results[l].attributes.name):r+=`
   May be safely ignored`);throw Error(r,e)}}const T={submitForm:ye};const ue={components:{CropSelector:se,DateSelector:X,LocationSelector:H,NumericInput:J,TraySizeSelector:re,TextDisplay:de,CommentBox:K,SubmitResetButtons:W},data(){return{form:{seedingDate:v().format("YYYY-MM-DD"),cropName:null,locationName:null,trays:1,traySize:null,seedsPerCell:1,comment:null},validity:{show:!1,seedingDate:!1,cropName:!1,locationName:!1,trays:!1,traySize:!1,seedsPerCell:!1,comment:!1},submitting:!1,errorShowing:!1,createdCount:0}},computed:{totalSeeds(){return(this.form.trays*parseInt(this.form.traySize)*this.form.seedsPerCell).toLocaleString(void 0)},pageDoneLoading(){return this.createdCount==10},submitEnabled(){return!this.validity.show||this.validToSubmit&&!this.submitting},resetEnabled(){return!this.submitting},validToSubmit(){return Object.entries(this.validity).filter(([n])=>n!=="show").every(n=>n[1]===!0)}},methods:{submit(){this.submitting=!0,this.validity.show=!0,this.validToSubmit?(S("Submitting tray seeding...","","top-center","success"),T.submitForm({...this.form}).then(()=>{C(),S("Tray seeding created.","","top-center","success",2).then(()=>{this.reset(!0),this.submitting=!1})}).catch(()=>{this.errorShowing||(C(),this.errorShowing=!0,S("Error creating tray seeding.","Check your network connection and try again.","top-center","danger",5).then(()=>{this.submitting=!1,this.errorShowing=!1}))})):this.submitting=!1},reset(n=!1){this.validity.show=!1,n||(this.form.seedingDate=v().format("YYYY-MM-DD"),this.form.locationName=null),this.form.cropName=null,this.form.trays=1,this.form.traySize=null,this.form.seedsPerCell=1,this.form.comment=null}},watch:{},created(){this.createdCount++,window.Cypress&&(document.defaultView.lib=T)}},me={id:"tray-seeding","data-cy":"tray-seeding"},ce=m("h2",{id:"tray-seeding-header","data-cy":"tray-seeding-header",class:"text-center"}," Tray Seeding ",-1),ge=m("hr",null,null,-1),pe=m("hr",null,null,-1);function Se(n,e,r,l,s,o){const y=ee,i=d("DateSelector"),c=d("CropSelector"),x=d("LocationSelector"),h=d("NumericInput"),N=d("TraySizeSelector"),B=d("TextDisplay"),A=d("CommentBox"),E=d("SubmitResetButtons"),k=te,R=$;return b(),w("div",me,[a(y,{id:"tray-seeding-toaster","data-cy":"tray-seeding-toaster"}),a(R,{id:"tray-seeding-card","data-cy":"tray-seeding-card","bg-variant":"light","header-tag":"header"},{header:u(()=>[ce]),default:u(()=>[a(k,{id:"tray-seeding-form","data-cy":"tray-seeding-form"},{default:u(()=>[a(i,{id:"tray-seeding-date","data-cy":"tray-seeding-date",required:"",date:s.form.seedingDate,"onUpdate:date":e[0]||(e[0]=t=>s.form.seedingDate=t),showValidityStyling:s.validity.show,onValid:e[1]||(e[1]=t=>s.validity.seedingDate=t),onReady:e[2]||(e[2]=t=>s.createdCount++)},null,8,["date","showValidityStyling"]),a(c,{id:"tray-seeding-crop","data-cy":"tray-seeding-crop",required:"",selected:s.form.cropName,"onUpdate:selected":e[3]||(e[3]=t=>s.form.cropName=t),showValidityStyling:s.validity.show,onValid:e[4]||(e[4]=t=>s.validity.cropName=t),onReady:e[5]||(e[5]=t=>s.createdCount++),onError:e[6]||(e[6]=t=>n.showErrorToast("Network Error",t))},null,8,["selected","showValidityStyling"]),a(x,{id:"tray-seeding-location","data-cy":"tray-seeding-location",required:"",includeGreenhouses:"",selected:s.form.locationName,"onUpdate:selected":e[7]||(e[7]=t=>s.form.locationName=t),allowBedSelection:!1,showValidityStyling:s.validity.show,onValid:e[8]||(e[8]=t=>s.validity.locationName=t),onReady:e[9]||(e[9]=t=>s.createdCount++),onError:e[10]||(e[10]=t=>n.showErrorToast("Network Error",t))},null,8,["selected","showValidityStyling"]),ge,a(h,{id:"tray-seeding-trays","data-cy":"tray-seeding-trays",required:"",label:"Trays",invalidFeedbackText:"Trays must be positive.",value:s.form.trays,"onUpdate:value":e[11]||(e[11]=t=>s.form.trays=t),showValidityStyling:s.validity.show,decimalPlaces:2,incDecValues:[1,5,10],minValue:.01,onValid:e[12]||(e[12]=t=>s.validity.trays=t),onReady:e[13]||(e[13]=t=>s.createdCount++)},null,8,["value","showValidityStyling"]),a(N,{id:"tray-seeding-tray-size","data-cy":"tray-seeding-tray-size",required:"",selected:s.form.traySize,"onUpdate:selected":e[14]||(e[14]=t=>s.form.traySize=t),showValidityStyling:s.validity.show,onValid:e[15]||(e[15]=t=>s.validity.traySize=t),onReady:e[16]||(e[16]=t=>s.createdCount++),onError:e[17]||(e[17]=t=>n.showErrorToast("Network Error",t))},null,8,["selected","showValidityStyling"]),a(h,{id:"tray-seeding-seeds","data-cy":"tray-seeding-seeds",required:"",label:"Seeds/Cell",invalidFeedbackText:"Seeds must be positive.",value:s.form.seedsPerCell,"onUpdate:value":e[18]||(e[18]=t=>s.form.seedsPerCell=t),showValidityStyling:s.validity.show,decimalPlaces:0,incDecValues:[1],minValue:1,onValid:e[19]||(e[19]=t=>s.validity.seedsPerCell=t),onReady:e[20]||(e[20]=t=>s.createdCount++)},null,8,["value","showValidityStyling"]),a(B,{id:"tray-seeding-total-seeds","data-cy":"tray-seeding-total-seeds",label:"Total Seeds",text:o.totalSeeds,onReady:e[21]||(e[21]=t=>s.createdCount++)},null,8,["text"]),pe,a(A,{id:"tray-seeding-comment","data-cy":"tray-seeding-comment",comment:s.form.comment,"onUpdate:comment":e[22]||(e[22]=t=>s.form.comment=t),onValid:e[23]||(e[23]=t=>s.validity.comment=t),onReady:e[24]||(e[24]=t=>s.createdCount++)},null,8,["comment"]),a(E,{id:"seeding-submit-reset","data-cy":"seeding-submit-reset",enableSubmit:o.submitEnabled,enableReset:o.resetEnabled,onReady:e[25]||(e[25]=t=>s.createdCount++),onSubmit:e[26]||(e[26]=t=>o.submit()),onReset:e[27]||(e[27]=t=>o.reset())},null,8,["enableSubmit","enableReset"])]),_:1})]),_:1}),D(m("div",{"data-cy":"page-loaded"},z(o.pageDoneLoading),513),[[L,!1]])])}const fe=f(ue,[["render",Se]]),V=Q(fe);V.use(P());V.mount("#app");

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc