diff --git a/config/env/torrents.js b/config/env/torrents.js index 0292a0fa..2a9ddbf7 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -2,7 +2,12 @@ module.exports = { - //[!config_content]// + /**------------------------------------------------------------------------------------------------ + * !IMPORTANT + * MEANTORRENT CONFIG START + * PLEASE DO NOT MODIFY THE ABOVE LINES !!! + --------------------------------------------------------------------------------------------------*/ + meanTorrentConfig: { /** * @app @@ -1220,5 +1225,10 @@ module.exports = { ] } } - //[!config_content]// + + /**------------------------------------------------------------------------------------------------ + * !IMPORTANT + * MEANTORRENT CONFIG START + * PLEASE DO NOT MODIFY THE FOLLOWING LINES !!! + --------------------------------------------------------------------------------------------------*/ }; diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 4ea0e074..cee652a4 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -1259,7 +1259,14 @@ //systems control panel SYSTEMS: { TORRENTS_CONFIG: 'System configure', - TEMPLATE_EDIT: 'Template editor' + TEMPLATE_EDIT: 'Template editor', + + CONFIG_BLUR_CONFIRM_CANCEL: 'Cancel', + CONFIG_BLUR_CONFIRM_SAVE: 'Save', + CONFIG_BLUR_HEADER_TEXT: 'Configure was changed', + CONFIG_BLUR_BODY_TEXT: 'Configure was changed, are you sure to quit and don`t save it?', + CONFIG_SAVE_SUCCESSFULLY: 'Configure save successfully', + CONFIG_SAVE_FAILED: 'Configure save failed' }, /////////////////////////resources tag fields/////////////////////////////////// diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 3960a992..359ae93c 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -1259,7 +1259,14 @@ //systems control panel SYSTEMS: { TORRENTS_CONFIG: '系统配置调整', - TEMPLATE_EDIT: '模板在线编辑' + TEMPLATE_EDIT: '模板在线编辑', + + CONFIG_BLUR_CONFIRM_CANCEL: '取消', + CONFIG_BLUR_CONFIRM_SAVE: '保存', + CONFIG_BLUR_HEADER_TEXT: '系统配置已更改', + CONFIG_BLUR_BODY_TEXT: '系统配置已被修改, 您确定要退出并放弃保存吗?', + CONFIG_SAVE_SUCCESSFULLY: '系统配置保存成功', + CONFIG_SAVE_FAILED: '系统配置保存失败' }, /////////////////////////resources tag fields/////////////////////////////////// diff --git a/modules/systems/client/controllers/ststems-config.client.controller.js b/modules/systems/client/controllers/ststems-config.client.controller.js index 8ebf3d64..816598c2 100644 --- a/modules/systems/client/controllers/ststems-config.client.controller.js +++ b/modules/systems/client/controllers/ststems-config.client.controller.js @@ -5,21 +5,71 @@ .module('systems') .controller('SystemConfigController', SystemConfigController); - SystemConfigController.$inject = ['$scope', '$state', '$timeout', '$translate', 'Authentication', 'SystemsService']; + SystemConfigController.$inject = ['$scope', '$state', '$timeout', '$translate', 'Authentication', 'SystemsService', 'ModalConfirmService', 'NotifycationService']; - function SystemConfigController($scope, $state, $timeout, $translate, Authentication, SystemsService) { + function SystemConfigController($scope, $state, $timeout, $translate, Authentication, SystemsService, ModalConfirmService, NotifycationService) { var vm = this; vm.user = Authentication.user; + vm.cmOption = { + lineNumbers: true, + mode: {name: 'javascript', json: true}, + tabSize: 2, + onLoad: function (_cm) { + vm.initConfigContent = function (value) { + _cm.setOption('value', value); + vm.contentChanged = false; + }; + + _cm.on('change', function () { + vm.contentChanged = true; + }); + } + }; + + /** + * remove side_overlay background + */ + $scope.$on('$stateChangeStart', function () { + if (vm.contentChanged) { + var modalOptions = { + closeButtonText: $translate.instant('SYSTEMS.CONFIG_BLUR_CONFIRM_CANCEL'), + actionButtonText: $translate.instant('SYSTEMS.CONFIG_BLUR_CONFIRM_SAVE'), + headerText: $translate.instant('SYSTEMS.CONFIG_BLUR_HEADER_TEXT'), + bodyText: $translate.instant('SYSTEMS.CONFIG_BLUR_BODY_TEXT') + }; + + ModalConfirmService.showModal({}, modalOptions) + .then(function (result) { + vm.saveConfigContent(); + }); + } + }); + /** * getConfigFile */ vm.getConfigFile = function () { SystemsService.getSystemConfig(function (res) { - vm.systemConfigContent = res.configContent; + vm.initConfigContent(res.configContent); + // vm.systemConfigContent = res.configContent; }, function (err) { }); }; + + /** + * saveConfigContent + */ + vm.saveConfigContent = function () { + var sc = new SystemsService({ + content: vm.systemConfigContent + }); + sc.$setSystemConfig(function (res) { + console.log(res); + // NotifycationService.showSuccessNotify('SYSTEMS.CONFIG_SAVE_SUCCESSFULLY'); + // vm.contentChanged = false; + }); + }; } }()); diff --git a/modules/systems/client/less/systems.less b/modules/systems/client/less/systems.less index 786423e0..284d6492 100644 --- a/modules/systems/client/less/systems.less +++ b/modules/systems/client/less/systems.less @@ -15,11 +15,9 @@ height: 100px; } .panel-body { - padding: 5px; - .config-content { - min-height: 400px; - max-height: 800px; - resize: vertical; + padding: 0; + .CodeMirror { + min-height: 500px; } } } \ No newline at end of file diff --git a/modules/systems/client/services/systems.client.service.js b/modules/systems/client/services/systems.client.service.js index 1739ad09..adc57c80 100644 --- a/modules/systems/client/services/systems.client.service.js +++ b/modules/systems/client/services/systems.client.service.js @@ -17,6 +17,10 @@ getSystemConfig: { method: 'GET', url: '/api/systems/systemConfig' + }, + setSystemConfig: { + method: 'PUT', + url: '/api/systems/systemConfig' } }); } diff --git a/modules/systems/client/views/config.client.view.html b/modules/systems/client/views/config.client.view.html index 3d865f08..c6238686 100644 --- a/modules/systems/client/views/config.client.view.html +++ b/modules/systems/client/views/config.client.view.html @@ -1,14 +1,19 @@
-
{{'SYSTEMS.TORRENTS_CONFIG' | translate}} - /config/env/torrent.js
+
{{'SYSTEMS.TORRENTS_CONFIG' | translate}} - + /config/env/torrent.js +
- +
\ No newline at end of file diff --git a/modules/systems/server/controllers/systems.server.controller.js b/modules/systems/server/controllers/systems.server.controller.js index cb2030a8..a5fdffb5 100644 --- a/modules/systems/server/controllers/systems.server.controller.js +++ b/modules/systems/server/controllers/systems.server.controller.js @@ -23,7 +23,35 @@ var serverNoticeConfig = config.meanTorrentConfig.serverNotice; */ exports.getSystemConfig = function (req, res) { var config = shell.cat(path.resolve('./config/env/torrents.js')); - res.json({ - configContent: config - }); + + if (req.user.isAdmin) { + res.json({ + configContent: config + }); + } else { + return res.status(403).json({ + message: 'SERVER.USER_IS_NOT_AUTHORIZED' + }); + } +}; + +/** + * setSystemConfig + * @param req + * @param res + */ +exports.setSystemConfig = function (req, res) { + // eslint-disable-next-line new-cap + var cc = shell.ShellString(req.body.content); + + if (req.user.isAdmin) { + cc.to('./config/env/torrents.js'); + res.json({ + message: 'SERVER.TORRENT_CONFIG_SAVE_SUCCESSFULLY' + }); + } else { + return res.status(403).json({ + message: 'SERVER.USER_IS_NOT_AUTHORIZED' + }); + } }; diff --git a/modules/systems/server/routes/systems.server.routes.js b/modules/systems/server/routes/systems.server.routes.js index b27a1c48..be8f01ce 100644 --- a/modules/systems/server/routes/systems.server.routes.js +++ b/modules/systems/server/routes/systems.server.routes.js @@ -8,5 +8,6 @@ var systemsPolicy = require('../policies/systems.server.policy'), module.exports = function (app) { app.route('/api/systems/systemConfig').all(systemsPolicy.isAllowed) - .get(systems.getSystemConfig); + .get(systems.getSystemConfig) + .put(systems.setSystemConfig); };