From 0f4f541b114d88cc8f19efd9ed6d6b07e05fc08e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 5 Nov 2020 14:41:54 -0500 Subject: [PATCH] some filtering logic for sends (#689) --- jslib | 2 +- src/app/send/add-edit.component.html | 1 + src/app/send/send.component.html | 15 ++++++- src/app/send/send.component.ts | 63 +++++++++++++++++++++++++--- src/locales/en/messages.json | 4 ++ 5 files changed, 77 insertions(+), 8 deletions(-) diff --git a/jslib b/jslib index 0e9e73ce95..9aa3cbf73d 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 0e9e73ce95a321ee05edbb62c50f9e1828f69c5a +Subproject commit 9aa3cbf73d9df9a2641654270911359593bcb5c5 diff --git a/src/app/send/add-edit.component.html b/src/app/send/add-edit.component.html index a4dcb9cb70..0692508bf1 100644 --- a/src/app/send/add-edit.component.html +++ b/src/app/send/add-edit.component.html @@ -52,6 +52,7 @@ +

{{'options' | i18n}}

diff --git a/src/app/send/send.component.html b/src/app/send/send.component.html index 0b58a5e68e..146e6321ee 100644 --- a/src/app/send/send.component.html +++ b/src/app/send/send.component.html @@ -51,9 +51,9 @@
- +
- +
+
+ + + {{'loading' | i18n}} + + +

{{'noSendsInList' | i18n}}

+ +
+
diff --git a/src/app/send/send.component.ts b/src/app/send/send.component.ts index 807c1efaad..5daa2c7f7e 100644 --- a/src/app/send/send.component.ts +++ b/src/app/send/send.component.ts @@ -32,18 +32,25 @@ export class SendComponent implements OnInit { @ViewChild('sendAddEdit', { read: ViewContainerRef, static: true }) sendAddEditModalRef: ViewContainerRef; sendType = SendType; + loaded = false; loading = true; + refreshing = false; expired: boolean = false; type: SendType = null; sends: SendView[] = []; + filteredSends: SendView[] = []; searchText: string; selectedType: SendType; selectedAll: boolean; searchPlaceholder: string; + filter: (cipher: SendView) => boolean; + searchPending = false; modal: ModalComponent = null; actionPromise: any; + private searchTimeout: any; + constructor(private apiService: ApiService, private userService: UserService, private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver, private platformUtilsService: PlatformUtilsService, private environmentService: EnvironmentService) { } @@ -51,8 +58,7 @@ export class SendComponent implements OnInit { async ngOnInit() { await this.load(); } - - async load() { + async load(filter: (send: SendView) => boolean = null) { this.loading = true; const userId = await this.userService.getUserId(); const sends = await this.apiService.getSends(); @@ -66,7 +72,45 @@ export class SendComponent implements OnInit { } } this.sends = sendsArr; + this.selectAll(); this.loading = false; + this.loaded = true; + } + + async reload(filter: (send: SendView) => boolean = null) { + this.loaded = false; + this.sends = []; + await this.load(filter); + } + + async refresh() { + try { + this.refreshing = true; + await this.reload(this.filter); + } finally { + this.refreshing = false; + } + } + + async applyFilter(filter: (send: SendView) => boolean = null) { + this.filter = filter; + await this.search(null); + } + + async search(timeout: number = null) { + this.searchPending = false; + if (this.searchTimeout != null) { + clearTimeout(this.searchTimeout); + } + if (timeout == null) { + this.filteredSends = this.sends.filter((s) => this.filter == null || this.filter(s)); + return; + } + this.searchPending = true; + this.searchTimeout = setTimeout(async () => { + this.filteredSends = this.sends.filter((s) => this.filter == null || this.filter(s)); + this.searchPending = false; + }, timeout); } addSend() { @@ -155,14 +199,23 @@ export class SendComponent implements OnInit { } searchTextChanged() { - // TODO + this.search(200); } selectAll() { - // TODO + this.clearSelections(); + this.selectedAll = true; + this.applyFilter(null); } selectType(type: SendType) { - // TODO + this.clearSelections(); + this.selectedType = type; + this.applyFilter((s) => s.type === type); + } + + clearSelections() { + this.selectedAll = false; + this.selectedType = null; } } diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 17a5c93fb7..4a9ceef357 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -3333,5 +3333,9 @@ }, "downloadFile": { "message": "Download File" + }, + "noSendsInList": { + "message": "There are no Sends to list.", + "description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated." } }