2018-04-05 17:12:00 +02:00
|
|
|
import {
|
|
|
|
Pipe,
|
|
|
|
PipeTransform,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { CipherView } from '../../models/view/cipherView';
|
|
|
|
|
2018-04-12 21:42:22 +02:00
|
|
|
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
|
|
|
|
2018-04-05 17:12:00 +02:00
|
|
|
@Pipe({
|
|
|
|
name: 'searchCiphers',
|
|
|
|
})
|
|
|
|
export class SearchCiphersPipe implements PipeTransform {
|
2018-04-12 21:42:22 +02:00
|
|
|
private onlySearchName = false;
|
|
|
|
|
|
|
|
constructor(private platformUtilsService: PlatformUtilsService) {
|
|
|
|
this.onlySearchName = platformUtilsService.isEdge();
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:12:00 +02:00
|
|
|
transform(ciphers: CipherView[], searchText: string): CipherView[] {
|
|
|
|
if (ciphers == null || ciphers.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchText == null || searchText.length < 2) {
|
|
|
|
return ciphers;
|
|
|
|
}
|
|
|
|
|
|
|
|
searchText = searchText.toLowerCase();
|
|
|
|
return ciphers.filter((c) => {
|
|
|
|
if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-12 21:42:22 +02:00
|
|
|
if (this.onlySearchName) {
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|