2018-01-26 16:00:07 +01:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
2018-03-02 13:52:12 +01:00
|
|
|
import { ActivatedRoute} from '@angular/router';
|
|
|
|
|
|
|
|
import { Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
|
|
|
|
|
|
|
|
import {SearchResult} from '../../openaireLibrary/utils/entities/searchResult';
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {SearchFields, FieldDetails} from '../../openaireLibrary/utils/properties/searchFields';
|
|
|
|
import {SearchPageTableViewComponent } from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.component';
|
|
|
|
import {SearchUtilsClass } from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
2018-04-04 14:31:14 +02:00
|
|
|
import {SearchCommunityDataprovidersService} from '../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
|
2018-03-29 10:28:04 +02:00
|
|
|
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
|
2018-04-11 12:40:29 +02:00
|
|
|
import {PiwikHelper} from '../../utils/piwikHelper';
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openaire-search-dataproviders',
|
|
|
|
template: `
|
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
<search-page-table pageTitle="OpenAIRE Content Providers Table"
|
|
|
|
type="content providers" entityType="dataprovider"
|
|
|
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
|
|
|
[columnNames]="columnNames"
|
|
|
|
[showResultCount]=false
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
searchFormClass="datasourcesTableSearchForm"
|
|
|
|
formPlaceholderText="Search for Content Providers">
|
|
|
|
</search-page-table>
|
2018-01-26 16:00:07 +01:00
|
|
|
`
|
2018-03-02 13:52:12 +01:00
|
|
|
|
2018-01-26 16:00:07 +01:00
|
|
|
})
|
|
|
|
export class OpenaireSearchDataprovidersComponent {
|
2018-03-02 13:52:12 +01:00
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
|
|
|
|
public columnNames = ['Name', 'Official Name'];
|
|
|
|
public results =[];
|
|
|
|
public filters =[];
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public sub: any; public subResults: any;
|
|
|
|
public _location:Location;
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = [];// = this.searchFields.JOURNAL_FIELDS;
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
|
2018-03-02 14:10:15 +01:00
|
|
|
private communityId: string = '';
|
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
2018-04-11 12:40:29 +02:00
|
|
|
piwikSiteId = null;
|
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchCommunityDataprovidersService) {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2018-04-11 12:40:29 +02:00
|
|
|
var communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
|
|
this.piwikSiteId = PiwikHelper.siteIDs[communityId];
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
2018-03-22 16:38:42 +01:00
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
//this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2018-03-02 14:10:15 +01:00
|
|
|
this.communityId = params['communityId'];
|
2018-03-22 16:38:42 +01:00
|
|
|
if(!this.communityId){
|
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
|
|
}
|
2018-03-02 13:52:12 +01:00
|
|
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
|
|
|
//this.filters = this.createFilters();
|
|
|
|
//this.searchPage.getParametersFromUrl(params);
|
|
|
|
|
|
|
|
this._getResults(params);
|
|
|
|
});
|
2018-03-22 16:38:42 +01:00
|
|
|
});
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
if(this.subResults){
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private _getResults(params){
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
|
|
|
let size: number = 0;
|
|
|
|
|
2018-03-02 14:10:15 +01:00
|
|
|
this.subResults = this._searchDataprovidersService.searchDataproviders(this.properties, this.communityId).subscribe(
|
2018-03-02 13:52:12 +01:00
|
|
|
data => {
|
|
|
|
//this.filters = this.createFilters(data, params);
|
|
|
|
console.info(data);
|
|
|
|
this.searchUtils.totalResults = data.length;
|
|
|
|
console.info("search Content Providers [total results:"+this.searchUtils.totalResults+"]");
|
|
|
|
this.results = data;
|
|
|
|
|
|
|
|
//this.searchPage.checkSelectedFilters(this.filters);
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
this.disableForms = false;
|
|
|
|
this.searchPage.triggerInitialLoad();
|
|
|
|
this.searchPage.transform(this.results);
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disableForms = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private setFilters(){
|
|
|
|
//TODO set filters from
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
private createFilters(data, params):Filter[] {
|
|
|
|
let length = Array.isArray(data) ? data.length : 1;
|
|
|
|
|
|
|
|
var filter_names=[];
|
|
|
|
var filter_ids=[];
|
|
|
|
var searchFields = new SearchFields();
|
|
|
|
var filter_original_ids = [];//searchFields.JOURNAL_FIELDS;
|
|
|
|
|
|
|
|
this.refineFields = ["relfunder"];
|
|
|
|
this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.searchPage.getParametersFromUrl(params);
|
|
|
|
|
|
|
|
var value_names=[];
|
|
|
|
var value_original_ids=[];
|
|
|
|
|
|
|
|
var funders = new Set<String>();
|
|
|
|
var value_name = [];
|
|
|
|
var value_original_id = [];
|
|
|
|
let i;
|
|
|
|
for(i=0; i<length; i++) {
|
|
|
|
let resData = Array.isArray(data) ? data[i] : data;
|
|
|
|
if(resData.funder && !funders.has(resData.funder)) {
|
|
|
|
funders.add(resData.funder);
|
|
|
|
value_name.push(resData.funder);
|
|
|
|
value_original_id.push(resData.funder.trim());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value_names.push(value_name);
|
|
|
|
value_original_ids.push(value_original_id);
|
|
|
|
|
|
|
|
var filters: Filter[] =[];
|
|
|
|
for(i =0 ; i < filter_names.length;i++){
|
|
|
|
var values:Value[] = [];
|
|
|
|
for(var j =0 ; j < value_names[i].length;j++){
|
|
|
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
|
|
|
values.push(value);
|
|
|
|
}
|
|
|
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
|
|
|
filters.push(filter);
|
|
|
|
}
|
|
|
|
console.info(filters);
|
2018-01-26 16:00:07 +01:00
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
*/
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|