refactor code
This commit is contained in:
parent
423d25b84e
commit
25c3bee90b
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('DownloadListController', ['$scope', '$window', '$location', '$interval', 'translateFilter', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $window, $location, $interval, translateFilter, aria2RpcService, ariaNgSettingService, utils) {
|
angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$interval', 'translateFilter', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($rootScope, $scope, $window, $location, $interval, translateFilter, aria2RpcService, ariaNgSettingService, utils) {
|
||||||
var location = $location.path().substring(1);
|
var location = $location.path().substring(1);
|
||||||
var downloadTaskRefreshPromise = null;
|
var downloadTaskRefreshPromise = null;
|
||||||
var needRequestWholeInfo = true;
|
var needRequestWholeInfo = true;
|
||||||
|
@ -40,9 +40,9 @@
|
||||||
return invokeMethod({
|
return invokeMethod({
|
||||||
params: params,
|
params: params,
|
||||||
callback: function (result) {
|
callback: function (result) {
|
||||||
if (!utils.extendArray(result, $scope.taskContext.list, 'gid')) {
|
if (!utils.extendArray(result, $rootScope.taskContext.list, 'gid')) {
|
||||||
if (needRequestWholeInfo) {
|
if (needRequestWholeInfo) {
|
||||||
$scope.taskContext.list = result;
|
$rootScope.taskContext.list = result;
|
||||||
needRequestWholeInfo = false;
|
needRequestWholeInfo = false;
|
||||||
} else {
|
} else {
|
||||||
needRequestWholeInfo = true;
|
needRequestWholeInfo = true;
|
||||||
|
@ -51,9 +51,9 @@
|
||||||
needRequestWholeInfo = false;
|
needRequestWholeInfo = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($scope.taskContext.list && $scope.taskContext.list.length > 0) {
|
if ($rootScope.taskContext.list && $rootScope.taskContext.list.length > 0) {
|
||||||
for (var i = 0; i < $scope.taskContext.list.length; i++) {
|
for (var i = 0; i < $rootScope.taskContext.list.length; i++) {
|
||||||
utils.processDownloadTask($scope.taskContext.list[i]);
|
utils.processDownloadTask($rootScope.taskContext.list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,11 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$scope.searchContext || !$scope.searchContext.text) {
|
if (!$rootScope.searchContext || !$rootScope.searchContext.text) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (task.taskName.toLowerCase().indexOf($scope.searchContext.text.toLowerCase()) >= 0);
|
return (task.taskName.toLowerCase().indexOf($rootScope.searchContext.text.toLowerCase()) >= 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getOrderType = function () {
|
$scope.getOrderType = function () {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('MainController', ['$scope', '$interval', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $interval, aria2RpcService, ariaNgSettingService, utils) {
|
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$interval', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($rootScope, $scope, $interval, aria2RpcService, ariaNgSettingService, utils) {
|
||||||
var globalStatRefreshPromise = null;
|
var globalStatRefreshPromise = null;
|
||||||
|
|
||||||
var processStatResult = function (stat) {
|
var processStatResult = function (stat) {
|
||||||
|
@ -26,57 +26,12 @@
|
||||||
|
|
||||||
refreshGlobalStat();
|
refreshGlobalStat();
|
||||||
|
|
||||||
$scope.searchContext = {
|
|
||||||
text: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.taskContext = {
|
|
||||||
list: [],
|
|
||||||
selected: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.isTaskSelected = function () {
|
$scope.isTaskSelected = function () {
|
||||||
var allTasks = $scope.taskContext.list;
|
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
|
||||||
|
|
||||||
if (!allTasks || allTasks.length < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedTasks = $scope.taskContext.selected;
|
|
||||||
|
|
||||||
for (var i = 0; i < allTasks.length; i++) {
|
|
||||||
var task = allTasks[i];
|
|
||||||
if (selectedTasks[task.gid]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.selectAllTasks = function () {
|
$scope.selectAllTasks = function () {
|
||||||
var allTasks = $scope.taskContext.list;
|
$rootScope.taskContext.selectAll();
|
||||||
|
|
||||||
if (!allTasks || allTasks.length < 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedTasks = $scope.taskContext.selected;
|
|
||||||
var isAllSelected = true;
|
|
||||||
|
|
||||||
for (var i = 0; i < allTasks.length; i++) {
|
|
||||||
var task = allTasks[i];
|
|
||||||
|
|
||||||
if (!selectedTasks[task.gid]) {
|
|
||||||
isAllSelected = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < allTasks.length; i++) {
|
|
||||||
var task = allTasks[i];
|
|
||||||
selectedTasks[task.gid] = !isAllSelected;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.changeDisplayOrder = function (type, autoSetReverse) {
|
$scope.changeDisplayOrder = function (type, autoSetReverse) {
|
||||||
|
|
|
@ -54,6 +54,53 @@
|
||||||
return angular.element('body').hasClass('sidebar-open');
|
return angular.element('body').hasClass('sidebar-open');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$rootScope.searchContext = {
|
||||||
|
text: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
$rootScope.taskContext = {
|
||||||
|
list: [],
|
||||||
|
selected: {},
|
||||||
|
getSelectedTaskIds: function () {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
if (!this.list || !this.selected || this.list.length < 1) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < this.list.length; i++) {
|
||||||
|
var task = this.list[i];
|
||||||
|
|
||||||
|
if (this.selected[task.gid]) {
|
||||||
|
result.push(task.gid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
selectAll: function () {
|
||||||
|
if (!this.list || !this.selected || this.list.length < 1) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isAllSelected = true;
|
||||||
|
|
||||||
|
for (var i = 0; i < this.list.length; i++) {
|
||||||
|
var task = this.list[i];
|
||||||
|
|
||||||
|
if (!this.selected[task.gid]) {
|
||||||
|
isAllSelected = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < this.list.length; i++) {
|
||||||
|
var task = this.list[i];
|
||||||
|
this.selected[task.gid] = !isAllSelected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$rootScope.swipeActions = {
|
$rootScope.swipeActions = {
|
||||||
leftSwipe: function () {
|
leftSwipe: function () {
|
||||||
if (isSidebarShowInSmallScreen()) {
|
if (isSidebarShowInSmallScreen()) {
|
||||||
|
@ -78,6 +125,12 @@
|
||||||
delete $rootScope.swipeActions.extentLeftSwipe;
|
delete $rootScope.swipeActions.extentLeftSwipe;
|
||||||
delete $rootScope.swipeActions.extentRightSwipe;
|
delete $rootScope.swipeActions.extentRightSwipe;
|
||||||
|
|
||||||
|
if (angular.isArray($rootScope.taskContext.list) && $rootScope.taskContext.list.length > 0) {
|
||||||
|
$rootScope.taskContext.list.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log($rootScope.taskContext.list);
|
||||||
|
|
||||||
SweetAlert.close();
|
SweetAlert.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue