openaire-library/searchPages/dataProviders/entityRegistries.component.ts

187 lines
8.3 KiB
TypeScript

import {Component, Input, ViewChild} from '@angular/core';
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 {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
import {SearchPageComponent } from '../searchUtils/searchPage.component';
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
import{EnvProperties} from '../../utils/properties/env-properties';
@Component({
selector: 'search-entity-registries',
template: `
<search-page pageTitle="Registries/ Databases"
formPlaceholderText = "Search for Registries/ Databases"
type="content providers" entityType="dataprovider" [(filters)] = "filters"
[(results)] = "results" [(searchUtils)] = "searchUtils"
[baseUrl] = "baseUrl" [showResultCount]=false
(queryChange)="queryChanged($event)"
[csvParams]="csvParams" csvPath="resources"
[disableForms]="disableForms"
[tableViewLink]="'/search/entity-registries-table'"
searchFormClass="entityRegistriesSearchForm">
</search-page>
`
})
export class SearchEntityRegistriesComponent {
private errorCodes: ErrorCodes;
public results =[];
public filters =[];
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.ENTITY_REGISTRIES_FIELDS;
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
public _prefixQueryFields: {field:string,opName:string,opValue:string,values:string[]}[] =[
{field:"type",opName:"tp",opValue:"and",values: ["other"]}];
// ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
public _prefixQuery: string = "";
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
"export":[]
};
public CSVDownloaded = false;
public disableForms: boolean = false;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
public resourcesQuery = "&query=((oaftype exact datasource) and(datasourcetypeuiid = other))";
public csvParams: string;
properties:EnvProperties;
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
this.errorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
for(var i = 0; i < this._prefixQueryFields.length; i++ ){
for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
+ this._prefixQueryFields[i].values[j] + "&" +
this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
}
}
this._prefixQuery+="&";
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.baseUrl = data.envSpecific.searchLinkToEntityRegistriesDataProviders;
});
this.searchPage.refineFields = this.refineFields;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
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();
var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
});
}
public ngOnDestroy() {
if(this.sub){
this.sub.unsubscribe();
}
if(this.subResults){
this.subResults.unsubscribe();
} }
private _getResults(parameters:string,refine:boolean, page: number, size: number){
this.csvParams = parameters+this.resourcesQuery+"&type=datasources";
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
//this.searchPage.openLoading();
this.disableForms = true;
this.results = [];
this.searchUtils.totalResults = 0;
this.subResults = this._searchDataprovidersService.searchEntityRegistries(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, [],this.properties).subscribe(
data => {
this.searchUtils.totalResults = data[0];
console.info("search Entity Registries: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
this.results = data[1];
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(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.searchPage.closeLoading();
this.disableForms = false;
},
err => {
console.log(err);
//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.searchPage.closeLoading();
this.disableForms = false;
}
);
}
private setFilters(){
//TODO set filters from
}
public queryChanged($event) {
var parameters = $event.index;
console.info("queryChanged: Execute search query "+parameters);
this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
}
private createFilters():Filter[] {
var filter_names=["Type","Compatibility Level"];
var filter_ids=["datasourcetypename","datasourcecompatibilityname"];
var searchFields = new SearchFields();
var filter_original_ids = searchFields.ENTITY_REGISTRIES_FIELDS;
var value_names=[
["Funder","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
["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=[
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
//["entityregistry::projects","entityregistry::repositories","scholarcomminfra","entityregistry","infospace","websource"],
//["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 filters: Filter[] =[];
for(var 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);
}
return filters;
}
}