mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-27 17:18:04 +01:00
move sort to service
This commit is contained in:
parent
7ce6634120
commit
ae6c609c91
@ -276,7 +276,7 @@ function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) {
|
||||
|
||||
menuOptionsLoaded = [];
|
||||
bg_loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) {
|
||||
sortLogins(logins);
|
||||
logins.sort(bg_loginService.sortLoginsByLastUsedThenName);
|
||||
|
||||
if (contextMenuEnabled) {
|
||||
for (var i = 0; i < logins.length; i++) {
|
||||
@ -588,37 +588,6 @@ function autofillPage() {
|
||||
pageDetailsToAutoFill = [];
|
||||
}
|
||||
|
||||
function sortLogins(logins) {
|
||||
logins.sort(function (a, b) {
|
||||
var lastUsedA = a.localData && a.localData.lastUsedDate ? a.localData.lastUsedDate : null;
|
||||
var lastUsedB = b.localData && b.localData.lastUsedDate ? b.localData.lastUsedDate : null;
|
||||
if (lastUsedA && lastUsedB && lastUsedA > lastUsedB) {
|
||||
return -1;
|
||||
}
|
||||
if (lastUsedA && lastUsedB && lastUsedA < lastUsedB) {
|
||||
return 1;
|
||||
}
|
||||
if (lastUsedA && !lastUsedB) {
|
||||
return -1;
|
||||
}
|
||||
if (!lastUsedA && lastUsedB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var nameA = (a.name + '_' + a.username).toUpperCase();
|
||||
var nameB = (b.name + '_' + b.username).toUpperCase();
|
||||
|
||||
if (nameA < nameB) {
|
||||
return -1;
|
||||
}
|
||||
if (nameA > nameB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
function loadLoginContextMenuOptions(login) {
|
||||
var title = login.name + (login.username && login.username !== '' ? ' (' + login.username + ')' : '');
|
||||
loadContextMenuOptions(title, login.id, login);
|
||||
|
@ -518,6 +518,25 @@ function initLoginService() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
LoginService.prototype.sortLoginsByLastUsedThenName = function (a, b) {
|
||||
var result = this.sortLoginsByLastUsed(a, b);
|
||||
if (result !== 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
var nameA = (a.name + '_' + a.username).toUpperCase();
|
||||
var nameB = (b.name + '_' + b.username).toUpperCase();
|
||||
|
||||
if (nameA < nameB) {
|
||||
return -1;
|
||||
}
|
||||
if (nameA > nameB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
function handleError(error, deferred) {
|
||||
deferred.reject(error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user