farmdata2-1.3.0/direct_seeding/direct_seeding.js
direct_seeding/direct_seeding.js
import{_ as R,r as c,c as A,a as d,w as m,b as D,d as g,t as P,o as T,v as k,e as W,f as U}from"../_plugin-vue_export-helper/_plugin-vue_export-helper.js";import{c as M,d as x,a as p,b as y,e as Y,f as I,g as j,h as H,i as O,r as Z,D as G,L as z,N as J,S as K,C as X,j as _,k as V,s as B,l as F,m as $,Z as ee,u as te,n as ie,p as ne}from"../uiUtil/uiUtil.js";import{C as se}from"../CropSelector/CropSelector.js";import{S as oe}from"../SoilDisturbance/SoilDisturbance.js";async function de(n){try{const e=[],r=[],a={name:"plantAsset",do:async()=>await M(n.seedingDate,n.cropName,n.comment),undo:async s=>{await x(s.plantAsset.id)}};e.push(a);const i={name:"bedFeetQuantity",do:async()=>await p("length",n.bedFeet,"Bed Feet","FEET"),undo:async s=>{s.seedingLog!="undone"&&await y(s.bedFeetQuantity.id)}};e.push(i);const l={name:"rowsPerBedQuantity",do:async()=>await p("ratio",n.rowsPerBed,"Rows/Bed","ROWS/BED"),undo:async s=>{s.seedingLog!="undone"&&await y(s.rowsPerBedQuantity.id)}};e.push(l);const b={name:"rowFeetQuantity",do:async s=>await p("length",n.bedFeet*n.rowsPerBed,"Row Feet","FEET",s.plantAsset,"increment"),undo:async s=>{s.seedingLog!="undone"&&await y(s.rowFeetQuantity.id)}};e.push(b);const w={name:"bedWidthQuantity",do:async()=>await p("length",n.bedWidth,"Bed Width","INCHES"),undo:async s=>{s.seedingLog!="undone"&&await y(s.bedWidthQuantity.id)}};e.push(w);const h={name:"seedingLog",do:async s=>await Y(n.seedingDate,n.locationName,n.beds,["seeding","seeding_direct"],s.plantAsset,[s.bedFeetQuantity,s.rowsPerBedQuantity,s.rowFeetQuantity,s.bedWidthQuantity]),undo:async s=>{await I(s.seedingLog.id)}};if(e.push(h),n.equipment.length>0){const s={name:"depthQuantity",do:async()=>await p("length",n.depth,"Depth","INCHES"),undo:async o=>{await y(o.depthQuantity.id)}};e.push(s);const f={name:"speedQuantity",do:async()=>await p("rate",n.speed,"Speed","MPH"),undo:async o=>{await y(o.speedQuantity.id)}};e.push(f);const v=await j();for(const o of n.equipment)r.push(v.get(o));const S={name:"activityLog",do:async o=>await H(n.seedingDate,n.locationName,n.beds,["tillage","seeding_direct"],o.plantAsset,[o.depthQuantity,o.speedQuantity,o.bedFeetQuantity],r),undo:async o=>{await O(o.activityLog.id)}};e.push(S)}const u=await Z(e);return r.length>0?u.equipment=r:(u.equipment=null,u.depthQuantity=null,u.speedQuantity=null,u.activityLog=null),u}catch(e){console.error(`DirectSeeding:
`+e.message),console.error(e);let r="Error creating direct seeding.";for(const a of Object.keys(e.results))e.results[a]&&e.results[a]!="undone"&&(r+=`
Result of operation `+a+" could not be cleaned up.",e.results[a].attributes&&e.results[a].attributes.name?(r+=`
Manually delete log or asset with:`,r+=`
name: `+e.results[a].attributes.name):r+=`
May be safely ignored`);throw Error(r,e)}}const Q={submitForm:de};const re={components:{CropSelector:se,DateSelector:G,LocationSelector:z,NumericInput:J,SelectorBase:K,SoilDisturbance:oe,CommentBox:X,SubmitResetButtons:_},data(){return{rowValues:["1","2","3","4","5","6","7","8","9","10"],form:{seedingDate:V().format("YYYY-MM-DD"),cropName:null,locationName:null,beds:[],bedFeet:100,rowsPerBed:"1",bedWidth:60,equipment:[],depth:0,speed:0,comment:null},validity:{show:!1,seedingDate:!1,cropName:!1,location:!1,bedFeet:!1,rowsPerBed:!1,bedWidth:!1,soilDisturbance:!1,comment:!1},submitting:!1,errorShowing:!1,createdCount:0}},computed:{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:{handleBedsUpdate(n){this.form.beds=n},submit(){this.submitting=!0,this.validity.show=!0,this.validToSubmit?(B("Submitting direct seeding...","","top-center","success"),Q.submitForm({...this.form}).then(()=>{F(),B("Direct seeding created.","","top-center","success",2).then(()=>{this.reset(!0),this.submitting=!1})}).catch(()=>{this.errorShowing||(F(),this.errorShowing=!0,B("Error creating direct 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.rowsPerBed="1",this.form.bedWidth=60,this.form.equipment=[],this.form.depth=0,this.form.speed=0),this.form.cropName=null,this.form.beds=[],this.form.bedFeet=100,this.form.comment=null}},watch:{},created(){this.createdCount++,window.Cypress&&(document.defaultView.lib=Q)}},ae={id:"direct-seeding","data-cy":"direct-seeding"},le=g("h2",{id:"direct-seeding-header","data-cy":"direct-seeding-header",class:"text-center"}," Direct Seeding ",-1),ue=g("hr",null,null,-1),ce=g("hr",null,null,-1),me=g("span",{id:"direct-seeding-soil-disturbance-accordion-title","data-cy":"direct-seeding-soil-disturbance-accordion-title",class:"w-100 text-center"}," Equipment & Soil Disturbance ",-1),pe=g("hr",null,null,-1);function ye(n,e,r,a,i,l){const b=ee,w=c("DateSelector"),h=c("CropSelector"),u=c("LocationSelector"),s=c("NumericInput"),f=c("SelectorBase"),v=c("SoilDisturbance"),S=te,o=ie,E=c("CommentBox"),N=c("SubmitResetButtons"),q=ne,L=$;return T(),A("div",ae,[d(b,{id:"direct-seeding-toaster","data-cy":"direct-seeding-toaster"}),d(L,{id:"direct-seeding-card","data-cy":"direct-seeding-card","bg-variant":"light","header-tag":"header"},{header:m(()=>[le]),default:m(()=>[d(q,{id:"direct-seeding-form","data-cy":"direct-seeding-form"},{default:m(()=>[d(w,{id:"direct-seeding-date","data-cy":"direct-seeding-date",required:"",date:i.form.seedingDate,"onUpdate:date":e[0]||(e[0]=t=>i.form.seedingDate=t),showValidityStyling:i.validity.show,onValid:e[1]||(e[1]=t=>i.validity.seedingDate=t),onReady:e[2]||(e[2]=t=>i.createdCount++)},null,8,["date","showValidityStyling"]),d(h,{id:"direct-seeding-crop","data-cy":"direct-seeding-crop",required:"",selected:i.form.cropName,"onUpdate:selected":e[3]||(e[3]=t=>i.form.cropName=t),showValidityStyling:i.validity.show,onValid:e[4]||(e[4]=t=>i.validity.cropName=t),onError:e[5]||(e[5]=t=>n.showErrorToast("Network Error",t)),onReady:e[6]||(e[6]=t=>i.createdCount++)},null,8,["selected","showValidityStyling"]),d(u,{id:"direct-seeding-location","data-cy":"direct-seeding-location",required:"",includeFields:"",includeGreenhousesWithBeds:"",selected:i.form.locationName,"onUpdate:selected":e[7]||(e[7]=t=>i.form.locationName=t),pickedBeds:i.form.beds,showValidityStyling:i.validity.show,onValid:e[8]||(e[8]=t=>i.validity.location=t),"onUpdate:beds":e[9]||(e[9]=t=>l.handleBedsUpdate(t)),onError:e[10]||(e[10]=t=>n.showErrorToast("Network Error",t)),onReady:e[11]||(e[11]=t=>i.createdCount++)},null,8,["selected","pickedBeds","showValidityStyling"]),ue,d(s,{id:"direct-seeding-bed-feet","data-cy":"direct-seeding-bed-feet",required:"",label:"Bed Feet",invalidFeedbackText:"Bed Feet must be positive.",value:i.form.bedFeet,"onUpdate:value":e[12]||(e[12]=t=>i.form.bedFeet=t),showValidityStyling:i.validity.show,decimalPlaces:0,incDecValues:[1,10,100],minValue:1,onValid:e[13]||(e[13]=t=>i.validity.bedFeet=t),onReady:e[14]||(e[14]=t=>i.createdCount++)},null,8,["value","showValidityStyling"]),d(s,{id:"direct-seeding-bed-width","data-cy":"direct-seeding-bed-width",required:"",label:"Bed Width (in)",invalidFeedbackText:"Bed width must be positive.",value:i.form.bedWidth,"onUpdate:value":e[15]||(e[15]=t=>i.form.bedWidth=t),showValidityStyling:i.validity.show,decimalPlaces:0,incDecValues:[1,10],minValue:1,onValid:e[16]||(e[16]=t=>i.validity.bedWidth=t),onReady:e[17]||(e[17]=t=>i.createdCount++)},null,8,["value","showValidityStyling"]),d(f,{id:"direct-seeding-rows-per-bed","data-cy":"direct-seeding-rows-per-bed",label:"Rows/Bed",invalidFeedbackText:"A number of rows is required",selected:i.form.rowsPerBed,"onUpdate:selected":e[18]||(e[18]=t=>i.form.rowsPerBed=t),options:i.rowValues,required:!0,showValidityStyling:i.validity.show,onValid:e[19]||(e[19]=t=>i.validity.rowsPerBed=t),onReady:e[20]||(e[20]=t=>i.createdCount++)},null,8,["selected","options","showValidityStyling"]),ce,d(o,{flush:"",id:"direct-seeding-soil-disturbance-accordion","data-cy":"direct-seeding-soil-disturbance-accordion"},{default:m(()=>[d(S,{id:"direct-seeding-soil-disturbance-accordion-item","data-cy":"direct-seeding-soil-disturbance-accordion-item"},{title:m(()=>[me]),default:m(()=>[d(v,{id:"direct-seeding-soil-disturbance","data-cy":"direct-seeding-soil-disturbance",showValidityStyling:i.validity.show,equipment:i.form.equipment,depth:i.form.depth,speed:i.form.speed,includeArea:!1,onValid:e[21]||(e[21]=t=>i.validity.soilDisturbance=t),"onUpdate:equipment":e[22]||(e[22]=t=>i.form.equipment=t),"onUpdate:depth":e[23]||(e[23]=t=>i.form.depth=t),"onUpdate:speed":e[24]||(e[24]=t=>i.form.speed=t),onError:e[25]||(e[25]=t=>n.showErrorToast("Network Error",t)),onReady:e[26]||(e[26]=t=>i.createdCount++)},null,8,["showValidityStyling","equipment","depth","speed"])]),_:1})]),_:1}),pe,d(E,{id:"direct-seeding-comment","data-cy":"direct-seeding-comment",comment:i.form.comment,"onUpdate:comment":e[27]||(e[27]=t=>i.form.comment=t),onValid:e[28]||(e[28]=t=>i.validity.comment=t),onReady:e[29]||(e[29]=t=>i.createdCount++)},null,8,["comment"]),d(N,{id:"direct-seeding-submit-reset","data-cy":"direct-seeding-submit-reset",enableSubmit:l.submitEnabled,enableReset:l.resetEnabled,onReady:e[30]||(e[30]=t=>i.createdCount++),onSubmit:e[31]||(e[31]=t=>l.submit()),onReset:e[32]||(e[32]=t=>l.reset())},null,8,["enableSubmit","enableReset"])]),_:1})]),_:1}),D(g("div",{id:"page-loaded","data-cy":"page-loaded"},P(l.pageDoneLoading),513),[[k,!1]])])}const ge=R(re,[["render",ye]]),C=W(ge);C.use(U());C.mount("#app");
