From 5c0d7681ef76e1f92dfcc64162bec11ed9ff9dc8 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Thu, 3 Nov 2016 13:11:36 +0000 Subject: [PATCH] Update to last unversal project, remove temporarily used refine service, fix the filters/ fields for datasets/ pubs/ org search pages git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44383 d315682c-612b-4755-9ff5-7f18f6832af3 --- portal-2/README.md | 26 ++++ portal-2/package.json | 8 +- portal-2/src/app.browser.module.ts | 8 +- portal-2/src/app/api.ts | 69 +++++++++ .../dataProvider/tabs.component.ts | 6 +- .../landingPages/person/person.component.ts | 6 +- .../landingPages/project/project.component.ts | 6 +- .../app/searchPages/find/search.component.ts | 7 +- .../searchPages/searchDatasets.component.ts | 88 ++++-------- .../searchOrganizations.component.ts | 136 ++++-------------- .../searchPublications.component.ts | 125 ++++------------ .../advancedSearchForm.component.ts | 15 +- .../app/services/searchDatasets.service.ts | 2 +- .../services/searchOrganizations.service.ts | 2 +- .../services/searchPublications.service.ts | 2 +- portal-2/src/app/services/services.module.ts | 3 +- .../servicesUtils/refineResuts.service.ts | 45 ------ portal-2/src/app/universal-cache.ts | 85 +++++++++++ .../src/app/utils/properties/searchFields.ts | 112 ++++++++------- .../utils/staticAutoComplete2.component.ts | 4 +- portal-2/src/server.ts | 23 ++- portal-2/webpack.config.ts | 34 ++++- 22 files changed, 407 insertions(+), 405 deletions(-) create mode 100644 portal-2/src/app/api.ts delete mode 100644 portal-2/src/app/services/servicesUtils/refineResuts.service.ts create mode 100644 portal-2/src/app/universal-cache.ts diff --git a/portal-2/README.md b/portal-2/README.md index 0a776153..1727209e 100644 --- a/portal-2/README.md +++ b/portal-2/README.md @@ -14,6 +14,21 @@ A minimal Angular 2 starter for Universal JavaScript using TypeScript 2 and Webp [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) +## Universal "Gotchas" + + - To use `templateUrl` or `stylesUrl` you must use **`angular2-template-loader`** in your TS loaders. + - This is already setup within this starter repo. Look at the webpack.config file [here](https://github.com/angular/universal-starter/blob/master/webpack.config.ts) for details & implementation. + - **`window`** & **`document`** do not exist on the server - so using them, or any library that uses them (jQuery for example) will not work. + - If you need to use them, consider limiting them to only your main.client and wrapping them situationally with the imported *isBrowser / isNode* features from Universal. `import { isBrowser, isNode } from 'angular2-universal'; + - The application runs XHR requests on the server & once again on the Client-side (when the application bootstraps) + - Use a [UniversalCache](https://github.com/angular/universal-starter/blob/master/src/app/universal-cache.ts) to save certain requests so they aren't re-ran again on the Client. + +## Upcoming Universal features + + - SeoServices + - Universal fixes for Angular Core 2.1.1 + - AoT funcionality is still a *work-in-progress*, but is available as of 2.1.0-rc1 + ## Installation * `npm install` @@ -29,7 +44,18 @@ A minimal Angular 2 starter for Universal JavaScript using TypeScript 2 and Webp ## Watch files * `npm run watch` to build your client app and start a web server +## Edge case of server compatibility with Promise polyfills +If you have node modules with promise polyfill dependency on server - there is chance to get the following exception: +``` +Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten. +``` +It occurs because [Zone.js](https://github.com/angular/zone.js/) Promise implementation is not +detected as Promise by some polyfills (e.g. [es6-promise](https://github.com/stefanpenner/es6-promise) before 4.x). + +To sort it out, you need such polyfills initialized before zone.js. Zone.js is initialized in 'angular2-universal-polyfills' +import of [server.ts](https://github.com/angular/universal-starter/blob/master/src/server.ts#L4). So import problematic +modules before this line. ### Documentation [Design Doc](https://docs.google.com/document/d/1q6g9UlmEZDXgrkY88AJZ6MUrUxcnwhBGS0EXbVlYicY) diff --git a/portal-2/package.json b/portal-2/package.json index 8c46b8db..2ec91946 100644 --- a/portal-2/package.json +++ b/portal-2/package.json @@ -31,6 +31,7 @@ "dependencies": { "@angular/common": "2.1.0", "@angular/compiler": "2.1.0", + "@angular/compiler-cli": "2.1.0", "@angular/core": "2.1.0", "@angular/forms": "2.1.0", "@angular/http": "2.1.0", @@ -38,6 +39,7 @@ "@angular/platform-browser-dynamic": "2.1.0", "@angular/platform-server": "2.1.0", "@angular/router": "3.1.0", + "@ngtools/webpack": "^1.1.4", "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.6", "angular2-express-engine": "~2.1.0-rc.1", "angular2-platform-node": "~2.1.0-rc.1", @@ -49,7 +51,7 @@ "methods": "~1.1.2", "preboot": "~4.5.2", "rxjs": "5.0.0-beta.12", - "zone.js": "~0.6.25" + "zone.js": "~0.6.26" }, "devDependencies": { "@types/body-parser": "0.0.29", @@ -62,14 +64,14 @@ "@types/node": "^6.0.38", "@types/serve-static": "^1.7.27", "angular2-template-loader": "^0.4.0", + "awesome-typescript-loader": "^2.2.4", "cookie-parser": "^1.4.3", "imports-loader": "^0.6.5", "json-loader": "^0.5.4", "nodemon": "^1.10.0", "raw-loader": "^0.5.1", "rimraf": "^2.5.4", - "string-replace-loader": "github:gdi2290/string-replace-loader", - "ts-loader": "^0.8.2", + "string-replace-loader": "^1.0.5", "ts-node": "^1.3.0", "typescript": "2.0.2", "webpack": "2.1.0-beta.25", diff --git a/portal-2/src/app.browser.module.ts b/portal-2/src/app.browser.module.ts index 8754dac8..ae3586cc 100644 --- a/portal-2/src/app.browser.module.ts +++ b/portal-2/src/app.browser.module.ts @@ -1,11 +1,11 @@ import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { UniversalModule } from 'angular2-universal'; +import { UniversalModule, isBrowser, isNode } from 'angular2-universal/browser'; // for AoT we need to manually split universal packages import { App } from './app/app'; //for routing: import { routing } from './app/app.routing'; import { Routes, RouterModule } from "@angular/router"; - +import { CacheService } from './app/universal-cache'; // custom modules:: import {ClaimModule} from './app/claimPages/claim.module'; import {SearchModule} from './app/searchPages/search.module'; @@ -43,7 +43,9 @@ import {TestComponent} from './app/test/test.component'; TestComponent ], providers: [ - + { provide: 'isBrowser', useValue: isBrowser }, + { provide: 'isNode', useValue: isNode }, + CacheService ] }) export class MainModule { diff --git a/portal-2/src/app/api.ts b/portal-2/src/app/api.ts new file mode 100644 index 00000000..cd39a0f3 --- /dev/null +++ b/portal-2/src/app/api.ts @@ -0,0 +1,69 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/observable/thorw'; +import 'rxjs/add/observable/of'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/share'; + +import { CacheService } from './universal-cache'; + +export function hashCode(str) { + let hash = 0; + if (str.length === 0) { + return hash; + } + for (let i = 0; i < str.length; i++) { + let char = str.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; // Convert to 32bit integer + } + return hash; +} + +@Injectable() +export class ApiService { + constructor(public _http: Http) { + + } + + /** + * whatever domain/feature method name + */ + get(url: string, options?: any) { + return this._http.get(url, options) + .map(res => res.json()) + .catch(err => { + console.log('Error: ', err); + return Observable.throw(err); + }); + } + +} + +@Injectable() +export class ModelService { + + constructor(public _api: ApiService, public _cache: Cache) { + + } + + /** + * whatever domain/feature method name + */ + get(url) { + // you want to return the cache if there is a response in it. This would cache the first response so if your API isn't idempotent you probably want to remove the item from the cache after you use it. LRU of 1 + let key = url; + + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + // you probably shouldn't .share() and you should write the correct logic + return this._api.get(url) + .do(json => { + this._cache.set(key, json); + }) + .share(); + } + +} diff --git a/portal-2/src/app/landingPages/dataProvider/tabs.component.ts b/portal-2/src/app/landingPages/dataProvider/tabs.component.ts index d9c873ea..8215cac4 100644 --- a/portal-2/src/app/landingPages/dataProvider/tabs.component.ts +++ b/portal-2/src/app/landingPages/dataProvider/tabs.component.ts @@ -5,7 +5,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication import { SearchPublicationsService } from '../../services/searchPublications.service'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsService } from '../../services/searchDatasets.service'; -import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service'; @Component({ selector: 'tabs', @@ -98,10 +97,9 @@ export class TabsComponent { constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService, - private _searchDatasetsService: SearchDatasetsService, - private _refineResultsService:RefineResultsService) { + private _searchDatasetsService: SearchDatasetsService) { this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); - this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService); + this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService); } ngOnInit() { diff --git a/portal-2/src/app/landingPages/person/person.component.ts b/portal-2/src/app/landingPages/person/person.component.ts index 5608b1d0..7ef162cb 100644 --- a/portal-2/src/app/landingPages/person/person.component.ts +++ b/portal-2/src/app/landingPages/person/person.component.ts @@ -8,7 +8,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication import { SearchPublicationsService } from '../../services/searchPublications.service'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsService } from '../../services/searchDatasets.service'; -import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service'; import { SearchResultComponent } from '../../searchPages/searchUtils/searchResult.component'; import {OpenaireProperties} from '../../utils/properties/openaireProperties'; @@ -38,11 +37,10 @@ export class PersonComponent { constructor (private _personService: PersonService, private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService, - private _searchDatasetsService: SearchDatasetsService, - private _refineResultsService:RefineResultsService) { + private _searchDatasetsService: SearchDatasetsService) { console.info('person constructor'); this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); - this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService); + this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService); } ngOnInit() { diff --git a/portal-2/src/app/landingPages/project/project.component.ts b/portal-2/src/app/landingPages/project/project.component.ts index 1330aa40..1134291c 100644 --- a/portal-2/src/app/landingPages/project/project.component.ts +++ b/portal-2/src/app/landingPages/project/project.component.ts @@ -9,7 +9,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication import {SearchPublicationsService} from '../../services/searchPublications.service'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsService } from '../../services/searchDatasets.service'; -import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service'; import {SearchResultComponent} from '../../searchPages/searchUtils/searchResult.component'; import {OpenaireProperties} from '../../utils/properties/openaireProperties'; @@ -45,12 +44,11 @@ export class ProjectComponent implements OnInit{ constructor (private _projectService: ProjectService, private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService, - private _searchDatasetsService: SearchDatasetsService, - private _refineResultsService:RefineResultsService) { + private _searchDatasetsService: SearchDatasetsService) { console.info('project constructor'); this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); - this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService); + this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService); } ngOnInit() { diff --git a/portal-2/src/app/searchPages/find/search.component.ts b/portal-2/src/app/searchPages/find/search.component.ts index 96b0eb30..8ea45ce6 100644 --- a/portal-2/src/app/searchPages/find/search.component.ts +++ b/portal-2/src/app/searchPages/find/search.component.ts @@ -16,7 +16,6 @@ import {SearchProjectsService} from '../../services/searchProjects.service'; import {SearchDatasetsService} from '../../services/searchDatasets.service'; import {SearchPeopleService} from '../../services/searchPeople.service'; import {SearchOrganizationsService} from '../../services/searchOrganizations.service'; -import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service'; import {OpenaireProperties} from '../../utils/properties/openaireProperties'; @@ -148,12 +147,12 @@ export class SearchComponent { private _searchDatasetsService: SearchDatasetsService, private _searchOrganizationsService: SearchOrganizationsService, private _searchPeopleService: SearchPeopleService, - private _refineResultsService: RefineResultsService, private location: Location ) { + private location: Location ) { this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService); this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService); - this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService,_refineResultsService); - this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService,_refineResultsService); + this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService); + this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService); this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService); } diff --git a/portal-2/src/app/searchPages/searchDatasets.component.ts b/portal-2/src/app/searchPages/searchDatasets.component.ts index a558faa6..8539193b 100644 --- a/portal-2/src/app/searchPages/searchDatasets.component.ts +++ b/portal-2/src/app/searchPages/searchDatasets.component.ts @@ -3,7 +3,6 @@ import { ActivatedRoute} from '@angular/router'; import {Location} from '@angular/common'; import { Filter, Value} from './searchUtils/searchHelperClasses.class'; -import {RefineResultsService} from '../services/servicesUtils/refineResuts.service'; import {SearchDatasetsService} from '../services/searchDatasets.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; @@ -31,25 +30,28 @@ export class SearchDatasetsComponent { private page :number = 1; private size :number = 10; private sub: any; - private refineFields = []; + private subResults: any; private searchFields:SearchFields = new SearchFields(); + private refineFields: string[] = this.searchFields.DATASET_INDEX; + private indexIdsMap: { [key:string]:string } = this.searchFields.DATASET_INDEX_PARAM_MAP; + private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.DATASET_FIELDS_MAP; + private urlParams : Map; private _location:Location; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; - constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService, private _refineResultsService:RefineResultsService ) { + constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService ) { var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchDatasets(); - this.refineFields = this.searchFields.DATASET_FIELDS; - if(!this.searchPage){ - this.searchPage = new SearchPageComponent(this._location); - } + } private ngOnInit() { this.searchPage.refineFields = this.refineFields; + this.searchPage.indexIdsMap = this.indexIdsMap; + this.searchPage.fieldIdsMap = this.fieldIdsMap; this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); @@ -57,64 +59,21 @@ export class SearchDatasetsComponent { // this.getRefineResults(); //this.getResults(this.keyword, this.page, this.size, "searchPage"); var queryParameters = this.searchPage.getQueryParametersFromUrl(params); - this.getResults(queryParameters, true, this.page, this.size); + this._getResults(queryParameters, true, this.page, this.size); + }); } private ngOnDestroy() { - this.sub.unsubscribe(); - } - public getRefineResults (){ - // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( - this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( - - data => { - - this.filters = data; - - }, - err => { - console.error(err); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - - } - ); - } - - /* - public getResults(parameters:string, page: number, size: number, flag: string){ - console.info("Search Datasets: Execute search query "+parameters); - if(flag == 'searchPage' || flag == 'claim') { - //parameters = parameters + this.searchPage.getRefineFieldsQuery(); + if(this.sub){ + this.sub.unsubscribe(); + } + if(this.subResults){ + this.subResults.unsubscribe(); } - this._searchDatasetsService.searchDatasets(parameters, page, size, flag, this.searchPage.getFields()).subscribe( - data => { - this.totalResults = data[0]; - console.info("Search Datasets: results="+this.totalResults); - this.results = data[1]; - this.filters = data[2]; - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.DONE; - if(this.totalResults == 0 ){ - this.status = errorCodes.NONE; - } - }, - err => { - console.error(err); - console.info("error"); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.NOT_AVAILABLE; - } - ); } -*/ + + public getResultsForEntity(entity:string, id:string, page: number, size: number){ var parameters = ""; @@ -161,14 +120,17 @@ public getResults(keyword:string,refine:boolean, page: number, size: number){ this._getResults(parameters,refine,page,size); } private _getResults(parameters:string,refine:boolean, page: number, size: number){ - - this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( + if(!refine && !this.searchPage){ + this.searchPage = new SearchPageComponent(this._location); + } + this.subResults = this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( data => { this.totalResults = data[0]; console.info("search Datasets: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); this.results = data[1]; - this.filters = this.searchPage.checkSelectedFilters(data[2]); - this.searchPage.updateBaseUrlWithParameters(this.filters); + this.filters = data[2]; + this.searchPage.checkSelectedFilters(this.filters); + this.searchPage.updateBaseUrlWithParameters(this.filters); var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; if(this.totalResults == 0 ){ diff --git a/portal-2/src/app/searchPages/searchOrganizations.component.ts b/portal-2/src/app/searchPages/searchOrganizations.component.ts index 7512b014..73daea69 100644 --- a/portal-2/src/app/searchPages/searchOrganizations.component.ts +++ b/portal-2/src/app/searchPages/searchOrganizations.component.ts @@ -1,10 +1,7 @@ import {Component, Input, ViewChild} from '@angular/core'; import { ActivatedRoute} from '@angular/router'; import {Location} from '@angular/common'; - import { Filter, Value} from './searchUtils/searchHelperClasses.class'; - -import {RefineResultsService} from '../services/servicesUtils/refineResuts.service'; import {SearchOrganizationsService} from '../services/searchOrganizations.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; @@ -32,90 +29,48 @@ export class SearchOrganizationsComponent { private page :number = 1; private size :number = 10; private sub: any; - private _location:Location; - private refineFields = []; + private subResults: any; private searchFields:SearchFields = new SearchFields(); + private refineFields: string[] = this.searchFields.ORGANIZATION_INDEX; + private indexIdsMap: { [key:string]:string } = this.searchFields.ORGANIZATION_INDEX_PARAM_MAP; + private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.ORGANIZATION_FIELDS_MAP; + private urlParams : Map; + private _location:Location; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; - constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService, private _refineResultsService:RefineResultsService ) { - //this.results =[]; - //this.filters =[]; + constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) { + var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchOrganizations(); - if(!this.searchPage){ - this.searchPage = new SearchPageComponent(this._location); - } + } private ngOnInit() { this.searchPage.refineFields = this.refineFields; + this.searchPage.indexIdsMap = this.indexIdsMap; + this.searchPage.fieldIdsMap = this.fieldIdsMap; this.sub = this.route.queryParams.subscribe(params => { - this.keyword = (params['keyword']?params['keyword']:''); - this.page = (params['page']=== undefined)?1:+params['page']; + this.keyword = (params['keyword']?params['keyword']:''); + this.page = (params['page']=== undefined)?1:+params['page']; - this.getRefineResults(); - this.getResults(this.keyword, true, this.page, this.size); + var queryParameters = this.searchPage.getQueryParametersFromUrl(params); + this._getResults(queryParameters, true, this.page, this.size); }); } private ngOnDestroy() { - this.sub.unsubscribe(); + if(this.sub){ + this.sub.unsubscribe(); + } + if(this.subResults){ + this.subResults.unsubscribe(); + } } - public getRefineResults (){ - // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( - this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( - - data => { - - this.filters = data; - - }, - err => { - console.error(err); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - - } - ); - } -/* - public getResults(parameters:string, page: number, size: number){ - console.info("getResults: Execute search query "+parameters); - - this._searchOrganizationsService.searchOrganizations(parameters, page, size).subscribe( - data => { - this.totalResults = data[0]; - console.info("searchPubl total="+this.totalResults); - this.results = data[1]; - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.DONE; - if(this.totalResults == 0 ){ - this.status = errorCodes.NONE; - } - }, - err => { - console.error(err); - console.info("error"); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.NOT_AVAILABLE; - } - ); - } - - */ - - public getResults(keyword:string,refine:boolean, page: number, size: number){ var parameters = ""; if(keyword.length > 0){ @@ -125,13 +80,17 @@ export class SearchOrganizationsComponent { } private _getResults(parameters:string,refine:boolean, page: number, size: number){ - this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( + if(!refine && !this.searchPage){ + this.searchPage = new SearchPageComponent(this._location); + } + this.subResults = this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( data => { this.totalResults = data[0]; console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); this.results = data[1]; - this.filters = this.searchPage.checkSelectedFilters(data[2]); - this.searchPage.updateBaseUrlWithParameters(this.filters); + this.filters = data[2]; + this.searchPage.checkSelectedFilters(this.filters); + this.searchPage.updateBaseUrlWithParameters(this.filters); var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; if(this.totalResults == 0 ){ @@ -150,45 +109,6 @@ export class SearchOrganizationsComponent { ); } -/* -public getResults(keyword:string,refine:boolean, page: number, size: number){ - var parameters = ""; - if(keyword.length > 0){ - parameters = "q=" + keyword + "&op=and"; - } - this._getResults(parameters,refine,page,size); -} -private _getResults(parameters:string,refine:boolean, page: number, size: number){ - - this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( - data => { - this.totalResults = data[0]; - console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); - this.results = data[1]; - this.filters = this.searchPage.checkSelectedFilters(data[2]); - this.searchPage.updateBaseUrlWithParameters(this.filters); - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.DONE; - if(this.totalResults == 0 ){ - this.status = errorCodes.NONE; - } - }, - err => { - console.error(err); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.ERROR; - } - ); -} -*/ - - private setFilters(){ - //TODO set filters from - } private queryChanged($event) { var parameters = $event.value; diff --git a/portal-2/src/app/searchPages/searchPublications.component.ts b/portal-2/src/app/searchPages/searchPublications.component.ts index 21badc1e..fd3e9e1b 100644 --- a/portal-2/src/app/searchPages/searchPublications.component.ts +++ b/portal-2/src/app/searchPages/searchPublications.component.ts @@ -32,118 +32,44 @@ export class SearchPublicationsComponent { private page :number = 1; private size :number = 10; private sub: any; - private refineFields = []; + private subResults: any; private searchFields:SearchFields = new SearchFields(); + private refineFields: string[] = this.searchFields.PUBLICATION_INDEX; + private indexIdsMap: { [key:string]:string } = this.searchFields.PUBLICATION_INDEX_PARAM_MAP; + private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PUBLICATION_FIELDS_MAP; + private urlParams : Map; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; private _location:Location; constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) { - //this.results =[]; - //this.filters =[]; var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchPublications(); - this.refineFields = this.searchFields.PUBLICATION_INDEX; - //get refine field filters from url parameters - if(!this.searchPage){ - this.searchPage = new SearchPageComponent(this._location); - } + } private ngOnInit() { this.searchPage.refineFields = this.refineFields; + this.searchPage.indexIdsMap = this.indexIdsMap; + this.searchPage.fieldIdsMap = this.fieldIdsMap; + this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); this.page = (params['page']=== undefined)?1:+params['page']; - for(var i=0; i<5 ; i++){ - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'} - if(i==0) { - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'} - this.filters.push(filter1); - this.getResults(this.keyword, true, this.page, this.size); - - } - - console.info(params); - if(params[filter.filterId] != undefined) { - let values = params[filter.filterId].split(","); - for(let value of values) { - for(let filterValue of filter.values) { - if(filterValue.id == value) { - filterValue.selected = true; - filter.countSelectedValues++; - } - } - } - } - } - + var queryParameters = this.searchPage.getQueryParametersFromUrl(params); + this._getResults(queryParameters, true, this.page, this.size); + }); } private ngOnDestroy() { - this.sub.unsubscribe(); + if(this.sub){ + this.sub.unsubscribe(); + } + if(this.subResults){ + this.subResults.unsubscribe(); + } } -/* - public getResults(parameters:string, page: number, size: number, flag: string){ - console.info("getResults: Execute search query "+parameters); - - this._searchPublicationsService.searchPublications(parameters, page, size, flag).subscribe( - data => { - this.totalResults = data[0]; - console.info("searchPubl total="+this.totalResults); - this.results = data[1]; - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.DONE; - if(this.totalResults == 0 ){ - this.status = errorCodes.NONE; - } - }, - err => { - console.error(err); - console.info("error"); - //TODO check erros (service not available, bad request) - // if( ){ - // this.status = ErrorCodes.ERROR; - // } - var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.NOT_AVAILABLE; - } - ); - } -*/ public getCSVResultsForEntity(entity:string, id:string): any { let exportPublications = []; @@ -247,14 +173,17 @@ public getResults(keyword:string,refine:boolean, page: number, size: number){ this._getResults(parameters,refine,page,size); } private _getResults(parameters:string,refine:boolean, page: number, size: number){ - - this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( + if(!refine && !this.searchPage){ + this.searchPage = new SearchPageComponent(this._location); + } + this.subResults = this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( data => { this.totalResults = data[0]; console.info("search Publications: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); this.results = data[1]; - this.filters = this.searchPage.checkSelectedFilters(data[2]); - this.searchPage.updateBaseUrlWithParameters(this.filters); + this.filters = data[2]; + this.searchPage.checkSelectedFilters(this.filters); + this.searchPage.updateBaseUrlWithParameters(this.filters); var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; if(this.totalResults == 0 ){ @@ -273,9 +202,7 @@ private _getResults(parameters:string,refine:boolean, page: number, size: number ); } - private setFilters(){ - //TODO set filters from - } + private queryChanged($event) { var parameters = $event.value; diff --git a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts index be3776c2..ae46a289 100644 --- a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts @@ -43,6 +43,14 @@ import {SearchFields} from '../../utils/properties/searchFields';
+
+ + Yes
+
+ + No
+
+
@@ -109,7 +117,12 @@ export class AdvancedSearchFormComponent { addField() { console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type); - this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name,this.fieldIdsMap[this.newFieldId].type,"","and")); + var type = this.fieldIdsMap[this.newFieldId].type; + if(type == "boolean"){ + this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "true", "and")); + }else{ + this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "", "and")); + } } diff --git a/portal-2/src/app/services/searchDatasets.service.ts b/portal-2/src/app/services/searchDatasets.service.ts index d4aae201..deb24241 100644 --- a/portal-2/src/app/services/searchDatasets.service.ts +++ b/portal-2/src/app/services/searchDatasets.service.ts @@ -19,7 +19,7 @@ export class SearchDatasetsService { if(params!= null && params != '' ) { url += params; } - if(refineParams!= null && params != '' ) { + if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+page+"&size="+size; diff --git a/portal-2/src/app/services/searchOrganizations.service.ts b/portal-2/src/app/services/searchOrganizations.service.ts index 2a5171d3..7905ea5a 100644 --- a/portal-2/src/app/services/searchOrganizations.service.ts +++ b/portal-2/src/app/services/searchOrganizations.service.ts @@ -20,7 +20,7 @@ export class SearchOrganizationsService { if(params!= null && params != '' ) { url += params; } - if(refineParams!= null && params != '' ) { + if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+page+"&size="+size; diff --git a/portal-2/src/app/services/searchPublications.service.ts b/portal-2/src/app/services/searchPublications.service.ts index 6d320762..2968cbd0 100644 --- a/portal-2/src/app/services/searchPublications.service.ts +++ b/portal-2/src/app/services/searchPublications.service.ts @@ -19,7 +19,7 @@ export class SearchPublicationsService { if(params!= null && params != '' ) { url += params; } - if(refineParams!= null && params != '' ) { + if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+page+"&size="+size; diff --git a/portal-2/src/app/services/services.module.ts b/portal-2/src/app/services/services.module.ts index 78090954..5961da90 100644 --- a/portal-2/src/app/services/services.module.ts +++ b/portal-2/src/app/services/services.module.ts @@ -22,7 +22,6 @@ import {SearchDatasetsService} from './searchDatasets.service'; import {SearchOrganizationsService} from './searchOrganizations.service'; import {SearchPeopleService} from './searchPeople.service'; import {SearchProjectsService} from './searchProjects.service'; -import {RefineResultsService} from './servicesUtils/refineResuts.service'; import {ISVocabulariesService} from './ISVocabularies.service'; import {RefineFieldResultsService} from './refineFieldResults.service' @@ -40,7 +39,7 @@ import {RefineFieldResultsService} from './refineFieldResults.service' SearchCrossrefService, SearchDataciteService, SearchOrcidService, SearchPublicationsService, SearchDataprovidersService, DataProviderService, SearchProjectsService, SearchDatasetsService, SearchOrganizationsService, - SearchPeopleService,RefineResultsService, ISVocabulariesService, + SearchPeopleService, ISVocabulariesService, RefineFieldResultsService ], exports: [ diff --git a/portal-2/src/app/services/servicesUtils/refineResuts.service.ts b/portal-2/src/app/services/servicesUtils/refineResuts.service.ts deleted file mode 100644 index 92e00f99..00000000 --- a/portal-2/src/app/services/servicesUtils/refineResuts.service.ts +++ /dev/null @@ -1,45 +0,0 @@ -import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; - // import {RefineParsingUtils} from './services-utils/refineResults.class'; - import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class'; - import { SearchFields} from '../../utils/properties/searchFields'; - -@Injectable() -export class RefineResultsService { - - constructor(private http: Http) {} - - getRefineResults(fields:string[]):any { - - return this.http.get('./refineResults.json') - .map(res => res.json()) - // .do(res => console.log(res)) - .map(res => this.parseRefineResults(res['refineResults'],fields)) - ; - } - public parseRefineResults (data, fields:string[]):Filter[] { - // var data = this.json.refineReuslts; - var searchFields:SearchFields = new SearchFields(); - var filters:Filter[] = []; - for(let j=0; j json[key] = value); + return json; + } + + /** + * convert server json into out initial state + */ + rehydrate(json: any): void { + Object.keys(json).forEach((key: string) => { + let _key = this.normalizeKey(key); + let value = json[_key]; + this._cache.set(_key, value); + }); + } + + /** + * allow JSON.stringify to work + */ + toJSON(): any { + return this.dehydrate(); + } + + /** + * convert numbers into strings + */ + normalizeKey(key: string | number): string { + if (isDevMode() && this._isInvalidValue(key)) { + throw new Error('Please provide a valid key to save in the CacheService'); + } + + return key + ''; + } + + _isInvalidValue(key): boolean { + return key === null || + key === undefined || + key === 0 || + key === '' || + typeof key === 'boolean' || + Number.isNaN(key); + } +} diff --git a/portal-2/src/app/utils/properties/searchFields.ts b/portal-2/src/app/utils/properties/searchFields.ts index 82aca666..473a4d88 100644 --- a/portal-2/src/app/utils/properties/searchFields.ts +++ b/portal-2/src/app/utils/properties/searchFields.ts @@ -1,5 +1,6 @@ export class SearchFields { //main Entities + //PUBLICATIONS public PUBLICATION_INDEX:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id", "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; @@ -37,15 +38,15 @@ export class SearchFields { public PROJECT_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={ ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, ["keywords"]:{name:"Keywords",operator:"ky", type:"keyword" , indexField:"projectkeywords"}, + ["acronym"]: {name:"Acronym",operator:"ar", type:"keyword", indexField:'projectacronym'}, + ["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"}, ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"funderid"}, ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"fundinglevel0_id"}, ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"fundinglevel1_id"}, ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"fundinglevel2_id"}, ["startyear"]:{name:"Start Year",operator:"sa", type:"keyword", indexField:"projectstartyear"}, ["endyear"]: {name:"End Year",operator:"ed", type:"keyword", indexField:"projectendyear"}, - ["sc39"]: {name:"Community",operator:"sc", type:"keyword", indexField:"projectecsc39"}, - ["acronym"]: {name:"Access Mode",operator:"ar", type:"keyword", indexField:'projectacronym'}, - ["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"}, + ["sc39"]: {name:"Special Clause 39",operator:"sc", type:"boolean", indexField:"projectecsc39"}, ["code"]: {name:"Project Code",operator:"cd", type:"keyword", indexField:"projectcode"} }; //DATAPROVIDERS @@ -73,15 +74,62 @@ export class SearchFields { - public DATASET_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "relfunderid", - "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id", - "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; - public DATAPROVIDER_FIELDS:string[] = ["datasourcetypeuiid", "datasourceodlanguages", "datasourceodcontenttypes", "datasourcecompatibilityid"]; - public ORGANIZATION_FIELDS:string[] = ["organizationcountryid","organizationeclegalbody"]; - public PROJECT_FIELDS:string[] = ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"]; - public PEOPLE_FIELDS:string[] = []; - //extra pages - public ENTITYREGISTRIES_DATAPROVIDER_FIELDS:string[] = []; + //DATASET + public DATASET_INDEX:string[] = ["instancetypenameid", "resultlanguageid", //"communityid", + "relfunderid", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id", + "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; + public ADVANCED_SEARCH_DATASET_PARAM:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0", + "funderlv1","funderlv2","community","access","hostedBy","collectedFrom"]; + public DATASET_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community", + [ "relfunderid"]:"funder", + ["relfundinglevel0_id"]:"funderlv0",["relfundinglevel1_id"]:"funderlv1",["relfundinglevel2_id"]:"funderlv2", + ["resultacceptanceyear"]:"year",["resultbestlicense"]:"access",["resulthostingdatasourceid"]:"hostedBy",["collectedfromdatasourceid"]:"collectedFrom"}; + public DATASET_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={ + ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, + ["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"}, + ["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"}, + ["publisher"]:{name:"Publisher",operator:"pb", type:"keyword", indexField:"resultpublisher"}, + ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"relfunderid"}, + ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"relfundinglevel0_id"}, + ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"relfundinglevel1_id"}, + ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"relfundinglevel2_id"}, + ["type"]:{name:"Type",operator:"tp", type:"vocabulary", indexField:"instancetypenameid"}, + ["lang"]: {name:"Language",operator:"ln", type:"vocabulary", indexField:"resultlanguageid"}, + ["community"]: {name:"Community",operator:"cm", type:"refine", indexField:"communityid"}, + ["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicense'}, + ["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid"}, + ["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid"} + }; + + + //ORGANIZATION + public ORGANIZATION_INDEX:string[] = ["organizationcountryid","organizationeclegalbody"]; + public ADVANCED_SEARCH_ORGANIZATION_INDEX_PARAM:string[] = ["q","contenttype","compatibility","country","type"]; + public ORGANIZATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["organizationlegalname"]:"contenttype", ["organizationlegalshortname"]:"compatibility", + ["organizationcountryid"]:"country",["organizationeclegalbody"]:"type"}; + public ORGANIZATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={ + ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, + ["contenttype"]:{name:"Legal Name",operator:"cn", type:"keyword" , indexField:"organizationlegalname"}, + ["compatibility"]:{name:"Legal Short Name",operator:"cm", type:"keyword", indexField:"organizationlegalshortname"}, + ["country"]:{name:"Country",operator:"pb", type:"keyword", indexField:"organizationcountryid"}, + ["type"]:{name:"Type",operator:"fn", type:"refine", indexField:"organizationeclegalbody"}, + + }; + + + + //PERSON + public PERSON_INDEX:string[] = []; + public ADVANCED_SEARCH_PERSON_INDEX_PARAM:string[] = ["q","contenttype","compatibility","country","type"]; + public PERSON_INDEX_INDEX_PARAM_MAP:{ [key:string]:string } = {["personsecondnames"]:"surname", ["personfirstname"]:"name", + ["personfullname"]:"fullname"}; + public PERSON_INDEX_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={ + ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, + ["surname"]:{name:"Surname",operator:"sr", type:"keyword" , indexField:"personsecondnames"}, + ["name"]:{name:"Name",operator:"nm", type:"keyword", indexField:"personfirstname"}, + ["fullname"]:{name:"Full name",operator:"fl", type:"keyword", indexField:"personfullname"}}; + + public HIDDEN_FIELDS:string[] = ["fundinglevel0_id","fundinglevel1_id","fundinglevel2_id", @@ -102,49 +150,9 @@ export class SearchFields { ["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country", ["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"}; - // public ADVANCED_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid", - // "relfundinglevel0_id","relfundinglevel1_id,relfundinglevel2_id", - // "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; - - public ADVANCED_FIELDS_PROJECTS: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={ - ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, - ["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"}, - ["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"}, - ["publisher"]:{name:"Publisher",operator:"pb", type:"keyword", indexField:"resultpublisher"}, - ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"relfunderid"}, - ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"relfundinglevel0_id"}, - ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"relfundinglevel1_id"}, - ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"relfundinglevel2_id"}, - ["type"]:{name:"Type",operator:"tp", type:"vocabulary", indexField:"instancetypenameid"}, - ["lang"]: {name:"Language",operator:"ln", type:"vocabulary", indexField:"resultlanguageid"}, - ["community"]: {name:"Community",operator:"cm", type:"refine", indexField:"communityid"}, - ["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicense'}, - ["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid"}, - ["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid"} - }; public ADVANCED_SEARCH_OPERATORS:[{name:string, id:string}] = [{name:"AND",id:"and"},{name:"OR",id:"or"},{name:"NOT",id:"not"}]; - - - - - - - - - // ,["communityid"]: "Context",["resultacceptanceyear"]:"Year", - // ["resultbestlicense"]:"Access Mode",["resulthostingdatasourceid"]:"Hosting Data provider", - // ["collectedfromdatasourceid"]:"Collected from", ["datasourcetypeuiid"]:"Compatibility Type", ["datasourceodlanguages"]:"Language", - // ["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country", - // ["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"}; - - - // public getPROJECT_FIELDS(){ - // return this.PROJECT_FIELDS; - // } - - constructor (){ } diff --git a/portal-2/src/app/utils/staticAutoComplete2.component.ts b/portal-2/src/app/utils/staticAutoComplete2.component.ts index e051cd89..067e35c7 100644 --- a/portal-2/src/app/utils/staticAutoComplete2.component.ts +++ b/portal-2/src/app/utils/staticAutoComplete2.component.ts @@ -66,8 +66,8 @@ export class StaticAutocomplete2Component { constructor ( private _vocabulariesService: ISVocabulariesService,private _refineService: RefineFieldResultsService, private myElement: ElementRef) { } ngOnDestroy(){ - if(this.sub){ - this.sub.destroy(); + if(this.sub && this.sub != undefined){ + this.sub.unsubscribe(); } } ngOnInit () { diff --git a/portal-2/src/server.ts b/portal-2/src/server.ts index ce9576ee..4ec4f82c 100644 --- a/portal-2/src/server.ts +++ b/portal-2/src/server.ts @@ -1,6 +1,17 @@ -// the polyfills must be the first thing imported in node.js +// the polyfills must be one of the first things imported in node.js. +// The only modules to be imported higher - node modules with es6-promise 3.x or other Promise polyfill dependency +// (rule of thumb: do it if you have zone.js exception that it has been overwritten) +// if you are including modules that modify Promise, such as NewRelic,, you must include them before polyfills import 'angular2-universal-polyfills'; +// Fix Universal Style +import { NodeDomRootRenderer, NodeDomRenderer } from 'angular2-universal/node'; +function renderComponentFix(componentProto: any) { + return new NodeDomRenderer(this, componentProto, this._animationDriver); +} +NodeDomRootRenderer.prototype.renderComponent = renderComponentFix; +// End Fix Universal Style + import * as path from 'path'; import * as express from 'express'; import * as bodyParser from 'body-parser'; @@ -21,7 +32,14 @@ const app = express(); const ROOT = path.join(path.resolve(__dirname, '..')); // Express View -app.engine('.html', createEngine({})); +app.engine('.html', createEngine({ + precompile: true, + ngModule: MainModule, + providers: [ + // stateless providers only since it's shared + ] +})); +app.set('port', process.env.PORT || 3000); app.set('views', __dirname); app.set('view engine', 'html'); @@ -43,7 +61,6 @@ function ngApp(req, res) { res.render('index', { req, res, - ngModule: MainModule, preboot: false, baseUrl: '/', requestUrl: req.originalUrl, diff --git a/portal-2/webpack.config.ts b/portal-2/webpack.config.ts index 80e4e5b7..f43f2253 100644 --- a/portal-2/webpack.config.ts +++ b/portal-2/webpack.config.ts @@ -1,7 +1,6 @@ var webpack = require('webpack'); var path = require('path'); - var commonConfig = { resolve: { extensions: ['.ts', '.js', '.json'] @@ -9,7 +8,7 @@ var commonConfig = { module: { loaders: [ // TypeScript - { test: /\.ts$/, loaders: ['ts-loader', 'angular2-template-loader'] }, + { test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] }, { test: /\.html$/, loader: 'raw-loader' }, { test: /\.css$/, loader: 'raw-loader' }, { test: /\.json$/, loader: 'json-loader' } @@ -20,8 +19,22 @@ var commonConfig = { // The (\\|\/) piece accounts for path separators in *nix and Windows /angular(\\|\/)core(\\|\/)src(\\|\/)linker/, root('./src'), - {} - ) + { + // your Angular Async Route paths relative to this root directory + } + ), + + // To use gzip, you can run 'npm install compression-webpack-plugin --save-dev' + // add 'var CompressionPlugin = require("compression-webpack-plugin");' on the top + // and comment out below codes + // + // new CompressionPlugin({ + // asset: "[path].gz[query]", + // algorithm: "gzip", + // test: /\.js$|\.css$|\.html$/, + // threshold: 10240, + // minRatio: 0.8 + // }) ] }; @@ -57,6 +70,17 @@ var serverConfig = { }, externals: includeClientPackages([ // include these client packages so we can transform their source with webpack loaders + + // '@angular/common', + // '@angular/compiler', + // '@angular/core', + // '@angular/forms', + // '@angular/http', + // '@angular/platform-browser', + // '@angular/platform-browser-dynamic', + // '@angular/platform-server', + // '@angular/router', + '@angular2-material/button', '@angular2-material/button', '@angular2-material/card', @@ -82,7 +106,7 @@ var serverConfig = { __dirname: true, __filename: true, process: true, - Buffer: true + Buffer: false } };