128 lines
4.4 KiB
TypeScript
128 lines
4.4 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 {Publication} from '../entities/publication';
|
|
import {PagingFormatter} from '../common/pagingFormatter.component';
|
|
import {PublicationTitleFormatter} from '../common/publicationTitleFormatter.component';
|
|
|
|
|
|
@Component({
|
|
selector: 'search-all',
|
|
directives: [...ROUTER_DIRECTIVES,PagingFormatter, PublicationTitleFormatter],
|
|
template: `
|
|
|
|
|
|
<div *ngIf="claim">
|
|
<h3>Selected publications:</h3>
|
|
<p *ngFor=" let item of selected "> <publication-title [title]="item.title" [url]="item.URL" > </publication-title> {{item.DOI}} --{{item.publisher}} <button (click)="remove(item)" type="button" class="btn btn-default">Remove</button></p>
|
|
</div>
|
|
|
|
<h1>Search</h1>
|
|
<form>
|
|
<input #term [(ngModel)]="keyword"/>
|
|
<button (click)="search(term)" type="submit" class="btn btn-default">Search</button>
|
|
</form>
|
|
<div>
|
|
<div *ngIf="resultsNum != null && resultsNum > 0">
|
|
<p > {{resultsNum }} Total Results </p>
|
|
<paging [currentPage]="page" [totalResults]="resultsNum" [navigateTo]="navigateTo" [term]="keyword" [size]="size"> </paging>
|
|
</div>
|
|
<div >
|
|
|
|
<p *ngFor=" let item of results "> <publication-title [title]="item.title" [url]="item.URL" > </publication-title> {{item.DOI}} --{{item.publisher}} <button *ngIf="claim" (click)="add(item)" type="button" class="btn btn-default">Select</button> </p>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
`,
|
|
providers:[JSONP_PROVIDERS, SearchCrossrefService]
|
|
})
|
|
export class SearchAllComponent {
|
|
constructor (private _searchService: SearchCrossrefService,
|
|
private _routeParams: RouteParams) {}
|
|
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;
|
|
this.keyword = this._routeParams.get('keyword');
|
|
if(this.keyword !=null){
|
|
this.searchCrossref(this.keyword,this.size,this.page);
|
|
}
|
|
}
|
|
|
|
page : number;
|
|
size:number;
|
|
keyword:string;
|
|
navigateTo: string = "Search";
|
|
|
|
@Input() public claim:boolean = true ; // add selection for claiming
|
|
@Input() public publication:boolean = true ; // true for publication/ false for dataset
|
|
@Input() public source:string = 'openaire' ; // other values : crossref/ datacite/orcid
|
|
@Input() public selected = [] ;
|
|
@Output() selectedChange = new EventEmitter();
|
|
results:string[];
|
|
resultsNum : Observable<number> ;
|
|
search(term: string, size : number, page : number) {
|
|
// if(this.source == 'crossref' && this.publication){
|
|
this.searchCrossref(term,size,page);
|
|
// }else if(this.source == 'openaire' && this.publication){
|
|
//
|
|
// }else if(this.source == 'openaire' && this.publication){
|
|
//
|
|
// }else if(this.source == 'openaire' && !this.publication){
|
|
//
|
|
// }else if(this.source == 'orcid' && this.publication){
|
|
//
|
|
// }else if(this.source == 'datacite' && !this.publication){
|
|
//
|
|
// }
|
|
}
|
|
searchCrossref (term: string, size : number, page : number) {
|
|
this._searchService.searchCrossrefResults(term, size, page).subscribe(
|
|
data => {
|
|
this.results = data.items;
|
|
this.page=page;
|
|
this.resultsNum = data['total-results'];
|
|
},
|
|
err => console.error(err)
|
|
);
|
|
}
|
|
searchOpenaire (term2: string) {
|
|
//this.items = this._searchService.httpSearchOpenaire(term2);
|
|
}
|
|
|
|
|
|
|
|
add(item){
|
|
this.selected.push(item);
|
|
console.info("Select:"+this.selected);
|
|
for (var i = 0; i < this.selected.length; i++) {
|
|
console.log(this.selected[i]);
|
|
}
|
|
|
|
|
|
var index:number =this.results.indexOf(item);
|
|
if (index > -1) {
|
|
this.results.splice(index, 1);
|
|
}
|
|
console.info("Item removed "+this.selected.indexOf(item));
|
|
this.selectedChange.emit({
|
|
value: this.selected
|
|
});
|
|
}
|
|
remove(item){
|
|
var index:number =this.selected.indexOf(item);
|
|
if (index > -1) {
|
|
this.selected.splice(index, 1);
|
|
}
|
|
this.selectedChange.emit({
|
|
value: this.selected
|
|
});
|
|
|
|
}
|
|
|
|
}
|