Rewrite search
This commit is contained in:
parent
753e80936c
commit
aa147cc93f
|
@ -41,3 +41,12 @@
|
||||||
font-family: sans-serif;
|
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 -->
|
<!-- {{{ download template -->
|
||||||
<h3 ng-show="totalAria2Downloads()">Download List</h3>
|
<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>
|
<fieldset>
|
||||||
<div class="span4">
|
<label for="download-filter" id="download-filter-label">Search</label>
|
||||||
<label for="downloadFilter">Search</label>
|
<input id="download-filter" type="text" ng-model="downloadFilter" ng-change="onDownloadFilter()" class="input-large"/>
|
||||||
<input id="downloadFilter" type="text" ng-model="downloadFilter" ng-change="onDownloadFilter()" class="input-large"/>
|
<button ng-click="clearFilter()" class="btn btn-default btn-mini">Clear</button>
|
||||||
<br>
|
<br>
|
||||||
<b>Found: {{totalDownloads}} / {{totalAria2Downloads()}} </b>
|
<label for="filter-active">
|
||||||
</div>
|
<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>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -125,17 +125,46 @@ function(
|
||||||
if (!scope.downloadFilterCommitted) {
|
if (!scope.downloadFilterCommitted) {
|
||||||
return downloads;
|
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) {
|
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 _.filter(d.files, function(f) {
|
||||||
return f.path.toLowerCase().indexOf(filter.toLowerCase()) != -1;
|
return filter.test(f.relpath);
|
||||||
// return f.path.search(filter) != -1;
|
|
||||||
}).length;
|
}).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
|
// max downloads shown in one page
|
||||||
scope.pageSize = 10;
|
scope.pageSize = 10;
|
||||||
|
|
||||||
|
@ -156,11 +185,37 @@ function(
|
||||||
|
|
||||||
// actual downloads used by the view
|
// actual downloads used by the view
|
||||||
scope.getDownloads = function() {
|
scope.getDownloads = function() {
|
||||||
var downloads =
|
var downloads = [];
|
||||||
scope.filterDownloads(
|
if (scope.filterActive) {
|
||||||
scope.active.concat( scope.waiting ).concat( scope.stopped )
|
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;
|
scope.totalDownloads = downloads.length;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user