From 032b91ae7a78ccad72a3a02a9463f6df5d00d223 Mon Sep 17 00:00:00 2001 From: argirok Date: Wed, 21 Sep 2022 17:29:46 +0300 Subject: [PATCH] very primitive tests for updating datatransfer with status and browse --- utils/dataTransfer/transferData.component.ts | 129 +++++++++++++++++-- 1 file changed, 115 insertions(+), 14 deletions(-) diff --git a/utils/dataTransfer/transferData.component.ts b/utils/dataTransfer/transferData.component.ts index 084fd853..cfca8f14 100644 --- a/utils/dataTransfer/transferData.component.ts +++ b/utils/dataTransfer/transferData.component.ts @@ -6,6 +6,7 @@ import {Location} from '@angular/common'; import {COOKIE} from "../../login/utils/helper.class"; import {Router} from "@angular/router"; import {properties} from "../../../../environments/environment"; +import {delay, repeat} from "rxjs/operators"; declare var UIkit; @Component({ @@ -58,6 +59,11 @@ declare var UIkit; [options]="destinationOptions">
+ + +
{{statusMessage}}
+ --> +
@@ -105,10 +115,13 @@ export class EGIDataTransferComponent { @ViewChild('egiTransferModal') egiTransferModal; APIURL = "https://eosc-data-transfer.vm.fedcloud.eu" // APIURL = "https://virtserver.swaggerhub.com/thebe14/eosc-future-data-transfer/1.0.0"; - status: "loading" | "success" | "errorParser" | "errorUser" | "errorTransfer" | "init" = "init"; + status: "loading" | "success" | "errorParser" | "errorUser" | "errorTransfer" | "init" | "canceled" = "init"; message; doiPrefix = properties.doiURL; validators = [Validators.required, this.pathValidator() /*StringUtils.urlValidator()*/]; + jobId = null; + statusMessage = null; + jobStatus; constructor(private http: HttpClient, private location: Location, private _router: Router) { } @@ -149,11 +162,7 @@ export class EGIDataTransferComponent { this.egiTransferModal.cancelButton = false; this.egiTransferModal.okButton = false; this.egiTransferModal.alertTitle = "EOSC data transfer service [demo]"; - this.destinationPath = ""; - this.selectedDestination = this.destinationOptions[0].value; - this.selectedSourceUrl = this.sourceUrls[0]; - this.message = null; - this.status = "init"; + this.init(); this.egiTransferModal.open(); } close(){ @@ -162,15 +171,20 @@ export class EGIDataTransferComponent { this.egiTransferModal.cancel(); } // this.downloadElements = []; + this.init(); + if(this._router.url.indexOf("&egiTransfer")){ + this.location.go(this._router.url.split("&egiTransfer")[0]); + } + + } + init(){ this.destinationPath = ""; this.selectedDestination = this.destinationOptions[0].value; this.selectedSourceUrl = this.sourceUrls[0]; this.message = null; this.status = "init"; - if(this._router.url.indexOf("&egiTransfer")){ - this.location.go(this._router.url.split("&egiTransfer")[0]); - } - + this.jobId = null; + this.statusMessage = null; } checkin(){ window.location.href = this.loginURL+"?redirect="+ encodeURIComponent(window.location.href + (window.location.href.indexOf("&egiTransfer=t")!=-1?"":"&egiTransfer=t")); @@ -237,8 +251,8 @@ export class EGIDataTransferComponent { timeout: 6000, pos: 'bottom-right' }); - - this.status = "success" + this.jobId = res['jobId']; + this.status = "success"; this.message = `
Transfer of ` + this.downloadElements.length + ` files to `+this.selectedDestination.label+` has began.`; @@ -258,6 +272,7 @@ export class EGIDataTransferComponent { this.message += `
` + // this.getStatus(true) }, error => { this.status = "errorTransfer"; @@ -282,6 +297,92 @@ export class EGIDataTransferComponent { } )); } + + getStatus(updateTransferMessage:boolean = false){ + if(this.jobId){ + + + let headers = new HttpHeaders({'Authorization': 'Bearer '+this.accessToken}); + let source = this.http.get(this.APIURL + "/transfer/" +this.jobId , {headers: headers}).pipe(delay(5000)); + this.subscriptions.push(source.pipe(repeat(3)).subscribe( + res => { + this.jobStatus = res; + this.message = ` + +
Transfer of ` + this.downloadElements.length + ` files to `+this.selectedDestination.label+` has began.`; + /*this.message += `
+
    + `; + // TODO LATER we can call status for each file and see if the transfer has been complete + for(let element of this.downloadElements){ + // console.log(element) + // this.message += `
  • `+ element.name+ `
  • `; + this.message += `
  • `+ element.name+ `
  • `; + } + this.message += ` +
+
+
`*/ + this.message += ` + + `; + console.log(res) + this.statusMessage = res['jobState'] + (res['reason']?(" :" + res['reason']):""); + UIkit.notification('got status! ', { + status: 'success', + timeout: 6000, + pos: 'bottom-right' + }); + + + + }, error => { + this.status = "errorTransfer"; + this.message = "Couldn't get status "; + UIkit.notification("Couldn't get status", { + status: 'error', + timeout: 6000, + pos: 'bottom-right' + }); + + } + )); + } + } + + + cancel(){ + if(this.jobId){ + + + let headers = new HttpHeaders({'Authorization': 'Bearer '+this.accessToken}); + this.subscriptions.push(this.http.delete(this.APIURL + "/transfer/" +this.jobId , {headers: headers}).subscribe( + res => { + console.log(res); + this.jobStatus = res; + this.statusMessage = res['jobState'] + (res['reason']?(" :" + res['reason']):""); + this.jobId = null; + this.status = "canceled"; + } + )); + } + } + browse(){ + + + + let headers = new HttpHeaders({'Authorization': 'Bearer '+this.accessToken}); + this.subscriptions.push(this.http.get(this.APIURL + "/storage/folder?dest="+this.selectedDestination.id+"&seUrl="+encodeURIComponent(this.destinationPath) , {headers: headers}).subscribe( + res => { + console.log(res); + this.jobStatus = res; + this.statusMessage = res['jobState'] + (res['reason']?(" :" + res['reason']):""); + this.jobId = null; + this.status = "canceled"; + } + )); + + } private parseFilename(url){ let filename = url.split("/")[url.split("/").length - 1]; return filename.split("?")[0];