2020-04-03 18:02:40 +02:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
2023-07-13 10:48:23 +02:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2018-03-02 13:52:12 +01:00
|
|
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
2023-07-13 10:48:23 +02:00
|
|
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
2020-04-03 18:02:40 +02:00
|
|
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
|
|
|
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';
|
2023-07-13 10:48:23 +02:00
|
|
|
import {
|
|
|
|
SearchCommunityDataprovidersService
|
|
|
|
} from '../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
|
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";
|
2021-03-08 16:40:49 +01:00
|
|
|
import {AdvancedField} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
|
|
|
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
|
|
|
import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult";
|
2018-01-26 16:00:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'openaire-search-dataproviders',
|
|
|
|
template: `
|
2021-03-08 16:40:49 +01:00
|
|
|
|
2023-07-24 18:19:26 +02:00
|
|
|
<new-search-page
|
2021-03-08 16:40:49 +01:00
|
|
|
pageTitle="Search Content Providers"
|
|
|
|
entityType="dataprovider"
|
|
|
|
type=" Content provider"
|
|
|
|
[results]="results"
|
|
|
|
[searchUtils]="searchUtils"
|
2023-07-24 18:19:26 +02:00
|
|
|
[sortedByChanged]="searchUtils.sortBy"
|
2021-03-08 16:40:49 +01:00
|
|
|
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
|
2023-07-24 18:19:26 +02:00
|
|
|
[simpleSearchLink]="properties.searchLinkToDataProviders"
|
2021-03-08 16:40:49 +01:00
|
|
|
[disableForms]="disableForms"
|
|
|
|
[disableRefineForms]="disableRefineForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
|
|
|
[openaireLink]="'https://' + (properties.environment == 'production'?'':'beta.') + 'explore.openaire.eu/search/find/dataproviders'"
|
|
|
|
[includeOnlyResultsAndFilter]="false"
|
2023-07-13 10:48:23 +02:00
|
|
|
[hasPrefix]="false"
|
2023-07-24 18:19:26 +02:00
|
|
|
searchFormClass="datasourcesTableSearchForm" [entitiesSelection]="false" [showSwitchSearchLink]="false"
|
2021-03-08 16:40:49 +01:00
|
|
|
[filters]="filters"
|
|
|
|
[simpleView]="true" formPlaceholderText="Search by name..."
|
|
|
|
[showResultCount]="false" [showIndexInfo]="false" [showDownload]="false"
|
2022-07-21 09:46:39 +02:00
|
|
|
[sort]="false" [showBreadcrumb]="true"
|
|
|
|
[customFilter]=customFilter [searchForm]="{dark: false, class: 'search-form'}">
|
2021-03-08 16:40:49 +01:00
|
|
|
</new-search-page>
|
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 = [];
|
2020-04-03 18:02:40 +02:00
|
|
|
customFilter: SearchCustomFilter = null;
|
2020-04-23 15:35:54 +02:00
|
|
|
initialLoad = true;
|
2021-03-08 16:40:49 +01:00
|
|
|
public allResults =[];
|
2021-07-14 16:51:20 +02:00
|
|
|
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent;
|
2021-03-08 16:40:49 +01:00
|
|
|
public fieldIds: string[] = this.searchFields.DATASOURCE_ADVANCED_FIELDS;
|
|
|
|
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
|
|
|
public selectedFields:AdvancedField[] = [];
|
|
|
|
public disableRefineForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
|
|
|
keyword;
|
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() {
|
2021-03-08 16:40:49 +01:00
|
|
|
this.searchUtils.baseUrl = this.properties.searchLinkToDataProviders;
|
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);
|
2021-03-08 16:40:49 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
this.searchUtils.page = (page <= 0) ? 1 : page;
|
2021-08-13 14:48:41 +02:00
|
|
|
this.searchUtils.validateSize(params['size']);
|
2021-03-26 16:54:07 +01:00
|
|
|
this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
2021-03-08 16:40:49 +01:00
|
|
|
this.selectedFields = [];
|
|
|
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, [], [], this.fieldIdsMap, this.customFilter, params, "dataprovider");
|
|
|
|
if (this.initialLoad) {
|
|
|
|
this.initialLoad = false;
|
|
|
|
this._getResults();
|
|
|
|
} else {
|
|
|
|
this.filterResults();
|
|
|
|
}
|
|
|
|
}));
|
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
|
|
|
}
|
2021-03-08 16:40:49 +01:00
|
|
|
private _getResults(){
|
2018-03-02 13:52:12 +01:00
|
|
|
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;
|
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 => {
|
2021-03-08 16:40:49 +01:00
|
|
|
this.allResults = this.parseResults(data);
|
2018-03-02 13:52:12 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
2021-03-08 16:40:49 +01:00
|
|
|
this.filterResults();
|
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
|
|
|
}
|
2021-03-08 16:40:49 +01:00
|
|
|
parseResults(data){
|
|
|
|
let results:SearchResult[]=[];
|
|
|
|
for(let result of data){
|
|
|
|
let sResult:SearchResult = new SearchResult();
|
|
|
|
sResult.id = result.openaireId;
|
2022-06-16 14:01:41 +02:00
|
|
|
sResult.title = {name:"", accessMode: null};
|
2021-03-08 16:40:49 +01:00
|
|
|
sResult.title.name = result.officialname?result.officialname:result.name;
|
|
|
|
results.push(sResult);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
filterResults(){
|
2021-03-26 16:54:07 +01:00
|
|
|
let results = this.allResults.filter(value => {return value.title.name && value.title.name.toLowerCase().indexOf(this.keyword.toLowerCase()) !=-1 });
|
2021-03-08 16:40:49 +01:00
|
|
|
// this.oldTotalResults = results.length;
|
|
|
|
this.searchUtils.totalResults = results.length;
|
|
|
|
this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size );
|
|
|
|
this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE;
|
|
|
|
this.searchPage.buildPageURLParameters(this.filters, [], false);
|
|
|
|
this.disableForms = false;
|
|
|
|
this.enableSearchView = true;
|
|
|
|
}
|
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
|
|
|
}
|