storage transfer: add path validator, fix hardcoded url, add scrolling in the list of files

This commit is contained in:
argirok 2022-05-24 14:24:54 +03:00
parent f16f2dd9e1
commit 9a2b8d3632
2 changed files with 22 additions and 19 deletions

View File

@ -443,7 +443,6 @@ export class ResultLandingComponent {
data => {
this.resultLandingInfo = data;
this.id = this.resultLandingInfo.objIdentifier;
console.log(this.resultLandingInfo.identifiers, this.resultLandingInfo.identifiers.get('doi'),this.resultLandingInfo.identifiers.get('doi').join('').indexOf('zenodo.'))
//old
// this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
// this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';

View File

@ -1,7 +1,7 @@
import {Component, Input} from '@angular/core';
import {Subscriber} from "rxjs";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Validators} from "@angular/forms";
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
import {Location} from '@angular/common';
import {StringUtils} from "../string-utils.class";
import {COOKIE} from "../../login/utils/helper.class";
@ -53,11 +53,12 @@ declare var UIkit;
[options]="sourceUrls" (valueChange)="this.parse()"></div>
<div class="uk-margin-top">
<div>Files to be transferred:</div>
<ul>
<div class="uk-height-xsmall uk-overflow-auto">
<ul>
<li *ngFor=" let element of this.downloadElements">{{ element.name}}
</li>
</ul>
</ul>
</div>
<div *ngIf="!this.downloadElements || this.downloadElements.length == 0"> - </div>
</div>
</div>
@ -66,7 +67,7 @@ declare var UIkit;
<div input type="select" [(value)]="selectedDestination" placeholder="Storage type" hint="Select..."
[options]="destinationOptions"></div>
<div input [(value)]="destinationPath" placeholder="Give a destination path..."
[validators]="validators[0]" class="uk-margin-top"></div>
[validators]="validators" class="uk-margin-top"></div>
<button (click)="transfer()"
class="uk-button uk-button-primary uk-margin-top"
[class.uk-disabled]="destinationPath.length == 0 || status == 'success' ||status == 'loading' ">
@ -106,7 +107,7 @@ export class EGIDataTransferComponent {
subscriptions = [];
accessToken = null;
@Input() dois;
loginURL = "http://rudie.di.uoa.gr:8580/openid_connect_login"
loginURL = properties.environment == "development"? "http://rudie.di.uoa.gr:8580/openid_connect_login":"https://explore.eosc-portal.eu/egi-login-service/openid_connect_login"
sourceUrls = []
selectedSourceUrl = null;
destinationPath = "";
@ -120,7 +121,7 @@ export class EGIDataTransferComponent {
status: "loading" | "success" | "errorParser" | "errorUser" | "errorTransfer" | "init" = "init";
message;
doiPrefix = properties.doiURL;
validators = [Validators.required, StringUtils.urlValidator()];
validators = [Validators.required, this.pathValidator() /*StringUtils.urlValidator()*/];
constructor(private http: HttpClient, private location: Location, private _router: Router) {
}
@ -182,15 +183,7 @@ export class EGIDataTransferComponent {
this.downloadElements = [];
this.subscriptions.push(this.http.get(this.APIURL + "/parser/zenodo?doi=" + encodeURIComponent(this.selectedSourceUrl)).subscribe(
res => {
for( let element of res['elements']){
//TODO remove
element.downloadUrl = "https://zenodo.org/record/6354460/files/preprocessed_data/weights/atlas_EUCP_ICTP_CMIP6_REA_tas_weights.nc?download=1";
//TODO can we use element.name instead?
// element.filename = element.name; //this.parseFilename(element.downloadUrl);
// console.log(element.filename)
this.downloadElements.push(element)
}
this.downloadElements= res['elements']
// console.log(this.downloadElements)
this.status = "init";
}, error => {
@ -249,7 +242,8 @@ export class EGIDataTransferComponent {
this.status = "success"
this.message = `
<div class="uk-text-large uk-margin-bottom">Data transfer has began!</div>
<div>Transfering ` + this.downloadElements.length + ` files to <a href="`+ this.selectedDestination.webpage + `" target=_blank> EGI Storage</a>:
<div>Transfering ` + this.downloadElements.length + ` files to <a href="`+ this.selectedDestination.webpage + `" target=_blank> EGI Storage</a>:
<div class="uk-height-xsmall uk-overflow-auto">
<ul>
`;
// TODO LATER we can call status for each file and see if the transfer has been complete
@ -260,6 +254,7 @@ export class EGIDataTransferComponent {
}
this.message += `
</ul>
</div>
</div>`
}, error => {
@ -289,5 +284,14 @@ export class EGIDataTransferComponent {
let filename = url.split("/")[url.split("/").length - 1];
return filename.split("?")[0];
}
pathValidator( ): ValidatorFn {
return (control: AbstractControl): { [key: string]: string } | null => {
let exp1 = /^\/([A-z0-9-_+]+\/)*$/g;
console.log(this.destinationPath, (this.destinationPath.length > 0 && this.destinationPath.match(exp1) == null))
if (this.destinationPath.length > 0 && this.destinationPath.match(exp1) == null) {
return {'error': 'Path should start and end with "/" e.g /path/'};
}
return null;
}
}
}