From d44d266cd220c19fc2009e56d86e322dfd5f9943 Mon Sep 17 00:00:00 2001 From: Rafael Milewski Date: Sun, 1 Oct 2023 12:56:14 +0800 Subject: [PATCH] Add column toggler support (#21) --- README.md | 2 +- dist/js/field.js | 2 +- .../js/components/CustomRelationshipField.vue | 20 +++++++++++++++++-- yarn.lock | 6 +++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6704372..1da8beb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Laravel Nova Filepond in action + Custom Relationship Field in action This field works just like as the default HasMany relationship field from nova but **without requiring a real relation** with the resource. diff --git a/dist/js/field.js b/dist/js/field.js index 5a4d416..c4aa37c 100644 --- a/dist/js/field.js +++ b/dist/js/field.js @@ -1 +1 @@ -(()=>{"use strict";var e={744:(e,t)=>{t.Z=(e,t)=>{const o=e.__vccOpts||e;for(const[e,i]of t)o[e]=i;return o}}},t={};function o(i){var r=t[i];if(void 0!==r)return r.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,o),n.exports}(()=>{const e=Vue;const t={emits:["actionExecuted"],props:["resourceName","resourceId","resource","field"],methods:{actionExecuted:function(){this.$emit("actionExecuted")}},computed:{encodedAttribute:function(){return btoa("".concat(this.field.attribute,"|_::_|").concat(this.field.name))}}};const i=(0,o(744).Z)(t,[["render",function(t,o,i,r,n,c){var a=(0,e.resolveComponent)("ResourceIndex");return(0,e.openBlock)(),(0,e.createBlock)(a,{field:i.field,"resource-name":i.field.resourceName,"via-resource":i.resourceName,"via-resource-id":i.resourceId,"via-relationship":null,"relationship-type":"CustomRelationshipField:".concat(c.encodedAttribute),onActionExecuted:c.actionExecuted,"load-cards":!1,"initial-per-page":i.field.perPage||5,"should-override-meta":!1,"custom-relationship-field-attribute":i.field.attribute,"custom-relationship-field-label":i.field.name},null,8,["field","resource-name","via-resource","via-resource-id","relationship-type","onActionExecuted","initial-per-page","custom-relationship-field-attribute","custom-relationship-field-label"])}]]);Nova.booting((function(e,t){e.component("detail-custom-relationship-field",i)}))})()})(); \ No newline at end of file +(()=>{"use strict";var e={744:(e,t)=>{t.Z=(e,t)=>{const i=e.__vccOpts||e;for(const[e,o]of t)i[e]=o;return i}}},t={};function i(o){var r=t[o];if(void 0!==r)return r.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,i),n.exports}(()=>{const e=Vue;const t={emits:["actionExecuted"],props:["resourceName","resourceId","resource","field"],methods:{actionExecuted:function(){this.$emit("actionExecuted")}},data:function(){return{eventCallback:null}},mounted:function(){var e=this;Nova.$on("custom-relationship-field:request-extra-params",this.eventCallback=function(){Nova.$emit("custom-relationship-field:extra-params",{relationshipType:e.relationshipType})})},unmounted:function(){Nova.$off("custom-relationship-field:request-extra-params",this.eventCallback)},computed:{encodedAttribute:function(){return btoa("".concat(this.field.attribute,"|_::_|").concat(this.field.name))},relationshipType:function(){return"CustomRelationshipField:".concat(this.encodedAttribute)}}};const o=(0,i(744).Z)(t,[["render",function(t,i,o,r,n,a){var c=(0,e.resolveComponent)("ResourceIndex");return(0,e.openBlock)(),(0,e.createBlock)(c,{field:o.field,"resource-name":o.field.resourceName,"via-resource":o.resourceName,"via-resource-id":o.resourceId,"via-relationship":null,"relationship-type":a.relationshipType,onActionExecuted:a.actionExecuted,"load-cards":!1,"initial-per-page":o.field.perPage||5,"should-override-meta":!1,"custom-relationship-field-attribute":o.field.attribute,"custom-relationship-field-label":o.field.name},null,8,["field","resource-name","via-resource","via-resource-id","relationship-type","onActionExecuted","initial-per-page","custom-relationship-field-attribute","custom-relationship-field-label"])}]]);Nova.booting((function(e,t){e.component("detail-custom-relationship-field",o)}))})()})(); \ No newline at end of file diff --git a/resources/js/components/CustomRelationshipField.vue b/resources/js/components/CustomRelationshipField.vue index 9b3098d..1706055 100644 --- a/resources/js/components/CustomRelationshipField.vue +++ b/resources/js/components/CustomRelationshipField.vue @@ -6,7 +6,7 @@ :via-resource="resourceName" :via-resource-id="resourceId" :via-relationship="null" - :relationship-type="`CustomRelationshipField:${ encodedAttribute }`" + :relationship-type="relationshipType" @actionExecuted="actionExecuted" :load-cards="false" :initial-per-page="field.perPage || 5" @@ -27,11 +27,27 @@ this.$emit('actionExecuted') }, }, + data() { + return { + eventCallback: null, + } + }, + mounted() { + Nova.$on('custom-relationship-field:request-extra-params', this.eventCallback = () => { + Nova.$emit('custom-relationship-field:extra-params', { relationshipType: this.relationshipType }) + }) + }, + unmounted() { + Nova.$off('custom-relationship-field:request-extra-params', this.eventCallback) + }, computed: { encodedAttribute() { return btoa(`${ this.field.attribute }|_::_|${ this.field.name }`) }, - } + relationshipType() { + return `CustomRelationshipField:${ this.encodedAttribute }` + }, + }, } diff --git a/yarn.lock b/yarn.lock index 365fe93..36455c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1227,9 +1227,9 @@ integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== "@types/node@*": - version "20.7.2" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.7.2.tgz#0bdc211f8c2438cfadad26dc8c040a874d478aed" - integrity sha512-RcdC3hOBOauLP+r/kRt27NrByYtDjsXyAuSbR87O6xpsvi763WI+5fbSIvYJrXnt9w4RuxhV6eAXfIs7aaf/FQ== + version "20.8.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.0.tgz#10ddf0119cf20028781c06d7115562934e53f745" + integrity sha512-LzcWltT83s1bthcvjBmiBvGJiiUe84NWRHkw+ZV6Fr41z2FbIzvc815dk2nQ3RAKMuN2fkenM/z3Xv2QzEpYxQ== "@types/parse-json@^4.0.0": version "4.0.0"