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
This commit is contained in:
argiro.kokogiannaki 2016-11-03 13:11:36 +00:00
parent ffecd991bc
commit 5c0d7681ef
22 changed files with 407 additions and 405 deletions

View File

@ -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) [![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 ## Installation
* `npm install` * `npm install`
@ -29,7 +44,18 @@ A minimal Angular 2 starter for Universal JavaScript using TypeScript 2 and Webp
## Watch files ## Watch files
* `npm run watch` to build your client app and start a web server * `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 ### Documentation
[Design Doc](https://docs.google.com/document/d/1q6g9UlmEZDXgrkY88AJZ6MUrUxcnwhBGS0EXbVlYicY) [Design Doc](https://docs.google.com/document/d/1q6g9UlmEZDXgrkY88AJZ6MUrUxcnwhBGS0EXbVlYicY)

View File

@ -31,6 +31,7 @@
"dependencies": { "dependencies": {
"@angular/common": "2.1.0", "@angular/common": "2.1.0",
"@angular/compiler": "2.1.0", "@angular/compiler": "2.1.0",
"@angular/compiler-cli": "2.1.0",
"@angular/core": "2.1.0", "@angular/core": "2.1.0",
"@angular/forms": "2.1.0", "@angular/forms": "2.1.0",
"@angular/http": "2.1.0", "@angular/http": "2.1.0",
@ -38,6 +39,7 @@
"@angular/platform-browser-dynamic": "2.1.0", "@angular/platform-browser-dynamic": "2.1.0",
"@angular/platform-server": "2.1.0", "@angular/platform-server": "2.1.0",
"@angular/router": "3.1.0", "@angular/router": "3.1.0",
"@ngtools/webpack": "^1.1.4",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.6", "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.6",
"angular2-express-engine": "~2.1.0-rc.1", "angular2-express-engine": "~2.1.0-rc.1",
"angular2-platform-node": "~2.1.0-rc.1", "angular2-platform-node": "~2.1.0-rc.1",
@ -49,7 +51,7 @@
"methods": "~1.1.2", "methods": "~1.1.2",
"preboot": "~4.5.2", "preboot": "~4.5.2",
"rxjs": "5.0.0-beta.12", "rxjs": "5.0.0-beta.12",
"zone.js": "~0.6.25" "zone.js": "~0.6.26"
}, },
"devDependencies": { "devDependencies": {
"@types/body-parser": "0.0.29", "@types/body-parser": "0.0.29",
@ -62,14 +64,14 @@
"@types/node": "^6.0.38", "@types/node": "^6.0.38",
"@types/serve-static": "^1.7.27", "@types/serve-static": "^1.7.27",
"angular2-template-loader": "^0.4.0", "angular2-template-loader": "^0.4.0",
"awesome-typescript-loader": "^2.2.4",
"cookie-parser": "^1.4.3", "cookie-parser": "^1.4.3",
"imports-loader": "^0.6.5", "imports-loader": "^0.6.5",
"json-loader": "^0.5.4", "json-loader": "^0.5.4",
"nodemon": "^1.10.0", "nodemon": "^1.10.0",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"rimraf": "^2.5.4", "rimraf": "^2.5.4",
"string-replace-loader": "github:gdi2290/string-replace-loader", "string-replace-loader": "^1.0.5",
"ts-loader": "^0.8.2",
"ts-node": "^1.3.0", "ts-node": "^1.3.0",
"typescript": "2.0.2", "typescript": "2.0.2",
"webpack": "2.1.0-beta.25", "webpack": "2.1.0-beta.25",

View File

@ -1,11 +1,11 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; 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'; import { App } from './app/app';
//for routing: //for routing:
import { routing } from './app/app.routing'; import { routing } from './app/app.routing';
import { Routes, RouterModule } from "@angular/router"; import { Routes, RouterModule } from "@angular/router";
import { CacheService } from './app/universal-cache';
// custom modules:: // custom modules::
import {ClaimModule} from './app/claimPages/claim.module'; import {ClaimModule} from './app/claimPages/claim.module';
import {SearchModule} from './app/searchPages/search.module'; import {SearchModule} from './app/searchPages/search.module';
@ -43,7 +43,9 @@ import {TestComponent} from './app/test/test.component';
TestComponent TestComponent
], ],
providers: [ providers: [
{ provide: 'isBrowser', useValue: isBrowser },
{ provide: 'isNode', useValue: isNode },
CacheService
] ]
}) })
export class MainModule { export class MainModule {

69
portal-2/src/app/api.ts Normal file
View File

@ -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();
}
}

View File

@ -5,7 +5,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication
import { SearchPublicationsService } from '../../services/searchPublications.service'; import { SearchPublicationsService } from '../../services/searchPublications.service';
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
import { SearchDatasetsService } from '../../services/searchDatasets.service'; import { SearchDatasetsService } from '../../services/searchDatasets.service';
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
@Component({ @Component({
selector: 'tabs', selector: 'tabs',
@ -98,10 +97,9 @@ export class TabsComponent {
constructor (private route: ActivatedRoute, constructor (private route: ActivatedRoute,
private _searchPublicationsService: SearchPublicationsService, private _searchPublicationsService: SearchPublicationsService,
private _searchDatasetsService: SearchDatasetsService, private _searchDatasetsService: SearchDatasetsService) {
private _refineResultsService:RefineResultsService) {
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); 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() { ngOnInit() {

View File

@ -8,7 +8,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication
import { SearchPublicationsService } from '../../services/searchPublications.service'; import { SearchPublicationsService } from '../../services/searchPublications.service';
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
import { SearchDatasetsService } from '../../services/searchDatasets.service'; import { SearchDatasetsService } from '../../services/searchDatasets.service';
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
import { SearchResultComponent } from '../../searchPages/searchUtils/searchResult.component'; import { SearchResultComponent } from '../../searchPages/searchUtils/searchResult.component';
import {OpenaireProperties} from '../../utils/properties/openaireProperties'; import {OpenaireProperties} from '../../utils/properties/openaireProperties';
@ -38,11 +37,10 @@ export class PersonComponent {
constructor (private _personService: PersonService, constructor (private _personService: PersonService,
private route: ActivatedRoute, private route: ActivatedRoute,
private _searchPublicationsService: SearchPublicationsService, private _searchPublicationsService: SearchPublicationsService,
private _searchDatasetsService: SearchDatasetsService, private _searchDatasetsService: SearchDatasetsService) {
private _refineResultsService:RefineResultsService) {
console.info('person constructor'); console.info('person constructor');
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); 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() { ngOnInit() {

View File

@ -9,7 +9,6 @@ import { SearchPublicationsComponent } from '../../searchPages/searchPublication
import {SearchPublicationsService} from '../../services/searchPublications.service'; import {SearchPublicationsService} from '../../services/searchPublications.service';
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component'; import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
import { SearchDatasetsService } from '../../services/searchDatasets.service'; import { SearchDatasetsService } from '../../services/searchDatasets.service';
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
import {SearchResultComponent} from '../../searchPages/searchUtils/searchResult.component'; import {SearchResultComponent} from '../../searchPages/searchUtils/searchResult.component';
import {OpenaireProperties} from '../../utils/properties/openaireProperties'; import {OpenaireProperties} from '../../utils/properties/openaireProperties';
@ -45,12 +44,11 @@ export class ProjectComponent implements OnInit{
constructor (private _projectService: ProjectService, constructor (private _projectService: ProjectService,
private route: ActivatedRoute, private route: ActivatedRoute,
private _searchPublicationsService: SearchPublicationsService, private _searchPublicationsService: SearchPublicationsService,
private _searchDatasetsService: SearchDatasetsService, private _searchDatasetsService: SearchDatasetsService) {
private _refineResultsService:RefineResultsService) {
console.info('project constructor'); console.info('project constructor');
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); 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() { ngOnInit() {

View File

@ -16,7 +16,6 @@ import {SearchProjectsService} from '../../services/searchProjects.service';
import {SearchDatasetsService} from '../../services/searchDatasets.service'; import {SearchDatasetsService} from '../../services/searchDatasets.service';
import {SearchPeopleService} from '../../services/searchPeople.service'; import {SearchPeopleService} from '../../services/searchPeople.service';
import {SearchOrganizationsService} from '../../services/searchOrganizations.service'; import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
import {OpenaireProperties} from '../../utils/properties/openaireProperties'; import {OpenaireProperties} from '../../utils/properties/openaireProperties';
@ -148,12 +147,12 @@ export class SearchComponent {
private _searchDatasetsService: SearchDatasetsService, private _searchDatasetsService: SearchDatasetsService,
private _searchOrganizationsService: SearchOrganizationsService, private _searchOrganizationsService: SearchOrganizationsService,
private _searchPeopleService: SearchPeopleService, private _searchPeopleService: SearchPeopleService,
private _refineResultsService: RefineResultsService, private location: Location ) { private location: Location ) {
this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService); this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService); this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService);
this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService); this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService);
this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService,_refineResultsService); this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService,_refineResultsService); this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService);
this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService); this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService);
} }

View File

@ -3,7 +3,6 @@ import { ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common'; import {Location} from '@angular/common';
import { Filter, Value} from './searchUtils/searchHelperClasses.class'; import { Filter, Value} from './searchUtils/searchHelperClasses.class';
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
import {SearchDatasetsService} from '../services/searchDatasets.service'; import {SearchDatasetsService} from '../services/searchDatasets.service';
import {SearchResult} from '../utils/entities/searchResult'; import {SearchResult} from '../utils/entities/searchResult';
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
@ -31,25 +30,28 @@ export class SearchDatasetsComponent {
private page :number = 1; private page :number = 1;
private size :number = 10; private size :number = 10;
private sub: any; private sub: any;
private refineFields = []; private subResults: any;
private searchFields:SearchFields = new SearchFields(); 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<string, string>;
private _location:Location; private _location:Location;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @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(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status =errorCodes.LOADING; this.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchDatasets(); this.baseUrl = OpenaireProperties.getLinkToSearchDatasets();
this.refineFields = this.searchFields.DATASET_FIELDS;
if(!this.searchPage){
this.searchPage = new SearchPageComponent(this._location);
}
} }
private ngOnInit() { private ngOnInit() {
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
this.searchPage.indexIdsMap = this.indexIdsMap;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
this.sub = this.route.queryParams.subscribe(params => { this.sub = this.route.queryParams.subscribe(params => {
this.keyword = (params['keyword']?params['keyword']:''); this.keyword = (params['keyword']?params['keyword']:'');
@ -57,64 +59,21 @@ export class SearchDatasetsComponent {
// this.getRefineResults(); // this.getRefineResults();
//this.getResults(this.keyword, this.page, this.size, "searchPage"); //this.getResults(this.keyword, this.page, this.size, "searchPage");
var queryParameters = this.searchPage.getQueryParametersFromUrl(params); var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
this.getResults(queryParameters, true, this.page, this.size); this._getResults(queryParameters, true, this.page, this.size);
}); });
} }
private ngOnDestroy() { private ngOnDestroy() {
this.sub.unsubscribe(); if(this.sub){
} this.sub.unsubscribe();
public getRefineResults (){ }
// this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( if(this.subResults){
this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( this.subResults.unsubscribe();
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();
} }
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){ public getResultsForEntity(entity:string, id:string, page: number, size: number){
var parameters = ""; var parameters = "";
@ -161,14 +120,17 @@ public getResults(keyword:string,refine:boolean, page: number, size: number){
this._getResults(parameters,refine,page,size); this._getResults(parameters,refine,page,size);
} }
private _getResults(parameters:string,refine:boolean, page: number, size: number){ private _getResults(parameters:string,refine:boolean, page: number, size: number){
if(!refine && !this.searchPage){
this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( this.searchPage = new SearchPageComponent(this._location);
}
this.subResults = this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
data => { data => {
this.totalResults = data[0]; this.totalResults = data[0];
console.info("search Datasets: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); console.info("search Datasets: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]");
this.results = data[1]; this.results = data[1];
this.filters = this.searchPage.checkSelectedFilters(data[2]); this.filters = data[2];
this.searchPage.updateBaseUrlWithParameters(this.filters); this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status = errorCodes.DONE; this.status = errorCodes.DONE;
if(this.totalResults == 0 ){ if(this.totalResults == 0 ){

View File

@ -1,10 +1,7 @@
import {Component, Input, ViewChild} from '@angular/core'; import {Component, Input, ViewChild} from '@angular/core';
import { ActivatedRoute} from '@angular/router'; import { ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common'; import {Location} from '@angular/common';
import { Filter, Value} from './searchUtils/searchHelperClasses.class'; import { Filter, Value} from './searchUtils/searchHelperClasses.class';
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
import {SearchOrganizationsService} from '../services/searchOrganizations.service'; import {SearchOrganizationsService} from '../services/searchOrganizations.service';
import {SearchResult} from '../utils/entities/searchResult'; import {SearchResult} from '../utils/entities/searchResult';
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
@ -32,90 +29,48 @@ export class SearchOrganizationsComponent {
private page :number = 1; private page :number = 1;
private size :number = 10; private size :number = 10;
private sub: any; private sub: any;
private _location:Location; private subResults: any;
private refineFields = [];
private searchFields:SearchFields = new SearchFields(); 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<string, string>;
private _location:Location;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService, private _refineResultsService:RefineResultsService ) { constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) {
//this.results =[];
//this.filters =[];
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status =errorCodes.LOADING; this.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchOrganizations(); this.baseUrl = OpenaireProperties.getLinkToSearchOrganizations();
if(!this.searchPage){
this.searchPage = new SearchPageComponent(this._location);
}
} }
private ngOnInit() { private ngOnInit() {
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
this.searchPage.indexIdsMap = this.indexIdsMap;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
this.sub = this.route.queryParams.subscribe(params => { this.sub = this.route.queryParams.subscribe(params => {
this.keyword = (params['keyword']?params['keyword']:''); this.keyword = (params['keyword']?params['keyword']:'');
this.page = (params['page']=== undefined)?1:+params['page']; this.page = (params['page']=== undefined)?1:+params['page'];
this.getRefineResults(); var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
this.getResults(this.keyword, true, this.page, this.size); this._getResults(queryParameters, true, this.page, this.size);
}); });
} }
private ngOnDestroy() { 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){ public getResults(keyword:string,refine:boolean, page: number, size: number){
var parameters = ""; var parameters = "";
if(keyword.length > 0){ if(keyword.length > 0){
@ -125,13 +80,17 @@ export class SearchOrganizationsComponent {
} }
private _getResults(parameters:string,refine:boolean, page: number, size: number){ 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 => { data => {
this.totalResults = data[0]; this.totalResults = data[0];
console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]");
this.results = data[1]; this.results = data[1];
this.filters = this.searchPage.checkSelectedFilters(data[2]); this.filters = data[2];
this.searchPage.updateBaseUrlWithParameters(this.filters); this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status = errorCodes.DONE; this.status = errorCodes.DONE;
if(this.totalResults == 0 ){ 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) { private queryChanged($event) {
var parameters = $event.value; var parameters = $event.value;

View File

@ -32,118 +32,44 @@ export class SearchPublicationsComponent {
private page :number = 1; private page :number = 1;
private size :number = 10; private size :number = 10;
private sub: any; private sub: any;
private refineFields = []; private subResults: any;
private searchFields:SearchFields = new SearchFields(); 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<string, string>;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
private _location:Location; private _location:Location;
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) { constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
//this.results =[];
//this.filters =[];
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status =errorCodes.LOADING; this.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchPublications(); 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() { private ngOnInit() {
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
this.searchPage.indexIdsMap = this.indexIdsMap;
this.searchPage.fieldIdsMap = this.fieldIdsMap;
this.sub = this.route.queryParams.subscribe(params => { this.sub = this.route.queryParams.subscribe(params => {
this.keyword = (params['keyword']?params['keyword']:''); this.keyword = (params['keyword']?params['keyword']:'');
this.page = (params['page']=== undefined)?1:+params['page']; this.page = (params['page']=== undefined)?1:+params['page'];
for(var i=0; i<5 ; i++){ var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
var values = []; this._getResults(queryParameters, true, this.page, this.size);
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++;
}
}
}
}
}
}); });
} }
private ngOnDestroy() { 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 { public getCSVResultsForEntity(entity:string, id:string): any {
let exportPublications = []; let exportPublications = [];
@ -247,14 +173,17 @@ public getResults(keyword:string,refine:boolean, page: number, size: number){
this._getResults(parameters,refine,page,size); this._getResults(parameters,refine,page,size);
} }
private _getResults(parameters:string,refine:boolean, page: number, size: number){ private _getResults(parameters:string,refine:boolean, page: number, size: number){
if(!refine && !this.searchPage){
this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( this.searchPage = new SearchPageComponent(this._location);
}
this.subResults = this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
data => { data => {
this.totalResults = data[0]; this.totalResults = data[0];
console.info("search Publications: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); console.info("search Publications: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]");
this.results = data[1]; this.results = data[1];
this.filters = this.searchPage.checkSelectedFilters(data[2]); this.filters = data[2];
this.searchPage.updateBaseUrlWithParameters(this.filters); this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.status = errorCodes.DONE; this.status = errorCodes.DONE;
if(this.totalResults == 0 ){ 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) { private queryChanged($event) {
var parameters = $event.value; var parameters = $event.value;

View File

@ -43,6 +43,14 @@ import {SearchFields} from '../../utils/properties/searchFields';
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group"> <div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group">
<static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2> <static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
</div> </div>
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'boolean'" class="input-group">
<span class="input-group-addon">
<input type="radio" [(ngModel)]="selectedField.value" [name]=selectedField.id value="true">Yes<br>
</span>
<span class="input-group-addon">
<input type="radio" [(ngModel)]="selectedField.value" [name]=selectedField.id value="false">No<br>
</span>
</div>
</div> </div>
@ -109,7 +117,12 @@ export class AdvancedSearchFormComponent {
addField() { addField() {
console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type); 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"));
}
} }

View File

@ -19,7 +19,7 @@ export class SearchDatasetsService {
if(params!= null && params != '' ) { if(params!= null && params != '' ) {
url += params; url += params;
} }
if(refineParams!= null && params != '' ) { if(refineParams!= null && refineParams != '' ) {
url += refineParams; url += refineParams;
} }
url += "&page="+page+"&size="+size; url += "&page="+page+"&size="+size;

View File

@ -20,7 +20,7 @@ export class SearchOrganizationsService {
if(params!= null && params != '' ) { if(params!= null && params != '' ) {
url += params; url += params;
} }
if(refineParams!= null && params != '' ) { if(refineParams!= null && refineParams != '' ) {
url += refineParams; url += refineParams;
} }
url += "&page="+page+"&size="+size; url += "&page="+page+"&size="+size;

View File

@ -19,7 +19,7 @@ export class SearchPublicationsService {
if(params!= null && params != '' ) { if(params!= null && params != '' ) {
url += params; url += params;
} }
if(refineParams!= null && params != '' ) { if(refineParams!= null && refineParams != '' ) {
url += refineParams; url += refineParams;
} }
url += "&page="+page+"&size="+size; url += "&page="+page+"&size="+size;

View File

@ -22,7 +22,6 @@ import {SearchDatasetsService} from './searchDatasets.service';
import {SearchOrganizationsService} from './searchOrganizations.service'; import {SearchOrganizationsService} from './searchOrganizations.service';
import {SearchPeopleService} from './searchPeople.service'; import {SearchPeopleService} from './searchPeople.service';
import {SearchProjectsService} from './searchProjects.service'; import {SearchProjectsService} from './searchProjects.service';
import {RefineResultsService} from './servicesUtils/refineResuts.service';
import {ISVocabulariesService} from './ISVocabularies.service'; import {ISVocabulariesService} from './ISVocabularies.service';
import {RefineFieldResultsService} from './refineFieldResults.service' import {RefineFieldResultsService} from './refineFieldResults.service'
@ -40,7 +39,7 @@ import {RefineFieldResultsService} from './refineFieldResults.service'
SearchCrossrefService, SearchDataciteService, SearchOrcidService, SearchCrossrefService, SearchDataciteService, SearchOrcidService,
SearchPublicationsService, SearchDataprovidersService, DataProviderService, SearchPublicationsService, SearchDataprovidersService, DataProviderService,
SearchProjectsService, SearchDatasetsService, SearchOrganizationsService, SearchProjectsService, SearchDatasetsService, SearchOrganizationsService,
SearchPeopleService,RefineResultsService, ISVocabulariesService, SearchPeopleService, ISVocabulariesService,
RefineFieldResultsService RefineFieldResultsService
], ],
exports: [ exports: [

View File

@ -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 => <any> 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<data.length; j++) {
var filter:Filter = new Filter();
filter.title = searchFields.FIELDS_NAMES[fields[j]];
filter.filterId = fields[j];
filter.originalFilterId = fields[j];
let field = data[j][fields[j]];
for(let i=0; i<field.length; i++) {
var value:Value = new Value();
value.name = field[i].name;
value.number = field[i].count;
value.id = field[i].id;
filter.values.push(value);
}
filters.push(filter);
}
return filters;
}
}

View File

@ -0,0 +1,85 @@
import { Injectable, isDevMode } from '@angular/core';
@Injectable()
export class CacheService {
static KEY = 'CacheService';
_cache = new Map();
/**
* check if there is a value in our store
*/
has(key: string | number): boolean {
let _key = this.normalizeKey(key);
return this._cache.has(_key);
}
/**
* store our state
*/
set(key: string | number, value: any): void {
let _key = this.normalizeKey(key);
this._cache.set(_key, value);
}
/**
* get our cached value
*/
get(key: string | number): any {
let _key = this.normalizeKey(key);
return this._cache.get(_key);
}
/**
* release memory refs
*/
clear(): void {
this._cache.clear();
}
/**
* convert to json for the client
*/
dehydrate(): any {
let json = {};
this._cache.forEach((value: any, key: string) => 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(<number>key);
}
}

View File

@ -1,5 +1,6 @@
export class SearchFields { export class SearchFields {
//main Entities //main Entities
//PUBLICATIONS
public PUBLICATION_INDEX:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid", public PUBLICATION_INDEX:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
"relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
"resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; "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 }} ={ public PROJECT_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null}, ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
["keywords"]:{name:"Keywords",operator:"ky", type:"keyword" , indexField:"projectkeywords"}, ["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"}, ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"funderid"},
["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"fundinglevel0_id"}, ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"fundinglevel0_id"},
["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"fundinglevel1_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"}, ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"fundinglevel2_id"},
["startyear"]:{name:"Start Year",operator:"sa", type:"keyword", indexField:"projectstartyear"}, ["startyear"]:{name:"Start Year",operator:"sa", type:"keyword", indexField:"projectstartyear"},
["endyear"]: {name:"End Year",operator:"ed", type:"keyword", indexField:"projectendyear"}, ["endyear"]: {name:"End Year",operator:"ed", type:"keyword", indexField:"projectendyear"},
["sc39"]: {name:"Community",operator:"sc", type:"keyword", indexField:"projectecsc39"}, ["sc39"]: {name:"Special Clause 39",operator:"sc", type:"boolean", indexField:"projectecsc39"},
["acronym"]: {name:"Access Mode",operator:"ar", type:"keyword", indexField:'projectacronym'},
["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"},
["code"]: {name:"Project Code",operator:"cd", type:"keyword", indexField:"projectcode"} ["code"]: {name:"Project Code",operator:"cd", type:"keyword", indexField:"projectcode"}
}; };
//DATAPROVIDERS //DATAPROVIDERS
@ -73,15 +74,62 @@ export class SearchFields {
public DATASET_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "relfunderid", //DATASET
"relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id", public DATASET_INDEX:string[] = ["instancetypenameid", "resultlanguageid", //"communityid",
"resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"]; "relfunderid", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
public DATAPROVIDER_FIELDS:string[] = ["datasourcetypeuiid", "datasourceodlanguages", "datasourceodcontenttypes", "datasourcecompatibilityid"]; "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
public ORGANIZATION_FIELDS:string[] = ["organizationcountryid","organizationeclegalbody"]; public ADVANCED_SEARCH_DATASET_PARAM:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0",
public PROJECT_FIELDS:string[] = ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"]; "funderlv1","funderlv2","community","access","hostedBy","collectedFrom"];
public PEOPLE_FIELDS:string[] = []; public DATASET_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community",
//extra pages [ "relfunderid"]:"funder",
public ENTITYREGISTRIES_DATAPROVIDER_FIELDS:string[] = []; ["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", public HIDDEN_FIELDS:string[] = ["fundinglevel0_id","fundinglevel1_id","fundinglevel2_id",
@ -102,49 +150,9 @@ export class SearchFields {
["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country", ["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country",
["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"}; ["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"}]; 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 (){ constructor (){
} }

View File

@ -66,8 +66,8 @@ export class StaticAutocomplete2Component {
constructor ( private _vocabulariesService: ISVocabulariesService,private _refineService: RefineFieldResultsService, private myElement: ElementRef) { constructor ( private _vocabulariesService: ISVocabulariesService,private _refineService: RefineFieldResultsService, private myElement: ElementRef) {
} }
ngOnDestroy(){ ngOnDestroy(){
if(this.sub){ if(this.sub && this.sub != undefined){
this.sub.destroy(); this.sub.unsubscribe();
} }
} }
ngOnInit () { ngOnInit () {

View File

@ -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'; 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 path from 'path';
import * as express from 'express'; import * as express from 'express';
import * as bodyParser from 'body-parser'; import * as bodyParser from 'body-parser';
@ -21,7 +32,14 @@ const app = express();
const ROOT = path.join(path.resolve(__dirname, '..')); const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View // 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('views', __dirname);
app.set('view engine', 'html'); app.set('view engine', 'html');
@ -43,7 +61,6 @@ function ngApp(req, res) {
res.render('index', { res.render('index', {
req, req,
res, res,
ngModule: MainModule,
preboot: false, preboot: false,
baseUrl: '/', baseUrl: '/',
requestUrl: req.originalUrl, requestUrl: req.originalUrl,

View File

@ -1,7 +1,6 @@
var webpack = require('webpack'); var webpack = require('webpack');
var path = require('path'); var path = require('path');
var commonConfig = { var commonConfig = {
resolve: { resolve: {
extensions: ['.ts', '.js', '.json'] extensions: ['.ts', '.js', '.json']
@ -9,7 +8,7 @@ var commonConfig = {
module: { module: {
loaders: [ loaders: [
// TypeScript // TypeScript
{ test: /\.ts$/, loaders: ['ts-loader', 'angular2-template-loader'] }, { test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] },
{ test: /\.html$/, loader: 'raw-loader' }, { test: /\.html$/, loader: 'raw-loader' },
{ test: /\.css$/, loader: 'raw-loader' }, { test: /\.css$/, loader: 'raw-loader' },
{ test: /\.json$/, loader: 'json-loader' } { test: /\.json$/, loader: 'json-loader' }
@ -20,8 +19,22 @@ var commonConfig = {
// The (\\|\/) piece accounts for path separators in *nix and Windows // The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)src(\\|\/)linker/, /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
root('./src'), 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([ externals: includeClientPackages([
// include these client packages so we can transform their source with webpack loaders // 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/button', '@angular2-material/button',
'@angular2-material/card', '@angular2-material/card',
@ -82,7 +106,7 @@ var serverConfig = {
__dirname: true, __dirname: true,
__filename: true, __filename: true,
process: true, process: true,
Buffer: true Buffer: false
} }
}; };