[Library|Trunk]

New Search:
	Create pages for project, organizations, datasources
	Add checks in new search page 


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58073 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2020-02-11 14:56:20 +00:00
parent 32e65be516
commit cce694ca7f
13 changed files with 748 additions and 40 deletions

View File

@ -0,0 +1,206 @@
import {Component, Input, 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";
@Component({
selector: 'search-dataproviders',
template: `
<new-search-page
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ 'content providers' | titlecase }}"
entityType="content provider"
type="content providers"
[(results)]="results"
[(searchUtils)]="searchUtils"
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
[csvParams]="csvParams" csvPath="projects"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
[disableForms]="disableForms"
[loadPaging]="loadPaging"
[oldTotalResults]="oldTotalResults"
[(openaireLink)]=openaireLink
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
searchFormClass="datasourcesSearchForm"
[(filters)]="filters"
[simpleView]="simpleView" formPlaceholderText="Search by title, country, organization, subject, type..."
>
</new-search-page>
`
})
export class SearchDataProvidersComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
@Input() piwikSiteId = null;
@Input() customFilter:SearchCustomFilter= null;
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;
public refineFields: string[] = this.searchFields.DATASOURCE_REFINE_FIELDS;
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
@Input() simpleView: boolean = true;
simpleSearchLink: string = "";
advancedSearchLink: string = "";
@Input() hasPrefix: boolean = true;
@Input() openaireLink: string;
constructor (private route: ActivatedRoute, private _searchDataProvidersService: SearchDataprovidersService ) {
this.results =[];
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
//console.info("Con -base url:"+this.searchUtils.baseUrl );
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties= data.envSpecific;
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;
});
var firstLoad = true;
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 =[];
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, this.fieldIdsMap,this.customFilter,params, "datasource");
// this.searchPage.selectedFields = this.selectedFields;
// this.searchPage.fieldIdsMap = this.fieldIdsMap;
// this.searchPage.customFilter = this.customFilter;
// this.searchPage.getSelectedFiltersFromUrl(params);
this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad));
});
}
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:'');
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
//this.searchPage.openLoading();
this.disableForms = true;
this.results = [];
this.searchUtils.totalResults = 0;
//console.info("Advanced Search for Content Providers: Execute search query "+parameters);
this._searchDataProvidersService.advancedSearchDataproviders(parameters, page, size, this.properties, (refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery).subscribe(
data => {
this.searchUtils.totalResults = data[0];
this.results = data[1];
if (refine) {
this.filters = this.searchPage.prepareFiltersToShow(data[2]);
}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;
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;
}
);
}
}
private handleError(message: string, error) {
console.error("Content Providers advanced Search Page: "+message, error);
}
}

View File

@ -0,0 +1,26 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {FreeGuard} from '../login/freeGuard.guard';
import {IsRouteEnabled} from '../error/isRouteEnabled.guard';
import {NewSearchPageModule} from "./searchUtils/newSearchPage.module";
import {DataProvidersServiceModule} from "../services/dataProvidersService.module";
import {SearchDataProvidersComponent} from "./searchDataProviders.component";
@NgModule({
imports: [
CommonModule, FormsModule,
DataProvidersServiceModule,
NewSearchPageModule
],
declarations: [
SearchDataProvidersComponent
],
providers: [FreeGuard, IsRouteEnabled],
exports: [
SearchDataProvidersComponent
]
})
export class SearchDataProvidersModule { }

View File

