Skip to content

Need media upload manager in modal #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: analysis-qxMm1B
Choose a base branch
from
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ Media manager for `local` disk.

## Installation

```
$ composer require laravel-admin-ext/media-manager -vvv
```shell
// For laravel-admin 1.x
composer require laravel-admin-ext/media-manager:1.x -vvv

// For laravel-admin 2.x
composer require laravel-admin-ext/media-manager:2.x -vvv

$ php artisan admin:import media-manager
php artisan admin:import media-manager
```

Add a disk config in `config/admin.php`:
Expand All @@ -30,9 +34,10 @@ Add a disk config in `config/admin.php`:
'extensions' => [

'media-manager' => [

           // Select a local disk that you configured in `config/filesystem.php`
        'disk' => 'public'
        'disk' => 'public',
'allowed_ext' => 'jpg,jpeg,png,pdf,doc,docx,zip'
],
],

Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
],
"require": {
"php": ">=7.0.0",
"laravel/framework": "5.5.*",
"encore/laravel-admin": "1.5.*"
"encore/laravel-admin": "~1.6"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"laravel/laravel": "5.*"
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -30,7 +28,6 @@
"providers": [
"Encore\\Admin\\Media\\MediaServiceProvider"
]

}
}
}
102 changes: 59 additions & 43 deletions resources/views/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,37 @@
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('admin.confirm') }}",
showLoaderOnConfirm: true,
closeOnConfirm: false,
cancelButtonText: "{{ trans('admin.cancel') }}"
},
function(){
$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]':[path],
_token:LA.token,
},
success: function (data) {
$.pjax.reload('#pjax-container');

if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
cancelButtonText: "{{ trans('admin.cancel') }}",
preConfirm: function() {
return new Promise(function(resolve) {

$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]':[path],
_token:LA.token
},
success: function (data) {
$.pjax.reload('#pjax-container');

resolve(data);
}
}
});

});
}
}).then(function(result){
var data = result.value;
if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
}
});
}
});
});

Expand Down Expand Up @@ -215,29 +223,37 @@ function closeModal() {
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('admin.confirm') }}",
showLoaderOnConfirm: true,
closeOnConfirm: false,
cancelButtonText: "{{ trans('admin.cancel') }}"
},
function(){
$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]': files,
_token:LA.token,
},
success: function (data) {
$.pjax.reload('#pjax-container');

if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
cancelButtonText: "{{ trans('admin.cancel') }}",
preConfirm: function() {
return new Promise(function(resolve) {

$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]': files,
_token:LA.token
},
success: function (data) {
$.pjax.reload('#pjax-container');

resolve(data);
}
}
});

});
}
}).then(function (result) {
var data = result.value;
if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
}
});
}
});
});
});
Expand Down Expand Up @@ -318,7 +334,7 @@ function(){
{!! $item['preview'] !!}

<div class="file-info">
<a href="{{ $item['link'] }}" class="file-name" title="{{ $item['name'] }}">
<a @if(!$item['isDir'])target="_blank"@endif href="{{ $item['link'] }}" class="file-name" title="{{ $item['name'] }}">
{{ $item['icon'] }} {{ basename($item['name']) }}
</a>
<span class="file-size">
Expand All @@ -333,7 +349,7 @@ function(){
<li><a href="#" class="file-rename" data-toggle="modal" data-target="#moveModal" data-name="{{ $item['name'] }}">Rename & Move</a></li>
<li><a href="#" class="file-delete" data-path="{{ $item['name'] }}">Delete</a></li>
@unless($item['isDir'])
<li><a href="{{ $item['download'] }}">Download</a></li>
<li><a target="_blank" href="{{ $item['download'] }}">Download</a></li>
@endunless
<li class="divider"></li>
<li><a href="#" data-toggle="modal" data-target="#urlModal" data-url="{{ $item['url'] }}">Url</a></li>
Expand Down Expand Up @@ -419,4 +435,4 @@ function(){
</form>
</div>
</div>
</div>
</div>
102 changes: 59 additions & 43 deletions resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,37 @@
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('admin.confirm') }}",
showLoaderOnConfirm: true,
closeOnConfirm: false,
cancelButtonText: "{{ trans('admin.cancel') }}"
},
function(){
$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]':[path],
_token:LA.token,
},
success: function (data) {
$.pjax.reload('#pjax-container');

if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
cancelButtonText: "{{ trans('admin.cancel') }}",
preConfirm: function() {
return new Promise(function(resolve) {

$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]':[path],
_token:LA.token
},
success: function (data) {
$.pjax.reload('#pjax-container');

resolve(data);
}
}
});

});
}
}).then(function(result){
var data = result.value;
if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
}
});
}
});
});

Expand Down Expand Up @@ -215,29 +223,37 @@ function closeModal() {
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "{{ trans('admin.confirm') }}",
showLoaderOnConfirm: true,
closeOnConfirm: false,
cancelButtonText: "{{ trans('admin.cancel') }}"
},
function(){
$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]': files,
_token:LA.token,
},
success: function (data) {
$.pjax.reload('#pjax-container');

if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
cancelButtonText: "{{ trans('admin.cancel') }}",
preConfirm: function() {
return new Promise(function(resolve) {

$.ajax({
method: 'delete',
url: '{{ $url['delete'] }}',
data: {
'files[]': files,
_token:LA.token
},
success: function (data) {
$.pjax.reload('#pjax-container');

resolve(data);
}
}
});

});
}
}).then(function (result) {
var data = result.value;
if (typeof data === 'object') {
if (data.status) {
swal(data.message, '', 'success');
} else {
swal(data.message, '', 'error');
}
});
}
});
});

Expand Down Expand Up @@ -336,7 +352,7 @@ function(){
<td>
{!! $item['preview'] !!}

<a href="{{ $item['link'] }}" class="file-name" title="{{ $item['name'] }}">
<a @if(!$item['isDir'])target="_blank"@endif href="{{ $item['link'] }}" class="file-name" title="{{ $item['name'] }}">
{{ $item['icon'] }} {{ basename($item['name']) }}
</a>
</td>
Expand All @@ -346,7 +362,7 @@ function(){
<a class="btn btn-default file-rename" data-toggle="modal" data-target="#moveModal" data-name="{{ $item['name'] }}"><i class="fa fa-edit"></i></a>
<a class="btn btn-default file-delete" data-path="{{ $item['name'] }}"><i class="fa fa-trash"></i></a>
@unless($item['isDir'])
<a href="{{ $item['download'] }}" class="btn btn-default"><i class="fa fa-download"></i></a>
<a target="_blank" href="{{ $item['download'] }}" class="btn btn-default"><i class="fa fa-download"></i></a>
@endunless
<a class="btn btn-default" data-toggle="modal" data-target="#urlModal" data-url="{{ $item['url'] }}"><i class="fa fa-internet-explorer"></i></a>
</div>
Expand Down Expand Up @@ -434,4 +450,4 @@ function(){
</form>
</div>
</div>
</div>
</div>
15 changes: 11 additions & 4 deletions src/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ public function download(Request $request)

$manager = new MediaManager($file);

return $manager->download();
try {
return $manager->download();
} catch (\Exception $e) {
return response()->json([
'status' => false,
'message' => $e->getMessage(),
]);
}
}

public function upload(Request $request)
Expand Down Expand Up @@ -69,7 +76,7 @@ public function delete(Request $request)
}
} catch (\Exception $e) {
return response()->json([
'status' => true,
'status' => false,
'message' => $e->getMessage(),
]);
}
Expand All @@ -91,7 +98,7 @@ public function move(Request $request)
}
} catch (\Exception $e) {
return response()->json([
'status' => true,
'status' => false,
'message' => $e->getMessage(),
]);
}
Expand All @@ -113,7 +120,7 @@ public function newFolder(Request $request)
}
} catch (\Exception $e) {
return response()->json([
'status' => true,
'status' => false,
'message' => $e->getMessage(),
]);
}
Expand Down
Loading