mirror of
https://github.com/bitwarden/browser
synced 2024-12-27 02:14:24 +01:00
move ciphers, groupings, and search pipe to jslib
This commit is contained in:
parent
a0ca51dda4
commit
22f0f97cda
60
src/angular/components/ciphers.component.ts
Normal file
60
src/angular/components/ciphers.component.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import {
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
} from '@angular/core';
|
||||
|
||||
import { CipherService } from '../../abstractions/cipher.service';
|
||||
|
||||
import { CipherView } from '../../models/view/cipherView';
|
||||
|
||||
export class CiphersComponent {
|
||||
@Input() activeCipherId: string = null;
|
||||
@Output() onCipherClicked = new EventEmitter<CipherView>();
|
||||
@Output() onCipherRightClicked = new EventEmitter<CipherView>();
|
||||
@Output() onAddCipher = new EventEmitter();
|
||||
@Output() onAddCipherOptions = new EventEmitter();
|
||||
|
||||
loaded: boolean = false;
|
||||
ciphers: CipherView[] = [];
|
||||
searchText: string;
|
||||
searchPlaceholder: string = null;
|
||||
private filter: (cipher: CipherView) => boolean = null;
|
||||
|
||||
constructor(protected cipherService: CipherService) { }
|
||||
|
||||
async load(filter: (cipher: CipherView) => boolean = null) {
|
||||
this.filter = filter;
|
||||
const ciphers = await this.cipherService.getAllDecrypted();
|
||||
|
||||
if (this.filter == null) {
|
||||
this.ciphers = ciphers;
|
||||
} else {
|
||||
this.ciphers = ciphers.filter(this.filter);
|
||||
}
|
||||
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
this.loaded = false;
|
||||
this.ciphers = [];
|
||||
await this.load(this.filter);
|
||||
}
|
||||
|
||||
selectCipher(cipher: CipherView) {
|
||||
this.onCipherClicked.emit(cipher);
|
||||
}
|
||||
|
||||
rightClickCipher(cipher: CipherView) {
|
||||
this.onCipherRightClicked.emit(cipher);
|
||||
}
|
||||
|
||||
addCipher() {
|
||||
this.onAddCipher.emit();
|
||||
}
|
||||
|
||||
addCipherOptions() {
|
||||
this.onAddCipherOptions.emit();
|
||||
}
|
||||
}
|
99
src/angular/components/groupings.component.ts
Normal file
99
src/angular/components/groupings.component.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
} from '@angular/core';
|
||||
|
||||
import { CipherType } from '../../enums/cipherType';
|
||||
|
||||
import { CollectionView } from '../../models/view/collectionView';
|
||||
import { FolderView } from '../../models/view/folderView';
|
||||
|
||||
import { CollectionService } from '../../abstractions/collection.service';
|
||||
import { FolderService } from '../../abstractions/folder.service';
|
||||
|
||||
export class GroupingsComponent {
|
||||
@Output() onAllClicked = new EventEmitter();
|
||||
@Output() onFavoritesClicked = new EventEmitter();
|
||||
@Output() onCipherTypeClicked = new EventEmitter<CipherType>();
|
||||
@Output() onFolderClicked = new EventEmitter<FolderView>();
|
||||
@Output() onAddFolder = new EventEmitter();
|
||||
@Output() onEditFolder = new EventEmitter<FolderView>();
|
||||
@Output() onCollectionClicked = new EventEmitter<CollectionView>();
|
||||
|
||||
folders: FolderView[];
|
||||
collections: CollectionView[];
|
||||
loaded: boolean = false;
|
||||
cipherType = CipherType;
|
||||
selectedAll: boolean = false;
|
||||
selectedFavorites: boolean = false;
|
||||
selectedType: CipherType = null;
|
||||
selectedFolder: boolean = false;
|
||||
selectedFolderId: string = null;
|
||||
selectedCollectionId: string = null;
|
||||
|
||||
constructor(protected collectionService: CollectionService, protected folderService: FolderService) { }
|
||||
|
||||
async load() {
|
||||
await this.loadFolders();
|
||||
await this.loadCollections();
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
async loadCollections() {
|
||||
this.collections = await this.collectionService.getAllDecrypted();
|
||||
}
|
||||
|
||||
async loadFolders() {
|
||||
this.folders = await this.folderService.getAllDecrypted();
|
||||
}
|
||||
|
||||
selectAll() {
|
||||
this.clearSelections();
|
||||
this.selectedAll = true;
|
||||
this.onAllClicked.emit();
|
||||
}
|
||||
|
||||
selectFavorites() {
|
||||
this.clearSelections();
|
||||
this.selectedFavorites = true;
|
||||
this.onFavoritesClicked.emit();
|
||||
}
|
||||
|
||||
selectType(type: CipherType) {
|
||||
this.clearSelections();
|
||||
this.selectedType = type;
|
||||
this.onCipherTypeClicked.emit(type);
|
||||
}
|
||||
|
||||
selectFolder(folder: FolderView) {
|
||||
this.clearSelections();
|
||||
this.selectedFolder = true;
|
||||
this.selectedFolderId = folder.id;
|
||||
this.onFolderClicked.emit(folder);
|
||||
}
|
||||
|
||||
addFolder() {
|
||||
this.onAddFolder.emit();
|
||||
}
|
||||
|
||||
editFolder(folder: FolderView) {
|
||||
this.onEditFolder.emit(folder);
|
||||
}
|
||||
|
||||
selectCollection(collection: CollectionView) {
|
||||
this.clearSelections();
|
||||
this.selectedCollectionId = collection.id;
|
||||
this.onCollectionClicked.emit(collection);
|
||||
}
|
||||
|
||||
clearSelections() {
|
||||
this.selectedAll = false;
|
||||
this.selectedFavorites = false;
|
||||
this.selectedType = null;
|
||||
this.selectedFolder = false;
|
||||
this.selectedFolderId = null;
|
||||
this.selectedCollectionId = null;
|
||||
}
|
||||
}
|
36
src/angular/pipes/search-ciphers.pipe.ts
Normal file
36
src/angular/pipes/search-ciphers.pipe.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import {
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
|
||||
import { CipherView } from '../../models/view/cipherView';
|
||||
|
||||
@Pipe({
|
||||
name: 'searchCiphers',
|
||||
})
|
||||
export class SearchCiphersPipe implements PipeTransform {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user