From d100e80ccfc73017062f289af5df06bfe519cd50 Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Mon, 29 Jun 2020 19:35:59 -0400 Subject: [PATCH] Added ability to clear all downloads in a session --- .../downloads/downloads.component.html | 3 +++ .../downloads/downloads.component.ts | 25 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/components/downloads/downloads.component.html b/src/app/components/downloads/downloads.component.html index 9bbf856..ff517f6 100644 --- a/src/app/components/downloads/downloads.component.html +++ b/src/app/components/downloads/downloads.component.html @@ -14,6 +14,9 @@ +
+ +
diff --git a/src/app/components/downloads/downloads.component.ts b/src/app/components/downloads/downloads.component.ts index 4b08b72..d7e7d2a 100644 --- a/src/app/components/downloads/downloads.component.ts +++ b/src/app/components/downloads/downloads.component.ts @@ -43,7 +43,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { valid_sessions_length = 0; sort_downloads = (a, b) => { - const result = a.value.timestamp_start < b.value.timestamp_start; + const result = b.value.timestamp_start - a.value.timestamp_start; return result; } @@ -81,7 +81,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { clearDownload(session_id, download_uid) { this.postsService.clearDownloads(false, session_id, download_uid).subscribe(res => { if (res['success']) { - this.downloads = res['downloads']; + // this.downloads = res['downloads']; } else { } }); @@ -107,11 +107,32 @@ export class DownloadsComponent implements OnInit, OnDestroy { assignNewValues(new_downloads_by_session) { const session_keys = Object.keys(new_downloads_by_session); + + // remove missing session IDs + const current_session_ids = Object.keys(this.downloads); + const missing_session_ids = current_session_ids.filter(session => session_keys.indexOf(session) === -1) + + for (const missing_session_id of missing_session_ids) { + delete this.downloads[missing_session_id]; + } + + // loop through sessions for (let i = 0; i < session_keys.length; i++) { const session_id = session_keys[i]; const session_downloads_by_id = new_downloads_by_session[session_id]; const session_download_ids = Object.keys(session_downloads_by_id); + if (this.downloads[session_id]) { + // remove missing download IDs + const current_download_ids = Object.keys(this.downloads[session_id]); + const missing_download_ids = current_download_ids.filter(download => session_download_ids.indexOf(download) === -1) + + for (const missing_download_id of missing_download_ids) { + console.log('removing missing download id'); + delete this.downloads[session_id][missing_download_id]; + } + } + if (!this.downloads[session_id]) { this.downloads[session_id] = session_downloads_by_id; } else {