Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
55389831
Unverified
Commit
55389831
authored
Sep 26, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding logic to batch destroy files
parent
5f1bac79
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
18 deletions
+170
-18
MediaList.vue
Modules/Media/Assets/js/components/MediaList.vue
+33
-4
BatchDestroyController.php
...les/Media/Http/Controllers/Api/BatchDestroyController.php
+72
-0
apiRoutes.php
Modules/Media/Http/apiRoutes.php
+6
-0
messages.php
Modules/Translation/Resources/lang/media/en/messages.php
+1
-0
app.js
public/js/app.js
+58
-14
No files found.
Modules/Media/Assets/js/components/MediaList.vue
View file @
55389831
...
@@ -25,7 +25,10 @@
...
@@ -25,7 +25,10 @@
<upload-button
:parent-id=
"folderId"
></upload-button>
<upload-button
:parent-id=
"folderId"
></upload-button>
<el-button-group>
<el-button-group>
<el-button
type=
"primary"
:disabled=
"selectedMedia.length === 0"
>
Move
</el-button>
<el-button
type=
"primary"
:disabled=
"selectedMedia.length === 0"
>
Move
</el-button>
<el-button
type=
"danger"
:disabled=
"selectedMedia.length === 0"
>
Delete
</el-button>
<el-button
type=
"danger"
:disabled=
"selectedMedia.length === 0"
@
click
.
preent=
"batchDelete"
:loading=
"filesAreDeleting"
>
Delete
</el-button>
</el-button-group>
</el-button-group>
</div>
</div>
<div
class=
"search el-col el-col-5"
>
<div
class=
"search el-col el-col-5"
>
...
@@ -148,6 +151,7 @@
...
@@ -148,6 +151,7 @@
folderBreadcrumb
:
[
folderBreadcrumb
:
[
{
id
:
0
,
name
:
'
Home
'
},
{
id
:
0
,
name
:
'
Home
'
},
],
],
filesAreDeleting
:
false
,
}
}
},
},
methods
:
{
methods
:
{
...
@@ -226,9 +230,6 @@
...
@@ -226,9 +230,6 @@
handleSelectionChange
(
selectedMedia
)
{
handleSelectionChange
(
selectedMedia
)
{
this
.
selectedMedia
=
selectedMedia
;
this
.
selectedMedia
=
selectedMedia
;
},
},
getEditMediaUrl
(
scope
)
{
return
route
(
'
admin.media.media.edit
'
,
{
media
:
scope
.
row
.
id
});
},
loadEditForm
(
scope
)
{
loadEditForm
(
scope
)
{
console
.
log
(
'
clicked edit to
'
+
scope
.
row
.
id
);
console
.
log
(
'
clicked edit to
'
+
scope
.
row
.
id
);
this
.
$router
.
push
({
name
:
'
admin.media.media.edit
'
,
params
:
{
mediaId
:
scope
.
row
.
id
}})
this
.
$router
.
push
({
name
:
'
admin.media.media.edit
'
,
params
:
{
mediaId
:
scope
.
row
.
id
}})
...
@@ -248,6 +249,34 @@
...
@@ -248,6 +249,34 @@
this
.
fetchFolderBreadcrumb
(
folderId
);
this
.
fetchFolderBreadcrumb
(
folderId
);
},
},
batchDelete
()
{
this
.
$confirm
(
this
.
trans
(
'
core.modal.confirmation-message
'
),
this
.
trans
(
'
core.modal.title
'
),
{
confirmButtonText
:
this
.
trans
(
'
core.button.delete
'
),
cancelButtonText
:
this
.
trans
(
'
core.button.cancel
'
),
type
:
'
warning
'
})
.
then
(()
=>
{
this
.
filesAreDeleting
=
true
;
axios
.
post
(
route
(
'
api.media.media.batch-destroy
'
),
{
files
:
this
.
selectedMedia
})
.
then
(
response
=>
{
this
.
$message
({
type
:
'
success
'
,
message
:
response
.
data
.
message
});
this
.
filesAreDeleting
=
false
;
this
.
$refs
.
mediaTable
.
clearSelection
();
this
.
queryServer
();
});
})
.
catch
(()
=>
{
this
.
$message
({
type
:
'
info
'
,
message
:
this
.
trans
(
'
core.delete cancelled
'
)
});
});
},
},
},
mounted
()
{
mounted
()
{
this
.
selectedMedia
.
length
=
0
;
this
.
selectedMedia
.
length
=
0
;
...
...
Modules/Media/Http/Controllers/Api/BatchDestroyController.php
0 → 100644
View file @
55389831
<?php
namespace
Modules\Media\Http\Controllers\Api
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Repositories\FileRepository
;
use
Modules\Media\Repositories\FolderRepository
;
class
BatchDestroyController
extends
Controller
{
/**
* @var FileRepository
*/
private
$file
;
/**
* @var FolderRepository
*/
private
$folder
;
/**
* @var Imagy
*/
private
$imagy
;
public
function
__construct
(
FileRepository
$file
,
FolderRepository
$folder
,
Imagy
$imagy
)
{
$this
->
file
=
$file
;
$this
->
folder
=
$folder
;
$this
->
imagy
=
$imagy
;
}
public
function
__invoke
(
Request
$request
)
{
foreach
(
$request
->
get
(
'files'
)
as
$file
)
{
if
(
$file
[
'is_folder'
]
===
true
)
{
$this
->
deleteFolder
(
$file
[
'id'
]);
continue
;
}
$this
->
deleteFile
(
$file
[
'id'
]);
}
return
response
()
->
json
([
'errors'
=>
false
,
'message'
=>
trans
(
'media::messages.selected items deleted'
),
]);
}
private
function
deleteFile
(
$fileId
)
{
$file
=
$this
->
file
->
find
(
$fileId
);
if
(
$file
===
null
)
{
return
;
}
$this
->
imagy
->
deleteAllFor
(
$file
);
$this
->
file
->
destroy
(
$file
);
}
private
function
deleteFolder
(
$folderId
)
{
$folder
=
$this
->
folder
->
findFolder
(
$folderId
);
if
(
$folder
===
null
)
{
return
;
}
$this
->
folder
->
destroy
(
$folder
);
}
}
Modules/Media/Http/apiRoutes.php
View file @
55389831
...
@@ -70,4 +70,10 @@ $router->group(['middleware' => 'api.token'], function (Router $router) {
...
@@ -70,4 +70,10 @@ $router->group(['middleware' => 'api.token'], function (Router $router) {
'as'
=>
'api.media.media.destroy'
,
'as'
=>
'api.media.media.destroy'
,
'middleware'
=>
'token-can:media.medias.destroy'
,
'middleware'
=>
'token-can:media.medias.destroy'
,
]);
]);
$router
->
post
(
'batch-destroy'
,
[
'uses'
=>
'BatchDestroyController'
,
'as'
=>
'api.media.media.batch-destroy'
,
'middleware'
=>
'token-can:media.medias.destroy'
,
]);
});
});
Modules/Translation/Resources/lang/media/en/messages.php
View file @
55389831
...
@@ -5,4 +5,5 @@ return [
...
@@ -5,4 +5,5 @@ return [
'file deleted'
=>
'File deleted'
,
'file deleted'
=>
'File deleted'
,
'folder updated'
=>
'Folder updated'
,
'folder updated'
=>
'Folder updated'
,
'folder deleted'
=>
'Folder deleted'
,
'folder deleted'
=>
'Folder deleted'
,
'selected items deleted'
=>
'The selected item(s) were deleted'
,
];
];
public/js/app.js
View file @
55389831
...
@@ -93961,6 +93961,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
...
@@ -93961,6 +93961,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
//
//
//
//
//
//
//
//
//
exports.default = {
exports.default = {
components: {
components: {
...
@@ -93987,7 +93990,8 @@ exports.default = {
...
@@ -93987,7 +93990,8 @@ exports.default = {
searchQuery: '',
searchQuery: '',
folderId: 0,
folderId: 0,
selectedMedia: {},
selectedMedia: {},
folderBreadcrumb: [{ id: 0, name: 'Home' }]
folderBreadcrumb: [{ id: 0, name: 'Home' }],
filesAreDeleting: false
};
};
},
},
...
@@ -94067,9 +94071,6 @@ exports.default = {
...
@@ -94067,9 +94071,6 @@ exports.default = {
handleSelectionChange: function handleSelectionChange(selectedMedia) {
handleSelectionChange: function handleSelectionChange(selectedMedia) {
this.selectedMedia = selectedMedia;
this.selectedMedia = selectedMedia;
},
},
getEditMediaUrl: function getEditMediaUrl(scope) {
return route('admin.media.media.edit', { media: scope.row.id });
},
loadEditForm: function loadEditForm(scope) {
loadEditForm: function loadEditForm(scope) {
console.log('clicked edit to' + scope.row.id);
console.log('clicked edit to' + scope.row.id);
this.$router.push({ name: 'admin.media.media.edit', params: { mediaId: scope.row.id } });
this.$router.push({ name: 'admin.media.media.edit', params: { mediaId: scope.row.id } });
...
@@ -94088,24 +94089,51 @@ exports.default = {
...
@@ -94088,24 +94089,51 @@ exports.default = {
}
}
this.fetchFolderBreadcrumb(folderId);
this.fetchFolderBreadcrumb(folderId);
},
batchDelete: function batchDelete() {
var _this3 = this;
this.$confirm(this.trans('core.modal.confirmation-message'), this.trans('core.modal.title'), {
confirmButtonText: this.trans('core.button.delete'),
cancelButtonText: this.trans('core.button.cancel'),
type: 'warning'
}).then(function () {
_this3.filesAreDeleting = true;
_axios2.default.post(route('api.media.media.batch-destroy'), {
files: _this3.selectedMedia
}).then(function (response) {
_this3.$message({
type: 'success',
message: response.data.message
});
_this3.filesAreDeleting = false;
_this3.$refs.mediaTable.clearSelection();
_this3.queryServer();
});
}).catch(function () {
_this3.$message({
type: 'info',
message: _this3.trans('core.delete cancelled')
});
});
}
}
},
},
mounted: function mounted() {
mounted: function mounted() {
var _this
3
= this;
var _this
4
= this;
this.selectedMedia.length = 0;
this.selectedMedia.length = 0;
this.fetchMediaData();
this.fetchMediaData();
this.$events.listen('fileWasUploaded', function (eventData) {
this.$events.listen('fileWasUploaded', function (eventData) {
_this
3
.tableIsLoading = true;
_this
4
.tableIsLoading = true;
_this
3
.queryServer({ folder_id: eventData.data.folder_id });
_this
4
.queryServer({ folder_id: eventData.data.folder_id });
});
});
this.$events.listen('folderWasCreated', function (eventData) {
this.$events.listen('folderWasCreated', function (eventData) {
_this
3
.tableIsLoading = true;
_this
4
.tableIsLoading = true;
_this
3
.queryServer({ folder_id: eventData.data.folder_id });
_this
4
.queryServer({ folder_id: eventData.data.folder_id });
});
});
this.$events.listen('folderWasUpdated', function (eventData) {
this.$events.listen('folderWasUpdated', function (eventData) {
_this
3
.tableIsLoading = true;
_this
4
.tableIsLoading = true;
_this
3
.queryServer({ folder_id: eventData.data.folder_id });
_this
4
.queryServer({ folder_id: eventData.data.folder_id });
});
});
}
}
};
};
...
@@ -95066,10 +95094,26 @@ var render = function() {
...
@@ -95066,10 +95094,26 @@ var render = function() {
{
{
attrs: {
attrs: {
type: "danger",
type: "danger",
disabled: _vm.selectedMedia.length === 0
disabled: _vm.selectedMedia.length === 0,
loading: _vm.filesAreDeleting
},
on: {
click: function($event) {
if (
!("button" in $event) &&
_vm._k($event.keyCode, "preent")
) {
return null
}
_vm.batchDelete($event)
}
}
}
},
},
[_vm._v("Delete")]
[
_vm._v(
"\n Delete\n "
)
]
)
)
],
],
1
1
...
@@ -96494,7 +96538,7 @@ exports.default = {
...
@@ -96494,7 +96538,7 @@ exports.default = {
}).catch(function (error) {
}).catch(function (error) {
vm.$message({
vm.$message({
type: 'error',
type: 'error',
message:
response
.data.message
message:
error
.data.message
});
});
});
});
}).catch(function () {
}).catch(function () {
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment