Rewrite search
This commit is contained in:
parent
753e80936c
commit
aa147cc93f
|
@ -41,3 +41,12 @@
|
|||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#download-filter {
|
||||
margin: 0;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#filters label {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
|
40
index.html
40
index.html
|
@ -260,14 +260,40 @@
|
|||
<!-- {{{ download template -->
|
||||
<h3 ng-show="totalAria2Downloads()">Download List</h3>
|
||||
|
||||
<form class="row" ng-show="(totalAria2Downloads() > pageSize) || downloadFilter.length">
|
||||
<form ng-show="(totalAria2Downloads() > pageSize) || downloadFilter.length" id="filters">
|
||||
<fieldset>
|
||||
<div class="span4">
|
||||
<label for="downloadFilter">Search</label>
|
||||
<input id="downloadFilter" type="text" ng-model="downloadFilter" ng-change="onDownloadFilter()" class="input-large"/>
|
||||
<br>
|
||||
<b>Found: {{totalDownloads}} / {{totalAria2Downloads()}} </b>
|
||||
</div>
|
||||
<label for="download-filter" id="download-filter-label">Search</label>
|
||||
<input id="download-filter" type="text" ng-model="downloadFilter" ng-change="onDownloadFilter()" class="input-large"/>
|
||||
<button ng-click="clearFilter()" class="btn btn-default btn-mini">Clear</button>
|
||||
<br>
|
||||
<label for="filter-active">
|
||||
<input type="checkbox" ng-model="filterActive" id="filter-active">
|
||||
active
|
||||
</label>
|
||||
<label for="filter-waiting">
|
||||
<input type="checkbox" ng-model="filterWaiting" id="filter-waiting">
|
||||
waiting
|
||||
</label>
|
||||
<label for="filter-complete">
|
||||
<input type="checkbox" ng-model="filterComplete" id="filter-complete">
|
||||
complete
|
||||
</label>
|
||||
<label for="filter-error">
|
||||
<input type="checkbox" ng-model="filterError" id="filter-error">
|
||||
error
|
||||
</label>
|
||||
<label for="filter-paused">
|
||||
<input type="checkbox" ng-model="filterPaused" id="filter-paused">
|
||||
paused
|
||||
</label>
|
||||
<label for="filter-removed">
|
||||
<input type="checkbox" ng-model="filterRemoved" id="filter-removed">
|
||||
removed
|
||||
</label>
|
||||
<button ng-click="toggleStateFilters()" class="btn btn-default btn-mini">Toggle</button>
|
||||
<br>
|
||||
<b>Found: {{totalDownloads}} / {{totalAria2Downloads()}} </b>
|
||||
<button ng-click="resetFilters()" class="btn btn-mini">Reset</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -125,17 +125,46 @@ function(
|
|||
if (!scope.downloadFilterCommitted) {
|
||||
return downloads;
|
||||
}
|
||||
var filter = scope.downloadFilterCommitted;
|
||||
var filter = scope.downloadFilterCommitted.
|
||||
replace(/[{}()\[\]\\^$.?]/g, "\\$&").
|
||||
replace(/\*/g, ".*").
|
||||
replace(/\./g, ".");
|
||||
filter = new RegExp(filter, "i");
|
||||
return _.filter(downloads, function(d) {
|
||||
if (!d.files.length) return true;
|
||||
|
||||
if (filter.test(d.name)) return true;
|
||||
return _.filter(d.files, function(f) {
|
||||
return f.path.toLowerCase().indexOf(filter.toLowerCase()) != -1;
|
||||
// return f.path.search(filter) != -1;
|
||||
return filter.test(f.relpath);
|
||||
}).length;
|
||||
});
|
||||
};
|
||||
|
||||
scope.clearFilter = function() {
|
||||
scope.downloadFilter = scope.downloadFilterCommitted = "";
|
||||
};
|
||||
|
||||
scope.toggleStateFilters = function() {
|
||||
scope.filterActive = !scope.filterActive;
|
||||
scope.filterWaiting = !scope.filterWaiting;
|
||||
scope.filterComplete = !scope.filterComplete;
|
||||
scope.filterError = !scope.filterError;
|
||||
scope.filterPaused = !scope.filterPaused;
|
||||
scope.filterRemoved = !scope.filterRemoved;
|
||||
};
|
||||
|
||||
scope.resetFilters = function() {
|
||||
scope.filterActive =
|
||||
scope.filterWaiting =
|
||||
scope.filterComplete =
|
||||
scope.filterError =
|
||||
scope.filterPaused =
|
||||
scope.filterRemoved =
|
||||
true;
|
||||
scope.clearFilter();
|
||||
};
|
||||
|
||||
scope.resetFilters();
|
||||
|
||||
|
||||
// max downloads shown in one page
|
||||
scope.pageSize = 10;
|
||||
|
||||
|
@ -156,11 +185,37 @@ function(
|
|||
|
||||
// actual downloads used by the view
|
||||
scope.getDownloads = function() {
|
||||
var downloads =
|
||||
scope.filterDownloads(
|
||||
scope.active.concat( scope.waiting ).concat( scope.stopped )
|
||||
)
|
||||
;
|
||||
var downloads = [];
|
||||
if (scope.filterActive) {
|
||||
downloads = scope.active;
|
||||
}
|
||||
if (scope.filterWaiting) {
|
||||
downloads = downloads.concat(_.filter(scope.waiting, function (e) {
|
||||
return e.status == "waiting";
|
||||
}));
|
||||
}
|
||||
if (scope.filterPaused) {
|
||||
downloads = downloads.concat(_.filter(scope.waiting, function (e) {
|
||||
return e.status == "paused";
|
||||
}));
|
||||
}
|
||||
if (scope.filterError) {
|
||||
downloads = downloads.concat(_.filter(scope.stopped, function (e) {
|
||||
return e.status == "error";
|
||||
}));
|
||||
}
|
||||
if (scope.filterComplete) {
|
||||
downloads = downloads.concat(_.filter(scope.stopped, function (e) {
|
||||
return e.status == "complete";
|
||||
}));
|
||||
}
|
||||
if (scope.filterRemoved) {
|
||||
downloads = downloads.concat(_.filter(scope.stopped, function (e) {
|
||||
return e.status == "removed";
|
||||
}));
|
||||
}
|
||||
|
||||
downloads = scope.filterDownloads(downloads);
|
||||
|
||||
scope.totalDownloads = downloads.length;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user