Skip to content

Commit e5dc821

Browse files
committed
Fixed error notifications
1 parent 0ec8de8 commit e5dc821

34 files changed

+88
-77
lines changed

public/js/bootstrap-notify.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/script.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,30 @@ function performLfmRequest(url, parameter, type) {
250250
dataType: type || 'text',
251251
url: lfm_route + '/' + url,
252252
data: data,
253-
cache: false
254-
}).fail(function (jqXHR, textStatus, errorThrown) {
255-
displayErrorResponse(jqXHR);
253+
cache: false,
254+
error: function (error) {
255+
var responseJSON = JSON.parse(error.responseText);
256+
if (responseJSON.message !== undefined) {
257+
$.notify({
258+
// options
259+
message: responseJSON.message,
260+
},{
261+
// settings
262+
type: 'danger',
263+
placement: {
264+
from: "top",
265+
align: "center"
266+
},
267+
animate: {
268+
enter: 'animated zoomInDown',
269+
exit: 'animated zoomOutUp'
270+
}
271+
});
272+
}
273+
}
256274
});
257275
}
258276

259-
function displayErrorResponse(jqXHR) {
260-
notify('<div style="max-height:50vh;overflow: scroll;">' + jqXHR.responseText + '</div>');
261-
}
262-
263277
var refreshFoldersAndItems = function (data) {
264278
loadFolders();
265279
if (data != 'OK') {

src/Controllers/DeleteController.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class DeleteController extends LfmController
1515
public function getDelete()
1616
{
1717
$item_names = request('items');
18-
$errors = [];
1918

2019
foreach ($item_names as $name_to_delete) {
2120
$file_to_delete = $this->lfm->pretty($name_to_delete);
@@ -24,19 +23,16 @@ public function getDelete()
2423
event(new ImageIsDeleting($file_path));
2524

2625
if (is_null($name_to_delete)) {
27-
array_push($errors, parent::error('folder-name'));
28-
continue;
26+
return parent::error('folder-name');
2927
}
3028

3129
if (! $this->lfm->setName($name_to_delete)->exists()) {
32-
array_push($errors, parent::error('folder-not-found', ['folder' => $file_path]));
33-
continue;
30+
return parent::error('folder-not-found', ['folder' => $file_path], 404);
3431
}
3532

3633
if ($this->lfm->setName($name_to_delete)->isDirectory()) {
3734
if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) {
38-
array_push($errors, parent::error('delete-folder'));
39-
continue;
35+
return parent::error('delete-folder');
4036
}
4137
} else {
4238
if ($file_to_delete->isImage()) {
@@ -49,10 +45,6 @@ public function getDelete()
4945
event(new ImageWasDeleted($file_path));
5046
}
5147

52-
if (count($errors) > 0) {
53-
return $errors;
54-
}
55-
5648
return parent::$success_response;
5749
}
5850
}

src/Controllers/FolderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getAddfolder()
4444
return $this->helper->error('folder-name');
4545
} elseif ($this->lfm->setName($folder_name)->exists()) {
4646
return $this->helper->error('folder-exist');
47-
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
47+
} elseif (config('lfm.alphanumeric_directory', true) && preg_match('/[^\w-]/i', $folder_name)) {
4848
return $this->helper->error('folder-alnum');
4949
} else {
5050
$this->lfm->setName($folder_name)->createFolder();

src/Controllers/LfmController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public function getErrors()
129129
* @param array $variables
130130
* @return mixed
131131
*/
132-
public function error($error_type, $variables = [])
132+
public function error($error_type, $variables = [], $code = 400)
133133
{
134-
return $this->helper->error($error_type, $variables);
134+
return $this->helper->error($error_type, $variables, $code);
135135
}
136136

137137
/**

src/Controllers/RenameController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function getRename()
2626
}
2727

2828
if ($is_directory) {
29-
if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) {
29+
if (config('lfm.alphanumeric_directory', true) && preg_match('/[^\w-]/i', $new_name)) {
3030
return parent::error('folder-alnum');
3131
} elseif ($this->lfm->setName($new_name)->exists()) {
3232
return parent::error('rename');
3333
}
3434
} else {
35-
if (config('lfm.alphanumeric_filename') && preg_match('/[^\w-]/i', $new_name)) {
35+
if (config('lfm.alphanumeric_filename', true) && preg_match('/[^\w-]/i', $new_name)) {
3636
return parent::error('file-alnum');
3737
}
3838

src/Lfm.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Contracts\Config\Repository as Config;
7+
use Illuminate\Http\JsonResponse;
78
use Illuminate\Http\Request;
89
use Illuminate\Support\Facades\Route;
910
use Illuminate\Support\Str;
@@ -225,12 +226,14 @@ public function isRunningOnWindows()
225226
*
226227
* @param mixed $error_type Key of message in lang file.
227228
* @param mixed $variables Variables the message needs.
228-
* @return string
229-
* @throws Exception
229+
* @return JsonResponse
230230
*/
231-
public function error($error_type, $variables = [])
231+
public function error($error_type, $variables = [], $code = 400)
232232
{
233-
throw new Exception(trans(self::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables));
233+
return response()->json([
234+
'status' => 'error',
235+
'message' => trans(self::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables)
236+
], $code);
234237
}
235238

236239
/**

src/LfmPath.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,22 @@ private function uploadValidator($file)
272272

273273
$new_file_name = $this->getNewName($file);
274274

275-
if ($this->setName($new_file_name)->exists() && !config('lfm.over_write_on_duplicate')) {
275+
if ($this->setName($new_file_name)->exists() && !config('lfm.over_write_on_duplicate', false)) {
276276
return $this->error('file-exist');
277277
}
278278

279-
if (config('lfm.should_validate_mime', false)) {
279+
if (config('lfm.should_validate_mime', true)) {
280280
$mimetype = $file->getMimeType();
281281
if (false === in_array($mimetype, $this->helper->availableMimeTypes())) {
282-
return $this->error('mime') . $mimetype;
282+
return $this->error('mime', ['mime' => $mimetype]);
283283
}
284284
}
285285

286-
if (config('lfm.should_validate_size', false)) {
286+
if (config('lfm.should_validate_size', true)) {
287287
// size to kb unit is needed
288288
$file_size = $file->getSize() / 1000;
289289
if ($file_size > $this->helper->maxUploadSize()) {
290-
return $this->error('size') . $file_size;
290+
return $this->error('size', ['size' => $file_size]);
291291
}
292292
}
293293

@@ -299,9 +299,9 @@ private function getNewName($file)
299299
$new_file_name = $this->helper
300300
->translateFromUtf8(trim(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)));
301301

302-
if (config('lfm.rename_file') === true) {
302+
if (config('lfm.rename_file', false) === true) {
303303
$new_file_name = uniqid();
304-
} elseif (config('lfm.alphanumeric_filename') === true) {
304+
} elseif (config('lfm.alphanumeric_filename', true) === true) {
305305
$new_file_name = preg_replace('/[^\w-]/i', '_', $new_file_name);
306306
}
307307

src/lang/ar/lfm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'error-folder-name' => 'اسم المجلد لا يمكن ان يكون فاغ!',
3535
'error-folder-exist'=> 'اسم المجلد مستخدما مسبقا!',
3636
'error-folder-alnum'=> 'Only alphanumeric folder names are allowed!',
37-
'error-mime' => 'نوع الملف غير معروف: ',
37+
'error-mime' => '(:mime) نوع الملف غير معروف:',
3838
'error-instance' => 'The uploaded file should be an instance of UploadedFile',
3939
'error-invalid' => 'طلب رفع غير صالح',
4040

src/lang/bg/lfm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'error-folder-name' => 'Моля изберете име на папката',
3535
'error-folder-exist'=> 'Папка с това име вече съществува!',
3636
'error-folder-alnum'=> 'Only alphanumeric folder names are allowed!',
37-
'error-mime' => 'Грешен тип на файла: ',
37+
'error-mime' => 'Грешен тип на файла: (:mime)',
3838
'error-instance' => 'The uploaded file should be an instance of UploadedFile ( Грешка )',
3939
'error-invalid' => 'Невалидна заявка за качване',
4040

0 commit comments

Comments
 (0)