2018-04-05 17:12:00 +02:00
|
|
|
import { Pipe, PipeTransform } from "@angular/core";
|
|
|
|
|
2021-06-03 18:58:57 +02:00
|
|
|
import { CipherView } from "jslib-common/models/view/cipherView";
|
2018-04-05 17:12:00 +02:00
|
|
|
|
|
|
|
@Pipe({
|
|
|
|
name: "searchCiphers",
|
|
|
|
})
|
|
|
|
export class SearchCiphersPipe implements PipeTransform {
|
2020-04-03 22:32:15 +02:00
|
|
|
transform(ciphers: CipherView[], searchText: string, deleted: boolean = false): CipherView[] {
|
2018-04-05 17:12:00 +02:00
|
|
|
if (ciphers == null || ciphers.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchText == null || searchText.length < 2) {
|
2021-02-04 16:49:23 +01:00
|
|
|
return ciphers.filter((c) => {
|
2020-04-03 22:32:15 +02:00
|
|
|
return deleted !== c.isDeleted;
|
|
|
|
});
|
2018-04-05 17:12:00 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 20:11:47 +02:00
|
|
|
searchText = searchText.trim().toLowerCase();
|
2021-02-04 16:49:23 +01:00
|
|
|
return ciphers.filter((c) => {
|
2020-04-03 22:32:15 +02:00
|
|
|
if (deleted !== c.isDeleted) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-12 16:10:05 +02:00
|
|
|
if (searchText.length >= 8 && c.id.startsWith(searchText)) {
|
2018-07-11 21:47:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-05 17:12:00 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|