openaire-library/searchPages/searchDataProviders.compone...

230 lines
10 KiB
TypeScript
Raw Normal View History

import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {AdvancedField} from './searchUtils/searchHelperClasses.class';
import {SearchDataprovidersService} from '../services/searchDataproviders.service';
import {ErrorCodes} from '../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../utils/errorMessages.component';
import {SearchFields} from '../utils/properties/searchFields';
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils/searchUtils.class';
import {EnvProperties} from '../utils/properties/env-properties';
import {NewSearchPageComponent} from "./searchUtils/newSearchPage.component";
import {DatasourcesHelperClass} from "./searchUtils/datasourcesHelper.class";
@Component({
selector: 'search-dataproviders',
template: `
<new-search-page
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ pageTitle }}"
entityType="dataprovider"
type="content providers"
[results]="results"
[searchUtils]="searchUtils"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[csvParams]="csvParams" csvPath="datasources"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
[disableForms]="disableForms"
[loadPaging]="loadPaging"
[oldTotalResults]="oldTotalResults"
[openaireLink]=openaireLink
[includeOnlyResultsAndFilter]="includeOnlyResultsAndFilter"
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
[searchFormClass]="type!='deposit'?'datasourcesSearchForm':''"
[entitiesSelection]="type=='all'" [showAdvancedSearchLink]="type=='all'"
[filters]="filters"
[simpleView]="simpleView" formPlaceholderText="Search by name, description, subject..."
[showResultCount]="(type=='all' || type == 'deposit')" [showLastIndex]="type!='deposit'"
[tableViewLink]="tableViewLink"
[sort]="false">
</new-search-page>
[Trunk | Library]: 1. src/assets/common-assets/common/custom.css: Add 'font-display: swap;' in '@font-face' css rules - improve performance. 2. dataProvider.component.html & organizations.component.html & project.component.html & resultLanding.component.html: Add check if 'indexUpdateDate' is initialized. 3. dataProvider.component.ts & organization.component.ts & project.component.ts & resultLanding.component.ts: Initialize 'indexUpdateDate' and tabs counts only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 4. resultLanding.component.ts: Get "provenanceActionVocabulary" and "altMetrics" only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 5. organization.component.ts: [Bug fix] Get 'indexUpdateDate' from service (not properties) if available. 6. project.component.ts: [Bug fix] Call 'getProjectInfo()' only once (was called twice). 7. project.service.ts: [Bug fix] Add check for rels.rel.to.class=="hasParticipant" (when not array). 8. metrics.component.ts: Get metrics if "typeof document !== 'undefined'" (javascript is enabled) | Show charts only if user clicked on metrics badge | Do not set "width" for <i-frame> elements. 9. iframe.component.ts: Add case when only height is sent as input. 10. searchDataProviders.component.ts & searchOrganizations.component.ts: [Bug fix] Set "firstLoad" to false after getting results (was asking refine filters in paging too). 11. search-tab.component.ts: [Bug fix]: In method "getEntityName()" add cases when 'entityType == "project"' and 'entityType == "dataprovider"' and fix case when 'entityType == "result"'. 12. navigationBar.component.ts: [Bug fix] Do not initialize navbar inside route.queryParams subscription - !!! check it carefully when deployed in all portals !!! . git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58874 d315682c-612b-4755-9ff5-7f18f6832af3
2020-06-10 13:05:59 +02:00
<!-- [filters]="filters"-->
`
})
export class SearchDataProvidersComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
@Input() piwikSiteId = null;
@Input() customFilter:SearchCustomFilter= null;
@Input() tableViewLink;
public results =[];
public filters =[];
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public searchFields:SearchFields = new SearchFields();
public fieldIds: string[] = this.searchFields.DATASOURCE_ADVANCED_FIELDS;
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
public selectedFields:AdvancedField[] = [];
public resourcesQuery = "(oaftype exact datasource)";
public csvParams: string;
public disableForms: boolean = false;
public loadPaging: boolean = true;
public oldTotalResults: number = 0;
public pagingLimit: number = 0;
public isPiwikEnabled;
properties:EnvProperties;
@Input() type: "all" | "registries" | "journals" | "compatible" | "deposit" = "all";
public refineFields: string[];
pageTitle;
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
@Input() simpleView: boolean = true;
@Input() simpleSearchLink: string = "";
advancedSearchLink: string = "";
@Input() hasPrefix: boolean = true;
@Input() openaireLink: string;
@Input() includeOnlyResultsAndFilter: boolean = false;
@Output() searchPageUpdates = new EventEmitter();
constructor (private route: ActivatedRoute, private _searchDataProvidersService: SearchDataprovidersService ) {
this.results =[];
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
}
ngOnInit() {
this.refineFields = DatasourcesHelperClass.getrefineFields(this.type);
this.pageTitle = DatasourcesHelperClass.getTitle(this.type);
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties= data.envSpecific;
if (!this.simpleSearchLink) {
this.simpleSearchLink = this.properties.searchLinkToDataProviders;
} this.advancedSearchLink = this.properties.searchLinkToAdvancedDataProviders;
this.searchUtils.baseUrl = (this.simpleView)?this.simpleSearchLink:this.advancedSearchLink;
this.pagingLimit = data.envSpecific.pagingLimit;
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
});
let firstLoad = true;
this.filters = DatasourcesHelperClass.createFilters(this.type);
this.sub = this.route.queryParams.subscribe(params => {
this.loadPaging = true;
if(params['page'] && this.searchUtils.page != params['page']) {
this.loadPaging = false;
this.oldTotalResults = this.searchUtils.totalResults;
}
var refine = true;
if (this.searchUtils.page != ((params['page'] === undefined) ? 1 : +params['page']) && this.filters && !firstLoad) {
refine = false;
}
let page = (params['page']=== undefined)?0:+params['page'];
this.searchUtils.page = ( page < 1 ) ? 1 : page;
this.searchUtils.size = (params['size']=== undefined)?10:+params['size'];
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
this.searchUtils.size = 10;
}
this.searchPage.fieldIds = this.fieldIds;
this.selectedFields =[];
if(this.type == "deposit"){
this.searchPage.keywordFields = this.searchFields.DEPOSIT_DATASOURCE_KEYWORD_FIELDS;
this.searchPage.usedBy = "deposit";
}
// console.log(this.refineFields)
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap,this.customFilter,params, "dataprovider");
this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad));
[Trunk | Library]: 1. src/assets/common-assets/common/custom.css: Add 'font-display: swap;' in '@font-face' css rules - improve performance. 2. dataProvider.component.html & organizations.component.html & project.component.html & resultLanding.component.html: Add check if 'indexUpdateDate' is initialized. 3. dataProvider.component.ts & organization.component.ts & project.component.ts & resultLanding.component.ts: Initialize 'indexUpdateDate' and tabs counts only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 4. resultLanding.component.ts: Get "provenanceActionVocabulary" and "altMetrics" only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 5. organization.component.ts: [Bug fix] Get 'indexUpdateDate' from service (not properties) if available. 6. project.component.ts: [Bug fix] Call 'getProjectInfo()' only once (was called twice). 7. project.service.ts: [Bug fix] Add check for rels.rel.to.class=="hasParticipant" (when not array). 8. metrics.component.ts: Get metrics if "typeof document !== 'undefined'" (javascript is enabled) | Show charts only if user clicked on metrics badge | Do not set "width" for <i-frame> elements. 9. iframe.component.ts: Add case when only height is sent as input. 10. searchDataProviders.component.ts & searchOrganizations.component.ts: [Bug fix] Set "firstLoad" to false after getting results (was asking refine filters in paging too). 11. search-tab.component.ts: [Bug fix]: In method "getEntityName()" add cases when 'entityType == "project"' and 'entityType == "dataprovider"' and fix case when 'entityType == "result"'. 12. navigationBar.component.ts: [Bug fix] Do not initialize navbar inside route.queryParams subscription - !!! check it carefully when deployed in all portals !!! . git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58874 d315682c-612b-4755-9ff5-7f18f6832af3
2020-06-10 13:05:59 +02:00
firstLoad = false;
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
sub: any;
public getResults(parameters:string, page: number, size: number, refine: boolean, refineFieldsFilterQuery = null){
if(page > this.pagingLimit ) {
size=0;
}
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
// if(parameters!= null && parameters != '' ) {
// this.csvParams ="&fq=( "+this.resourcesQuery + "and (" + parameters + "))";
// }else{
// this.csvParams ="&fq="+this.resourcesQuery;
// }
// this.csvParams += (refineFieldsFilterQuery?refineFieldsFilterQuery:'');
this.csvParams = (parameters ? ("&fq=("+parameters) : "") + (parameters ? ")" : "");
this.csvParams += (refineFieldsFilterQuery ? refineFieldsFilterQuery : "");
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
//this.searchPage.openLoading();
this.disableForms = true;
this.searchPageUpdates.emit({disableForms: this.disableForms,searchUtils: this.searchUtils});
this.results = [];
this.searchUtils.totalResults = 0;
//console.info("Advanced Search for Content Providers: Execute search query "+parameters);
let datasourceQueryPrefix = DatasourcesHelperClass.getQueryPrefix(this.type);
this._searchDataProvidersService.advancedSearchDataproviders( datasourceQueryPrefix +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' and (':'') + parameters +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' ) ':''), page, size, this.properties, (refine && (this.type=="all" || this.type == "deposit")) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery, (this.type == "deposit")).subscribe(
data => {
this.searchUtils.totalResults = data[0];
this.results = data[1];
//console.log(this.results);
if (refine) {
[Trunk | Library]: 1. src/assets/common-assets/common/custom.css: Add 'font-display: swap;' in '@font-face' css rules - improve performance. 2. dataProvider.component.html & organizations.component.html & project.component.html & resultLanding.component.html: Add check if 'indexUpdateDate' is initialized. 3. dataProvider.component.ts & organization.component.ts & project.component.ts & resultLanding.component.ts: Initialize 'indexUpdateDate' and tabs counts only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 4. resultLanding.component.ts: Get "provenanceActionVocabulary" and "altMetrics" only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 5. organization.component.ts: [Bug fix] Get 'indexUpdateDate' from service (not properties) if available. 6. project.component.ts: [Bug fix] Call 'getProjectInfo()' only once (was called twice). 7. project.service.ts: [Bug fix] Add check for rels.rel.to.class=="hasParticipant" (when not array). 8. metrics.component.ts: Get metrics if "typeof document !== 'undefined'" (javascript is enabled) | Show charts only if user clicked on metrics badge | Do not set "width" for <i-frame> elements. 9. iframe.component.ts: Add case when only height is sent as input. 10. searchDataProviders.component.ts & searchOrganizations.component.ts: [Bug fix] Set "firstLoad" to false after getting results (was asking refine filters in paging too). 11. search-tab.component.ts: [Bug fix]: In method "getEntityName()" add cases when 'entityType == "project"' and 'entityType == "dataprovider"' and fix case when 'entityType == "result"'. 12. navigationBar.component.ts: [Bug fix] Do not initialize navbar inside route.queryParams subscription - !!! check it carefully when deployed in all portals !!! . git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58874 d315682c-612b-4755-9ff5-7f18f6832af3
2020-06-10 13:05:59 +02:00
this.filters =
this.searchPage.prepareFiltersToShow((this.type=="all" || this.type == "deposit")?data[2]:this.filters, this.searchUtils.totalResults);
}else{
this.searchPage.buildPageURLParameters(this.filters, [], false);
}
// this.searchPage.updateBaseUrlWithParameters();
//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;
this.searchPageUpdates.emit({disableForms: this.disableForms,searchUtils: this.searchUtils});
if(this.searchUtils.status == this.errorCodes.DONE) {
// Page out of limit
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1);
}
if(totalPages < page) {
this.searchUtils.totalResults = 0;
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
}
}
},
err => {
//console.log(err);
this.handleError("Error getting 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.NOT_AVAILABLE;
/*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;
this.searchPageUpdates.emit({disableForms: this.disableForms,searchUtils: this.searchUtils});
}
);
}
}
private handleError(message: string, error) {
console.error("Content Providers advanced Search Page: "+message, error);
}
}