2020-04-03 18:02:40 +02:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
2018-03-02 13:52:12 +01:00
|
|
|
import { ActivatedRoute} from '@angular/router';
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
2019-02-19 13:17:53 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
2020-04-03 18:02:40 +02:00
|
|
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
2018-03-02 13:52:12 +01:00
|
|
|
import {SearchPageTableViewComponent } from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.component';
|
2020-04-03 18:02:40 +02:00
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
2018-03-02 13:52:12 +01:00
|
|
|
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';
|
2020-11-12 16:59:26 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2020-11-30 18:04:05 +01:00
|
|
|
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
|
|
|
|
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
|
|
|
|
import {Subscriber} from "rxjs";
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openaire-search-dataproviders',
|
|
|
|
template: `
|
|
|
|
|
2019-08-02 16:56:03 +02:00
|
|
|
<search-page-table pageTitle="Search Content Providers"
|
2018-03-02 13:52:12 +01:00
|
|
|
type="content providers" entityType="dataprovider"
|
2020-04-03 18:02:40 +02:00
|
|
|
[results] = "results" [searchUtils] = "searchUtils"
|
2018-03-02 13:52:12 +01:00
|
|
|
[columnNames]="columnNames"
|
|
|
|
[showResultCount]=false
|
2020-11-30 18:04:05 +01:00
|
|
|
[openaireLink]="'https://' + (properties.environment == 'production'?'':'beta.') + 'explore.openaire.eu/search/find/dataproviders'"
|
2018-03-02 13:52:12 +01:00
|
|
|
[disableForms]="disableForms"
|
2018-05-23 15:29:07 +02:00
|
|
|
[enableSearchView]="enableSearchView"
|
2018-03-02 13:52:12 +01:00
|
|
|
searchFormClass="datasourcesTableSearchForm"
|
2020-05-07 12:29:52 +02:00
|
|
|
formPlaceholderText="Search by name..."
|
2020-04-27 10:22:46 +02:00
|
|
|
[piwikSiteId]="piwikSiteId" [hasPrefix]="false" [customFilter]="customFilter" [enableEntitySelection]="true"
|
2020-05-07 12:29:52 +02:00
|
|
|
[includeOnlyResultsAndFilter]="false" [showBreadcrumb]="true">
|
2018-03-02 13:52:12 +01:00
|
|
|
</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;
|
2019-02-19 13:17:53 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2018-03-02 13:52:12 +01:00
|
|
|
public columnNames = ['Name', 'Official Name'];
|
|
|
|
public results =[];
|
|
|
|
public filters =[];
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = [];// = this.searchFields.JOURNAL_FIELDS;
|
2021-02-19 18:52:12 +01:00
|
|
|
properties:EnvProperties= properties;
|
2018-03-02 13:52:12 +01:00
|
|
|
|
|
|
|
public disableForms: boolean = false;
|
2018-05-23 15:29:07 +02:00
|
|
|
public enableSearchView: boolean = true;
|
2018-03-02 13:52:12 +01:00
|
|
|
|
2018-03-02 14:10:15 +01:00
|
|
|
private communityId: string = '';
|
2020-11-30 18:04:05 +01:00
|
|
|
subscriptions = [];
|
2018-03-02 13:52:12 +01:00
|
|
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
2018-04-11 12:40:29 +02:00
|
|
|
piwikSiteId = null;
|
2020-04-03 18:02:40 +02:00
|
|
|
customFilter: SearchCustomFilter = null;
|
2020-04-23 15:35:54 +02:00
|
|
|
initialLoad = true;
|
2020-11-30 18:04:05 +01:00
|
|
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchCommunityDataprovidersService, private _communitiesService: CommunitiesService, private _communityService: CommunityService) {
|
2018-03-02 13:52:12 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
2019-02-19 13:17:53 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2018-03-02 13:52:12 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2019-03-01 12:34:19 +01:00
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2020-11-30 18:04:05 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
2021-02-19 18:52:12 +01:00
|
|
|
this.subscriptions.push(this._communityService.getCommunityAsObservable().subscribe(community =>{
|
|
|
|
if(community != null) {
|
|
|
|
this.communityId = community.communityId;
|
|
|
|
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, community.shortTitle);
|
|
|
|
this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment);
|
|
|
|
this.searchUtils.keyword = (params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
|
|
|
//this.filters = this.createFilters();
|
|
|
|
//this.searchPage.getParametersFromUrl(params);
|
|
|
|
if(this.initialLoad) {
|
|
|
|
this.initialLoad = false;
|
|
|
|
console.log("Init get results")
|
|
|
|
this._getResults(params);
|
|
|
|
} else {
|
|
|
|
// this.searchPage.transform(this.results);
|
|
|
|
this.searchPage.goTo(1);
|
|
|
|
console.log("Init transfrm " + this.searchUtils.keyword)
|
|
|
|
}
|
2020-11-30 18:04:05 +01:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
2020-11-12 16:59:26 +01:00
|
|
|
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2020-11-30 18:04:05 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
|
|
|
private _getResults(params){
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = false;
|
2018-03-02 13:52:12 +01:00
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
|
|
|
let size: number = 0;
|
|
|
|
|
2020-11-30 18:04:05 +01:00
|
|
|
this.subscriptions.push(this._searchDataprovidersService.searchDataproviders(this.properties, this.communityId).subscribe(
|
2018-03-02 13:52:12 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data.length;
|
|
|
|
this.results = data;
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
2018-05-23 15:29:07 +02:00
|
|
|
} else {
|
|
|
|
this.searchPage.triggerInitialLoad();
|
2020-05-11 13:07:36 +02:00
|
|
|
this.searchPage.transform(this.results, this.searchUtils);
|
2018-05-23 15:29:07 +02:00
|
|
|
this.disableForms = false;
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = true;
|
2018-03-02 13:52:12 +01:00
|
|
|
},
|
|
|
|
err => {
|
2019-02-19 13:17:53 +01:00
|
|
|
/*
|
2018-03-02 13:52:12 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
*/
|
|
|
|
this.handleError("Error getting content providers for community with id: "+this.communityId, err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
2018-03-02 13:52:12 +01:00
|
|
|
|
2018-05-23 15:29:07 +02:00
|
|
|
this.enableSearchView = true;
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
2020-11-30 18:04:05 +01:00
|
|
|
));
|
2018-03-02 13:52:12 +01:00
|
|
|
}
|
2019-02-19 13:17:53 +01:00
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Content Providers simple Search Page: "+message, error);
|
|
|
|
}
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|