2021-12-16 13:36:21 +01:00
|
|
|
import { Pipe, PipeTransform } from "@angular/core";
|
2018-04-05 17:12:00 +02:00
|
|
|
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
2018-04-05 17:12:00 +02:00
|
|
|
|
|
|
|
@Pipe({
|
2021-12-16 13:36:21 +01:00
|
|
|
name: "searchCiphers",
|
2018-04-05 17:12:00 +02:00
|
|
|
})
|
|
|
|
export class SearchCiphersPipe implements PipeTransform {
|
2022-02-22 15:39:11 +01:00
|
|
|
transform(ciphers: CipherView[], searchText: string, deleted = false): CipherView[] {
|
2021-12-16 13:36:21 +01:00
|
|
|
if (ciphers == null || ciphers.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
if (searchText == null || searchText.length < 2) {
|
|
|
|
return ciphers.filter((c) => {
|
|
|
|
return deleted !== c.isDeleted;
|
|
|
|
});
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
searchText = searchText.trim().toLowerCase();
|
|
|
|
return ciphers.filter((c) => {
|
|
|
|
if (deleted !== c.isDeleted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (searchText.length >= 8 && c.id.startsWith(searchText)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(searchText) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(searchText) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
}
|