@ -0,0 +1,208 @@
import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {AdvancedField} from './searchUtils/searchHelperClasses.class';
import {SearchOrganizationsService} from '../services/searchOrganizations.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";
@Component({
selector: 'search-organizations',
template: `
<new-search-page
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ 'organizations' | titlecase }}"
entityType="organization"
type="organizations"
[(results)]="results"
[(searchUtils)]="searchUtils"
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
[csvParams]="csvParams" csvPath="organizations"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
[disableForms]="disableForms"
[loadPaging]="loadPaging"
[oldTotalResults]="oldTotalResults"
[(openaireLink)]=openaireLink
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
searchFormClass="organizationSearchForm"
[(filters)]="filters"
[simpleView]="simpleView" formPlaceholderText="Search by title, author, doi, abstract content..."
>
</new-search-page>
`
})
export class SearchOrganizationsComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
properties:EnvProperties;
@Input() piwikSiteId = null;
public results =[];
public filters =[];
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public searchFields:SearchFields = new SearchFields();
public fieldIds: string[] = this.searchFields.ORGANIZATION_ADVANCED_FIELDS;
public fieldIdsMap = this.searchFields.ORGANIZATION_FIELDS;
public selectedFields:AdvancedField[] = [];
public csvParams: string;
public disableForms: boolean = false;
public loadPaging: boolean = true;
public oldTotalResults: number = 0;
public pagingLimit: number = 0;
public isPiwikEnabled;
@Input() customFilter:SearchCustomFilter= null;
public refineFields: string[] = this.searchFields.ORGANIZATION_REFINE_FIELDS;
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
@Input() simpleView: boolean = true;
simpleSearchLink: string = "";
advancedSearchLink: string = "";
@Input() hasPrefix: boolean = true;
@Input() openaireLink: string;
public resourcesQuery = "(oaftype exact organization)";
constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) {
this.results =[];
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties= data.envSpecific;
this.simpleSearchLink = this.properties.searchLinkToProjects;
this.advancedSearchLink = this.properties.searchLinkToAdvancedProjects;
this.searchUtils.baseUrl = (this.simpleView)?this.simpleSearchLink:this.advancedSearchLink;
this.pagingLimit = data.envSpecific.pagingLimit;
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
});
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
var firstLoad = true;
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)?1:+params['page'];
this.searchUtils.page = ( page <= 0 ) ? 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 =[];
// this.searchPage.selectedFields = this.selectedFields;
// this.searchPage.fieldIdsMap = this.fieldIdsMap;
// this.searchPage.customFilter = this.customFilter;
// this.searchPage.getSelectedFiltersFromUrl(params);
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, this.fieldIdsMap,this.customFilter,params, "organization");
this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad));
});
}
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;
}
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
//this.searchPage.openLoading();
this.disableForms = true;
this.results = [];
this.searchUtils.totalResults = 0;
//console.info("Advanced Search for Organizations: Execute search query "+parameters);
this._searchOrganizationsService.advancedSearchOrganizations(parameters, page, size, this.properties,(refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery).subscribe(
data => {
this.searchUtils.totalResults = data[0];
this.results = data[1];
if (refine) {
this.filters = this.searchPage.prepareFiltersToShow(data[2]);
}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;
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 organizations", 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;
}
);
}
}
private setFilters(){
//TODO set filters from
}
private handleError(message: string, error) {
console.error("Organizations advanced Search Page: "+message, error);
}
}

View File

@ -0,0 +1,26 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {FreeGuard} from '../login/freeGuard.guard';
import {IsRouteEnabled} from '../error/isRouteEnabled.guard';
import {NewSearchPageModule} from "./searchUtils/newSearchPage.module";
import {OrganizationsServiceModule} from "../services/organizationsService.module";
import {SearchOrganizationsComponent} from "./searchOrganizations.component";
@NgModule({
imports: [
CommonModule, FormsModule,
OrganizationsServiceModule,
NewSearchPageModule
],
declarations: [
SearchOrganizationsComponent
],
providers: [FreeGuard, IsRouteEnabled],
exports: [
SearchOrganizationsComponent
]
})
export class SearchOrganizationsModule { }

View File

