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
This commit is contained in:
parent
51846c9917
commit
5da8b4e8ac
|
@ -12,50 +12,20 @@ import {ClaimProject} from '../../utils/entities/claimEntities.class';
|
|||
|
||||
template: `
|
||||
<div class="panel-body" >
|
||||
|
||||
<!-- <select [(ngModel)]="selectedFunderId" (ngModelChange)="funderChanged()" >
|
||||
<option [ngValue]="'0'">Funder:</option>
|
||||
<option *ngFor="let funder of funders" [ngValue]="funder.field.field[1]['@value_original']">{{funder.field.field[1]['@value']}}</option>
|
||||
</select> -->
|
||||
<form class="form-group form-inline"><!-- *ngIf=" !inline "-->
|
||||
<div class="input-group">
|
||||
<form class="form-group " [class.form-inline]="!inline">
|
||||
<div [class.input-group]="!inline">
|
||||
<div class="input-group-btn" >
|
||||
<button type="button" class="btn btn-info dropdown-toggle" id="dropdownFunder" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
{{selectedFunderName}}
|
||||
</button>
|
||||
<ul class="dropdown-menu " aria-labelledby="dropdownFunder">
|
||||
<ul class="dropdown-menu custom-hidden-dropdown-menu " aria-labelledby="dropdownFunder">
|
||||
<li (click)="funderChanged('0','Select funder:')"><a >Select funder:</a></li>
|
||||
<li *ngFor="let funder of funders" (click)="funderChanged(funder.id,funder.name)" ><a >{{funder.name}}</a></li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<entities-autocomplete entityName="project" [funderId]="selectedFunderId" [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Search for Projects'" title = "Projects:" [multipleSelections]=true (addItem) = "select($event)" ></entities-autocomplete>
|
||||
<!--input id="community" type="text" class="form-control" placeholder="Search for Projects" [(ngModel)]=query name="query" (keyup)="search()"-->
|
||||
<!--autocomplete
|
||||
<div class="bs-docs-grid">
|
||||
<div class = "row-fluid form-inline auto-complete-box panel panel-default">
|
||||
<div class="panel-heading">Projects</div>
|
||||
<div class="panel-body">
|
||||
<span *ngIf = "showSelected">
|
||||
<span class="row-fluid show-grid auto-complete-choice" *ngFor="let item of selected" >
|
||||
<span >{{showItem(item)}} </span>
|
||||
<span (click)="remove(item)" aria-hidden="true" class=" remove glyphicon glyphicon-remove"></span>
|
||||
</span>
|
||||
</span>
|
||||
<input name="searchkeyword" type="text" class="auto-complete-input validate filter-input input-sm form-control " placeholder="Search for Projects" [(ngModel)]=query (keyup)=search() >
|
||||
<div class="suggestions" >
|
||||
<ul class="list-group" >
|
||||
<li class="list-group-item" *ngFor=" let item of filtered | async">
|
||||
<a (click)="select(item)">{{showItem(item)}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div *ngIf="warningMessage.length > 0" class="alert alert-warning row-fluid " role="alert">{{warningMessage}}</div>
|
||||
<div *ngIf="filtered.length == 0 && keyword.length >=3 " class="alert alert-info row-fluid " role="alert">No results Found</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
autocomplete -->
|
||||
|
||||
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -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';
|
|||
<input id="exampleInputFile" type="file" (change)="fileChangeEvent($event)" placeholder="Upload file..." />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-success" type="button" (click)="upload()">Upload</button>
|
||||
<button class="btn btn-success" [class.disabled]="!enableUpload" type="button" (click)="upload()">Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
<p class="help-block">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</p>
|
||||
<div class="help-block">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.
|
||||
<a (click)="showInfo = !showInfo"> More information</a>
|
||||
<div *ngIf = "showInfo">
|
||||
CSV format:
|
||||
<ul>
|
||||
<li>The format of CSV file should be "DOI","ACCESS_MODE","DATE".</li>
|
||||
<li>Access mode column should have values: "OPEN","CLOSED" or "EMBARGO".</li>
|
||||
<li>Date column valid format is YYYY-MM-DD and is required when access mode has value EMBARGO.</li>
|
||||
<li>In case access mode is not available default value is "OPEN".</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="showReport" class="alert alert-info" role="alert" >
|
||||
{{all}} DOIs found. {{found}} fetched from CrossRef, {{duplicate}} were duplicates and {{notFound}} not found in crossref.
|
||||
<span>{{all}} rows found in file.</span>
|
||||
<span>{{found}} results fetched from CrossRef.</span>
|
||||
<span *ngIf ="duplicate > 0" [title] = "'Duplicate DOIs: '+ duplicateIds.join()">"{{duplicate}} DOIs were duplicates. </span>
|
||||
<span *ngIf = "notFound > 0" [title] = "'Not found DOIs: '+ notFoundIds.join()" >{{notFound}} DOIs not found in crossref. </span>
|
||||
<span *ngIf = "all == 0 || found == 0" > Please make sure you are using the right format for he csv file... </span>
|
||||
|
||||
</div>
|
||||
<div *ngIf="errorMessage.length > 0 "> <div class="alert alert-danger" role="alert">{{errorMessage}}</div></div>
|
||||
<div *ngIf="errorMessage.length > 0 " class="alert alert-danger" role="alert">{{errorMessage}}</div>
|
||||
<modal-loading [message]= "'Please wait...'"></modal-loading>
|
||||
`
|
||||
|
||||
|
@ -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<k.length;i++){
|
||||
if(k[i] && k[i] != null ){
|
||||
for(i=0;i<rows.length;i++){
|
||||
if(rows[i] && rows[i] != null ){
|
||||
var values = rows[i].split(',');
|
||||
|
||||
this.all++;
|
||||
var id=k[i];
|
||||
var id=this.removeDoubleQuotes(values[0]);
|
||||
var accessMode = (values[1] != undefined) ? this.removeDoubleQuotes(values[1]):"OPEN";
|
||||
accessMode = (this.validateAccessMode(accessMode)?accessMode:"OPEN");
|
||||
var embargoDate =(values[2] != undefined) ? this.removeDoubleQuotes(values[2]):Dates.getDateToday();
|
||||
embargoDate = (Dates.isValidDate(embargoDate)?embargoDate:Dates.getDateToday());
|
||||
if(this.allIds.indexOf(id)>-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 = <Array<File>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() ;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue