Skip to content

Commit

Permalink
Merge pull request #233 from ddannewitz/grails3
Browse files Browse the repository at this point in the history
Added functionality to delete multiple files at once #178
  • Loading branch information
dularion committed Dec 15, 2016
2 parents f5c4e18 + 769bf93 commit f91c735
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ angular.module('streama').controller('adminFileManagerCtrl', ['$scope', 'apiServ

$scope.activeListDisplay = 'table';

$scope.selectedFiles = [];

$scope.changeListDisplay = function (displayType) {
$scope.activeListDisplay = displayType;
};
Expand All @@ -35,6 +37,37 @@ angular.module('streama').controller('adminFileManagerCtrl', ['$scope', 'apiServ
})
};

$scope.removeMultipleFiles = function() {
if($scope.selectedFiles.length > 0) {
var confirmText = "This will delete all selected Files. Do you want to proceed?";
alertify.set({ buttonReverse: true, labels: {ok: "Yes", cancel : "Cancel"}});
alertify.confirm(confirmText, function (confirmed) {
if(confirmed){
apiService.video.removeMultipleFilesFromDisk($scope.selectedFiles).success(function () {
_.forEach($scope.selectedFiles.forEach, id => {
// TODO investigate why {id: id} doesn't work
_.remove($scope.files, function(file) {
return file.id === id;
});
});
selectedFiles = [];
alertify.success('Files deleted.');
});
}
});
}
};

$scope.addOrRemoveFromSelection = function($event, file) {
if($event.target.checked) {
$scope.selectedFiles.push(file.id);
} else {
_.remove($scope.selectedFiles, function(id) {
return id === file.id;
});
}
};

$scope.pageChanged = function () {
var newOffset = $scope.maxPerPage*($scope.pagination.currentPage-1);
loadFiles({max: $scope.maxPerPage, filter: $scope.listFilter, offset: newOffset});
Expand Down
6 changes: 4 additions & 2 deletions grails-app/assets/javascripts/streama/services/api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ angular.module('streama').factory('apiService', function ($http, $rootScope, con
return $http.get('user/current.json');
},


tvShow: {
get: function (id) {
return $http.get('tvShow/show.json', {params: {id: id}});
Expand Down Expand Up @@ -95,6 +94,9 @@ angular.module('streama').factory('apiService', function ($http, $rootScope, con
removeFileFromDisk: function (id, path) {
return $http.delete('file/removeFileFromDisk.json', {params: {id: id, path: path}});
},
removeMultipleFilesFromDisk: function(bulk) {
return $http.delete('file/removeMultipleFilesFromDisk.json', {params: {id: bulk}})
},
cleanUpFiles: function (type) {
return $http.delete('file/cleanUpFiles.json', {params: {type: type}});
},
Expand All @@ -117,7 +119,7 @@ angular.module('streama').factory('apiService', function ($http, $rootScope, con
return $http.get('file/localFiles.json', {params: {path: path}});
}
},

episode: {
get: function (id) {
return $http.get('episode/show.json', {params: {id: id}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ <h1>
Files that only exist on Hard-Drive
</button>
</div>

<button class="btn btn-danger btn-sm pull-right" ng-click="removeMultipleFiles()">
Delete Multiple Files
</button>
</div>

</div>
Expand All @@ -42,6 +46,7 @@ <h1>
<table class="table table-striped file-manager-table" ng-if="activeListDisplay == 'table'">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Uploaded</th>
<th>Content-Type</th>
Expand All @@ -52,6 +57,7 @@ <h1>
</thead>
<tbody>
<tr ng-repeat="file in files">
<td><input type="checkbox" ng-click="addOrRemoveFromSelection($event, file)"/></td>
<td>
<div><strong>{{file.originalFilename}}</strong></div>
<div ng-if="file.src"><a href="{{file.src}}">{{file.src}}</a></div>
Expand Down
9 changes: 9 additions & 0 deletions grails-app/controllers/streama/FileController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class FileController {
respond status: NO_CONTENT
}

def removeMultipleFilesFromDisk() {
def idBulk = params.list('id').collect({it.toLong()})
idBulk.each { id ->
def file = File.get(id)
fileService.fullyRemoveFile(file)
}
respond status: NO_CONTENT
}

def cleanUpFiles(){
def type = params.type
def files = File.list()
Expand Down

0 comments on commit f91c735

Please sign in to comment.