Files
dockerStuff/config/tandoor/staticfiles/vue3/assets/PropertyEditorPage-DFfeym2k.js
2025-11-16 21:46:46 +00:00

2 lines
8.7 KiB
JavaScript

import{d as oe,b8 as ae,c as te,r as s,o as de,A as U,Q as F,R as b,b as V,g as o,w as t,K as ue,aN as ne,F as _,M as S,N as re,j as k,t as p,O as B,ag as L,h as m,e as v,z as i,k as W,V as E,aj as se,i as n,p as q,G as A,_ as J,W as ie,S as C,aO as pe,f as r,ai as j,l as fe,af as X}from"./main-BhFWIRV_.js";import{_ as me}from"./BtnCopy.vue_vue_type_script_setup_true_lang-B_1A58TG.js";import{_ as ve}from"./FdcSearchDialog.vue_vue_type_script_setup_true_lang-C-bx54-t.js";import{o as ce}from"./fdc-CkSQIsAv.js";import"./VTooltip-CP00KBBq.js";const Fe=oe({__name:"PropertyEditorPage",setup(ye){const R=ae("history",{}),g=te(()=>(I.value/D.value*N.value).toFixed(2)),$=s(!1),h=s(100),T=s(void 0),I=s(250),D=s(500),N=s(100),M=s(!1),x=s(void 0),f=s(),w=s([]),c=s(new Map),z=s(!1),O=s(!1);de(()=>{Y(),R.recipe&&typeof R.recipe=="string"&&!isNaN(parseInt(R.recipe))&&H(parseInt(R.recipe))});function H(a){let e=new U;z.value=!0,e.apiRecipeRetrieve({id:a}).then(l=>{f.value=l,G()}).catch(l=>{F().addError(b.FETCH_ERROR,l)}).finally(()=>{z.value=!1})}function Y(){let a=new U;O.value=!0,a.apiPropertyTypeList().then(e=>{w.value=e.results,G()}).catch(e=>{F().addError(b.FETCH_ERROR,e)}).finally(()=>{O.value=!1})}function G(){c.value=new Map,f.value!=null&&f.value.steps.forEach(a=>{a.ingredients.forEach(e=>{if(e.food&&!c.value.has(e.food.id)){let l=K(e);l.loading=!1,c.value.set(l.food.id,l)}})})}function K(a){let e=new Map;return a.food.properties.forEach(l=>{e.set(l.propertyType.id,l)}),a.food.properties=[],w.value.forEach(l=>{e.has(l.id)?a.food.properties.push(e.get(l.id)):a.food.properties.push({propertyType:l,propertyAmount:null})}),a}function Z(a,e){let l=new U;a.id?(e.loading=!0,l.apiPropertyDestroy({id:a.id}).then(d=>{a.propertyAmount=null}).catch(d=>{F().addError(b.DELETE_ERROR,d)}).finally(()=>{e.loading=!1})):a.propertyAmount=null}function y(a){let e=new U;a.loading=!0,e.apiFoodPartialUpdate({id:a.food.id,patchedFood:a.food}).then(l=>{}).catch(l=>{F().addError(b.UPDATE_ERROR,l)}).finally(()=>{a.loading=!1})}function Q(a){let e=new U;a.food.fdcId&&(a.loading=!0,e.apiFoodFdcCreate({id:a.food.id,food:a.food}).then(l=>{a.food=l,c.value.set(l.id,K(a))}).catch(l=>{F().addError(b.UPDATE_ERROR,l)}).finally(()=>{a.loading=!1}))}function ee(a){c.value.forEach(e=>{e.food.propertiesFoodUnit=a,y(e)})}function le(a){c.value.forEach(e=>{e.food.propertiesFoodAmount=a,y(e)})}return(a,e)=>(r(),V(_,null,[o(ue,null,{default:t(()=>[o(S,{loading:z.value||O.value},{default:t(()=>[o(re,null,{default:t(()=>[k(p(a.$t("Property_Editor")),1)]),_:1}),o(B,null,{default:t(()=>[o(L,{"append-to-body":"",model:"Recipe",modelValue:f.value,"onUpdate:modelValue":[e[0]||(e[0]=l=>f.value=l),e[1]||(e[1]=l=>H(f.value.id))]},{append:t(()=>[f.value!=null?(r(),m(i,{key:0,icon:"fa-solid fa-arrow-up-right-from-square",to:{name:"RecipeViewPage",params:{id:f.value.id}}},null,8,["to"])):v("",!0)]),_:1},8,["modelValue"])]),_:1})]),_:1},8,["loading"]),o(W,null,{default:t(()=>[o(E,null,{default:t(()=>[o(se,{class:"mt-2"},{default:t(()=>[n("thead",null,[n("tr",null,[n("th",null,p(a.$t("Food")),1),n("th",null,[o(i,{variant:"outlined",block:"",href:"https://fdc.nal.usda.gov/food-search",target:"_blank","prepend-icon":"$search",stacked:""},{default:t(()=>[k(p(a.$t("FDC_ID")),1)]),_:1})]),n("th",null,[o(i,{variant:"outlined",onClick:e[2]||(e[2]=l=>$.value=!0),block:"",stacked:""},{default:t(()=>[k(p(a.$t("Amount")),1)]),_:1})]),n("th",null,[o(i,{variant:"outlined",onClick:e[3]||(e[3]=l=>$.value=!0),block:"",stacked:""},{default:t(()=>[k(p(a.$t("Properties_Food_Unit")),1)]),_:1})]),(r(!0),V(_,null,q(w.value,l=>(r(),V("th",{key:l.id},[o(i,{stacked:"",block:"",variant:"outlined",class:"mt-2 mb-2"},{default:t(()=>[n("span",null,p(l.name),1),n("span",null,[o(j,{color:"info",size:"x-small"},{default:t(()=>[o(A,{icon:"fa-solid fa-arrow-down-1-9"}),k(p(l.order),1)]),_:2},1024),l.fdcId?(r(),m(j,{key:0,color:"success",size:"x-small"},{default:t(()=>[o(A,{icon:"fa-solid fa-check"}),e[17]||(e[17]=k("FDC"))]),_:1,__:[17]})):v("",!0),l.fdcId?v("",!0):(r(),m(j,{key:1,color:"error",size:"x-small"},{default:t(()=>[o(A,{icon:"fa-solid fa-times"}),e[18]||(e[18]=k("FDC"))]),_:1,__:[18]}))]),o(J,{model:"PropertyType",item:l},null,8,["item"])]),_:2},1024)]))),128)),n("th",null,[o(i,{color:"create",class:"mt-1 float-right"},{default:t(()=>[o(A,{icon:"$create"}),o(J,{model:"PropertyType",onCreate:e[4]||(e[4]=l=>w.value.push(l))})]),_:1})])])]),n("tbody",null,[(r(!0),V(_,null,q(c.value.entries(),([l,d])=>(r(),V("tr",null,[n("td",null,p(d.food.name),1),n("td",null,[o(C,{type:"number",modelValue:d.food.fdcId,"onUpdate:modelValue":u=>d.food.fdcId=u,density:"compact","hide-details":"",onChange:u=>y(d),style:{"min-width":"180px"},loading:d.loading},{"append-inner":t(()=>[d.food.fdcId==null?(r(),m(i,{key:0,icon:"$search",size:"small",density:"compact",variant:"plain",onClick:u=>{x.value=d,M.value=!0}},null,8,["onClick"])):v("",!0),d.food.fdcId?(r(),m(i,{key:1,onClick:u=>Q(d),icon:"fa-solid fa-arrows-rotate",size:"small",density:"compact",variant:"plain"},null,8,["onClick"])):v("",!0),d.food.fdcId?(r(),m(i,{key:2,onClick:u=>fe(ce)(d.food.fdcId),href:`https://fdc.nal.usda.gov/food-details/${d.food.fdcId}/nutrients`,target:"_blank",icon:"fa-solid fa-arrow-up-right-from-square",size:"small",variant:"plain"},null,8,["onClick","href"])):v("",!0)]),_:2},1032,["modelValue","onUpdate:modelValue","onChange","loading"])]),n("td",null,[o(X,{modelValue:d.food.propertiesFoodAmount,"onUpdate:modelValue":u=>d.food.propertiesFoodAmount=u,density:"compact","hide-details":"",onChange:u=>y(d),loading:d.loading,style:{"min-width":"100px"},"control-variant":"hidden",precision:2},null,8,["modelValue","onUpdate:modelValue","onChange","loading"])]),n("td",null,[o(L,{model:"Unit",density:"compact",modelValue:d.food.propertiesFoodUnit,"onUpdate:modelValue":[u=>d.food.propertiesFoodUnit=u,u=>y(d)],"hide-details":"",loading:d.loading},null,8,["modelValue","onUpdate:modelValue","loading"])]),(r(!0),V(_,null,q(d.food.properties,u=>(r(),V("td",{key:`${d.food.id}_${u.propertyType.id}`},[u.propertyAmount!=null?(r(),m(X,{key:0,modelValue:u.propertyAmount,"onUpdate:modelValue":P=>u.propertyAmount=P,density:"compact","hide-details":"",onChange:P=>y(d),precision:2,loading:d.loading,"onClick:clear":P=>Z(u,d),style:{"min-width":"120px"},"control-variant":"hidden",clearable:""},null,8,["modelValue","onUpdate:modelValue","onChange","loading","onClick:clear"])):v("",!0),u.propertyAmount==null?(r(),m(i,{key:1,variant:"outlined",color:"create",block:"",onClick:P=>{u.propertyAmount=0,y(d)}},{default:t(()=>[o(A,{icon:"$create"})]),_:2},1032,["onClick"])):v("",!0)]))),128)),e[19]||(e[19]=n("td",null,null,-1))]))),256))]),o(ie,{style:{"margin-top":"120px"}})]),_:1}),o(S,{"prepend-icon":"fa-solid fa-calculator",title:a.$t("Calculator")},{default:t(()=>[o(B,null,{default:t(()=>[o(W,{dense:""},{default:t(()=>[o(E,{cols:"3"},{default:t(()=>[o(C,{type:"number",modelValue:I.value,"onUpdate:modelValue":e[5]||(e[5]=l=>I.value=l)},{append:t(()=>e[20]||(e[20]=[n("i",{class:"fa-solid fa-divide"},null,-1)])),_:1},8,["modelValue"])]),_:1}),o(E,{cols:"3"},{default:t(()=>[o(C,{type:"number",modelValue:D.value,"onUpdate:modelValue":e[6]||(e[6]=l=>D.value=l)},{append:t(()=>e[21]||(e[21]=[n("i",{class:"fa-solid fa-equals"},null,-1)])),_:1},8,["modelValue"])]),_:1}),o(E,{cols:"3"},{default:t(()=>[o(C,{type:"number",modelValue:g.value,"onUpdate:modelValue":e[7]||(e[7]=l=>g.value=l)},{append:t(()=>e[22]||(e[22]=[n("i",{class:"fa-solid fa-divide"},null,-1)])),"append-inner":t(()=>[o(me,{variant:"plain","copy-value":g.value},null,8,["copy-value"])]),_:1},8,["modelValue"])]),_:1}),o(E,{cols:"3"},{default:t(()=>[o(C,{type:"number",modelValue:N.value,"onUpdate:modelValue":e[8]||(e[8]=l=>N.value=l)},null,8,["modelValue"])]),_:1})]),_:1})]),_:1})]),_:1},8,["title"])]),_:1})]),_:1}),o(ve,{modelValue:M.value,"onUpdate:modelValue":e[9]||(e[9]=l=>M.value=l),onSelected:e[10]||(e[10]=l=>{x.value.food.fdcId=l,Q(x.value)})},null,8,["modelValue"])]),_:1}),o(ne,{modelValue:$.value,"onUpdate:modelValue":e[16]||(e[16]=l=>$.value=l),"max-width":"600"},{default:t(()=>[o(S,null,{default:t(()=>[o(pe,{modelValue:$.value,"onUpdate:modelValue":e[11]||(e[11]=l=>$.value=l),title:a.$t("Update")},null,8,["modelValue","title"]),o(B,null,{default:t(()=>[n("p",null,p(a.$t("Update_Existing_Data")),1),o(L,{model:"Unit",label:a.$t("Properties_Food_Unit"),modelValue:T.value,"onUpdate:modelValue":e[13]||(e[13]=l=>T.value=l)},{append:t(()=>[o(i,{onClick:e[12]||(e[12]=l=>ee(T.value)),icon:"$save",color:"save",disabled:T.value==null},null,8,["disabled"])]),_:1},8,["label","modelValue"]),o(C,{type:"number",label:a.$t("Properties_Food_Amount"),modelValue:h.value,"onUpdate:modelValue":e[15]||(e[15]=l=>h.value=l)},{append:t(()=>[o(i,{onClick:e[14]||(e[14]=l=>le(h.value)),icon:"$save",color:"save"})]),_:1},8,["label","modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue"])],64))}});export{Fe as default};