From af14d09329a1dc25fdac8a22dcbfc4aaa7050fde Mon Sep 17 00:00:00 2001 From: OldHawk Date: Tue, 31 Oct 2017 14:13:29 +0800 Subject: [PATCH] feat(backup): admin delete the backup files --- .../controllers/backup.client.controller.js | 59 +++++++++++++++++-- .../client/views/backup.client.view.html | 2 +- .../controllers/backup.server.controller.js | 18 +++++- modules/core/client/app/trans-string-en.js | 5 +- modules/core/client/app/trans-string-zh.js | 5 +- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/modules/backup/client/controllers/backup.client.controller.js b/modules/backup/client/controllers/backup.client.controller.js index 41569a76..6a5ebcaa 100644 --- a/modules/backup/client/controllers/backup.client.controller.js +++ b/modules/backup/client/controllers/backup.client.controller.js @@ -5,16 +5,17 @@ .module('backup') .controller('BackupController', BackupController); - BackupController.$inject = ['$scope', '$timeout', 'getStorageLangService', 'MeanTorrentConfig', 'BackupService', 'NotifycationService', - 'DebugConsoleService', '$filter']; + BackupController.$inject = ['$scope', '$timeout', 'Authentication', '$translate', 'MeanTorrentConfig', 'BackupService', 'NotifycationService', + 'DebugConsoleService', '$filter', 'ModalConfirmService']; - function BackupController($scope, $timeout, getStorageLangService, MeanTorrentConfig, BackupService, NotifycationService, - mtDebug, $filter) { + function BackupController($scope, $timeout, Authentication, $translate, MeanTorrentConfig, BackupService, NotifycationService, + mtDebug, $filter, ModalConfirmService) { var vm = this; - vm.lang = getStorageLangService.getLang(); - vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app; + vm.user = Authentication.user; vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage; + vm.deleteList = []; + /** * buildPager */ @@ -66,5 +67,51 @@ vm.buildPager(); }); }; + + /** + * deleteSelected + */ + vm.deleteSelected = function () { + vm.deleteList = []; + var modalOptions = { + closeButtonText: $translate.instant('ABOUT.DELETE_CONFIRM_CANCEL'), + actionButtonText: $translate.instant('ABOUT.DELETE_CONFIRM_OK'), + headerText: $translate.instant('ABOUT.DELETE_CONFIRM_HEADER_TEXT'), + bodyText: $translate.instant('BACKUP.DELETE_CONFIRM_BODY_TEXT') + }; + + angular.forEach(vm.selected, function (item, id) { + if (item) { + vm.deleteList.push(id); + } + }); + + mtDebug.info(vm.deleteList); + + if (vm.deleteList.length > 0) { + ModalConfirmService.showModal({}, modalOptions) + .then(function (result) { + BackupService.remove({ + names: vm.deleteList + }, function (res) { + var s = []; + angular.forEach(vm.fileList, function (f) { + if (vm.deleteList.indexOf(f.name) !== -1) { + s.push(f); + } + }); + + angular.forEach(s, function (f) { + vm.fileList.splice(vm.fileList.indexOf(f), 1); + }); + vm.figureOutItemsToDisplay(); + + NotifycationService.showSuccessNotify('BACKUP.DELETED_SUCCESSFULLY'); + }, function (res) { + NotifycationService.showErrorNotify(res.data.message, 'BACKUP.DELETED_ERROR'); + }); + }); + } + }; } }()); diff --git a/modules/backup/client/views/backup.client.view.html b/modules/backup/client/views/backup.client.view.html index c7200c6b..3f7fc9db 100644 --- a/modules/backup/client/views/backup.client.view.html +++ b/modules/backup/client/views/backup.client.view.html @@ -28,7 +28,7 @@ - + {{f.name}} diff --git a/modules/backup/server/controllers/backup.server.controller.js b/modules/backup/server/controllers/backup.server.controller.js index cb21b0ee..7013c62c 100644 --- a/modules/backup/server/controllers/backup.server.controller.js +++ b/modules/backup/server/controllers/backup.server.controller.js @@ -32,8 +32,24 @@ exports.list = function (req, res) { }; /** - * Delete an collection + * delete + * @param req + * @param res */ exports.delete = function (req, res) { + if (req.query.names) { + if (Array.isArray(req.query.names)) { + req.query.names.forEach(function (n) { + var tfile = backupConfig.dir + n; + fs.unlinkSync(tfile); + }); + } else { + var tfile = backupConfig.dir + req.query.names; + fs.unlinkSync(tfile); + } + return res.status(200).send({ + message: 'delete successfully' + }); + } }; diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index b09b63f8..972dbaf0 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -549,7 +549,10 @@ LIST_ERROR: 'Files list error', FIELD_NAME: 'File name', FIELD_SIZE: 'File size', - FIELD_TIME: 'Backup time' + FIELD_TIME: 'Backup time', + DELETE_CONFIRM_BODY_TEXT: 'Are you sure want to delete these files?', + DELETED_SUCCESSFULLY: 'File deleted successfully', + DELETED_ERROR: 'File deleted failed' }, //user settings diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index c7761bc2..535a5835 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -549,7 +549,10 @@ LIST_ERROR: '备份文件列表错误', FIELD_NAME: '文件名', FIELD_SIZE: '文件大小', - FIELD_TIME: '备份时间' + FIELD_TIME: '备份时间', + DELETE_CONFIRM_BODY_TEXT: '您确定要删除这些备份文件吗?', + DELETED_SUCCESSFULLY: '备份文件删除成功', + DELETED_ERROR: '备份文件删除失败' }, //user settings