import {Component, Input, ViewChild} from '@angular/core';
import {Location} from '@angular/common';
import { ActivatedRoute} from '@angular/router';
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
import {SearchResult} from '../../utils/entities/searchResult';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
import {SearchPageTableViewComponent } from '../searchUtils/searchPageTableView.component';
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
import{EnvProperties} from '../../utils/properties/env-properties';
@Component({
selector: 'search-content-providers-table',
template: `
`
})
export class SearchCompatibleDataprovidersTableComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
public results =[];
public filters =[];
public columnNames = ["Name", "Type", "Country", "Institution", "Compatibility"];
public baseUrl:string;
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public sub: any; public subResults: any;
public _location:Location;
public searchFields:SearchFields = new SearchFields();
public refineFields: string[] = this.searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
public mapUrl: string;
/*public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
"export":[]
};
public CSVDownloaded = false;
public csvParams: string;
public resourcesQuery = "&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))";*/
public disableForms: boolean = false;
public enableSearchView: boolean = true;
properties:EnvProperties;
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.baseUrl = data.envSpecific.searchLinkToEntityRegistriesDataProvidersTable;
this.mapUrl = this.properties.statisticsFrameAPIURL+"markers-test.html";
});
this.refineFields.push("datasourcecountryname");
this.searchPage.refineFields = this.refineFields;
this.sub = this.route.queryParams.subscribe(params => {
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
//this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
//this.filters = this.createFilters();
//this.searchPage.getParametersFromUrl(params);
this._getResults(params);
});
}
public ngOnDestroy() {
if(this.sub){
this.sub.unsubscribe();
}
if(this.subResults){
this.subResults.unsubscribe();
} }
private _getResults(params){
//this.csvParams = this.resourcesQuery+"&type=datasources";
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
this.disableForms = true;
this.enableSearchView = false;
this.results = [];
this.searchUtils.totalResults = 0;
let size: number = 0;
this.subResults = this._searchDataprovidersService.searchCompatibleDataprovidersTable(this.properties).subscribe(
data => {
size = data;
if(size > 0) {
this.subResults = this._searchDataprovidersService.searchCompatibleDataproviders("", null, 1, size, [],this.properties).subscribe(
data => {
this.filters = this.createFilters(data[1], params);
this.searchUtils.totalResults = data[0];
this.results = data[1];
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;
} else {
this.searchPage.triggerInitialLoad();
this.searchPage.transform(this.results);
this.disableForms = false;
}
this.enableSearchView = true;
},
err => {
//console.log(err);
this.handleError("Error getting compatible content providers", err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
//TODO check erros (service not available, bad request)
// if( ){
// this.searchUtils.status = ErrorCodes.ERROR;
// }
//var errorCodes:ErrorCodes = new ErrorCodes();
//this.searchUtils.status = errorCodes.ERROR;
/*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.enableSearchView = true;
}
);
} else {
this.searchPage.checkSelectedFilters(this.filters);
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.NONE;
this.enableSearchView = true;
}
},
err => {
//console.log(err);
this.handleError("Error getting compatible content providers (size=0)", err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
//TODO check erros (service not available, bad request)
// if( ){
// this.searchUtils.status = ErrorCodes.ERROR;
// }
//var errorCodes:ErrorCodes = new ErrorCodes();
//this.searchUtils.status = errorCodes.ERROR;
/*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.enableSearchView = true;
}
);
}
private setFilters(){
//TODO set filters from
}
private createFilters(data, params):Filter[] {
let length = Array.isArray(data) ? data.length : 1;
var filter_names=["Type","Compatibility","Country"];
var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname","datasourcecountryname"];
var searchFields = new SearchFields();
var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
filter_original_ids.push("datasourcecountryname");
var filter_valueIsExact = [true, true, false];
//this.refineFields = ["relfunder"];
//this.searchPage.refineFields = this.refineFields;
this.searchPage.getParametersFromUrl(params);
var value_names=[
/*[
"Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
"Institutional Repositories Aggregators",
"Thematic Repositories Aggregators", "Other Repositories Aggregators",
"Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
*/
[
"Institutional Repository", "Thematic Repository", "Publication Repository",
"Institutional Repository Aggregator",
"Thematic Repository Aggregator", "Publication Repository Aggregator",
"Data Repository", "Data Repository Aggregator", "CRIS Systems", "Publication Catalogue",
"Software Repository", "Software Repository Aggregator"],
["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)",
"collected from a compatible aggregator", "proprietary", "under validation"]];
var value_original_ids=[
["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::institutional","aggregator::pubsrepository::thematic","aggregator::pubsrepository::unknown",
"datarepository::unknown", "aggregator::datarepository", "cris", "pubscatalogue::unknown", "softwarerepository", "aggregator::softwarerepository"],
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)",
"collected from a compatible aggregator", "proprietary", "under validation"]];
var countries = new Set();
var value_name = [];
var value_original_id = [];
let i, j;
for(i=0; i