@ -0,0 +1,211 @@
import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {AdvancedField} from './searchUtils/searchHelperClasses.class';
import {SearchProjectsService} from '../services/searchProjects.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";
@Component({
selector: 'search-projects',
template: `
<new-search-page
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ 'projects' | titlecase }}"
entityType="project"
type="projects"
[(results)]="results"
[(searchUtils)]="searchUtils"
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
[csvParams]="csvParams" csvPath="projects"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
[disableForms]="disableForms"
[loadPaging]="loadPaging"
[oldTotalResults]="oldTotalResults"
[(openaireLink)]=openaireLink
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
searchFormClass="projectSearchForm"
[(filters)]="filters"
[simpleView]="simpleView" formPlaceholderText="Search by title, author, doi, abstract content..."
>
</new-search-page>
`
})
export class SearchProjectsComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
@Input() piwikSiteId = null;
@Input() customFilter:SearchCustomFilter= null;
public results =[];
public filters =[];
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public searchFields:SearchFields = new SearchFields();
public fieldIds: string[] = this.searchFields.PROJECT_ADVANCED_FIELDS;
public fieldIdsMap = this.searchFields.PROJECT_FIELDS;
public selectedFields:AdvancedField[] = [];
properties:EnvProperties;
public resourcesQuery = "(oaftype exact project)";
public csvParams: string;
public disableForms: boolean = false;
public loadPaging: boolean = true;
public oldTotalResults: number = 0;
public pagingLimit: number = 0;
public isPiwikEnabled;
public refineFields: string[] = this.searchFields.PROJECT_REFINE_FIELDS;
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
@Input() simpleView: boolean = true;
simpleSearchLink: string = "";
advancedSearchLink: string = "";
@Input() hasPrefix: boolean = true;
@Input() openaireLink: string;
constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService ) {
this.results =[];
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties= data.envSpecific;
this.simpleSearchLink = this.properties.searchLinkToProjects;
this.advancedSearchLink = this.properties.searchLinkToAdvancedProjects;
this.searchUtils.baseUrl = (this.simpleView)?this.simpleSearchLink:this.advancedSearchLink;
this.pagingLimit = data.envSpecific.pagingLimit;
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
});
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
var firstLoad = true;
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)?1:+params['page'];
this.searchUtils.page = ( page <= 0 ) ? 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 = [];
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, this.fieldIdsMap,this.customFilter,params, "project");
// this.selectedFields =[];
// this.searchPage.selectedFields = this.selectedFields;
// this.searchPage.fieldIdsMap = this.fieldIdsMap;
// this.searchPage.customFilter = this.customFilter;
// this.searchPage.getSelectedFiltersFromUrl(params);
this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad));
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:'');
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
//this.searchPage.openLoading();
this.disableForms = true;
this.results = [];
this.searchUtils.totalResults = 0;
//console.info("Advanced Search for Publications: Execute search query "+parameters);
this._searchProjectsService.advancedSearchProjects(parameters, page, size, this.properties,(refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery).subscribe(
data => {
this.searchUtils.totalResults = data[0];
this.results = data[1];
// this.searchPage.updateBaseUrlWithParameters();
if (refine) {
this.filters = this.searchPage.prepareFiltersToShow(data[2]);
}else{
this.searchPage.buildPageURLParameters(this.filters, false);
}
//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;
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 projects", 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;
}
);
}
}
private handleError(message: string, error) {
console.error("Projects advanced Search Page: "+message, error);
}
}

View File

@ -0,0 +1,26 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {FreeGuard} from '../login/freeGuard.guard';
import {IsRouteEnabled} from '../error/isRouteEnabled.guard';
import {NewSearchPageModule} from "./searchUtils/newSearchPage.module";
import {SearchProjectsComponent} from "./searchProjects.component";
import {ProjectsServiceModule} from "../services/projectsService.module";
@NgModule({
imports: [
CommonModule, FormsModule,
ProjectsServiceModule,
NewSearchPageModule
],
declarations: [
SearchProjectsComponent
],
providers: [FreeGuard, IsRouteEnabled],
exports: [
SearchProjectsComponent
]
})
export class SearchProjectsModule {
}

View File

