refactor code

This commit is contained in:
MaysWind 2016-06-21 00:20:30 +08:00
parent 3d5af32860
commit 9bb73aa3f4
10 changed files with 58 additions and 48 deletions

View file

@ -71,7 +71,7 @@
dragulaService.options($scope, 'task-list', {
revertOnSpill: true,
moves: function (el, container, handle) {
moves: function () {
return $scope.isSupportDragTask();
}
});

View file

@ -7,17 +7,15 @@
$scope.context = {
currentTab: 'download',
urls: '',
availableOptions: (function () {
var keys = aria2SettingService.getNewTaskOptionKeys();
return aria2SettingService.getSpecifiedOptions(keys);
})(),
globalOptions: null,
availableOptions: [],
options: {}
};
$scope.context.availableOptions = (function () {
var keys = aria2SettingService.getNewTaskOptionKeys();
return aria2SettingService.getSpecifiedOptions(keys);
})();
$scope.changeTab = function (tabName) {
if (tabName == 'options') {
$scope.loadDefaultOption();

View file

@ -4,16 +4,19 @@
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);
$scope.availableOptions = (function (type) {
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
$scope.context = {
availableOptions: (function (type) {
var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type);
if (!keys) {
ariaNgCommonService.showError('Type is illegal!');
return;
}
if (!keys) {
ariaNgCommonService.showError('Type is illegal!');
return;
}
return aria2SettingService.getSpecifiedOptions(keys);
})(location);
return aria2SettingService.getSpecifiedOptions(keys);
})(location),
globalOptions: []
};
$scope.setGlobalOption = function (key, value, optionStatus) {
return aria2SettingService.setGlobalOption(key, value, function (response) {
@ -28,7 +31,7 @@
$rootScope.loadPromise = (function () {
return aria2SettingService.getGlobalOption(function (response) {
if (response.success) {
$scope.globalOptions = response.data;
$scope.context.globalOptions = response.data;
}
});
})();

View file

@ -2,9 +2,12 @@
'use strict';
angular.module('ariaNg').controller('AriaNgSettingsController', ['$scope', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', function ($scope, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService) {
$scope.languages = ariaNgLanguages;
$scope.availableTime = ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true);
$scope.settings = ariaNgSettingService.getAllOptions();
$scope.context = {
languages: ariaNgLanguages,
availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true),
settings: ariaNgSettingService.getAllOptions()
};
$scope.settingService = ariaNgSettingService;
}]);
})();

View file

@ -2,6 +2,10 @@
'use strict';
angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, ariaNgCommonService, aria2SettingService) {
$scope.context = {
aria2Status: null
};
$scope.saveSession = function () {
return aria2SettingService.saveSession(function (response) {
if (response.success && response.data == 'OK') {
@ -23,7 +27,7 @@
$rootScope.loadPromise = (function () {
return aria2SettingService.getAria2Status(function (response) {
if (response.success) {
$scope.aria2Status = response.data;
$scope.context.aria2Status = response.data;
}
});
})();

View file

@ -28,11 +28,11 @@
var peers = response.data;
if (!ariaNgCommonService.extendArray(peers, $scope.peers, 'peerId')) {
$scope.peers = peers;
if (!ariaNgCommonService.extendArray(peers, $scope.context.btPeers, 'peerId')) {
$scope.context.btPeers = peers;
}
$scope.context.healthPercent = aria2TaskService.estimateHealthPercentFromPeers(task, $scope.peers);
$scope.context.healthPercent = aria2TaskService.estimateHealthPercentFromPeers(task, $scope.context.btPeers);
}, silent, true);
};
@ -76,9 +76,11 @@
$scope.context = {
currentTab: 'overview',
btPeers: [],
healthPercent: 0,
statusData: ariaNgMonitorService.getEmptyStatsData($routeParams.gid),
availableOptions: []
availableOptions: [],
options: []
};
$scope.changeTab = function (tabName) {
@ -185,7 +187,7 @@
$scope.loadTaskOption = function (task) {
$rootScope.loadPromise = aria2TaskService.getTaskOptions(task.gid, function (response) {
if (response.success) {
$scope.options = response.data;
$scope.context.options = response.data;
}
});
};

View file

@ -1,6 +1,6 @@
<section class="content no-padding">
<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>
</div>
</section>

View file

@ -5,9 +5,9 @@
<span translate>Language</span>
</div>
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="settings.language"
ng-options="type as (language.name | translate) for (type, language) in languages"
ng-change="settingService.setLanguage(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 context.languages"
ng-change="settingService.setLanguage(context.settings.language)">
</select>
</div>
</div>
@ -18,10 +18,10 @@
</div>
<div class="setting-value col-sm-8">
<div class="input-group">
<span class="input-group-addon" ng-bind="settings.protocol + '://'"></span>
<input class="form-control" type="text" ng-model="settings.rpcHost" ng-change="settingService.setRpcHost(settings.rpcHost)"/>
<span class="input-group-addon" ng-bind="context.settings.protocol + '://'"></span>
<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" ng-bind="settings.rpcPort"></span>
<span class="input-group-addon" ng-bind="context.settings.rpcPort"></span>
</div>
</div>
</div>
@ -31,7 +31,7 @@
<span class="asterisk">*</span>
</div>
<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 class="row">
@ -40,7 +40,7 @@
<span class="asterisk">*</span>
</div>
<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="https" translate>Https</option>
<option value="ws" translate>WebSocket</option>
@ -54,7 +54,7 @@
<span class="asterisk">*</span>
</div>
<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 class="row">
@ -63,9 +63,9 @@
<span class="asterisk">*</span>
</div>
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="settings.globalStatRefreshInterval"
ng-change="settingService.setGlobalStatRefreshInterval(settings.globalStatRefreshInterval)"
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in availableTime">
<select class="form-control" style="width: 100%;" ng-model="context.settings.globalStatRefreshInterval"
ng-change="settingService.setGlobalStatRefreshInterval(context.settings.globalStatRefreshInterval)"
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in context.availableTime">
</select>
</div>
</div>
@ -75,9 +75,9 @@
<span class="asterisk">*</span>
</div>
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="settings.downloadTaskRefreshInterval"
ng-change="settingService.setDownloadTaskRefreshInterval(settings.downloadTaskRefreshInterval)"
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in availableTime">
<select class="form-control" style="width: 100%;" ng-model="context.settings.downloadTaskRefreshInterval"
ng-change="settingService.setDownloadTaskRefreshInterval(context.settings.downloadTaskRefreshInterval)"
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in context.availableTime">
</select>
</div>
</div>

View file

@ -5,7 +5,7 @@
<span translate>Aria2 Version</span>
</div>
<div class="setting-value col-sm-8">
<span ng-bind="aria2Status.version"></span>
<span ng-bind="context.aria2Status.version"></span>
</div>
</div>
<div class="row">
@ -13,10 +13,10 @@
<span translate>Enabled Features</span>
</div>
<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 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">
<span translate>Functions</span>
</div>

View file

@ -212,7 +212,7 @@
</div>
</div>
<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">
<span ng-bind="peer.name | translate"></span>
</div>
@ -233,7 +233,7 @@
</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">
<span translate>No connected peers</span>
</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="settings-table striped hoverable">
<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>