From 5da8b4e8ac2882f7acdaf4d1996dfe9afbb135cd Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Tue, 15 Nov 2016 13:44:48 +0000 Subject: [PATCH] chnage the display of claimproject, in bulkmode : accept csv files with extra columns for access mode and date,accept double quotes, disable upload file while uploading and fetching, update information about the file format and the report git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44502 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../claim-utils/claimProject.component.ts | 38 +-------- .../linking/bulkClaim/bulkClaim.component.ts | 81 +++++++++++++------ portal-2/src/app/test/test.component.ts | 11 ++- portal-2/src/app/utils/dates.class.ts | 35 ++++++++ 4 files changed, 104 insertions(+), 61 deletions(-) create mode 100644 portal-2/src/app/utils/dates.class.ts diff --git a/portal-2/src/app/claimPages/claim-utils/claimProject.component.ts b/portal-2/src/app/claimPages/claim-utils/claimProject.component.ts index afeacc40..d60a9bd5 100644 --- a/portal-2/src/app/claimPages/claim-utils/claimProject.component.ts +++ b/portal-2/src/app/claimPages/claim-utils/claimProject.component.ts @@ -12,50 +12,20 @@ import {ClaimProject} from '../../utils/entities/claimEntities.class'; template: `
- - -
-
+ +
-
- - +
diff --git a/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts b/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts index ae1f2019..cc31a158 100644 --- a/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts +++ b/portal-2/src/app/claimPages/linking/bulkClaim/bulkClaim.component.ts @@ -2,7 +2,7 @@ import {Component, Input, Output, EventEmitter,ViewChild} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {SearchCrossrefService} from '../../../services/searchCrossref.service'; import {ModalLoading} from '../../../utils/modal/loading.component'; - +import {Dates} from '../../../utils/dates.class'; @Component({ @@ -14,15 +14,31 @@ import {ModalLoading} from '../../../utils/modal/loading.component';
- +
-

Upload a csv file with DOIs. For each DOI, metadata will be fetched from CrossRef. Available Results can be linked with the selected Projects and Contexts

+
Upload a csv file containing DOIs. For each DOI found in file, metadata will be fetched from CrossRef. + Available results can be linked with the selected Projects and Contexts. + More information +
+ CSV format: +
    +
  • The format of CSV file should be "DOI","ACCESS_MODE","DATE".
  • +
  • Access mode column should have values: "OPEN","CLOSED" or "EMBARGO".
  • +
  • Date column valid format is YYYY-MM-DD and is required when access mode has value EMBARGO.
  • +
  • In case access mode is not available default value is "OPEN".
  • +
+
+
-
+ ` @@ -36,7 +52,6 @@ export class BulkClaimComponent { resultsFromSearch:number; @Input() public select:boolean = true ; @Input() public publications; - // @Output() publicationsChange = new EventEmitter(); all:number = 0; allIds:string[] = []; found:number = 0; @@ -45,22 +60,21 @@ export class BulkClaimComponent { duplicateIds:string[] = []; notFound:number = 0; notFoundIds:string[] = []; - todayDate = ''; - nextDate = ''; showReport:boolean = false; + showInfo :boolean = false; @ViewChild (ModalLoading) loading : ModalLoading ; errorMessage = ""; infoMEssage = ""; + private enableUpload:boolean = true; constructor(private _searchCrossrefService: SearchCrossrefService) { this.filesToUpload = []; - var myDate = new Date(); - this.todayDate = myDate.getFullYear()+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ; - this.nextDate = (myDate.getFullYear()+100)+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ; + } ngOnInit() {} upload() { + this.enableUpload = false; this.showReport = false; this.errorMessage = ""; if(this.filesToUpload.length == 0){ @@ -68,7 +82,7 @@ export class BulkClaimComponent { return ; } this.makeFileRequest("http://localhost:8000/upload", [], this.filesToUpload).then((result) => { - var k = (result as any).split('\n'); // I have used space, you can use any thing. + var rows = (result as any).split('\n'); // I have used space, you can use any thing. var i = 0; this.all = 0; this.duplicate = 0; @@ -80,29 +94,52 @@ export class BulkClaimComponent { this.notFound = 0; this.notFoundIds = []; - for(i=0;i-1){ this.duplicate++; this.duplicateIds.push(id); }else{ this.allIds.push(id); - this.fetchResult(id); + this.fetchResult(id,accessMode,embargoDate); } } } }, (error) => { + this.enableUpload = true; console.error(error); // this.loading.close(); this.errorMessage = "An error occured while uploading..."; }); } + private removeDoubleQuotes(value){ + if(value.indexOf('"')== 0){ + value = value.substring(1,value.length); + } + var index =+value.indexOf('"'); + if(index == (value.length - 1) || index == (value.length - 2) ){ + value = value.substring(0,index); + } + return value; + } + private validateAccessMode(value){ + var accessModes = ["OPEN", "CLOSED", "EMBARGO"]; + if(accessModes.indexOf(value) > -1){ + return true; + } + return false; + } fileChangeEvent(fileInput: any){ this.filesToUpload = > fileInput.target.files; @@ -129,7 +166,7 @@ export class BulkClaimComponent { }); } - fetchResult(id:string){ + fetchResult(id:string,accessMode:string,date:string){ this._searchCrossrefService.searchCrossrefByDOI(id).subscribe( data => { @@ -138,11 +175,9 @@ export class BulkClaimComponent { this.found++; this.foundIds.push(id); var result = {id: id, type :'publication', source : 'crossref', - title: crossrefResult.title,url: crossrefResult.URL, result: crossrefResult, accessRights: 'OPEN', embargoEndDate: this.nextDate, date : crossrefResult.created['date-time']}; + title: crossrefResult.title,url: crossrefResult.URL, result: crossrefResult, accessRights: accessMode, embargoEndDate: date, date : crossrefResult.created['date-time']}; this.publications.push(result); - // this.publicationsChange.emit({ - // value: this.publications - // }); + }else{ this.notFound++; @@ -160,11 +195,9 @@ export class BulkClaimComponent { } endOfFetching(){ - console.info("here"); if(this.all == this.found+this.notFound+ this.duplicate ){ this.showReport = true; - // this.loading.close(); - console.debug("theeere"); + this.enableUpload = true; } } diff --git a/portal-2/src/app/test/test.component.ts b/portal-2/src/app/test/test.component.ts index 54483a58..e7d93bb1 100644 --- a/portal-2/src/app/test/test.component.ts +++ b/portal-2/src/app/test/test.component.ts @@ -3,8 +3,7 @@ import { Subject } from 'rxjs/Subject'; import {Observable} from 'rxjs/Observable'; import {OpenaireProjectsService} from '../services/openaireProjects.service'; import {ISVocabulariesService} from '../services/ISVocabularies.service'; - - +import {Dates} from '../utils/dates.class'; @Component({ selector: 'test', template: ` @@ -76,7 +75,13 @@ export class TestComponent { this.types = this._vocabulariesService.getPublicationTypesJsonFile(); this.user.email = localStorage.getItem("email"); this.user.password = localStorage.getItem("password"); - +console.info("2001-12-12" + Dates.isValidDate("2001-12-12")); +console.info("2001/1/12" + Dates.isValidDate("2001/1/12")); +console.info("2001-03-12" + Dates.isValidDate("2001-03-12")); +console.info("12-03-107" + Dates.isValidDate("212-03-107")); +console.info("2016-02-29" + Dates.isValidDate("2016-02-29")); +console.info("2017-02-29" + Dates.isValidDate("2017-02-29")); +console.info("29-02-2016" + Dates.isValidDate("29-02-2016")); } login(){ localStorage.setItem("email",this.user.email); diff --git a/portal-2/src/app/utils/dates.class.ts b/portal-2/src/app/utils/dates.class.ts new file mode 100644 index 00000000..adc75ac8 --- /dev/null +++ b/portal-2/src/app/utils/dates.class.ts @@ -0,0 +1,35 @@ +export class Dates { + + //format YYYY-MM-DD + public static isValidDate(dateString) + { + // First check for the pattern + if(!/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(dateString)) + return false; + + // Parse the date parts to integers + var parts = dateString.split("-"); + var day = parseInt(parts[2], 10); + var month = parseInt(parts[1], 10); + var year = parseInt(parts[0], 10); + + // Check the ranges of month and year + if(year < 1000 || year > 3000 || month == 0 || month > 12) + return false; + + var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; + + // Adjust for leap years + if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) + monthLength[1] = 29; + + // Check the range of the day + return day > 0 && day <= monthLength[month - 1]; + + } + public static getDateToday(){ + var myDate = new Date(); + return myDate.getFullYear()+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ; + + } +}