mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
added i18n sorting to folders, ciphers, collection
This commit is contained in:
parent
78dcbac7fa
commit
ce4f683b96
@ -1,4 +1,7 @@
|
|||||||
export abstract class I18nService {
|
export abstract class I18nService {
|
||||||
|
locale: string;
|
||||||
|
translationLocale: string;
|
||||||
|
collator: Intl.Collator;
|
||||||
t: (id: string) => string;
|
t: (id: string) => string;
|
||||||
translate: (id: string) => string;
|
translate: (id: string) => string;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import { ConstantsService } from './constants.service';
|
|||||||
import { ApiService } from '../abstractions/api.service';
|
import { ApiService } from '../abstractions/api.service';
|
||||||
import { CipherService as CipherServiceAbstraction } from '../abstractions/cipher.service';
|
import { CipherService as CipherServiceAbstraction } from '../abstractions/cipher.service';
|
||||||
import { CryptoService } from '../abstractions/crypto.service';
|
import { CryptoService } from '../abstractions/crypto.service';
|
||||||
|
import { I18nService } from '../abstractions/i18n.service';
|
||||||
import { SettingsService } from '../abstractions/settings.service';
|
import { SettingsService } from '../abstractions/settings.service';
|
||||||
import { StorageService } from '../abstractions/storage.service';
|
import { StorageService } from '../abstractions/storage.service';
|
||||||
import { UserService } from '../abstractions/user.service';
|
import { UserService } from '../abstractions/user.service';
|
||||||
@ -84,7 +85,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
|
|
||||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||||
private settingsService: SettingsService, private apiService: ApiService,
|
private settingsService: SettingsService, private apiService: ApiService,
|
||||||
private storageService: StorageService) {
|
private storageService: StorageService, private i18nService: I18nService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCache(): void {
|
clearCache(): void {
|
||||||
@ -189,6 +190,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
decCiphers.sort(this.getLocaleSortingFunction())
|
||||||
this.decryptedCipherCache = decCiphers;
|
this.decryptedCipherCache = decCiphers;
|
||||||
return this.decryptedCipherCache;
|
return this.decryptedCipherCache;
|
||||||
}
|
}
|
||||||
@ -445,6 +447,13 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
|
private getLocaleSortingFunction(): (a: CipherView, b: CipherView) => number {
|
||||||
|
return (a, b) => {
|
||||||
|
return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) :
|
||||||
|
a.name.localeCompare(b.name);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async encryptObjProperty<V extends View, D extends Domain>(model: V, obj: D,
|
private async encryptObjProperty<V extends View, D extends Domain>(model: V, obj: D,
|
||||||
map: any, key: SymmetricCryptoKey): Promise<void> {
|
map: any, key: SymmetricCryptoKey): Promise<void> {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
@ -6,6 +6,7 @@ import { CollectionView } from '../models/view/collectionView';
|
|||||||
|
|
||||||
import { CollectionService as CollectionServiceAbstraction } from '../abstractions/collection.service';
|
import { CollectionService as CollectionServiceAbstraction } from '../abstractions/collection.service';
|
||||||
import { CryptoService } from '../abstractions/crypto.service';
|
import { CryptoService } from '../abstractions/crypto.service';
|
||||||
|
import { I18nService } from '../abstractions/i18n.service';
|
||||||
import { StorageService } from '../abstractions/storage.service';
|
import { StorageService } from '../abstractions/storage.service';
|
||||||
import { UserService } from '../abstractions/user.service';
|
import { UserService } from '../abstractions/user.service';
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
decryptedCollectionCache: CollectionView[];
|
decryptedCollectionCache: CollectionView[];
|
||||||
|
|
||||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||||
private storageService: StorageService) {
|
private storageService: StorageService, private i18nService: I18nService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCache(): void {
|
clearCache(): void {
|
||||||
@ -66,6 +67,7 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
decCollections.sort(this.getLocaleSortingFunction());
|
||||||
this.decryptedCollectionCache = decCollections;
|
this.decryptedCollectionCache = decCollections;
|
||||||
return this.decryptedCollectionCache;
|
return this.decryptedCollectionCache;
|
||||||
}
|
}
|
||||||
@ -122,4 +124,11 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
await this.storageService.save(Keys.collectionsPrefix + userId, collections);
|
await this.storageService.save(Keys.collectionsPrefix + userId, collections);
|
||||||
this.decryptedCollectionCache = null;
|
this.decryptedCollectionCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getLocaleSortingFunction(): (a: CollectionView, b: CollectionView) => number {
|
||||||
|
return (a, b) => {
|
||||||
|
return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) :
|
||||||
|
a.name.localeCompare(b.name);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import { FolderView } from '../models/view/folderView';
|
|||||||
import { ApiService } from '../abstractions/api.service';
|
import { ApiService } from '../abstractions/api.service';
|
||||||
import { CryptoService } from '../abstractions/crypto.service';
|
import { CryptoService } from '../abstractions/crypto.service';
|
||||||
import { FolderService as FolderServiceAbstraction } from '../abstractions/folder.service';
|
import { FolderService as FolderServiceAbstraction } from '../abstractions/folder.service';
|
||||||
|
import { I18nService } from '../abstractions/i18n.service';
|
||||||
import { StorageService } from '../abstractions/storage.service';
|
import { StorageService } from '../abstractions/storage.service';
|
||||||
import { UserService } from '../abstractions/user.service';
|
import { UserService } from '../abstractions/user.service';
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ export class FolderService implements FolderServiceAbstraction {
|
|||||||
|
|
||||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||||
private noneFolder: () => string, private apiService: ApiService,
|
private noneFolder: () => string, private apiService: ApiService,
|
||||||
private storageService: StorageService) {
|
private storageService: StorageService, private i18nService: I18nService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCache(): void {
|
clearCache(): void {
|
||||||
@ -83,6 +84,7 @@ export class FolderService implements FolderServiceAbstraction {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
decFolders.sort(this.getLocaleSortingFunction());
|
||||||
this.decryptedFolderCache = decFolders;
|
this.decryptedFolderCache = decFolders;
|
||||||
return this.decryptedFolderCache;
|
return this.decryptedFolderCache;
|
||||||
}
|
}
|
||||||
@ -160,4 +162,16 @@ export class FolderService implements FolderServiceAbstraction {
|
|||||||
await this.apiService.deleteFolder(id);
|
await this.apiService.deleteFolder(id);
|
||||||
await this.delete(id);
|
await this.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getLocaleSortingFunction(): (a: FolderView, b: FolderView) => number {
|
||||||
|
return (a, b) => {
|
||||||
|
if (a.id == null) {
|
||||||
|
// No folder is always last
|
||||||
|
return Number.MAX_SAFE_INTEGER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) :
|
||||||
|
a.name.localeCompare(b.name);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user