mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
move search functions to utils helper
This commit is contained in:
parent
c82ded58eb
commit
df7ccaea9d
@ -10,6 +10,8 @@ import { CollectionResponse } from '../models/response/collectionResponse';
|
||||
import { FolderResponse } from '../models/response/folderResponse';
|
||||
import { ListResponse } from '../models/response/listResponse';
|
||||
|
||||
import { CliUtils } from '../utils';
|
||||
|
||||
export class ListCommand {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService) { }
|
||||
@ -69,19 +71,7 @@ export class ListCommand {
|
||||
}
|
||||
|
||||
if (cmd.search != null && cmd.search.trim() !== '') {
|
||||
const search = cmd.search.toLowerCase();
|
||||
ciphers = ciphers.filter((c) => {
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ciphers = CliUtils.searchCiphers(ciphers, cmd.search);
|
||||
}
|
||||
|
||||
const res = new ListResponse(ciphers.map((o) => new CipherResponse(o)));
|
||||
@ -92,13 +82,7 @@ export class ListCommand {
|
||||
let folders = await this.folderService.getAllDecrypted();
|
||||
|
||||
if (cmd.search != null && cmd.search.trim() !== '') {
|
||||
const search = cmd.search.toLowerCase();
|
||||
folders = folders.filter((f) => {
|
||||
if (f.name != null && f.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
folders = CliUtils.searchFolders(folders, cmd.search);
|
||||
}
|
||||
|
||||
const res = new ListResponse(folders.map((o) => new FolderResponse(o)));
|
||||
@ -118,13 +102,7 @@ export class ListCommand {
|
||||
}
|
||||
|
||||
if (cmd.search != null && cmd.search.trim() !== '') {
|
||||
const search = cmd.search.toLowerCase();
|
||||
collections = collections.filter((c) => {
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
collections = CliUtils.searchCollections(collections, cmd.search);
|
||||
}
|
||||
|
||||
const res = new ListResponse(collections.map((o) => new CollectionResponse(o)));
|
||||
|
41
src/utils.ts
Normal file
41
src/utils.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { CipherView } from 'jslib/models/view/cipherView';
|
||||
import { CollectionView } from 'jslib/models/view/collectionView';
|
||||
import { FolderView } from 'jslib/models/view/folderView';
|
||||
|
||||
export class CliUtils {
|
||||
static searchCiphers(ciphers: CipherView[], search: string) {
|
||||
search = search.toLowerCase();
|
||||
return ciphers.filter((c) => {
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
static searchFolders(folders: FolderView[], search: string) {
|
||||
search = search.toLowerCase();
|
||||
return folders.filter((f) => {
|
||||
if (f.name != null && f.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
static searchCollections(collections: CollectionView[], search: string) {
|
||||
search = search.toLowerCase();
|
||||
return collections.filter((c) => {
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(search) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user