Skip to content

Commit ccd50b4

Browse files
author
Alex Mitrakhovich
committed
fix bug with empty filename on editing filename
1 parent 2948181 commit ccd50b4

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

app/Http/Controllers/FileController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function edit($id, Request $request)
106106
}
107107

108108
$this->validate($request, [
109-
'name' => 'unique:files'
109+
'name' => 'required|unique:files'
110110
]);
111111

112112
$old_filename = '/public/' . $this->getUserDir() . '/' . $file->type . '/' . $file->name . '.' . $file->extension;

resources/assets/js/app.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,26 @@ const app = new Vue({
149149
endEditing(file) {
150150
this.editingFile = {};
151151

152-
if (file.name.trim() === '') {
153-
alert('Filename cannot be empty!');
154-
this.fetchFile(this.activeTab);
155-
} else {
156-
let formData = new FormData();
157-
formData.append('name', file.name);
158-
formData.append('type', file.type);
159-
formData.append('extension', file.extension);
160-
161-
axios.post('files/edit/' + file.id, formData)
162-
.then(response => {
163-
if (response.data === true) {
164-
this.showNotification('Filename successfully changed!', true);
165-
166-
var src = document.querySelector('[alt="' + file.name +'"]').getAttribute("src");
167-
document.querySelector('[alt="' + file.name +'"]').setAttribute('src', src);
168-
}
169-
})
170-
.catch(error => {
171-
this.errors = error.response.data.errors;
172-
this.showNotification(error.response.data.message, false);
173-
});
174-
175-
this.fetchFile(this.activeTab, this.pagination.current_page);
176-
}
152+
let formData = new FormData();
153+
formData.append('name', file.name);
154+
formData.append('type', file.type);
155+
formData.append('extension', file.extension);
156+
157+
axios.post('files/edit/' + file.id, formData)
158+
.then(response => {
159+
if (response.data === true) {
160+
this.showNotification('Filename successfully changed!', true);
161+
162+
var src = document.querySelector('[alt="' + file.name +'"]').getAttribute("src");
163+
document.querySelector('[alt="' + file.name +'"]').setAttribute('src', src);
164+
}
165+
})
166+
.catch(error => {
167+
this.errors = error.response.data.errors;
168+
this.showNotification(error.response.data.message, false);
169+
});
170+
171+
this.fetchFile(this.activeTab, this.pagination.current_page);
177172
},
178173

179174
showNotification(text, success) {

resources/views/layouts/confirm.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
</div>
1919
</div>
2020
</div>
21-
</transition>
21+
</transition>

resources/views/main.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
&nbsp;Download
8585
</a>
8686
</div>
87-
</div>
88-
<div class="card-content">
87+
</div>
88+
<div class="card-content">
8989
<div class="content">
9090
<p v-if="file !== editingFile" @dblclick="editFile(file)" :title="'Double click for editing filename'">
9191
@{{ file.name + '.' + file.extension}}

0 commit comments

Comments
 (0)