support filter valid urls from user input in new task page
This commit is contained in:
parent
541bc10b0b
commit
0bf8c725a4
|
@ -360,6 +360,7 @@
|
||||||
<script src="scripts/directives/setting.js"></script>
|
<script src="scripts/directives/setting.js"></script>
|
||||||
<script src="scripts/directives/settingDialog.js"></script>
|
<script src="scripts/directives/settingDialog.js"></script>
|
||||||
<script src="scripts/directives/tooltip.js"></script>
|
<script src="scripts/directives/tooltip.js"></script>
|
||||||
|
<script src="scripts/directives/validUrls.js"></script>
|
||||||
<script src="scripts/filters/dateDuration.js"></script>
|
<script src="scripts/filters/dateDuration.js"></script>
|
||||||
<script src="scripts/filters/fileOrderBy.js"></script>
|
<script src="scripts/filters/fileOrderBy.js"></script>
|
||||||
<script src="scripts/filters/longDate.js"></script>
|
<script src="scripts/filters/longDate.js"></script>
|
||||||
|
|
|
@ -243,6 +243,7 @@ time.minutes={{value}} 分钟
|
||||||
time.hour={{value}} 小时
|
time.hour={{value}} 小时
|
||||||
time.hours={{value}} 小时
|
time.hours={{value}} 小时
|
||||||
requires.aria2-version=需要 aria2 v{{version}} 或更高版本
|
requires.aria2-version=需要 aria2 v{{version}} 或更高版本
|
||||||
|
task.new.download-links=下载链接 ({{count}} 个链接):
|
||||||
task.pieceinfo=已完成: {{completed}}, 共计: {{total}} 块
|
task.pieceinfo=已完成: {{completed}}, 共计: {{total}} 块
|
||||||
task.error-occurred=发生错误 ({{errorcode}})
|
task.error-occurred=发生错误 ({{errorcode}})
|
||||||
settings.file-count=({{count}} 个文件)
|
settings.file-count=({{count}} 个文件)
|
||||||
|
|
|
@ -243,6 +243,7 @@ time.minutes={{value}} 分鐘
|
||||||
time.hour={{value}} 小時
|
time.hour={{value}} 小時
|
||||||
time.hours={{value}} 小時
|
time.hours={{value}} 小時
|
||||||
requires.aria2-version=需要 aria2 v{{version}} 或更高版本
|
requires.aria2-version=需要 aria2 v{{version}} 或更高版本
|
||||||
|
task.new.download-links=下載鏈接 ({{count}} 个鏈接):
|
||||||
task.pieceinfo=已完成: {{completed}}, 共計: {{total}} 塊
|
task.pieceinfo=已完成: {{completed}}, 共計: {{total}} 塊
|
||||||
task.error-occurred=發生錯誤 ({{errorcode}})
|
task.error-occurred=發生錯誤 ({{errorcode}})
|
||||||
settings.file-count=({{count}} 個文件)
|
settings.file-count=({{count}} 個文件)
|
||||||
|
|
|
@ -246,6 +246,7 @@
|
||||||
'time.hour': '{{value}} Hour',
|
'time.hour': '{{value}} Hour',
|
||||||
'time.hours': '{{value}} Hours',
|
'time.hours': '{{value}} Hours',
|
||||||
'requires.aria2-version': 'Requires aria2 v{{version}} or higher',
|
'requires.aria2-version': 'Requires aria2 v{{version}} or higher',
|
||||||
|
'task.new.download-links': 'Download Links ({{count}} Links):',
|
||||||
'task.pieceinfo': 'Completed: {{completed}}, Total: {{total}}',
|
'task.pieceinfo': 'Completed: {{completed}}, Total: {{total}}',
|
||||||
'task.error-occurred': 'Error Occurred ({{errorcode}})',
|
'task.error-occurred': 'Error Occurred ({{errorcode}})',
|
||||||
'settings.file-count': '({{count}} Files)',
|
'settings.file-count': '({{count}} Files)',
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
var tabOrders = ['links', 'options'];
|
var tabOrders = ['links', 'options'];
|
||||||
|
|
||||||
var downloadByLinks = function (pauseOnAdded, responseCallback) {
|
var downloadByLinks = function (pauseOnAdded, responseCallback) {
|
||||||
var urls = $scope.context.urls.split('\n');
|
var urls = ariaNgCommonService.parseUrlsFromOriginInput($scope.context.urls);
|
||||||
var options = angular.copy($scope.context.options);
|
var options = angular.copy($scope.context.options);
|
||||||
var tasks = [];
|
var tasks = [];
|
||||||
|
|
||||||
|
@ -174,6 +174,11 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.getValidUrlsCount = function () {
|
||||||
|
var urls = ariaNgCommonService.parseUrlsFromOriginInput($scope.context.urls);
|
||||||
|
return urls ? urls.length : 0;
|
||||||
|
};
|
||||||
|
|
||||||
$rootScope.loadPromise = $timeout(function () {}, 100);
|
$rootScope.loadPromise = $timeout(function () {}, 100);
|
||||||
}]);
|
}]);
|
||||||
}());
|
}());
|
||||||
|
|
28
src/scripts/directives/validUrls.js
Normal file
28
src/scripts/directives/validUrls.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('ariaNg').directive('ngValidUrls', ['ariaNgCommonService', function (ariaNgCommonService) {
|
||||||
|
var DIRECTIVE_ID = 'invalidUrls';
|
||||||
|
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
require: '?ngModel',
|
||||||
|
link: function (scope, element, attrs, ngModel) {
|
||||||
|
var handleChange = function (value) {
|
||||||
|
if (angular.isUndefined(value) || value === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var urls = ariaNgCommonService.parseUrlsFromOriginInput(value);
|
||||||
|
var valid = urls && urls.length > 0;
|
||||||
|
|
||||||
|
ngModel.$setValidity(DIRECTIVE_ID, valid);
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.$watch(function () {
|
||||||
|
return ngModel.$viewValue;
|
||||||
|
}, handleChange);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}]);
|
||||||
|
}());
|
|
@ -58,6 +58,26 @@
|
||||||
|
|
||||||
return filePath.substring(filePath.lastIndexOf('.'));
|
return filePath.substring(filePath.lastIndexOf('.'));
|
||||||
},
|
},
|
||||||
|
parseUrlsFromOriginInput: function (s) {
|
||||||
|
if (!s) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var lines = s.split('\n');
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < lines.length; i++) {
|
||||||
|
var line = lines[i];
|
||||||
|
|
||||||
|
if (line.match(/^(http|https|ftp|sftp):\/\/.+$/)) {
|
||||||
|
result.push(line);
|
||||||
|
} else if (line.match(/^magnet:\?.+$/)) {
|
||||||
|
result.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
decodePercentEncodedString: function (s) {
|
decodePercentEncodedString: function (s) {
|
||||||
if (!s) {
|
if (!s) {
|
||||||
return s;
|
return s;
|
||||||
|
|
|
@ -41,12 +41,11 @@
|
||||||
<div class="new-task-table" ng-if="context.taskType === 'urls'">
|
<div class="new-task-table" ng-if="context.taskType === 'urls'">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<p translate>Download Links:</p>
|
<p ng-bind="'format.task.new.download-links' | translate: {count: getValidUrlsCount()}">Download Links:</p>
|
||||||
<div class="form-group has-feedback no-margin" ng-class="{ 'has-error' : newTaskForm.urls.$invalid && newTaskForm.urls.$dirty, 'has-success' : newTaskForm.urls.$valid && newTaskForm.urls.$dirty }">
|
<div class="form-group has-feedback no-margin" ng-class="{ 'has-error' : newTaskForm.urls.$invalid && newTaskForm.urls.$dirty, 'has-success' : newTaskForm.urls.$valid && newTaskForm.urls.$dirty }">
|
||||||
<textarea name="urls" class="form-control" rows="10" autofocus="autofocus" ng-auto-focus
|
<textarea name="urls" class="form-control" rows="10" autofocus="autofocus" ng-auto-focus ng-valid-urls
|
||||||
ng-model="context.urls" ng-required="true" ng-keydown="urlTextboxKeyDown($event)"
|
ng-model="context.urls" ng-required="true" ng-keydown="urlTextboxKeyDown($event)"
|
||||||
ng-placeholder="'Support multiple URLs, one URL per line.' | translate"
|
ng-placeholder="'Support multiple URLs, one URL per line.' | translate"></textarea>
|
||||||
ng-pattern="/^(\n?(((http|https|ftp|sftp):\/\/.+)|(magnet:\?.+)))*$/i"></textarea>
|
|
||||||
<div class="form-control-icon" ng-if="newTaskForm.urls.$dirty">
|
<div class="form-control-icon" ng-if="newTaskForm.urls.$dirty">
|
||||||
<i class="fa form-control-feedback" ng-class="{'fa-check':newTaskForm.urls.$valid, 'fa-times':newTaskForm.urls.$invalid}"></i>
|
<i class="fa form-control-feedback" ng-class="{'fa-check':newTaskForm.urls.$valid, 'fa-times':newTaskForm.urls.$invalid}"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue