Skip to content

Commit

Permalink
chore: support minimum version v5.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvroroy committed Jan 16, 2025
1 parent c0c61b9 commit e203531
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 129 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": "^8.1",
"laravel/nova": "^5.0.6"
"laravel/nova": "^5.1.4"
},
"require-dev": {
"laravel/nova-devtool": "^1.1",
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tool.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions resources/js/composables/usePanelVisibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { reactive, ref, watch } from 'vue'

export function usePanelVisibility(
panel = { attribute: 'default', fields: [] },
emitter = null
) {
const visibleFieldsForPanel = {}
const visibleFieldsCount = ref(0)

panel.fields.forEach(field => {
visibleFieldsForPanel[field.attribute] = field.visible
})

const handleFieldShown = field => {
visibleFieldsForPanel[field] = true

if (emitter !== null) {
emitter('field-shown', field)
}

syncVisibleFieldsCount(visibleFieldsForPanel)
}

const handleFieldHidden = field => {
visibleFieldsForPanel[field] = false

if (emitter !== null) {
emitter('field-shown', field)
}

syncVisibleFieldsCount(visibleFieldsForPanel)
}

const syncVisibleFieldsCount = fields => {
visibleFieldsCount.value = Object.values(fields).filter(
visible => visible === true
).length
}

syncVisibleFieldsCount(visibleFieldsForPanel)

return {
handleFieldShown,
handleFieldHidden,
visibleFieldsCount,
}
}
9 changes: 8 additions & 1 deletion resources/js/mixins/Collapsable.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
export default {
props: {
collapsable: {
type: Boolean,
default: true,
},
},

data: () => ({ collapsed: false }),

created() {
const value = localStorage.getItem(this.localStorageKey)

if (value !== 'undefined') {
if (value !== 'undefined' && this.collapsable === true) {
this.collapsed = JSON.parse(value) ?? this.collapsedByDefault
}
},
Expand Down
54 changes: 54 additions & 0 deletions resources/js/mixins/HandlesFieldPreviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { mapProps } from './propTypes'
import filled from '../util/filled'

export default {
props: mapProps([
'field',
'resourceName',
'resourceId',
'viaResource',
'viaResourceId',
'viaRelationship',
'relatedResourceName',
'relatedResourceId',
'mode',
]),

methods: {
async fetchPreviewContent(value) {
Nova.$progress.start()

let editMode = this.resourceId == null ? 'create' : 'update'
let endpoint =
this.resourceId == null
? `/nova-api/${this.resourceName}/field/${this.field.attribute}/preview`
: `/nova-api/${this.resourceName}/${this.resourceId}/field/${this.field.attribute}/preview`

if (filled(this.relatedResourceName)) {
editMode = this.relatedResourceId == null ? 'attach' : 'update-attached'

endpoint = `${endpoint}/${this.relatedResourceName}`
}

const {
data: { preview },
} = await Nova.request().post(
endpoint,
{ value },
{
params: {
editing: true,
editMode: editMode,
viaResource: this.viaResource,
viaResourceId: this.viaResourceId,
viaRelationship: this.viaRelationship,
},
}
)

Nova.$progress.done()

return preview
},
},
}
18 changes: 7 additions & 11 deletions resources/js/mixins/HandlesPanelVisibility.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { usePanelVisibility } from '../composables/usePanelVisibility'

export default {
emits: ['field-shown', 'field-hidden'],

data: () => ({
visibleFieldsForPanel: {},
visibleFieldsForPanel: null,
}),

created() {
this.panel.fields.forEach(field => {
this.visibleFieldsForPanel[field.attribute] = field.visible
})
this.visibleFieldsForPanel = usePanelVisibility(this.panel, this.$emit)
},

methods: {
/**
* @param {string} field
*/
handleFieldShown(field) {
this.visibleFieldsForPanel[field] = true
this.$emit('field-shown', field)
this.visibleFieldsForPanel.handleFieldShown(field)
},

/**
* @param {string} field
*/
handleFieldHidden(field) {
this.visibleFieldsForPanel[field] = false
this.$emit('field-hidden', field)
this.visibleFieldsForPanel.handleFieldHidden(field)
},
},

Expand All @@ -34,9 +32,7 @@ export default {
* @returns {number}
*/
visibleFieldsCount() {
return Object.values(this.visibleFieldsForPanel).filter(
visible => visible === true
).length
return this.visibleFieldsForPanel.visibleFieldsCount
},
},
}
2 changes: 2 additions & 0 deletions resources/js/mixins/HandlesValidationErrors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { mapProps } from './propTypes'
import { Errors } from '../util/FormValidation'

export default {
props: {
errors: { default: () => new Errors() },
...mapProps(['field']),
},

inject: { index: { default: null }, viaParent: { default: null } },
Expand Down
10 changes: 4 additions & 6 deletions resources/js/mixins/IndexConcerns.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,9 @@ export default {
},

/**
<<<<<<< HEAD
* Update the resource selection status.
*
* @param {object} resource
=======
* Deselect all selections
*
* @param {Event} e
*/
deselectAllResources(e) {
if (e) {
Expand All @@ -232,7 +229,8 @@ export default {

/*
* Update the resource selection status
>>>>>>> 5.0
*
* @param {object} resource
*/
updateSelectionStatus(resource) {
if (!includes(this.selectedResources, resource)) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/mixins/InteractsWithQueryString.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
url: nextUrl,
// clearHistory: page.clearHistory,
encryptHistory: page.encryptHistory,
reserveScroll: true,
preserveScroll: true,
preserveState: true,
})
}
Expand Down
1 change: 1 addition & 0 deletions resources/js/mixins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as MetricBehavior } from './MetricBehavior'
export { default as FormEvents } from './FormEvents'
export { default as FormField } from './FormField'
export { default as HandlesFieldAttachments } from './HandlesFieldAttachments'
export { default as HandlesFieldPreviews } from './HandlesFieldPreviews'
export { default as HandlesValidationErrors } from './HandlesValidationErrors'
export { default as LoadsResources } from './LoadsResources'
export { default as TogglesTrashed } from './TogglesTrashed'
Expand Down
2 changes: 2 additions & 0 deletions resources/js/mixins/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
} from './CopiesToClipboard'
export { default as PreventsFormAbandonment } from './PreventsFormAbandonment'
export { default as PreventsModalAbandonment } from './PreventsModalAbandonment'
export { default as BehavesAsPanel } from './BehavesAsPanel'
export { default as DependentFormField } from './DependentFormField'
export { default as HandlesFormRequest } from './HandlesFormRequest'
export { default as HandlesUploads } from './HandlesUploads'
Expand All @@ -15,6 +16,7 @@ export { default as FieldValue } from './FieldValue'
export { default as FormEvents } from './FormEvents'
export { default as FormField } from './FormField'
export { default as HandlesFieldAttachments } from './HandlesFieldAttachments'
export { default as HandlesFieldPreviews } from './HandlesFieldPreviews'
export { default as HandlesValidationErrors } from './HandlesValidationErrors'
export { default as HasCards } from './HasCards'
export { default as HandlesPanelVisibility } from './HandlesPanelVisibility'
Expand Down
57 changes: 0 additions & 57 deletions resources/js/util/axios.js

This file was deleted.

18 changes: 0 additions & 18 deletions resources/js/util/inertia.js

This file was deleted.

32 changes: 0 additions & 32 deletions resources/js/util/numbro.js

This file was deleted.

1 change: 1 addition & 0 deletions resources/js/views/Attach.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
:options="availableResources"
:debounce="field.debounce"
trackBy="value"
:autocomplete="field.autocomplete"
class="w-full"
:dusk="`${field.resourceName}-search-input`"
>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/views/Lens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/>

<div class="inline-flex items-center gap-2 ml-auto">
<custom-index-toolbar
<custom-lens-toolbar
v-if="!viaResource"
:resource-name="resourceName"
:via-resource="viaResource"
Expand Down

0 comments on commit e203531

Please sign in to comment.