File manager - Edit - /home/autoph/.trash/assets/access-e6e7aefc.js
Back
import{L as A,I,T as O,s as D,C as F}from"./index-479e0467.js";import"./index-629fd9e2.js";import{_ as C,r as c,o as l,c as m,g as _,b as g,f as n,w as U,e as r,d as a,J as y,G as x,I as B}from"./index-e5373ec2.js";import{B as E}from"./index-63f57c33.js";import{S as G,U as T}from"./UpdateButton-cd065730.js";/* empty css */import"./array-6d4b6a20.js";import{R as k}from"./RoleService-8442efd0.js";import{M as j}from"./ModuleService-66f591e4.js";import{P as N}from"./PermissionService-446c1c34.js";import{L as q}from"./Loading-a86a6dc0.js";import"./lodash-2486ead9.js";import"./vue-cleave.min-e92e35a0.js";import"./xhebrhsj-3bff658e.js";import"./es.string.replace-def824ef.js";const J={components:{Button:E},props:{text:{type:String,default:"Back"},link:[String,Object],title:{type:String,default:"Go back"}},setup(){}};function Y(s,e,t,h,i,d){const u=c("Button");return l(),m(u,{btnClass:"btn-secondary pl-3 py-2",icon:"carbon:arrow-left",iconClass:"text-2xl",text:t.text,link:t.link},null,8,["text","link"])}const z=C(J,[["render",Y]]),H={components:{Layout:A,InputGroup:I,TextInput:O,SubmitButton:G,UpdateButton:T,BackButton:z,Multiselect:D,Loading:q,Checkbox:F},data(){return{form:{id:this.$route.params.id??null,company_id:null,dealership_id:null,modules:[]},searchModule:"",modules:[],permissions:[],companyOptions:[],dealerships:[],rolePermissions:[],errors:{},state:{isEdit:this.$route.params.id!==void 0&&this.$route.params.id!==null,isSaving:!1,isLoading:!1},checkAllPermissions:[],id:this.$route.params.id??null,title:"Role Access",theme:"warning",headerIcon:"heroicons:document-text"}},watch:{"form.company_id":{handler(){this.resetForm()}},"form.dealership_id":{handler(){this.resetForm()}}},computed:{filteredModules:function(){return this.form.modules.filter(s=>s.name.toLowerCase().includes(this.searchModule.toLowerCase()))},dealershipOptions:function(){let s=[];return this.form.company_id&&(s=this.dealerships.filter(e=>this.form.company_id==e.company_id).map(e=>({label:e.name,value:e.id}))),s}},methods:{showDetail(s){console.log("detail"),console.log(s)},async fetchRecord(){this.state.isLoading=!0,await k.fetchRecord(this.$route.params.id).then(s=>{if(console.log(s),s.status==200){let e=s.data.data;this.companyOptions=e.companies.map(t=>({label:t.name,value:t.id})),this.dealerships=e.dealerships}}).catch(s=>{console.log(s)}).finally(()=>{this.state.isLoading=!1})},async fetchModules(){await j.fetchRecords().then(s=>{s.status==200&&(this.modules=s.data.data.map(e=>({id:e.id,name:e.name})))})},async fetchPermissions(){await N.fetchRecords().then(s=>{s.status==200&&(this.permissions=s.data.data.map(e=>({id:e.id,name:e.name})))})},async fetchRolePermission(){this.state.isLoading=!0,await k.fetchRolePermission(this.$route.params.id).then(s=>{s.status==200&&(this.rolePermissions=s.data.data,this.modules.length>0&&this.permissions.length>0&&(this.form.company_id=this.rolePermissions[0].company_id,this.form.dealership_id=this.rolePermissions[0].dealership_id!=0?this.rolePermissions[0].dealership_id:null,this.resetForm()))}).finally(()=>{this.state.isLoading=!1})},async submitForm(){this.state.isSaving=!0,console.log(this.form);let s={};s=this.form,s.modules=s.modules.map(e=>({...e,permissions:e.permissions.filter(t=>t.checked==!0)})).filter(e=>e.permissions!==null&&e.permissions.length>0),console.log("formData"),console.log(s),await k.savePermission(s).then(e=>{e.status==201?(this.$swal.fire({title:"Great!",text:"Record successfully saved.",icon:"success",timer:2e3}),this.fetchRolePermission()):this.$swal.fire({title:"Ooops! something is wrong.",text:e.data.message,icon:"error",timer:2e3})}).catch(e=>{console.log(e),e.response.status==422?this.$swal.fire({title:"Ooops! something is wrong.",text:e.response.data.message??null,icon:"warning"}):this.$swal.fire({title:"Ooops! something is wrong.",text:"Please contact system administrator",icon:"error",timer:2e3})}).finally(()=>{this.state.isSaving=!1})},confirmSubmit(){this.$swal.fire({title:"Are you sure you want to save this record?",text:"",icon:"question",showCancelButton:!0,confirmButtonColor:"#34c38f",cancelButtonColor:"#f46a6a",confirmButtonText:"Yes",cancelButtonText:"No"}).then(s=>{s.value&&this.submitForm()})},resetForm(){this.form.modules=[],this.checkAllPermissions=[],this.modules.forEach(s=>{let e=this.filteredPermissions(s.id),t=[];this.permissions.forEach(h=>{t.push({id:h.id,checked:e.length>0&&e.includes(h.id)})}),this.form.modules.push({id:s.id,name:s.name,permissions:t})}),console.log("this.form"),console.log(this.form)},checkAll(s){if(this.checkAllPermissions.includes(s)){const e=this.checkAllPermissions.indexOf(s);this.checkAllPermissions.splice(e)}else this.checkAllPermissions.push(s);this.form.modules.forEach(e=>{e.permissions.forEach(t=>{t.id==s&&(this.checkAllPermissions.includes(t.id)?t.checked=!0:t.checked=!1)})})},filteredPermissions(s){let e=[];return this.rolePermissions.length>0&&(e=this.rolePermissions.filter(t=>t.company_id==this.form.company_id&&t.dealership_id==(this.form.dealership_id??0)&&t.module_id==s).map(t=>t.permission_id)),e}},mounted(){this.fetchModules(),this.fetchPermissions(),this.$route.params.id&&(this.fetchRolePermission(),this.fetchRecord())}},K={class:"p-2"},Q={class:"w-full grid lg:flex lg:flex-row gap-2"},W={class:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-2"},X={class:"flex justify-end"},Z={class:"flex gap-1 justify-end"},$={class:"overflow-x-auto"},ee={key:0,class:"min-w-full bg-white border border-gray-300 text-xs lg:text-base"},se=n("th",{class:"py-2 px-4"},"MODULES",-1),te={class:"border-b border-slate-300"},ie={class:"flex justify-center"},oe={class:"py-2 px-4 border-b font-semibold text-[#116466]"},ne={class:"flex justify-center"};function le(s,e,t,h,i,d){const u=c("Loading"),v=c("Multiselect"),b=c("InputGroup"),S=c("SubmitButton"),L=c("BackButton"),V=c("TextInput"),w=c("Checkbox"),M=c("Layout");return l(),m(M,{header:i.title,theme:i.theme,headerIcon:i.headerIcon},{default:_(()=>[i.state.isLoading?(l(),m(u,{key:0,text:"Fetching record"})):g("",!0),i.state.isSaving?(l(),m(u,{key:1,text:"Saving record"})):g("",!0),n("div",K,[n("form",{onSubmit:e[3]||(e[3]=U((...o)=>d.confirmSubmit&&d.confirmSubmit(...o),["prevent"])),class:"space-y-4"},[n("div",Q,[n("div",W,[r(b,{label:"Company",labelClass:"border border-slate-300 bg-success-600 px-3 py-2 text-white"},{default:_(()=>[r(v,{modelValue:i.form.company_id,"onUpdate:modelValue":e[0]||(e[0]=o=>i.form.company_id=o),id:"company_id","close-on-select":!0,searchable:!0,options:i.companyOptions},null,8,["modelValue","options"])]),_:1}),r(b,{label:"Dealership",labelClass:"border border-slate-300 bg-success-600 px-3 py-2 text-white"},{default:_(()=>[r(v,{modelValue:i.form.dealership_id,"onUpdate:modelValue":e[1]||(e[1]=o=>i.form.dealership_id=o),id:"dealership","close-on-select":!0,searchable:!0,options:d.dealershipOptions},null,8,["modelValue","options"])]),_:1})]),n("div",X,[n("div",Z,[r(S,{text:"Save"}),r(L,{link:{name:"roles"}})])])]),n("div",$,[!i.state.isSaving&&!i.state.isLoading?(l(),a("table",ee,[n("thead",null,[n("tr",null,[se,(l(!0),a(y,null,x(i.permissions,(o,p)=>(l(),a("th",{class:"py-2 px-4",key:p},B(o.name),1))),128))]),n("tr",null,[n("td",te,[i.form.modules.length>0?(l(),m(b,{key:0,icon:"heroicons:magnifying-glass-20-solid"},{default:_(()=>[r(V,{type:"text",modelValue:i.searchModule,"onUpdate:modelValue":e[2]||(e[2]=o=>i.searchModule=o),hasBorder:!1},null,8,["modelValue"])]),_:1})):g("",!0)]),(l(!0),a(y,null,x(i.permissions,o=>(l(),a("td",{key:o.id,class:"py-2 px-4 border-b border-slate-300"},[n("div",ie,[r(w,{activeClass:"ring-[#116466] bg-[#116466]",checked:i.checkAllPermissions.includes(o.id),onClick:p=>d.checkAll(o.id)},null,8,["checked","onClick"])])]))),128))])]),n("tbody",null,[(l(!0),a(y,null,x(d.filteredModules,(o,p)=>(l(),a("tr",{key:p},[n("td",oe,B(o.name),1),(l(!0),a(y,null,x(o.permissions,(f,R)=>(l(),a("td",{class:"py-2 px-4 border-b",key:R},[n("div",ne,[r(w,{modelValue:f.checked,"onUpdate:modelValue":P=>f.checked=P,activeClass:"ring-[#116466] bg-[#116466]",checked:f.checked,onClick:P=>d.showDetail(o),value:f.checked},null,8,["modelValue","onUpdate:modelValue","checked","onClick","value"])])]))),128))]))),128))])])):g("",!0)])],32)])]),_:1},8,["header","theme","headerIcon"])}const ve=C(H,[["render",le]]);export{ve as default};
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings