-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Christian Widlund <[email protected]>
- Loading branch information
Showing
15 changed files
with
5,380 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,17 @@ | |
"custom" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://github.com/dcasia/custom-relationship-field", | ||
"authors": [ | ||
{ | ||
"name": "Christian Widlund", | ||
"email": "[email protected]", | ||
"role": "Contributer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.0" | ||
"php": ">=8.0", | ||
"laravel/nova": "^4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/*! | ||
* vuex v4.0.2 | ||
* (c) 2021 Evan You | ||
* @license MIT | ||
*/ | ||
|
||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const mix = require('laravel-mix') | ||
const webpack = require('webpack') | ||
const path = require('path') | ||
|
||
class NovaExtension { | ||
name() { | ||
return 'nova-extension' | ||
} | ||
|
||
register(name) { | ||
this.name = name | ||
} | ||
|
||
webpackConfig(webpackConfig) { | ||
webpackConfig.externals = { | ||
vue: 'Vue', | ||
} | ||
|
||
webpackConfig.resolve.alias = { | ||
...(webpackConfig.resolve.alias || {}), | ||
'@': path.resolve(__dirname, '../vendor/laravel/nova/resources/js/'), | ||
} | ||
|
||
webpackConfig.output = { | ||
uniqueName: this.name, | ||
} | ||
} | ||
} | ||
|
||
mix.extend('nova', new NovaExtension()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,88 @@ | ||
<script> | ||
import IndexComponent from '~~nova~~/views/Index.vue' | ||
import IndexComponent from '@/pages/Index.vue' | ||
import { defineComponent } from 'vue' | ||
export default { | ||
extends: IndexComponent, | ||
props: [ 'customRelationshipFieldAttribute', 'customRelationshipFieldLabel' ], | ||
beforeCreate() { | ||
const novaRequest = Nova.request | ||
const interceptor = Nova.request().interceptors.request.use( | ||
config => { | ||
const interceptors = [] | ||
const interceptorsInstance = [] | ||
if (/^\/nova-api\/\S.+\/(filters|action)$/.test(config.url)) { | ||
Nova.request = (...params) => { | ||
if (config.method === 'post' && config.params.viaResourceId === '') { | ||
for (const param of params) { | ||
return config | ||
for (const interceptor of interceptors) { | ||
interceptor(param) | ||
} | ||
} | ||
} | ||
config.params[ 'customRelationshipFieldAttribute' ] = this.customRelationshipFieldAttribute | ||
config.params[ 'customRelationshipFieldLabel' ] = this.customRelationshipFieldLabel | ||
const axiosInstance = novaRequest(...params) | ||
} | ||
if (axiosInstance instanceof Promise) { | ||
return axiosInstance | ||
} | ||
return config | ||
for (const interceptor of interceptors) { | ||
} | ||
) | ||
interceptorsInstance.push({ | ||
instance: axiosInstance, | ||
interceptor: axiosInstance.interceptors.request.use(config => interceptor(config)), | ||
}) | ||
} | ||
return axiosInstance | ||
this.$on('hook:destroyed', () => Nova.request().interceptors.request.eject(interceptor)) | ||
} | ||
export default defineComponent({ | ||
extends: IndexComponent, | ||
props: { | ||
customRelationshipFieldAttribute: { | ||
type: String, | ||
required: true, | ||
}, | ||
customRelationshipFieldLabel: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
/** | ||
* Build the resource request query string. | ||
*/ | ||
resourceRequestQueryString() { | ||
return { | ||
search: this.currentSearch, | ||
filters: this.encodedFilters, | ||
orderBy: this.currentOrderBy, | ||
orderByDirection: this.currentOrderByDirection, | ||
perPage: this.currentPerPage, | ||
trashed: this.currentTrashed, | ||
page: this.currentPage, | ||
viaResource: this.viaResource, | ||
viaResourceId: this.viaResourceId, | ||
viaRelationship: this.viaRelationship, | ||
viaResourceRelationship: this.viaResourceRelationship, | ||
relationshipType: this.relationshipType, | ||
customRelationshipFieldAttribute: this.customRelationshipFieldAttribute, | ||
customRelationshipFieldLabel: this.customRelationshipFieldLabel | ||
beforeCreate() { | ||
interceptors.push(config => { | ||
if (config.params === undefined) { | ||
config.params = {} | ||
} | ||
} | ||
const regex = new RegExp(`^\/nova-api\/(${ this.resourceName })\/?(filters|actions|relate-authorization)?`) | ||
if (regex.test(config.url)) { | ||
config.params[ 'customRelationshipFieldAttribute' ] = this.customRelationshipFieldAttribute | ||
config.params[ 'customRelationshipFieldLabel' ] = this.customRelationshipFieldLabel | ||
} | ||
return config | ||
}) | ||
}, | ||
methods: { | ||
/** | ||
* Get the actions available for the current resource. | ||
*/ | ||
getActions() { | ||
this.actions = [] | ||
this.pivotActions = null | ||
return Nova.request() | ||
.get(`/nova-api/${ this.resourceName }/actions`, { | ||
params: { | ||
viaResource: this.viaResource, | ||
viaResourceId: this.viaResourceId, | ||
viaRelationship: this.viaRelationship, | ||
relationshipType: this.relationshipType, | ||
customRelationshipFieldAttribute: this.customRelationshipFieldAttribute, | ||
customRelationshipFieldLabel: this.customRelationshipFieldLabel | ||
} | ||
}) | ||
.then(response => { | ||
this.actions = _.filter(response.data.actions, a => a.showOnIndex) | ||
this.pivotActions = response.data.pivotActions | ||
}) | ||
beforeUnmount() { | ||
for (const { instance, interceptor } of interceptorsInstance) { | ||
instance.interceptors.request.eject(interceptor) | ||
} | ||
} | ||
} | ||
while (interceptorsInstance.length) { | ||
interceptorsInstance.pop() | ||
interceptors.pop() | ||
} | ||
}, | ||
}) | ||
</script> |
Oops, something went wrong.