@ -1,6 +1,6 @@
import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {AdvancedField} from './searchUtils/searchHelperClasses.class';
import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class';
import {SearchResearchResultsService} from '../services/searchResearchResults.service';
import {ErrorCodes} from '../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../utils/errorMessages.component';
@ -13,7 +13,6 @@ import {NewSearchPageComponent} from "./searchUtils/newSearchPage.component";
@Component({
selector: 'search-research-results',
template: `
{{resultType}}
<new-search-page
pageTitle="{{(simpleView?'':'Advanced ')}} Search for {{ getEntityName(resultType, true, true) | titlecase }}"
[entityType]="resultType"
@ -30,7 +29,7 @@ import {NewSearchPageComponent} from "./searchUtils/newSearchPage.component";
[piwikSiteId]=piwikSiteId [hasPrefix]="hasPrefix"
searchFormClass="publicationsSearchForm"
[(sort)]=sort
[(filters)]="filters"
[(filters)]="filters" [quickFilter]="quickFilter"
[simpleView]="simpleView" formPlaceholderText="Search by title, author, doi, abstract content..."
>
</new-search-page>
@ -71,7 +70,12 @@ export class SearchResearchResultsComponent {
public refineFields: string[] = this.searchFields.RESULT_REFINE_FIELDS;
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
@Input() simpleView: boolean = true;
quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
filter: null,
selected: true,
filterId: "resultbestaccessright",
value: "Open Access"
};
constructor(private route: ActivatedRoute, private _searchResearchResultsService: SearchResearchResultsService) {
this.results = [];
this.errorCodes = new ErrorCodes();
@ -85,21 +89,11 @@ export class SearchResearchResultsComponent {
this.pagingLimit = data.envSpecific.pagingLimit;
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
// this.searchLink = "/search/research-results";
// this.searchUtils.baseUrl = this.searchLink;
this.simpleSearchLink = this.properties.searchLinkToResults;
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
this.searchUtils.baseUrl = (this.simpleView)?this.simpleSearchLink:this.advancedSearchLink;
// } else if(this.resultType == "dataset") {
// this.simpleSearchLink = this.properties.searchLinkToDatasets;
// this.searchUtils.baseUrl = this.properties.searchLinkToAdvancedDatasets;
// } else if(this.resultType == "software") {
// this.simpleSearchLink = this.properties.searchLinkToSoftware;
// this.searchUtils.baseUrl = this.properties.searchLinkToAdvancedSoftware;
// } else if(this.resultType == "other") {
// this.simpleSearchLink = this.properties.searchLinkToOrps;
// this.searchUtils.baseUrl = this.properties.searchLinkToAdvancedOrps;
// }
});
this.searchUtils.status = this.errorCodes.LOADING;

View File

@ -62,12 +62,7 @@ export class NewSearchPageComponent {
@Input() simpleView: boolean = true;
@Input() formPlaceholderText = "Type Keywords...";
@Input() @Output() resultTypes = null;
@Input() @Output() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
filter: null,
selected: true,
filterId: "resultbestaccessright",
value: "Open Access"
};
@Input() @Output() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
piwiksub: any;
public parameterNames: string[] = [];
@ -301,7 +296,7 @@ export class NewSearchPageComponent {
}
}
} else if (this.quickFilter.filterId == filter.filterId && this.quickFilter.selected) {
} else if (this.quickFilter && this.quickFilter.filterId == filter.filterId && this.quickFilter.selected) {
for (let filterValue of filter.values) {
if (filterValue.id == this.quickFilter.value) {
filterValue.selected = true;
@ -315,7 +310,7 @@ export class NewSearchPageComponent {
filterValue.selected = false;
}
}
if (filter.filterId == this.quickFilter.filterId) {
if (this.quickFilter && filter.filterId == this.quickFilter.filterId) {
this.quickFilter.filter = filter;
}
}
@ -548,6 +543,7 @@ export class NewSearchPageComponent {
/**
* Create Search API query based on the filters of refine fields
* @param URLparams
* @param firstLoad
*/
getSearchAPIQueryForRefineFields(URLparams, firstLoad: boolean) {
@ -764,7 +760,7 @@ export class NewSearchPageComponent {
let filterId = this.refineFields[i];
if (URLparams[filterId] != undefined) {
let filter = new Filter();
filter.title = fields.getFieldName(filterId, "publication");
filter.title = fields.getFieldName(filterId, this.entityType);
filter.filterId = filterId;
filter.originalFilterId = filterId;
filter.values = [];

View File

@ -107,10 +107,10 @@ export class QuickSelectionsComponent implements OnChanges {
setFormValues() {
this.control.setValue({
publication: this.resultTypes.publication,
dataset: this.resultTypes.dataset,
software: this.resultTypes.software,
other: this.resultTypes.software,
publication: (this.resultTypes && this.resultTypes.publication)?this.resultTypes.publication:null,
dataset: (this.resultTypes && this.resultTypes.dataset)?this.resultTypes.dataset:null,
software: (this.resultTypes && this.resultTypes.software)?this.resultTypes.software:null,
other: (this.resultTypes && this.resultTypes.other)?this.resultTypes.other:null,
QFselected: this.QFselected
});
}

View File

@ -34,7 +34,7 @@ export class SearchDataprovidersService {
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource", usedBy)]));
}
//((oaftype exact datasource) and(collectedfromdatasourceid exact "openaire____::47ce9e9f4fad46e732cff06419ecaabb"))
advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties ):any {
advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any {
let url = properties.searchResourcesAPIURL;
var basicQuery = "(oaftype exact datasource) " +
'and (datasourcecompatibilityid <> "UNKNOWN")';
@ -44,13 +44,18 @@ export class SearchDataprovidersService {
}else{
url +=" ( "+basicQuery+ " ) ";
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
if(refineQuery) {
url += "&" + refineQuery;
}
url += "&page="+(page-1)+"&size="+size+"&format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
//.do(res => console.info(res))
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]))
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]));
}
searchCompatibleDataprovidersTable ( properties:EnvProperties):any {

View File

@ -56,7 +56,7 @@ export class SearchOrganizationsService {
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")]));
}
advancedSearchOrganizations (params: string, page: number, size: number, properties:EnvProperties ):any {
advancedSearchOrganizations (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any {
let url = properties.searchResourcesAPIURL;
var basicQuery = "oaftype exact organization and "
+"(reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or " +
@ -69,14 +69,19 @@ export class SearchOrganizationsService {
}else{
url +=" ( "+basicQuery+ " ) ";
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
if(refineQuery) {
url += "&" + refineQuery;
}
url += "&page="+(page-1)+"&size="+size;
url += "&format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")]));
}
parseResults(data: any): SearchResult[] {
let results: SearchResult[] = [];

View File

@ -51,7 +51,7 @@ export class SearchProjectsService {
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
}
advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties ):any {
advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any {
let url = properties.searchResourcesAPIURL;
var basicQuery = "(oaftype exact project) "
url += "?query=";
@ -60,12 +60,17 @@ export class SearchProjectsService {
}else{
url +=" ( "+basicQuery+ " ) ";
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
if(refineQuery) {
url += "&" + refineQuery;
}
url += "&page="+(page-1)+"&size="+size;
url += "&format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
}
getProjectsForOrganizations (organizationId: string, filterquery: string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any {
let url = properties.searchResourcesAPIURL;

View File

@ -160,7 +160,7 @@ export class SearchFields {
constructor (){
}
getFieldName(fieldId:string,fieldType:string):string{
if(fieldType == "publication" || fieldType == "dataset" || fieldType == "software" || fieldType == "other"){
if(fieldType == "publication" || fieldType == "dataset" || fieldType == "software" || fieldType == "other" || fieldType == "result"){
return this.RESULT_FIELDS[fieldId].name;
}else if(fieldType == "project"){
return this.PROJECT_FIELDS[fieldId].name;
@ -174,7 +174,7 @@ export class SearchFields {
}
fieldHasUniqueValue(fieldId:string,fieldType:string,usedBy:string="search"):boolean{
if(fieldType == "publication" || fieldType == "dataset" || fieldType == "software" || fieldType == "other"){
if(fieldType == "publication" || fieldType == "dataset" || fieldType == "software" || fieldType == "other"|| fieldType == "result"){
return this.RESULT_FIELDS[fieldId].uniqueValue;
}else if(fieldType == "project"){
return this.PROJECT_FIELDS[fieldId].uniqueValue;