refactor code
This commit is contained in:
parent
3d5af32860
commit
9bb73aa3f4
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
dragulaService.options($scope, 'task-list', {
|
dragulaService.options($scope, 'task-list', {
|
||||||
revertOnSpill: true,
|
revertOnSpill: true,
|
||||||
moves: function (el, container, handle) {
|
moves: function () {
|
||||||
return $scope.isSupportDragTask();
|
return $scope.isSupportDragTask();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,16 +7,14 @@
|
||||||
$scope.context = {
|
$scope.context = {
|
||||||
currentTab: 'download',
|
currentTab: 'download',
|
||||||
urls: '',
|
urls: '',
|
||||||
globalOptions: null,
|
availableOptions: (function () {
|
||||||
availableOptions: [],
|
|
||||||
options: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.context.availableOptions = (function () {
|
|
||||||
var keys = aria2SettingService.getNewTaskOptionKeys();
|
var keys = aria2SettingService.getNewTaskOptionKeys();
|
||||||
|
|
||||||
return aria2SettingService.getSpecifiedOptions(keys);
|
return aria2SettingService.getSpecifiedOptions(keys);
|
||||||
})();
|
})(),
|
||||||
|
globalOptions: null,
|
||||||
|
options: {}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.changeTab = function (tabName) {
|
$scope.changeTab = function (tabName) {
|
||||||
if (tabName == 'options') {
|
if (tabName == 'options') {
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
angular.module('ariaNg').controller('Aria2SettingsController', ['$rootScope', '$scope', '$location', 'ariaNgConstants', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, $location, ariaNgConstants, ariaNgCommonService, aria2SettingService) {
|
angular.module('ariaNg').controller('Aria2SettingsController', ['$rootScope', '$scope', '$location', 'ariaNgConstants', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, $location, ariaNgConstants, ariaNgCommonService, aria2SettingService) {
|
||||||
var location = $location.path().substring($location.path().lastIndexOf('/') + 1);
|
var location = $location.path().substring($location.path().lastIndexOf('/') + 1);
|
||||||
|
|
||||||
$scope.availableOptions = (function (type) {
|
$scope.context = {
|
||||||
|
availableOptions: (function (type) {
|
||||||
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
|
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
|
||||||
|
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
|
@ -13,7 +14,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return aria2SettingService.getSpecifiedOptions(keys);
|
return aria2SettingService.getSpecifiedOptions(keys);
|
||||||
})(location);
|
})(location),
|
||||||
|
globalOptions: []
|
||||||
|
};
|
||||||
|
|
||||||
$scope.setGlobalOption = function (key, value, optionStatus) {
|
$scope.setGlobalOption = function (key, value, optionStatus) {
|
||||||
return aria2SettingService.setGlobalOption(key, value, function (response) {
|
return aria2SettingService.setGlobalOption(key, value, function (response) {
|
||||||
|
@ -28,7 +31,7 @@
|
||||||
$rootScope.loadPromise = (function () {
|
$rootScope.loadPromise = (function () {
|
||||||
return aria2SettingService.getGlobalOption(function (response) {
|
return aria2SettingService.getGlobalOption(function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
$scope.globalOptions = response.data;
|
$scope.context.globalOptions = response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('AriaNgSettingsController', ['$scope', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', function ($scope, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService) {
|
angular.module('ariaNg').controller('AriaNgSettingsController', ['$scope', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', function ($scope, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService) {
|
||||||
$scope.languages = ariaNgLanguages;
|
$scope.context = {
|
||||||
$scope.availableTime = ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true);
|
languages: ariaNgLanguages,
|
||||||
$scope.settings = ariaNgSettingService.getAllOptions();
|
availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true),
|
||||||
|
settings: ariaNgSettingService.getAllOptions()
|
||||||
|
};
|
||||||
|
|
||||||
$scope.settingService = ariaNgSettingService;
|
$scope.settingService = ariaNgSettingService;
|
||||||
}]);
|
}]);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, ariaNgCommonService, aria2SettingService) {
|
angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, ariaNgCommonService, aria2SettingService) {
|
||||||
|
$scope.context = {
|
||||||
|
aria2Status: null
|
||||||
|
};
|
||||||
|
|
||||||
$scope.saveSession = function () {
|
$scope.saveSession = function () {
|
||||||
return aria2SettingService.saveSession(function (response) {
|
return aria2SettingService.saveSession(function (response) {
|
||||||
if (response.success && response.data == 'OK') {
|
if (response.success && response.data == 'OK') {
|
||||||
|
@ -23,7 +27,7 @@
|
||||||
$rootScope.loadPromise = (function () {
|
$rootScope.loadPromise = (function () {
|
||||||
return aria2SettingService.getAria2Status(function (response) {
|
return aria2SettingService.getAria2Status(function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
$scope.aria2Status = response.data;
|
$scope.context.aria2Status = response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -28,11 +28,11 @@
|
||||||
|
|
||||||
var peers = response.data;
|
var peers = response.data;
|
||||||
|
|
||||||
if (!ariaNgCommonService.extendArray(peers, $scope.peers, 'peerId')) {
|
if (!ariaNgCommonService.extendArray(peers, $scope.context.btPeers, 'peerId')) {
|
||||||
$scope.peers = peers;
|
$scope.context.btPeers = peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.context.healthPercent = aria2TaskService.estimateHealthPercentFromPeers(task, $scope.peers);
|
$scope.context.healthPercent = aria2TaskService.estimateHealthPercentFromPeers(task, $scope.context.btPeers);
|
||||||
}, silent, true);
|
}, silent, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,9 +76,11 @@
|
||||||
|
|
||||||
$scope.context = {
|
$scope.context = {
|
||||||
currentTab: 'overview',
|
currentTab: 'overview',
|
||||||
|
btPeers: [],
|
||||||
healthPercent: 0,
|
healthPercent: 0,
|
||||||
statusData: ariaNgMonitorService.getEmptyStatsData($routeParams.gid),
|
statusData: ariaNgMonitorService.getEmptyStatsData($routeParams.gid),
|
||||||
availableOptions: []
|
availableOptions: [],
|
||||||
|
options: []
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.changeTab = function (tabName) {
|
$scope.changeTab = function (tabName) {
|
||||||
|
@ -185,7 +187,7 @@
|
||||||
$scope.loadTaskOption = function (task) {
|
$scope.loadTaskOption = function (task) {
|
||||||
$rootScope.loadPromise = aria2TaskService.getTaskOptions(task.gid, function (response) {
|
$rootScope.loadPromise = aria2TaskService.getTaskOptions(task.gid, function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
$scope.options = response.data;
|
$scope.context.options = response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<section class="content no-padding">
|
<section class="content no-padding">
|
||||||
<div class="settings-table striped hoverable">
|
<div class="settings-table striped hoverable">
|
||||||
<ng-setting ng-repeat="option in availableOptions" option="option" ng-model="globalOptions[option.key]"
|
<ng-setting ng-repeat="option in context.availableOptions" option="option" ng-model="context.globalOptions[option.key]"
|
||||||
on-change-value="setGlobalOption(key, value, optionStatus)"></ng-setting>
|
on-change-value="setGlobalOption(key, value, optionStatus)"></ng-setting>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
<span translate>Language</span>
|
<span translate>Language</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<select class="form-control" style="width: 100%;" ng-model="settings.language"
|
<select class="form-control" style="width: 100%;" ng-model="context.settings.language"
|
||||||
ng-options="type as (language.name | translate) for (type, language) in languages"
|
ng-options="type as (language.name | translate) for (type, language) in context.languages"
|
||||||
ng-change="settingService.setLanguage(settings.language)">
|
ng-change="settingService.setLanguage(context.settings.language)">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,10 +18,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon" ng-bind="settings.protocol + '://'"></span>
|
<span class="input-group-addon" ng-bind="context.settings.protocol + '://'"></span>
|
||||||
<input class="form-control" type="text" ng-model="settings.rpcHost" ng-change="settingService.setRpcHost(settings.rpcHost)"/>
|
<input class="form-control" type="text" ng-model="context.settings.rpcHost" ng-change="settingService.setRpcHost(context.settings.rpcHost)"/>
|
||||||
<span class="input-group-addon" style="border-left: 0">:</span>
|
<span class="input-group-addon" style="border-left: 0">:</span>
|
||||||
<span class="input-group-addon" ng-bind="settings.rpcPort"></span>
|
<span class="input-group-addon" ng-bind="context.settings.rpcPort"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<span class="asterisk">*</span>
|
<span class="asterisk">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<input class="form-control" type="text" ng-model="settings.rpcPort" ng-change="settingService.setRpcPort(settings.rpcPort)"/>
|
<input class="form-control" type="text" ng-model="context.settings.rpcPort" ng-change="settingService.setRpcPort(context.settings.rpcPort)"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
<span class="asterisk">*</span>
|
<span class="asterisk">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<select class="form-control" style="width: 100%;" ng-model="settings.protocol" ng-change="settingService.setProtocol(settings.protocol)">
|
<select class="form-control" style="width: 100%;" ng-model="context.settings.protocol" ng-change="settingService.setProtocol(context.settings.protocol)">
|
||||||
<option value="http" translate>Http</option>
|
<option value="http" translate>Http</option>
|
||||||
<option value="https" translate>Https</option>
|
<option value="https" translate>Https</option>
|
||||||
<option value="ws" translate>WebSocket</option>
|
<option value="ws" translate>WebSocket</option>
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
<span class="asterisk">*</span>
|
<span class="asterisk">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<input class="form-control" type="password" ng-model="settings.secret" ng-change="settingService.setSecret(settings.secret)"/>
|
<input class="form-control" type="password" ng-model="context.settings.secret" ng-change="settingService.setSecret(context.settings.secret)"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -63,9 +63,9 @@
|
||||||
<span class="asterisk">*</span>
|
<span class="asterisk">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<select class="form-control" style="width: 100%;" ng-model="settings.globalStatRefreshInterval"
|
<select class="form-control" style="width: 100%;" ng-model="context.settings.globalStatRefreshInterval"
|
||||||
ng-change="settingService.setGlobalStatRefreshInterval(settings.globalStatRefreshInterval)"
|
ng-change="settingService.setGlobalStatRefreshInterval(context.settings.globalStatRefreshInterval)"
|
||||||
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in availableTime">
|
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in context.availableTime">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -75,9 +75,9 @@
|
||||||
<span class="asterisk">*</span>
|
<span class="asterisk">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<select class="form-control" style="width: 100%;" ng-model="settings.downloadTaskRefreshInterval"
|
<select class="form-control" style="width: 100%;" ng-model="context.settings.downloadTaskRefreshInterval"
|
||||||
ng-change="settingService.setDownloadTaskRefreshInterval(settings.downloadTaskRefreshInterval)"
|
ng-change="settingService.setDownloadTaskRefreshInterval(context.settings.downloadTaskRefreshInterval)"
|
||||||
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in availableTime">
|
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in context.availableTime">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<span translate>Aria2 Version</span>
|
<span translate>Aria2 Version</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<span ng-bind="aria2Status.version"></span>
|
<span ng-bind="context.aria2Status.version"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
<span translate>Enabled Features</span>
|
<span translate>Enabled Features</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value col-sm-8">
|
<div class="setting-value col-sm-8">
|
||||||
<span class="wholeline" ng-repeat="feature in aria2Status.enabledFeatures" ng-bind="feature"></span>
|
<span class="wholeline" ng-repeat="feature in context.aria2Status.enabledFeatures" ng-bind="feature"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row ng-cloak" ng-if="aria2Status">
|
<div class="row ng-cloak" ng-if="context.aria2Status">
|
||||||
<div class="setting-key setting-key-without-desc col-sm-4">
|
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||||
<span translate>Functions</span>
|
<span translate>Functions</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -212,7 +212,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="task-table-body">
|
<div class="task-table-body">
|
||||||
<div class="row" ng-repeat="peer in peers | peerOrderBy: getPeerListOrderType()">
|
<div class="row" ng-repeat="peer in context.btPeers | peerOrderBy: getPeerListOrderType()">
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<span ng-bind="peer.name | translate"></span>
|
<span ng-bind="peer.name | translate"></span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -233,7 +233,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" ng-if="!peers || peers.length < 1">
|
<div class="row" ng-if="!context.btPeers || context.btPeers.length < 1">
|
||||||
<div class="col-sm-12 text-center">
|
<div class="col-sm-12 text-center">
|
||||||
<span translate>No connected peers</span>
|
<span translate>No connected peers</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -244,7 +244,7 @@
|
||||||
<div class="tab-pane" ng-class="{'active': context.currentTab == 'settings'}" ng-if="task && (task.status == 'active' || task.status == 'waiting' || task.status == 'paused')">
|
<div class="tab-pane" ng-class="{'active': context.currentTab == 'settings'}" ng-if="task && (task.status == 'active' || task.status == 'waiting' || task.status == 'paused')">
|
||||||
<div class="settings-table striped hoverable">
|
<div class="settings-table striped hoverable">
|
||||||
<ng-setting ng-repeat="option in context.availableOptions" option="option"
|
<ng-setting ng-repeat="option in context.availableOptions" option="option"
|
||||||
ng-model="options[option.key]" on-change-value="setOption(key, value, optionStatus)"></ng-setting>
|
ng-model="context.options[option.key]" on-change-value="setOption(key, value, optionStatus)"></ng-setting>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue