From 2004ec6c9ba62ad0a889e9e9a01d9c48f61d897e Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 1 Jun 2016 00:09:11 +0800 Subject: [PATCH] support drag to change waiting task order when display order is set default --- app/index.html | 2 ++ app/scripts/controllers/list.js | 32 ++++++++++++++++++++++- app/scripts/core/app.js | 3 ++- app/scripts/services/aria2RpcService.js | 9 ++++--- app/scripts/services/ariaNgTaskService.js | 8 ++++++ app/styles/aria-ng.css | 14 ++++++++++ app/views/list.html | 2 +- bower.json | 1 + 8 files changed, 65 insertions(+), 6 deletions(-) diff --git a/app/index.html b/app/index.html index c070e4a..be8576c 100644 --- a/app/index.html +++ b/app/index.html @@ -21,6 +21,7 @@ + @@ -252,6 +253,7 @@ + diff --git a/app/scripts/controllers/list.js b/app/scripts/controllers/list.js index e95899b..6334dd5 100644 --- a/app/scripts/controllers/list.js +++ b/app/scripts/controllers/list.js @@ -1,12 +1,17 @@ (function () { 'use strict'; - angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgTaskService', function ($rootScope, $scope, $window, $location, $interval, ariaNgCommonService, ariaNgSettingService, ariaNgTaskService) { + angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$route', '$interval', 'dragulaService', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgTaskService', function ($rootScope, $scope, $window, $location, $route, $interval, dragulaService, ariaNgCommonService, ariaNgSettingService, ariaNgTaskService) { var location = $location.path().substring(1); var downloadTaskRefreshPromise = null; + var pauseDownloadTaskRefresh = false; var needRequestWholeInfo = true; var refreshDownloadTask = function () { + if (pauseDownloadTaskRefresh) { + return; + } + return ariaNgTaskService.getTaskList(location, needRequestWholeInfo, function (result) { if (!ariaNgCommonService.extendArray(result, $rootScope.taskContext.list, 'gid')) { if (needRequestWholeInfo) { @@ -42,12 +47,37 @@ return ariaNgSettingService.getDisplayOrder(); }; + $scope.isSupportDragTask = function () { + var displayOrder = ariaNgCommonService.parseOrderType(ariaNgSettingService.getDisplayOrder()); + + return location == 'waiting' && displayOrder.type == 'default'; + }; + if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) { downloadTaskRefreshPromise = $interval(function () { refreshDownloadTask(); }, ariaNgSettingService.getDownloadTaskRefreshInterval()); } + dragulaService.options($scope, 'task-list', { + revertOnSpill: true, + moves: function (el, container, handle) { + return $scope.isSupportDragTask(); + } + }); + + $scope.$on('task-list.drop-model', function (el, target, source) { + var element = angular.element(target); + var gid = element.attr('data-gid'); + var index = element.index(); + + pauseDownloadTaskRefresh = true; + + ariaNgTaskService.changeTaskPosition(gid, index, function (result) { + pauseDownloadTaskRefresh = false; + }); + }); + $scope.$on('$destroy', function () { if (downloadTaskRefreshPromise) { $interval.cancel(downloadTaskRefreshPromise); diff --git a/app/scripts/core/app.js b/app/scripts/core/app.js index 4d20ce7..8aee2d9 100644 --- a/app/scripts/core/app.js +++ b/app/scripts/core/app.js @@ -15,6 +15,7 @@ 'LocalStorageModule', 'cgBusy', 'ui.bootstrap-slider', - 'oitozero.ngSweetAlert' + 'oitozero.ngSweetAlert', + angularDragula(angular) ]); })(); diff --git a/app/scripts/services/aria2RpcService.js b/app/scripts/services/aria2RpcService.js index 64744c2..1c62ee8 100644 --- a/app/scripts/services/aria2RpcService.js +++ b/app/scripts/services/aria2RpcService.js @@ -234,9 +234,12 @@ return invoke('tellStopped', requestContext); }, - // changePosition: function (context) { - // return invoke('changePosition', context); - // }, + changePosition: function (context) { + return invoke('changePosition', { + params: [context.gid, context.pos, context.how], + callback: context.callback + }); + }, // changeUri: function (context) { // return invoke('changeUri', context); // }, diff --git a/app/scripts/services/ariaNgTaskService.js b/app/scripts/services/ariaNgTaskService.js index dcdfa73..23a8228 100644 --- a/app/scripts/services/ariaNgTaskService.js +++ b/app/scripts/services/ariaNgTaskService.js @@ -169,6 +169,14 @@ callback: callback }); }, + changeTaskPosition: function (gid, position, callback) { + return aria2RpcService.changePosition({ + gid: gid, + pos: position, + how: 'POS_SET', + callback: callback + }) + }, processDownloadTasks: function (tasks) { if (!angular.isArray(tasks)) { return; diff --git a/app/styles/aria-ng.css b/app/styles/aria-ng.css index 0e0dbd4..f39606a 100644 --- a/app/styles/aria-ng.css +++ b/app/styles/aria-ng.css @@ -408,6 +408,13 @@ td { border-color: #208fe5; } +/* angular-dragula extend */ +.gu-mirror { + cursor: grabbing; + cursor: -moz-grabbing; + cursor: -webkit-grabbing; +} + /* task-table */ .task-table { margin-left: 15px; @@ -429,6 +436,13 @@ td { cursor: pointer; } +.task-table > .task-table-body.draggable { + cursor: move; + cursor: grab; + cursor: -moz-grab; + cursor: -webkit-grab; +} + .task-table > .task-table-body > div.row { padding-top: 8px; padding-bottom: 8px; diff --git a/app/views/list.html b/app/views/list.html index 304afe7..320963a 100644 --- a/app/views/list.html +++ b/app/views/list.html @@ -32,7 +32,7 @@ -
+
diff --git a/bower.json b/bower.json index 225f334..f87ebc4 100644 --- a/bower.json +++ b/bower.json @@ -46,6 +46,7 @@ "angular-base64": "^2.0.5", "angular-local-storage": "^0.2.7", "angular-busy": "^4.1.3", + "angular-dragula": "^1.2.7", "angular-bootstrap-slider": "^0.1.28", "ngSweetAlert": "https://github.com/oitozero/ngSweetAlert.git#8df6c30b0996f09cb4cf5e90a41115a6c09fa852" }