Skip to content

Commit

Permalink
Fix download and delete with Image::make class
Browse files Browse the repository at this point in the history
  • Loading branch information
kongulov committed Dec 29, 2021
1 parent f163f17 commit 72ce7df
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div v-for="(component, index) in field.fields" v-show="selectedLang === component.locale && component.showOnDetail">
<component
:key="index"
:data-default="true"
:class="{'remove-bottom-border ': (index + 1) % field.originalFieldsCount !== 0}"
:is="resolveComponentName(component)"
:resource-name="resourceName"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
v-show="selectedLang === component.locale && checkVisibility(component)">
<component
:key="index"
:data-default="true"
:class="{'remove-bottom-border ': (index + 1) % field.originalFieldsCount !== 0}"
:is="resolveComponentName(component)"
:resource-name="resourceName"
Expand Down
26 changes: 23 additions & 3 deletions resources/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Nova.booting((Vue, router, store) => {

const BaseFormFileField = Vue.options.components["form-file-field"];
const CustomFormFileField = BaseFormFileField.extend({
props: [
'resourceId',
'relatedResourceName',
'relatedResourceId',
'viaRelationship',
'dataDefault',
],
methods: {
async removeFile() {
this.uploadErrors = new Errors()
Expand All @@ -20,15 +27,22 @@ Nova.booting((Vue, router, store) => {
} = this
const attribute = this.field.attribute



const uri =
var uri =
this.viaRelationship &&
this.relatedResourceName &&
this.relatedResourceId
? `/nova-api/kongulov/nova-tab-translatable/${resourceName}/${resourceId}/${relatedResourceName}/${relatedResourceId}/field/${attribute}?viaRelationship=${viaRelationship}`
: `/nova-api/kongulov/nova-tab-translatable/${resourceName}/${resourceId}/field/${attribute}`

if (!this.dataDefault){
uri =
this.viaRelationship &&
this.relatedResourceName &&
this.relatedResourceId
? `/nova-api/${resourceName}/${resourceId}/${relatedResourceName}/${relatedResourceId}/field/${attribute}?viaRelationship=${viaRelationship}`
: `/nova-api/${resourceName}/${resourceId}/field/${attribute}`
}

try {
await Nova.request().delete(uri)
this.closeRemoveModal()
Expand All @@ -49,13 +63,19 @@ Nova.booting((Vue, router, store) => {

const BaseDetailFileField = Vue.options.components["detail-file-field"];
const CustomDetailFileField = BaseDetailFileField.extend({
props: ['resource', 'resourceName', 'resourceId', 'field', 'dataDefault'],
methods: {
download() {
const { resourceName, resourceId } = this
const attribute = this.field.attribute

let link = document.createElement('a')

link.href = `/nova-api/kongulov/nova-tab-translatable/${resourceName}/${resourceId}/download/${attribute}`
if (!this.dataDefault) {
link.href = `/nova-api/${resourceName}/${resourceId}/download/${attribute}`
}

link.download = 'download'
document.body.appendChild(link)
link.click()
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/FieldDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function show(NovaRequest $request)

if (!Storage::disk($disk)->exists($value)) abort(404);

$path = Storage::disk($disk)->get($value);
$path = Storage::disk($disk)->path($value);

return response()->download($path);
}
Expand Down

0 comments on commit 72ce7df

Please sign in to comment.