filter state in query params
This commit is contained in:
parent
375f2a1e02
commit
b0e78be1f6
|
@ -27,7 +27,7 @@ export class CiphersComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
await this.load();
|
//await this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(filter: (cipher: CipherView) => boolean = null) {
|
async load(filter: (cipher: CipherView) => boolean = null) {
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
(onAllClicked)="clearGroupingFilters()"
|
(onAllClicked)="clearGroupingFilters()"
|
||||||
(onFavoritesClicked)="filterFavorites()"
|
(onFavoritesClicked)="filterFavorites()"
|
||||||
(onCipherTypeClicked)="filterCipherType($event)"
|
(onCipherTypeClicked)="filterCipherType($event)"
|
||||||
(onFolderClicked)="filterFolder($event)"
|
(onFolderClicked)="filterFolder($event.id)"
|
||||||
(onCollectionClicked)="filterCollection($event)">
|
(onCollectionClicked)="filterCollection($event.id)">
|
||||||
</app-vault-groupings>
|
</app-vault-groupings>
|
||||||
<app-vault-ciphers id="items"
|
<app-vault-ciphers id="items"
|
||||||
(onCipherClicked)="viewCipher($event)"
|
(onCipherClicked)="viewCipher($event)"
|
||||||
|
|
|
@ -28,14 +28,18 @@ import { FolderView } from 'jslib/models/view/folderView';
|
||||||
export class VaultComponent implements OnInit {
|
export class VaultComponent implements OnInit {
|
||||||
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
|
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
|
||||||
|
|
||||||
cipherId: string;
|
|
||||||
action: string;
|
action: string;
|
||||||
|
cipherId: string = null;
|
||||||
|
favorites: boolean = false;
|
||||||
|
type: CipherType = null;
|
||||||
|
folderId: string = null;
|
||||||
|
collectionId: string = null;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private router: Router, private location: Location) {
|
constructor(private route: ActivatedRoute, private router: Router, private location: Location) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe(async (params) => {
|
||||||
if (params['cipherId']) {
|
if (params['cipherId']) {
|
||||||
const cipherView = new CipherView();
|
const cipherView = new CipherView();
|
||||||
cipherView.id = params['cipherId'];
|
cipherView.id = params['cipherId'];
|
||||||
|
@ -47,6 +51,18 @@ export class VaultComponent implements OnInit {
|
||||||
} else if (params['action'] === 'add') {
|
} else if (params['action'] === 'add') {
|
||||||
this.addCipher();
|
this.addCipher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params['favorites']) {
|
||||||
|
await this.filterFavorites();
|
||||||
|
} else if (params['type']) {
|
||||||
|
await this.filterCipherType(parseInt(params['type']));
|
||||||
|
} else if (params['folderId']) {
|
||||||
|
await this.filterFolder(params['folderId']);
|
||||||
|
} else if (params['collectionId']) {
|
||||||
|
await this.filterCollection(params['collectionId']);
|
||||||
|
} else {
|
||||||
|
await this.ciphersComponent.load();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,25 +122,58 @@ export class VaultComponent implements OnInit {
|
||||||
|
|
||||||
async clearGroupingFilters() {
|
async clearGroupingFilters() {
|
||||||
await this.ciphersComponent.load();
|
await this.ciphersComponent.load();
|
||||||
|
this.clearFilters();
|
||||||
|
this.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
async filterFavorites() {
|
async filterFavorites() {
|
||||||
await this.ciphersComponent.load((c) => c.favorite);
|
await this.ciphersComponent.load((c) => c.favorite);
|
||||||
|
this.clearFilters();
|
||||||
|
this.favorites = true;
|
||||||
|
this.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
async filterCipherType(type: CipherType) {
|
async filterCipherType(type: CipherType) {
|
||||||
await this.ciphersComponent.load((c) => c.type === type);
|
await this.ciphersComponent.load((c) => c.type === type);
|
||||||
|
this.clearFilters();
|
||||||
|
this.type = type;
|
||||||
|
this.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
async filterFolder(folder: FolderView) {
|
async filterFolder(folderId: string) {
|
||||||
await this.ciphersComponent.load((c) => c.folderId === folder.id);
|
folderId = folderId === 'none' ? null : folderId;
|
||||||
|
await this.ciphersComponent.load((c) => c.folderId === folderId);
|
||||||
|
this.clearFilters();
|
||||||
|
this.folderId = folderId == null ? 'none' : folderId;
|
||||||
|
this.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
async filterCollection(collection: CollectionView) {
|
async filterCollection(collectionId: string) {
|
||||||
await this.ciphersComponent.load((c) => c.collectionIds.indexOf(collection.id) > -1);
|
await this.ciphersComponent.load((c) => c.collectionIds.indexOf(collectionId) > -1);
|
||||||
|
this.clearFilters();
|
||||||
|
this.collectionId = collectionId;
|
||||||
|
this.go();
|
||||||
|
}
|
||||||
|
|
||||||
|
private clearFilters() {
|
||||||
|
this.folderId = null;
|
||||||
|
this.collectionId = null;
|
||||||
|
this.favorites = false;
|
||||||
|
this.type = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private go(queryParams: any = null) {
|
||||||
|
if (queryParams == null) {
|
||||||
|
queryParams = {
|
||||||
|
action: this.action,
|
||||||
|
cipherId: this.cipherId,
|
||||||
|
favorites: this.favorites ? true : null,
|
||||||
|
type: this.type,
|
||||||
|
folderId: this.folderId,
|
||||||
|
collectionId: this.collectionId,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private go(queryParams: any) {
|
|
||||||
const url = this.router.createUrlTree(['vault'], { queryParams: queryParams }).toString();
|
const url = this.router.createUrlTree(['vault'], { queryParams: queryParams }).toString();
|
||||||
this.location.go(url);
|
this.location.go(url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue