Change sort behavior (#24)
Sort behavior is now as follows: * The single most recently used login is first * All used logins are next, ordered by usage count from most to least * All remaining logins follow, ordered alphabetically
This commit is contained in:
@@ -163,26 +163,39 @@ function search(s) {
|
|||||||
|
|
||||||
// get candidate list
|
// get candidate list
|
||||||
var candidates = this.logins.map(result => Object.assign(result, { display: result.login }));
|
var candidates = this.logins.map(result => Object.assign(result, { display: result.login }));
|
||||||
|
var mostRecent = null;
|
||||||
if (this.currentDomainOnly) {
|
if (this.currentDomainOnly) {
|
||||||
var recent = candidates.filter(login => login.recent.count > 0);
|
var recent = candidates.filter(function(login) {
|
||||||
|
if (login.recent.count > 0) {
|
||||||
|
// find most recently used login
|
||||||
|
if (!mostRecent || login.recent.when > mostRecent.recent.when) {
|
||||||
|
mostRecent = login;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
var remainingInCurrentDomain = candidates.filter(
|
var remainingInCurrentDomain = candidates.filter(
|
||||||
login => login.inCurrentDomain && !login.recent.count
|
login => login.inCurrentDomain && !login.recent.count
|
||||||
);
|
);
|
||||||
candidates = recent.concat(remainingInCurrentDomain);
|
candidates = recent.concat(remainingInCurrentDomain);
|
||||||
}
|
}
|
||||||
candidates.sort(function(a, b) {
|
candidates.sort(function(a, b) {
|
||||||
if (a.store.when != b.store.when) {
|
// sort most recent first
|
||||||
return b.store.when - a.store.when;
|
if (a === mostRecent) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (a.recent.count != b.recent.count) {
|
if (b === mostRecent) {
|
||||||
return b.recent.count - a.recent.count;
|
return 1;
|
||||||
}
|
}
|
||||||
if (a.recent.when != b.recent.when) {
|
|
||||||
return b.recent.when - a.recent.when;
|
// sort by count
|
||||||
}
|
var countDiff = b.recent.count - a.recent.count;
|
||||||
if (a.store.name != b.store.name) {
|
if (countDiff) {
|
||||||
return a.store.name.localeCompare(b.store.name);
|
return countDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort alphabetically
|
||||||
return a.login.localeCompare(b.login);
|
return a.login.localeCompare(b.login);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user