247 lines
7.5 KiB
TypeScript
247 lines
7.5 KiB
TypeScript
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
import {JSONP_PROVIDERS} from '@angular/http';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import { RouteParams, RouteConfig, ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
|
|
import {SearchCrossrefService} from '../../../../services/searchCrossref.service';
|
|
import {SearchOrcidService} from '../../../../services/searchOrcid.service';
|
|
import {Publication} from '../../../../entities/publication';
|
|
import {pagingFormatterNoLoad} from '../../../../common/pagingFormatterNoLoad.component';
|
|
import {PublicationTitleFormatter} from '../../../../common/publicationTitleFormatter.component';
|
|
|
|
|
|
@Component({
|
|
selector: 'claim-publication',
|
|
directives: [...ROUTER_DIRECTIVES,pagingFormatterNoLoad, PublicationTitleFormatter],
|
|
templateUrl: 'src/app/claimPages/linking/claimResult/claimPublication/claimPublication.component.html',
|
|
providers:[JSONP_PROVIDERS, SearchCrossrefService, SearchOrcidService]
|
|
})
|
|
export class ClaimPublicationComponent {
|
|
constructor (private _searchCrossrefService: SearchCrossrefService,private _searchOrcidService: SearchOrcidService,
|
|
private _routeParams: RouteParams) {
|
|
var myDate = new Date();
|
|
this.todayDate = myDate.getFullYear()+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ;
|
|
this.nextDate = (myDate.getFullYear()+100)+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ;
|
|
|
|
}
|
|
ngOnInit() {
|
|
let page = +this._routeParams.get('page');
|
|
let size = +this._routeParams.get('size');
|
|
this.page = ( page <= 0 ) ? 1 : page;
|
|
this.size = ( size <= 0 ) ? 10 : size;
|
|
if(this.keyword !=null && this.keyword.length > 0){
|
|
this.search(this.keyword,this.size,this.page);
|
|
}
|
|
}
|
|
|
|
page : number = 1;
|
|
size:number = 10;
|
|
@Input() public keyword:string = "";
|
|
navigateTo: string = "Search";
|
|
source: string = "crossref";
|
|
type : string = "publication";
|
|
@Input() public select:boolean = true ;
|
|
@Input() public selectedPublications = [] ;
|
|
@Output() publicationsChange = new EventEmitter();
|
|
|
|
crossrefResults=[];
|
|
crossrefResultsNum : Observable<number> ;
|
|
|
|
orcidResults: string[];
|
|
orcidResultsNum: number ;
|
|
totalPages: number;
|
|
orcidResultsToShow: string[];
|
|
|
|
authorId: string;
|
|
authorGivenName: string;
|
|
authorFamilyName: string;
|
|
|
|
authorIds: string[];
|
|
authorGivenNames: string[];
|
|
authorFamilyNames: string[];
|
|
|
|
authorsNum : number ;
|
|
|
|
public warningMessage = "";
|
|
public infoMessage = "";
|
|
|
|
todayDate = '';
|
|
nextDate = '';
|
|
|
|
private searchOrcid (term: string) {
|
|
this.authorIds = new Array<string>();
|
|
this.authorGivenNames = new Array<string>();
|
|
this.authorFamilyNames = new Array<string>();
|
|
|
|
this.getOrcidAuthor(term);
|
|
|
|
console.info('searchOrcid in searchOrcid file');
|
|
}
|
|
|
|
private readData(data: any) {
|
|
this.authorIds.push(data[2].path);
|
|
|
|
if(data[0] != null) {
|
|
this.authorGivenNames.push(data[0].value);
|
|
} else {
|
|
this.authorGivenNames.push("");
|
|
}
|
|
if(data[1] != null) {
|
|
this.authorFamilyNames.push(data[1].value);
|
|
} else {
|
|
this.authorFamilyNames.push("");
|
|
}
|
|
}
|
|
|
|
private getOrcidAuthor (term: string) {
|
|
this.orcidResultsNum = null;
|
|
|
|
this._searchOrcidService.searchOrcidAuthor(term).subscribe(
|
|
data => {
|
|
if(data[2] != null) {
|
|
this.readData(data);
|
|
this.getOrcidResultsById(0);
|
|
}
|
|
|
|
},
|
|
err => this.errorHandler(err, term)
|
|
);
|
|
}
|
|
|
|
private errorHandler(err: any, term: string) {
|
|
if(err.status == 404){
|
|
this.getOrcidAuthors(term);
|
|
} else {
|
|
console.error(err.status);
|
|
}
|
|
}
|
|
|
|
private getOrcidAuthors (term: string) {
|
|
this.orcidResultsNum = null;
|
|
|
|
this._searchOrcidService.searchOrcidAuthors(term).subscribe(
|
|
data => {
|
|
if(data[2] != null) {
|
|
this.readData(data);
|
|
this.getOrcidResultsById(0);
|
|
}
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}
|
|
|
|
|
|
private getOrcidResultsById (index:number) {
|
|
let id = this.authorIds[index];
|
|
|
|
console.info("getOrcidResultsById: "+id);
|
|
this._searchOrcidService.searchOrcidPublications(id).subscribe(
|
|
data => {
|
|
if(data != null) {
|
|
this.orcidResults=data['orcid-work'];
|
|
this.orcidResultsNum = data['orcid-work'].length;
|
|
this.page = 1;
|
|
if((this.orcidResultsNum % this.size) == 0){
|
|
this.totalPages=parseInt(''+(this.orcidResultsNum/this.size));
|
|
} else{
|
|
this.totalPages=parseInt(''+(this.orcidResultsNum/this.size+1));
|
|
}
|
|
|
|
this.orcidResultsToShow = this.orcidResults.slice(0,10);
|
|
} else {
|
|
this.orcidResultsNum = 0;
|
|
this.totalPages=0;
|
|
}
|
|
this.authorGivenName = this.authorGivenNames[index];
|
|
this.authorFamilyName = this.authorFamilyNames[index];
|
|
this.authorId = id;
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
|
|
console.info("totalPages = " +this.totalPages);
|
|
}
|
|
|
|
public search(term: string, size : number, page : number){
|
|
this.warningMessage = "";
|
|
this.infoMessage = "";
|
|
this.getCrossrefResults(term,size,page);
|
|
this.searchOrcid(term);
|
|
|
|
}
|
|
|
|
|
|
private getCrossrefResults (term: string, size : number, page : number) {
|
|
this._searchCrossrefService.searchCrossrefResults(term, size, page).subscribe(
|
|
data => {
|
|
this.crossrefResults = data.items;
|
|
this.page=page;
|
|
this.crossrefResultsNum = data['total-results'];
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
|
|
}
|
|
|
|
|
|
private add(item, id, itemSource, itemType, itemUrl, itemTitle){
|
|
var result ;
|
|
if(itemSource == 'crossref'){
|
|
result = {id: id, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: 'OPEN', embargoEndDate: this.nextDate};
|
|
}else if (itemSource == 'orcid'){
|
|
result = {id:id, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: 'OPEN', embargoEndDate: this.nextDate};
|
|
}else if (itemSource == 'openaire'){
|
|
|
|
}
|
|
var found:boolean = this.isSelected(result.id);
|
|
this.warningMessage = "";
|
|
if (!found) {
|
|
this.selectedPublications.push(result);
|
|
this.publicationsChange.emit({
|
|
value: this.selectedPublications
|
|
});
|
|
}else{
|
|
this.warningMessage = "Publication already in selected list";
|
|
}
|
|
|
|
}
|
|
private remove(item){
|
|
this.warningMessage = "";
|
|
this.infoMessage = "";
|
|
var index:number =this.selectedPublications.indexOf(item);
|
|
item.selected=false;
|
|
if (index > -1) {
|
|
this.selectedPublications.splice(index, 1);
|
|
this.publicationsChange.emit({
|
|
value: this.selectedPublications
|
|
});
|
|
}
|
|
|
|
}
|
|
private pageChange($event) {
|
|
this.page=$event.value;
|
|
this.crossrefResults=[];
|
|
this.getCrossrefResults(this.keyword,this.size,this.page);
|
|
}
|
|
private orcidPageChange($event) {
|
|
this.page=$event.value;
|
|
this.orcidResultsToShow=[];
|
|
this.orcidResultsToShow = this.orcidResults.slice(($event.value-1)*this.size, $event.value*this.size);
|
|
}
|
|
|
|
private isSelected(id:string){
|
|
|
|
var found:boolean = false;
|
|
this.warningMessage = "";
|
|
for (var _i = 0; _i < this.selectedPublications.length; _i++) {
|
|
let item = this.selectedPublications[_i];
|
|
if(item.id == id){
|
|
found=true;
|
|
this.warningMessage = "Publication already in selected list";
|
|
}
|
|
}
|
|
return found;
|
|
|
|
|
|
}
|
|
}
|