From c0e4df0714e2d9662aa0e9ad1cfde1bdc515757a Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 2 Mar 2018 12:52:12 +0000 Subject: [PATCH] 1. 'Search Content Providers' page gets its content by Community API - 'searchDataproviders' service added. 2. In 'Search Content Providers' page. datatable is used to show results - no filters exist. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@51012 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../simple/searchDataProviders.module.ts | 8 +- .../simple/searchDataproviders.component.ts | 159 +++++++++++++++++- .../simple/searchProjects.component.ts | 5 +- .../services/searchDataproviders.service.ts | 21 +++ .../searchDataprovidersService.module.ts | 20 +++ 5 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 src/app/services/searchDataproviders.service.ts create mode 100644 src/app/services/searchDataprovidersService.module.ts diff --git a/src/app/searchPages/simple/searchDataProviders.module.ts b/src/app/searchPages/simple/searchDataProviders.module.ts index fbfaf1e..45f131e 100644 --- a/src/app/searchPages/simple/searchDataProviders.module.ts +++ b/src/app/searchPages/simple/searchDataProviders.module.ts @@ -7,10 +7,16 @@ import {FreeGuard} from '../../openaireLibrary/login/freeGuard.guard'; import {PreviousRouteRecorder} from '../../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; import {IsRouteEnabled} from '../../openaireLibrary/error/isRouteEnabled.guard' import {SearchDataProvidersModule} from '../../openaireLibrary/searchPages/simple/searchDataProviders.module'; + +import {SearchPageTableViewModule} from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.module'; +//import {DataProvidersServiceModule} from '../../openaireLibrary/services/dataProvidersService.module'; +import {SearchFormModule} from '../../openaireLibrary/searchPages/searchUtils/searchForm.module'; +import {SearchDataprovidersServiceModule} from '../../services/searchDataprovidersService.module'; @NgModule({ imports: [ CommonModule, FormsModule, -SearchDataProvidersModule, SearchDataProvidersRoutingModule +SearchDataProvidersModule, SearchDataProvidersRoutingModule, +SearchPageTableViewModule, /*DataProvidersServiceModule,*/ SearchFormModule, SearchDataprovidersServiceModule ], declarations: [ diff --git a/src/app/searchPages/simple/searchDataproviders.component.ts b/src/app/searchPages/simple/searchDataproviders.component.ts index d71593a..67f55c3 100644 --- a/src/app/searchPages/simple/searchDataproviders.component.ts +++ b/src/app/searchPages/simple/searchDataproviders.component.ts @@ -1,14 +1,167 @@ import {Component, Input, ViewChild} from '@angular/core'; +import { ActivatedRoute} from '@angular/router'; + +import { Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class'; + +import {SearchResult} from '../../openaireLibrary/utils/entities/searchResult'; +import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes'; +import {SearchFields, FieldDetails} from '../../openaireLibrary/utils/properties/searchFields'; +import {SearchPageTableViewComponent } from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.component'; +import {SearchUtilsClass } from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class'; +import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; +import {SearchCommunityDataprovidersService} from '../../services/searchDataproviders.service'; @Component({ selector: 'openaire-search-dataproviders', template: ` - - - + + ` + }) export class OpenaireSearchDataprovidersComponent { + private errorCodes: ErrorCodes; + public columnNames = ['Name', 'Official Name']; + public results =[]; + public filters =[]; + public searchUtils:SearchUtilsClass = new SearchUtilsClass(); + public sub: any; public subResults: any; + public _location:Location; + public searchFields:SearchFields = new SearchFields(); + public refineFields: string[] = [];// = this.searchFields.JOURNAL_FIELDS; + properties:EnvProperties; + + public disableForms: boolean = false; + + @ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ; + + constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchCommunityDataprovidersService) { + this.errorCodes = new ErrorCodes(); + this.searchUtils.status = this.errorCodes.LOADING; + } + + public ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + }); + //this.searchPage.refineFields = this.refineFields; + this.sub = this.route.queryParams.subscribe(params => { + this.searchUtils.keyword = (params['keyword']?params['keyword']:''); + //this.filters = this.createFilters(); + //this.searchPage.getParametersFromUrl(params); + + this._getResults(params); + }); + } + + public ngOnDestroy() { + if(this.sub){ + this.sub.unsubscribe(); + } + if(this.subResults){ + this.subResults.unsubscribe(); + } + } + private _getResults(params){ + this.searchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.results = []; + this.searchUtils.totalResults = 0; + + let size: number = 0; + + this.subResults = this._searchDataprovidersService.searchDataproviders(this.properties).subscribe( + data => { + //this.filters = this.createFilters(data, params); + console.info(data); + this.searchUtils.totalResults = data.length; + console.info("search Content Providers [total results:"+this.searchUtils.totalResults+"]"); + this.results = data; + + //this.searchPage.checkSelectedFilters(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.disableForms = false; + this.searchPage.triggerInitialLoad(); + this.searchPage.transform(this.results); + }, + err => { + 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; + } + + this.disableForms = false; + } + ); + } + private setFilters(){ + //TODO set filters from + } +/* + private createFilters(data, params):Filter[] { + let length = Array.isArray(data) ? data.length : 1; + + var filter_names=[]; + var filter_ids=[]; + var searchFields = new SearchFields(); + var filter_original_ids = [];//searchFields.JOURNAL_FIELDS; + + this.refineFields = ["relfunder"]; + this.searchPage.refineFields = this.refineFields; + this.searchPage.getParametersFromUrl(params); + + var value_names=[]; + var value_original_ids=[]; + + var funders = new Set(); + var value_name = []; + var value_original_id = []; + let i; + for(i=0; i ` @@ -45,7 +44,7 @@ export class OpenaireSearchProjectsComponent { @ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ; - constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService, private _searchProjectsService: SearchCommunityProjectsService) { + constructor (private route: ActivatedRoute, private _searchProjectsService: SearchCommunityProjectsService) { this.errorCodes = new ErrorCodes(); this.searchUtils.status = this.errorCodes.LOADING; } diff --git a/src/app/services/searchDataproviders.service.ts b/src/app/services/searchDataproviders.service.ts new file mode 100644 index 0000000..c796e91 --- /dev/null +++ b/src/app/services/searchDataproviders.service.ts @@ -0,0 +1,21 @@ +import {Injectable} from '@angular/core'; +import {Http, Response} from '@angular/http'; +import {Observable} from 'rxjs/Observable'; +import 'rxjs/add/observable/of'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/share'; +import {SearchResult} from '../openaireLibrary/utils/entities/searchResult'; +import {RefineResultsUtils} from '../openaireLibrary/services/servicesUtils/refineResults.class'; +import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; + +@Injectable() +export class SearchCommunityDataprovidersService { + constructor(private http: Http ) {} + + searchDataproviders (properties:EnvProperties ):any { + let url = properties.communityAPI+"egi/contentproviders"; + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + .map(res => res.json()) + } +} diff --git a/src/app/services/searchDataprovidersService.module.ts b/src/app/services/searchDataprovidersService.module.ts new file mode 100644 index 0000000..3c33cf7 --- /dev/null +++ b/src/app/services/searchDataprovidersService.module.ts @@ -0,0 +1,20 @@ +import { NgModule} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import {SearchCommunityDataprovidersService} from './searchDataproviders.service'; + + +@NgModule({ + imports: [ + CommonModule, FormsModule + ], + declarations: [ + ], + providers:[ + SearchCommunityDataprovidersService +], + exports: [ + ] +}) +export class SearchDataprovidersServiceModule { }