Skip to content

Commit

Permalink
Add column toggler support (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski authored Oct 1, 2023
1 parent f4cc845 commit d44d266
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/dcasia/custom-relationship-field/main/screenshots/dark.png">
<img alt="Laravel Nova Filepond in action" src="https://raw.githubusercontent.com/dcasia/custom-relationship-field/main/screenshots/light.png">
<img alt="Custom Relationship Field in action" src="https://raw.githubusercontent.com/dcasia/custom-relationship-field/main/screenshots/light.png">
</picture>

This field works just like as the default HasMany relationship field from nova but **without requiring a real relation** with the resource.
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions resources/js/components/CustomRelationshipField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }`
},
},
}
</script>
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d44d266

Please sign in to comment.