"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[248],{90248:(e,t,r)=>{r.r(t);var s=r(94430),a=r(28120),i=r(16682),n=r(80692),o=r(71277),l=r(9201),c=r(15494);r(67475),r(68784);const d=[{type:"gutter",gutterName:"dirty"},{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",icon:"edit"}],u={pages:[20,30,50,100,200]};class h extends s.oi{static get styles(){return s.iv`
      :host {
        display: flex;
        flex-direction: row;
      }

      ox-grist {
        flex: 1;
      }
    `}static get properties(){return{mode:String,columns:Array,_config:Object,fetchHandler:Object,fetchOptions:Object,editHandler:Object}}render(){return s.dy`
      <ox-grist
        .mode=${this.mode}
        .config=${this._config}
        .editHandler=${this.editHandler}
        .fetchHandler=${this.fetchHandler}
        .fetchOptions=${this.fetchOptions}
      >
      </ox-grist>
    `}get dataGrist(){return this.shadowRoot.querySelector("ox-grist")}fetch(){this.dataGrist.fetch()}get data(){return this.dataGrist._data}buildConfig(){var e=this.columns.map((e=>{let{name:t,gridWidth:r,gridAlign:s,term:a}=e,i=e.refType&&e.refType.toLowerCase(),n=e.colType;return(i&&"entity"===i||"menu"===i)&&(n="object"),{name:t,type:n,hidden:!1,width:r,resizable:!0,sortable:!0,header:a,record:{align:s}}})),t=this.columns.filter((e=>e.sortRank)).map((e=>({name:e.name,desc:!!e.reverseSort})));return{columns:[...d,...e],pagination:{...u,infinite:!1},rows:{appendable:!0,insertable:!0,selectable:{multiple:!0}},sorters:t}}updated(e){e.has("columns")&&(this._config=this.buildConfig())}}customElements.define("data-list-wrapper",h);var m=r(51266);function p(e){if(e.indexOf("_")>0){const t=e.split("_");e=t.map(((e,t)=>(t>0&&(e=e.replace(e[0],e[0].toUpperCase())),e))).join("")}return e}class f extends((0,a.$)(n.h)(n.B4)){static get styles(){return[l.Ix,s.iv`
        :host {
          display: flex;
          flex-direction: column;

          overflow: hidden;
        }

        search-form {
          overflow: visible;
        }

        data-list-wrapper {
          flex: 1;

          overflow: hidden;
        }
      `]}static get properties(){return{resourceId:String,_searchFields:Array,_columns:Array}}get context(){return{title:this.menuTitle,exportable:{name:this.menuTitle,data:this._exportableData.bind(this)},importable:{handler:()=>{}},printable:{accept:["paper","preview"],content:()=>this},actions:(this.buttons||[]).map((e=>({title:e.text,action:e.action})))}}firstUpdated(){c.z.store.on("added",((e,t)=>{m.trace("이 메시지 발생 시 꼭 확인되어야 함."),this._parseResourceMeta()}))}_exportableData(){return this.dataList.exportRecords()}render(){return s.dy`
      <search-form
        id="search-form"
        .fields=${this._searchFields}
        initFocus="description"
        @submit=${e=>this.dataList.fetch()}
      ></search-form>

      <data-list-wrapper
        pulltorefresh
        .mode=${(0,o.s2)()?"LIST":"GRID"}
        .columns=${this._columns}
        .records=${this.items}
        .fetchHandler=${this.fetchHandler.bind(this)}
      >
      </data-list-wrapper>
    `}async fetchHandler({page:e,limit:t,sorters:r=[]}){if(!this.resourceUrl)return;const s=await n.Lp.query({query:i.ZP`
        ${this._queryBuilder({page:e,limit:t,sorters:r,filters:this.buildFilters()})}
      `});return{total:s.data.response.total||0,page:e,limit:t,records:s.data.response.items||[]}}get searchForm(){return this.shadowRoot.querySelector("#search-form")}get dataList(){return this.shadowRoot.querySelector("data-list-wrapper")}async _getResourceData(){this.columns=[];const e=await n.Lp.query({query:i.ZP`
        query {
          menu(name: "${this.resourceId}") {
            name,
            resourceUrl,
            buttons {
              text
            },
            columns {
              name
              term
              colType
              colSize
              nullable
              refType
              refName
              refUrl
              refRelated
              searchRank
              sortRank
              reverseSort
              searchEditor
              searchOper
              searchInitVal
              gridRank
              gridEditor
              gridFormat
              gridValidator
              gridWidth
              gridAlign
              formEditor
              formValidator
              formFormat
              defVal
              rangeVal
              ignoreOnSave
            }
          }
        }
      `});this.menuMeta=e.data.menu,this.menuTitle=this.menuMeta.name,this.resourceUrl=p(this.menuMeta.resourceUrl),this.searchForm.form.reset(),this._parseResourceMeta(),this.updateContext()}_parseResourceMeta(){if(this.menuMeta){var e=this.menuMeta;this._columns=e.columns.filter((e=>e.gridRank>0)).map((e=>(e.term=c.z.t(e.term),e))).sort(((e,t)=>e.gridRank>t.gridRank?1:-1)),this.buttons=e.buttons,this._searchFields=e.columns.filter((e=>e.searchRank&&e.searchRank>0)).sort(((e,t)=>e.searchRank>t.searchRank?1:-1)).map((e=>({name:e.name,type:e.searchEditor?e.searchEditor:"text",props:{min:e.rangeVal?e.rangeVal.split(",")[0]:null,max:e.rangeVal?e.rangeVal.split(",")[1]:null,searchOper:e.searchOper?e.searchOper:"eq",placeholder:e.term},value:e.searchInitVal})))}}_queryBuilder({page:e,limit:t,sorters:r,filters:s}){var a=this._columns&&this._columns.length>0?this._columns.map((e=>"Entity"==e.refType||"Menu"==e.refType?`${p(e.name).replace("Id","")} { id name description }`:p(e.name))).join():"id";return`\n    query {\n      response: ${this.resourceUrl} (\n        ${o.Lg.buildArgs({filters:s,pagination:{limit:t,page:e},sortings:r.map((e=>({name:e.name,desc:!!e.descending})))})}\n      ) {\n        items {\n          ${a}\n        }\n        total\n      }\n    }\n  `}buildFilters(){const e=[];return this.searchForm.formFields.forEach((t=>{t.value&&e.push({name:t.name,operator:t.getAttribute("searchOper"),value:t.value,dataType:this._columns.find((e=>e.name===t.name)).colType})})),e}stateChanged(e){this.resourceId=e.route.resourceId}updated(e){e.has("resourceId")&&this._getResourceData()}}window.customElements.define("resource-ui",f)}}]);