move groupings, ciphers, and search pipe to jslib
This commit is contained in:
parent
0adc40ec57
commit
0f2860c716
|
@ -35,7 +35,7 @@ import { StopClickDirective } from 'jslib/angular/directives/stop-click.directiv
|
||||||
import { StopPropDirective } from 'jslib/angular/directives/stop-prop.directive';
|
import { StopPropDirective } from 'jslib/angular/directives/stop-prop.directive';
|
||||||
|
|
||||||
import { I18nPipe } from 'jslib/angular/pipes/i18n.pipe';
|
import { I18nPipe } from 'jslib/angular/pipes/i18n.pipe';
|
||||||
import { SearchCiphersPipe } from './pipes/search-ciphers.pipe';
|
import { SearchCiphersPipe } from 'jslib/angular/pipes/search-ciphers.pipe';
|
||||||
|
|
||||||
import { AddEditComponent } from './vault/add-edit.component';
|
import { AddEditComponent } from './vault/add-edit.component';
|
||||||
import { AttachmentsComponent } from './vault/attachments.component';
|
import { AttachmentsComponent } from './vault/attachments.component';
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
import {
|
|
||||||
Pipe,
|
|
||||||
PipeTransform,
|
|
||||||
} from '@angular/core';
|
|
||||||
|
|
||||||
import { CipherView } from 'jslib/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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,8 +8,8 @@
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<ng-container *ngIf="(ciphers | searchCiphers: searchText) as searchedCiphers">
|
<ng-container *ngIf="(ciphers | searchCiphers: searchText) as searchedCiphers">
|
||||||
<div class="list" *ngIf="searchedCiphers.length > 0">
|
<div class="list" *ngIf="searchedCiphers.length > 0">
|
||||||
<a *ngFor="let c of searchedCiphers" appStopClick (click)="cipherClicked(c)"
|
<a *ngFor="let c of searchedCiphers" appStopClick (click)="selectCipher(c)"
|
||||||
(contextmenu)="cipherRightClicked(c)" href="#" title="{{'viewItem' | i18n}}"
|
(contextmenu)="rightClickCipher(c)" href="#" title="{{'viewItem' | i18n}}"
|
||||||
[ngClass]="{'active': c.id === activeCipherId}">
|
[ngClass]="{'active': c.id === activeCipherId}">
|
||||||
<app-vault-icon [cipher]="c"></app-vault-icon>
|
<app-vault-icon [cipher]="c"></app-vault-icon>
|
||||||
<span class="text">
|
<span class="text">
|
||||||
|
|
|
@ -1,67 +1,17 @@
|
||||||
import * as template from './ciphers.component.html';
|
import * as template from './ciphers.component.html';
|
||||||
|
|
||||||
import {
|
import { Component } from '@angular/core';
|
||||||
Component,
|
|
||||||
EventEmitter,
|
|
||||||
Input,
|
|
||||||
Output,
|
|
||||||
} from '@angular/core';
|
|
||||||
|
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
|
|
||||||
import { CipherView } from 'jslib/models/view/cipherView';
|
import { CiphersComponent as BaseCiphersComponent } from 'jslib/angular/components/ciphers.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-vault-ciphers',
|
selector: 'app-vault-ciphers',
|
||||||
template: template,
|
template: template,
|
||||||
})
|
})
|
||||||
export class CiphersComponent {
|
export class CiphersComponent extends BaseCiphersComponent {
|
||||||
@Input() activeCipherId: string = null;
|
constructor(cipherService: CipherService) {
|
||||||
@Output() onCipherClicked = new EventEmitter<CipherView>();
|
super(cipherService);
|
||||||
@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(private 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
cipherClicked(cipher: CipherView) {
|
|
||||||
this.onCipherClicked.emit(cipher);
|
|
||||||
}
|
|
||||||
|
|
||||||
cipherRightClicked(cipher: CipherView) {
|
|
||||||
this.onCipherRightClicked.emit(cipher);
|
|
||||||
}
|
|
||||||
|
|
||||||
addCipher() {
|
|
||||||
this.onAddCipher.emit();
|
|
||||||
}
|
|
||||||
|
|
||||||
addCipherOptions() {
|
|
||||||
this.onAddCipherOptions.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,105 +1,18 @@
|
||||||
import * as template from './groupings.component.html';
|
import * as template from './groupings.component.html';
|
||||||
|
|
||||||
import {
|
import { Component } from '@angular/core';
|
||||||
Component,
|
|
||||||
EventEmitter,
|
|
||||||
Input,
|
|
||||||
Output,
|
|
||||||
} from '@angular/core';
|
|
||||||
|
|
||||||
import { CipherType } from 'jslib/enums/cipherType';
|
|
||||||
|
|
||||||
import { CollectionView } from 'jslib/models/view/collectionView';
|
|
||||||
import { FolderView } from 'jslib/models/view/folderView';
|
|
||||||
|
|
||||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||||
|
|
||||||
|
import { GroupingsComponent as BaseGroupingsComponent } from 'jslib/angular/components/groupings.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-vault-groupings',
|
selector: 'app-vault-groupings',
|
||||||
template: template,
|
template: template,
|
||||||
})
|
})
|
||||||
export class GroupingsComponent {
|
export class GroupingsComponent extends BaseGroupingsComponent {
|
||||||
@Output() onAllClicked = new EventEmitter();
|
constructor(collectionService: CollectionService, folderService: FolderService) {
|
||||||
@Output() onFavoritesClicked = new EventEmitter();
|
super(collectionService, folderService);
|
||||||
@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(private collectionService: CollectionService, private 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue