Project

General

Profile

« Previous | Next » 

Revision 44383

Update to last unversal project, remove temporarily used refine service, fix the filters/ fields for datasets/ pubs/ org search pages

View differences:

modules/uoa-services-portal/trunk/portal-2/src/app/services/servicesUtils/refineResuts.service.ts
1
import {Injectable} from '@angular/core';
2
import {Http, Response} from '@angular/http';
3
import {Observable}     from 'rxjs/Observable';
4
 // import {RefineParsingUtils} from './services-utils/refineResults.class';
5
 import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
6
 import { SearchFields} from '../../utils/properties/searchFields';
7

  
8
@Injectable()
9
export class RefineResultsService {
10

  
11
    constructor(private http: Http) {}
12

  
13
    getRefineResults(fields:string[]):any {
14

  
15
        return this.http.get('./refineResults.json')
16
                    .map(res => <any> res.json())
17
                    // .do(res => console.log(res))
18
                    .map(res => this.parseRefineResults(res['refineResults'],fields))
19
                    ;
20
    }
21
    public  parseRefineResults (data, fields:string[]):Filter[] {
22
          // var data = this.json.refineReuslts;
23
          var searchFields:SearchFields = new SearchFields();
24
          var filters:Filter[] = [];
25
          for(let j=0; j<data.length; j++) {
26

  
27
            var filter:Filter = new Filter();
28
            filter.title = searchFields.FIELDS_NAMES[fields[j]];
29
            filter.filterId = fields[j];
30
            filter.originalFilterId = fields[j];
31
            let field = data[j][fields[j]];
32
            for(let i=0; i<field.length; i++) {
33
              var value:Value = new Value();
34
              value.name = field[i].name;
35
              value.number = field[i].count;
36
              value.id = field[i].id;
37
              filter.values.push(value);
38

  
39
          }
40
          filters.push(filter);
41
      }
42
        return filters;
43
    }
44

  
45
}
modules/uoa-services-portal/trunk/portal-2/package.json
31 31
  "dependencies": {
32 32
    "@angular/common": "2.1.0",
33 33
    "@angular/compiler": "2.1.0",
34
    "@angular/compiler-cli": "2.1.0",
34 35
    "@angular/core": "2.1.0",
35 36
    "@angular/forms": "2.1.0",
36 37
    "@angular/http": "2.1.0",
......
38 39
    "@angular/platform-browser-dynamic": "2.1.0",
39 40
    "@angular/platform-server": "2.1.0",
40 41
    "@angular/router": "3.1.0",
42
    "@ngtools/webpack": "^1.1.4",
41 43
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.6",
42 44
    "angular2-express-engine": "~2.1.0-rc.1",
43 45
    "angular2-platform-node": "~2.1.0-rc.1",
......
49 51
    "methods": "~1.1.2",
50 52
    "preboot": "~4.5.2",
51 53
    "rxjs": "5.0.0-beta.12",
52
    "zone.js": "~0.6.25"
54
    "zone.js": "~0.6.26"
53 55
  },
54 56
  "devDependencies": {
55 57
    "@types/body-parser": "0.0.29",
......
62 64
    "@types/node": "^6.0.38",
63 65
    "@types/serve-static": "^1.7.27",
64 66
    "angular2-template-loader": "^0.4.0",
67
    "awesome-typescript-loader": "^2.2.4",
65 68
    "cookie-parser": "^1.4.3",
66 69
    "imports-loader": "^0.6.5",
67 70
    "json-loader": "^0.5.4",
68 71
    "nodemon": "^1.10.0",
69 72
    "raw-loader": "^0.5.1",
70 73
    "rimraf": "^2.5.4",
71
    "string-replace-loader": "github:gdi2290/string-replace-loader",
72
    "ts-loader": "^0.8.2",
74
    "string-replace-loader": "^1.0.5",
73 75
    "ts-node": "^1.3.0",
74 76
    "typescript": "2.0.2",
75 77
    "webpack": "2.1.0-beta.25",
modules/uoa-services-portal/trunk/portal-2/webpack.config.ts
1 1
var webpack = require('webpack');
2 2
var path = require('path');
3 3

  
4

  
5 4
var commonConfig = {
6 5
  resolve: {
7 6
    extensions: ['.ts', '.js', '.json']
......
9 8
  module: {
10 9
    loaders: [
11 10
      // TypeScript
12
      { test: /\.ts$/, loaders: ['ts-loader', 'angular2-template-loader'] },
11
      { test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] },
13 12
      { test: /\.html$/, loader: 'raw-loader' },
14 13
      { test: /\.css$/, loader: 'raw-loader' },
15 14
      { test: /\.json$/, loader: 'json-loader' }
......
20 19
      // The (\\|\/) piece accounts for path separators in *nix and Windows
21 20
      /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
22 21
      root('./src'),
23
      {}
24
    )
22
      {
23
        // your Angular Async Route paths relative to this root directory
24
      }
25
    ),
26

  
27
    // To use gzip, you can run 'npm install compression-webpack-plugin --save-dev'
28
    // add 'var CompressionPlugin = require("compression-webpack-plugin");' on the top
29
    // and comment out below codes
30
    //
31
    // new CompressionPlugin({
32
    //   asset: "[path].gz[query]",
33
    //   algorithm: "gzip",
34
    //   test: /\.js$|\.css$|\.html$/,
35
    //   threshold: 10240,
36
    //   minRatio: 0.8
37
    // })
25 38
  ]
26 39

  
27 40
};
......
57 70
  },
58 71
  externals: includeClientPackages([
59 72
    // include these client packages so we can transform their source with webpack loaders
73

  
74
    // '@angular/common',
75
    // '@angular/compiler',
76
    // '@angular/core',
77
    // '@angular/forms',
78
    // '@angular/http',
79
    // '@angular/platform-browser',
80
    // '@angular/platform-browser-dynamic',
81
    // '@angular/platform-server',
82
    // '@angular/router',
83

  
60 84
    '@angular2-material/button',
61 85
    '@angular2-material/button',
62 86
    '@angular2-material/card',
......
82 106
    __dirname: true,
83 107
    __filename: true,
84 108
    process: true,
85
    Buffer: true
109
    Buffer: false
86 110
  }
87 111
};
88 112

  
modules/uoa-services-portal/trunk/portal-2/src/app/utils/staticAutoComplete2.component.ts
66 66
    constructor ( private _vocabulariesService: ISVocabulariesService,private _refineService: RefineFieldResultsService, private myElement: ElementRef) {
67 67
    }
68 68
    ngOnDestroy(){
69
      if(this.sub){
70
        this.sub.destroy();
69
      if(this.sub && this.sub != undefined){
70
        this.sub.unsubscribe();
71 71
      }
72 72
    }
73 73
    ngOnInit () {
modules/uoa-services-portal/trunk/portal-2/src/app/utils/properties/searchFields.ts
1 1
export class SearchFields {
2 2
    //main Entities
3
    //PUBLICATIONS
3 4
     public PUBLICATION_INDEX:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
4 5
      "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
5 6
      "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
......
37 38
       public PROJECT_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
38 39
       ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
39 40
       ["keywords"]:{name:"Keywords",operator:"ky", type:"keyword" , indexField:"projectkeywords"},
41
       ["acronym"]: {name:"Acronym",operator:"ar", type:"keyword", indexField:'projectacronym'},
42
       ["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"},
40 43
       ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"funderid"},
41 44
       ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"fundinglevel0_id"},
42 45
       ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"fundinglevel1_id"},
43 46
       ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"fundinglevel2_id"},
44 47
       ["startyear"]:{name:"Start Year",operator:"sa", type:"keyword", indexField:"projectstartyear"},
45 48
       ["endyear"]: {name:"End Year",operator:"ed", type:"keyword", indexField:"projectendyear"},
46
       ["sc39"]: {name:"Community",operator:"sc", type:"keyword", indexField:"projectecsc39"},
47
       ["acronym"]: {name:"Access Mode",operator:"ar", type:"keyword", indexField:'projectacronym'},
48
       ["title"]: {name:"Title",operator:"tt", type:"keyword", indexField:"projecttitle"},
49
       ["sc39"]: {name:"Special Clause 39",operator:"sc", type:"boolean", indexField:"projectecsc39"},
49 50
       ["code"]: {name:"Project Code",operator:"cd", type:"keyword", indexField:"projectcode"}
50 51
       };
51 52
       //DATAPROVIDERS
......
73 74

  
74 75

  
75 76

  
76
     public DATASET_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "relfunderid",
77
      "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
78
      "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
79
     public DATAPROVIDER_FIELDS:string[] = ["datasourcetypeuiid", "datasourceodlanguages", "datasourceodcontenttypes", "datasourcecompatibilityid"];
80
     public ORGANIZATION_FIELDS:string[] = ["organizationcountryid","organizationeclegalbody"];
81
     public PROJECT_FIELDS:string[] = ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"];
82
     public PEOPLE_FIELDS:string[] = [];
83
    //extra pages
84
     public ENTITYREGISTRIES_DATAPROVIDER_FIELDS:string[] = [];
77
        //DATASET
78
        public DATASET_INDEX:string[] = ["instancetypenameid", "resultlanguageid", //"communityid",
79
         "relfunderid", "relfundinglevel0_id","relfundinglevel1_id","relfundinglevel2_id",
80
         "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
81
         public ADVANCED_SEARCH_DATASET_PARAM:string[] = ["q","title","author","publisher","type", "lang", "funder", "funderlv0",
82
          "funderlv1","funderlv2","community","access","hostedBy","collectedFrom"];
83
          public DATASET_INDEX_PARAM_MAP:{ [key:string]:string } = {["instancetypenameid"]:"type", ["resultlanguageid"]:"lang",["communityid"]:"community",
84
          [ "relfunderid"]:"funder",
85
           ["relfundinglevel0_id"]:"funderlv0",["relfundinglevel1_id"]:"funderlv1",["relfundinglevel2_id"]:"funderlv2",
86
           ["resultacceptanceyear"]:"year",["resultbestlicense"]:"access",["resulthostingdatasourceid"]:"hostedBy",["collectedfromdatasourceid"]:"collectedFrom"};
87
         public DATASET_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
88
         ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
89
         ["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"},
90
         ["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"},
91
         ["publisher"]:{name:"Publisher",operator:"pb", type:"keyword", indexField:"resultpublisher"},
92
         ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"relfunderid"},
93
         ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"relfundinglevel0_id"},
94
         ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"relfundinglevel1_id"},
95
         ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"relfundinglevel2_id"},
96
         ["type"]:{name:"Type",operator:"tp", type:"vocabulary", indexField:"instancetypenameid"},
97
         ["lang"]: {name:"Language",operator:"ln", type:"vocabulary", indexField:"resultlanguageid"},
98
         ["community"]: {name:"Community",operator:"cm", type:"refine", indexField:"communityid"},
99
         ["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicense'},
100
         ["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid"},
101
         ["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid"}
102
         };
85 103

  
86 104

  
105
         //ORGANIZATION
106
         public ORGANIZATION_INDEX:string[] = ["organizationcountryid","organizationeclegalbody"];
107
        public ADVANCED_SEARCH_ORGANIZATION_INDEX_PARAM:string[] = ["q","contenttype","compatibility","country","type"];
108
           public ORGANIZATION_INDEX_PARAM_MAP:{ [key:string]:string } = {["organizationlegalname"]:"contenttype", ["organizationlegalshortname"]:"compatibility",
109
            ["organizationcountryid"]:"country",["organizationeclegalbody"]:"type"};
110
          public ORGANIZATION_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
111
          ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
112
          ["contenttype"]:{name:"Legal Name",operator:"cn", type:"keyword" , indexField:"organizationlegalname"},
113
          ["compatibility"]:{name:"Legal Short Name",operator:"cm", type:"keyword", indexField:"organizationlegalshortname"},
114
          ["country"]:{name:"Country",operator:"pb", type:"keyword", indexField:"organizationcountryid"},
115
          ["type"]:{name:"Type",operator:"fn", type:"refine", indexField:"organizationeclegalbody"},
116

  
117
          };
118

  
119

  
120

  
121
        //PERSON
122
        public PERSON_INDEX:string[] = [];
123
        public ADVANCED_SEARCH_PERSON_INDEX_PARAM:string[] = ["q","contenttype","compatibility","country","type"];
124
        public PERSON_INDEX_INDEX_PARAM_MAP:{ [key:string]:string } = {["personsecondnames"]:"surname", ["personfirstname"]:"name",
125
                      ["personfullname"]:"fullname"};
126
        public PERSON_INDEX_FIELDS_MAP: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
127
                    ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
128
                    ["surname"]:{name:"Surname",operator:"sr", type:"keyword" , indexField:"personsecondnames"},
129
                    ["name"]:{name:"Name",operator:"nm", type:"keyword", indexField:"personfirstname"},
130
                    ["fullname"]:{name:"Full name",operator:"fl", type:"keyword", indexField:"personfullname"}};
131

  
132

  
133

  
134

  
87 135
     public HIDDEN_FIELDS:string[] = ["fundinglevel0_id","fundinglevel1_id","fundinglevel2_id",
88 136
     "relfundinglevel0_id","relfundinglevel1_id,relfundinglevel2_id"];
89 137

  
......
102 150
     ["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country",
103 151
     ["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"};
104 152

  
105
    //  public ADVANCED_FIELDS:string[] = ["instancetypenameid", "resultlanguageid", "communityid", "relfunderid",
106
    //   "relfundinglevel0_id","relfundinglevel1_id,relfundinglevel2_id",
107
    //   "resultacceptanceyear","resultbestlicense","resulthostingdatasourceid","collectedfromdatasourceid"];
108 153

  
109

  
110
    public ADVANCED_FIELDS_PROJECTS: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} ={
111
      ["q"]:{name:"All fields",operator:"op", type:"keyword", indexField:null},
112
      ["title"]:{name:"Title",operator:"tt", type:"keyword" , indexField:"resulttitle"},
113
      ["author"]:{name:"Author",operator:"at", type:"keyword", indexField:"relperson"},
114
      ["publisher"]:{name:"Publisher",operator:"pb", type:"keyword", indexField:"resultpublisher"},
115
      ["funder"]:{name:"Funder",operator:"fn", type:"refine", indexField:"relfunderid"},
116
      ["funderlv0"]:{name:"Funding Stream",operator:"fn0", type:"refine", indexField:"relfundinglevel0_id"},
117
      ["funderlv1"]:{name:"Funding Substream Level 1",operator:"fn1", type:"refine", indexField:"relfundinglevel1_id"},
118
      ["funderlv2"]:{name:"Funding Substream Level 2",operator:"fn2", type:"refine", indexField:"relfundinglevel2_id"},
119
      ["type"]:{name:"Type",operator:"tp", type:"vocabulary", indexField:"instancetypenameid"},
120
      ["lang"]: {name:"Language",operator:"ln", type:"vocabulary", indexField:"resultlanguageid"},
121
      ["community"]: {name:"Community",operator:"cm", type:"refine", indexField:"communityid"},
122
      ["access"]: {name:"Access Mode",operator:"ac", type:"vocabulary", indexField:'resultbestlicense'},
123
      ["hostedBy"]: {name:"Hosted by data provider",operator:"hs", type:"refine", indexField:"resulthostingdatasourceid"},
124
      ["collectedFrom"]: {name:"Collected from data provider",operator:"cl", type:"refine", indexField:"collectedfromdatasourceid"}
125
    };
126 154
      public ADVANCED_SEARCH_OPERATORS:[{name:string, id:string}] = [{name:"AND",id:"and"},{name:"OR",id:"or"},{name:"NOT",id:"not"}];
127 155

  
128

  
129

  
130

  
131

  
132

  
133

  
134

  
135

  
136
      // ,["communityid"]: "Context",["resultacceptanceyear"]:"Year",
137
      // ["resultbestlicense"]:"Access Mode",["resulthostingdatasourceid"]:"Hosting Data provider",
138
      // ["collectedfromdatasourceid"]:"Collected from", ["datasourcetypeuiid"]:"Compatibility Type", ["datasourceodlanguages"]:"Language",
139
      // ["datasourceodcontenttypes"]: "Type", ["datasourcecompatibilityid"]:"Compatibility Type", ["organizationcountryid"]:"Country",
140
      // ["organizationeclegalbody"]:"Type",["projectstartyear"]:"Start Year",["projectendyear"]:"End Year",["projectecsc39"]:"Special Clause 39"};
141

  
142

  
143
      // public getPROJECT_FIELDS(){
144
      //   return this.PROJECT_FIELDS;
145
      // }
146

  
147

  
148 156
     constructor (){
149 157
     }
150 158

  
modules/uoa-services-portal/trunk/portal-2/src/app/services/searchDatasets.service.ts
19 19
        if(params!= null && params != ''  ) {
20 20
            url += params;
21 21
        }
22
        if(refineParams!= null && params != ''  ) {
22
        if(refineParams!= null && refineParams != ''  ) {
23 23
            url += refineParams;
24 24
        }
25 25
        url += "&page="+page+"&size="+size;
modules/uoa-services-portal/trunk/portal-2/src/app/services/services.module.ts
22 22
import {SearchOrganizationsService} from './searchOrganizations.service';
23 23
import {SearchPeopleService} from './searchPeople.service';
24 24
import {SearchProjectsService} from './searchProjects.service';
25
import {RefineResultsService} from './servicesUtils/refineResuts.service';
26 25

  
27 26
import {ISVocabulariesService} from './ISVocabularies.service';
28 27
import {RefineFieldResultsService} from './refineFieldResults.service'
......
40 39
    SearchCrossrefService, SearchDataciteService, SearchOrcidService,
41 40
    SearchPublicationsService, SearchDataprovidersService, DataProviderService,
42 41
    SearchProjectsService, SearchDatasetsService, SearchOrganizationsService,
43
    SearchPeopleService,RefineResultsService, ISVocabulariesService,
42
    SearchPeopleService, ISVocabulariesService,
44 43
    RefineFieldResultsService
45 44
],
46 45
  exports: [
modules/uoa-services-portal/trunk/portal-2/src/app/services/searchOrganizations.service.ts
20 20
        if(params!= null && params != ''  ) {
21 21
            url += params;
22 22
        }
23
        if(refineParams!= null && params != ''  ) {
23
        if(refineParams!= null && refineParams != ''  ) {
24 24
            url += refineParams;
25 25
        }
26 26
        url += "&page="+page+"&size="+size;
modules/uoa-services-portal/trunk/portal-2/src/app/services/searchPublications.service.ts
19 19
        if(params!= null && params != ''  ) {
20 20
            url += params;
21 21
        }
22
        if(refineParams!= null && params != ''  ) {
22
        if(refineParams!= null && refineParams != ''  ) {
23 23
            url += refineParams;
24 24
        }
25 25
        url += "&page="+page+"&size="+size;
modules/uoa-services-portal/trunk/portal-2/src/app/searchPages/find/search.component.ts
16 16
import {SearchDatasetsService} from '../../services/searchDatasets.service';
17 17
import {SearchPeopleService} from '../../services/searchPeople.service';
18 18
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
19
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
20 19

  
21 20
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
22 21

  
......
148 147
      private _searchDatasetsService: SearchDatasetsService,
149 148
      private _searchOrganizationsService: SearchOrganizationsService,
150 149
      private _searchPeopleService: SearchPeopleService,
151
      private _refineResultsService: RefineResultsService, private location: Location ) {
150
      private location: Location ) {
152 151
    this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
153 152
    this.searchDataProvidersComponent = new SearchDataprovidersComponent(this.route,this._searchDataprovidersService);
154 153
    this.searchProjectsComponent = new SearchProjectsComponent(this.route, this._searchProjectsService);
155
    this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService,_refineResultsService);
156
    this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService,_refineResultsService);
154
    this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
155
    this.searchOrganizationsComponent = new SearchOrganizationsComponent(this.route, this._searchOrganizationsService);
157 156
    this.searchPeopleComponent = new SearchPeopleComponent(this.route, this._searchPeopleService);
158 157
  }
159 158

  
modules/uoa-services-portal/trunk/portal-2/src/app/searchPages/searchOrganizations.component.ts
1 1
import {Component, Input, ViewChild} from '@angular/core';
2 2
import { ActivatedRoute} from '@angular/router';
3 3
import {Location} from '@angular/common';
4

  
5 4
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
6

  
7
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
8 5
import {SearchOrganizationsService} from '../services/searchOrganizations.service';
9 6
import {SearchResult}     from '../utils/entities/searchResult';
10 7
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
......
32 29
  private page :number = 1;
33 30
  private size :number = 10;
34 31
  private sub: any;
32
  private subResults: any;
33
  private searchFields:SearchFields = new SearchFields();
34
  private refineFields: string[] =  this.searchFields.ORGANIZATION_INDEX;
35
  private indexIdsMap: { [key:string]:string } = this.searchFields.ORGANIZATION_INDEX_PARAM_MAP;
36
  private fieldIdsMap:  { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.ORGANIZATION_FIELDS_MAP;
37
  private urlParams : Map<string, string>;
35 38
  private _location:Location;
36
  private refineFields = [];
37
  private searchFields:SearchFields = new SearchFields();
38 39

  
39 40
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
40 41

  
41
  constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService,  private _refineResultsService:RefineResultsService  ) {
42
    //this.results =[];
43
    //this.filters =[];
42
  constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) {
43

  
44 44
    var errorCodes:ErrorCodes = new ErrorCodes();
45 45
    this.status =errorCodes.LOADING;
46 46
    this.baseUrl = OpenaireProperties.getLinkToSearchOrganizations();
47
    if(!this.searchPage){
48
      this.searchPage = new SearchPageComponent(this._location);
49
    }
47

  
50 48
  }
51 49

  
52 50
  private ngOnInit() {
53 51
    this.searchPage.refineFields = this.refineFields;
52
    this.searchPage.indexIdsMap = this.indexIdsMap;
53
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
54 54

  
55 55
    this.sub =  this.route.queryParams.subscribe(params => {
56
    this.keyword = (params['keyword']?params['keyword']:'');
57
    this.page = (params['page']=== undefined)?1:+params['page'];
56
      this.keyword = (params['keyword']?params['keyword']:'');
57
      this.page = (params['page']=== undefined)?1:+params['page'];
58 58

  
59
    this.getRefineResults();
60
    this.getResults(this.keyword, true, this.page, this.size);
59
      var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
60
       this._getResults(queryParameters, true, this.page, this.size);
61 61
    });
62 62
  }
63 63

  
64 64
  private ngOnDestroy() {
65
    this.sub.unsubscribe();
65
    if(this.sub){
66
      this.sub.unsubscribe();
67
    }
68
    if(this.subResults){
69
      this.subResults.unsubscribe();
70
    }
66 71
  }
67 72

  
68 73

  
69
  public getRefineResults (){
70
    // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe(
71
    this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe(
72

  
73
        data => {
74

  
75
            this.filters = data;
76

  
77
        },
78
        err => {
79
            console.error(err);
80
             //TODO check erros (service not available, bad request)
81
            // if( ){
82
            //   this.status = ErrorCodes.ERROR;
83
            // }
84

  
85
        }
86
    );
87
  }
88
/*
89
  public getResults(parameters:string, page: number, size: number){
90
    console.info("getResults: Execute search query "+parameters);
91

  
92
    this._searchOrganizationsService.searchOrganizations(parameters, page, size).subscribe(
93
        data => {
94
            this.totalResults = data[0];
95
            console.info("searchPubl total="+this.totalResults);
96
            this.results = data[1];
97
            var errorCodes:ErrorCodes = new ErrorCodes();
98
             this.status = errorCodes.DONE;
99
            if(this.totalResults == 0 ){
100
              this.status = errorCodes.NONE;
101
            }
102
        },
103
        err => {
104
            console.error(err);
105
            console.info("error");
106
            //TODO check erros (service not available, bad request)
107
            // if( ){
108
            //   this.status = ErrorCodes.ERROR;
109
            // }
110
            var errorCodes:ErrorCodes = new ErrorCodes();
111
            this.status = errorCodes.NOT_AVAILABLE;
112
        }
113
    );
114
  }
115

  
116
  */
117

  
118

  
119 74
    public getResults(keyword:string,refine:boolean, page: number, size: number){
120 75
      var parameters = "";
121 76
      if(keyword.length > 0){
......
125 80
    }
126 81
    private _getResults(parameters:string,refine:boolean, page: number, size: number){
127 82

  
128
      this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
83
      if(!refine && !this.searchPage){
84
          this.searchPage = new SearchPageComponent(this._location);
85
      }
86
      this.subResults = this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
129 87
          data => {
130 88
              this.totalResults = data[0];
131 89
              console.info("search Organizations: [Parameters:"+parameters+" ]  [total results:"+this.totalResults+"]");
132 90
              this.results = data[1];
133
                this.filters = this.searchPage.checkSelectedFilters(data[2]);
134
                this.searchPage.updateBaseUrlWithParameters(this.filters);
91
              this.filters = data[2];
92
              this.searchPage.checkSelectedFilters(this.filters);
93
              this.searchPage.updateBaseUrlWithParameters(this.filters);
135 94
              var errorCodes:ErrorCodes = new ErrorCodes();
136 95
              this.status = errorCodes.DONE;
137 96
              if(this.totalResults == 0 ){
......
150 109
      );
151 110
    }
152 111

  
153
/*
154
public getResults(keyword:string,refine:boolean, page: number, size: number){
155
  var parameters = "";
156
  if(keyword.length > 0){
157
    parameters = "q=" + keyword + "&op=and";
158
  }
159
  this._getResults(parameters,refine,page,size);
160
}
161
private _getResults(parameters:string,refine:boolean, page: number, size: number){
162 112

  
163
  this._searchOrganizationsService.searchOrganizations(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
164
      data => {
165
          this.totalResults = data[0];
166
          console.info("search Organizations: [Parameters:"+parameters+" ]  [total results:"+this.totalResults+"]");
167
          this.results = data[1];
168
            this.filters = this.searchPage.checkSelectedFilters(data[2]);
169
            this.searchPage.updateBaseUrlWithParameters(this.filters);
170
          var errorCodes:ErrorCodes = new ErrorCodes();
171
          this.status = errorCodes.DONE;
172
          if(this.totalResults == 0 ){
173
            this.status = errorCodes.NONE;
174
          }
175
      },
176
      err => {
177
          console.error(err);
178
           //TODO check erros (service not available, bad request)
179
          // if( ){
180
          //   this.status = ErrorCodes.ERROR;
181
          // }
182
          var errorCodes:ErrorCodes = new ErrorCodes();
183
          this.status = errorCodes.ERROR;
184
      }
185
  );
186
}
187
*/
188

  
189
  private setFilters(){
190
    //TODO set filters from
191
  }
192

  
193 113
  private queryChanged($event) {
194 114
    var parameters = $event.value;
195 115
    console.info("queryChanged: Execute search query "+parameters);
modules/uoa-services-portal/trunk/portal-2/src/app/searchPages/searchDatasets.component.ts
3 3
import {Location} from '@angular/common';
4 4
import { Filter, Value} from './searchUtils/searchHelperClasses.class';
5 5

  
6
import {RefineResultsService} from '../services/servicesUtils/refineResuts.service';
7 6
import {SearchDatasetsService} from '../services/searchDatasets.service';
8 7
import {SearchResult}     from '../utils/entities/searchResult';
9 8
import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties';
......
31 30
  private page :number = 1;
32 31
  private size :number = 10;
33 32
  private sub: any;
34
  private refineFields = [];
33
  private subResults: any;
35 34
  private searchFields:SearchFields = new SearchFields();
35
  private refineFields: string[] =  this.searchFields.DATASET_INDEX;
36
  private indexIdsMap: { [key:string]:string } = this.searchFields.DATASET_INDEX_PARAM_MAP;
37
  private fieldIdsMap:  { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.DATASET_FIELDS_MAP;
38
  private urlParams : Map<string, string>;
36 39
  private _location:Location;
37 40

  
38 41

  
39 42
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
40
  constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService,  private _refineResultsService:RefineResultsService ) {
43
  constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService ) {
41 44

  
42 45
    var errorCodes:ErrorCodes = new ErrorCodes();
43 46
    this.status =errorCodes.LOADING;
44 47
    this.baseUrl = OpenaireProperties.getLinkToSearchDatasets();
45
    this.refineFields = this.searchFields.DATASET_FIELDS;
46
    if(!this.searchPage){
47
      this.searchPage = new SearchPageComponent(this._location);
48
    }
48

  
49 49
  }
50 50

  
51 51
  private ngOnInit() {
52 52
    this.searchPage.refineFields = this.refineFields;
53
    this.searchPage.indexIdsMap = this.indexIdsMap;
54
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
53 55

  
54 56
    this.sub =  this.route.queryParams.subscribe(params => {
55 57
      this.keyword = (params['keyword']?params['keyword']:'');
......
57 59
      // this.getRefineResults();
58 60
      //this.getResults(this.keyword, this.page, this.size, "searchPage");
59 61
      var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
60
      this.getResults(queryParameters, true, this.page, this.size);
62
       this._getResults(queryParameters, true, this.page, this.size);
63

  
61 64
    });
62 65
  }
63 66

  
64 67
  private ngOnDestroy() {
65
    this.sub.unsubscribe();
68
    if(this.sub){
69
      this.sub.unsubscribe();
70
    }
71
    if(this.subResults){
72
      this.subResults.unsubscribe();
73
    }
66 74
  }
67
  public getRefineResults (){
68
    // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe(
69
    this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe(
70 75

  
71
        data => {
72 76

  
73
            this.filters = data;
74

  
75
        },
76
        err => {
77
            console.error(err);
78
             //TODO check erros (service not available, bad request)
79
            // if( ){
80
            //   this.status = ErrorCodes.ERROR;
81
            // }
82

  
83
        }
84
    );
85
  }
86

  
87
  /*
88
  public getResults(parameters:string, page: number, size: number, flag: string){
89
    console.info("Search Datasets: Execute search query "+parameters);
90
    if(flag == 'searchPage' || flag == 'claim') {
91
        //parameters = parameters + this.searchPage.getRefineFieldsQuery();
92
    }
93
    this._searchDatasetsService.searchDatasets(parameters, page, size, flag, this.searchPage.getFields()).subscribe(
94
        data => {
95
            this.totalResults = data[0];
96
            console.info("Search Datasets: results="+this.totalResults);
97
            this.results = data[1];
98
            this.filters = data[2];
99
            var errorCodes:ErrorCodes = new ErrorCodes();
100
             this.status = errorCodes.DONE;
101
            if(this.totalResults == 0 ){
102
              this.status = errorCodes.NONE;
103
            }
104
        },
105
        err => {
106
            console.error(err);
107
            console.info("error");
108
            //TODO check erros (service not available, bad request)
109
            // if( ){
110
            //   this.status = ErrorCodes.ERROR;
111
            // }
112
            var errorCodes:ErrorCodes = new ErrorCodes();
113
            this.status = errorCodes.NOT_AVAILABLE;
114
        }
115
    );
116
  }
117
*/
118 77
public getResultsForEntity(entity:string, id:string, page: number, size: number){
119 78
  var parameters = "";
120 79

  
......
161 120
  this._getResults(parameters,refine,page,size);
162 121
}
163 122
private _getResults(parameters:string,refine:boolean, page: number, size: number){
164

  
165
  this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
123
  if(!refine && !this.searchPage){
124
      this.searchPage = new SearchPageComponent(this._location);
125
  }
126
  this.subResults = this._searchDatasetsService.searchDatasets(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
166 127
      data => {
167 128
          this.totalResults = data[0];
168 129
          console.info("search Datasets: [Parameters:"+parameters+" ]  [total results:"+this.totalResults+"]");
169 130
          this.results = data[1];
170
            this.filters = this.searchPage.checkSelectedFilters(data[2]);
171
            this.searchPage.updateBaseUrlWithParameters(this.filters);
131
          this.filters = data[2];
132
          this.searchPage.checkSelectedFilters(this.filters);
133
          this.searchPage.updateBaseUrlWithParameters(this.filters);
172 134
          var errorCodes:ErrorCodes = new ErrorCodes();
173 135
          this.status = errorCodes.DONE;
174 136
          if(this.totalResults == 0 ){
modules/uoa-services-portal/trunk/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts
43 43
                    <div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group">
44 44
                    <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>
45 45
                    </div>
46
                    <div *ngIf = "fieldIdsMap[selectedField.id].type == 'boolean'" class="input-group">
47
                       <span class="input-group-addon">
48
                          <input type="radio" [(ngModel)]="selectedField.value"  [name]=selectedField.id value="true">Yes<br>
49
                      </span>
50
                      <span class="input-group-addon">
51
                        <input type="radio" [(ngModel)]="selectedField.value"  [name]=selectedField.id value="false">No<br>
52
                      </span>
53
                  </div>
46 54
                </div>
47 55

  
48 56

  
......
109 117

  
110 118
    addField() {
111 119
        console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type);
112
        this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name,this.fieldIdsMap[this.newFieldId].type,"","and"));
120
        var type = this.fieldIdsMap[this.newFieldId].type;
121
        if(type == "boolean"){
122
          this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
123
        }else{
124
          this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
125
        }
113 126

  
114 127
    }
115 128

  
modules/uoa-services-portal/trunk/portal-2/src/app/searchPages/searchPublications.component.ts
32 32
  private page :number = 1;
33 33
  private size :number = 10;
34 34
  private sub: any;
35
  private refineFields = [];
35
  private subResults: any;
36 36
  private searchFields:SearchFields = new SearchFields();
37
  private refineFields: string[] =  this.searchFields.PUBLICATION_INDEX;
38
  private indexIdsMap: { [key:string]:string } = this.searchFields.PUBLICATION_INDEX_PARAM_MAP;
39
  private fieldIdsMap:  { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PUBLICATION_FIELDS_MAP;
40
  private urlParams : Map<string, string>;
37 41
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
38 42
  private _location:Location;
39 43

  
40 44
  constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
41
    //this.results =[];
42
    //this.filters =[];
43 45
    var errorCodes:ErrorCodes = new ErrorCodes();
44 46
    this.status =errorCodes.LOADING;
45 47
    this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
46
    this.refineFields = this.searchFields.PUBLICATION_INDEX;
47
    //get refine field filters  from url parameters
48
    if(!this.searchPage){
49
      this.searchPage = new SearchPageComponent(this._location);
50
    }
48

  
51 49
  }
52 50

  
53 51
  private ngOnInit() {
54 52
    this.searchPage.refineFields = this.refineFields;
53
    this.searchPage.indexIdsMap = this.indexIdsMap;
54
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
55

  
55 56
    this.sub =  this.route.queryParams.subscribe(params => {
56 57
    this.keyword = (params['keyword']?params['keyword']:'');
57 58
    this.page = (params['page']=== undefined)?1:+params['page'];
58
    for(var i=0; i<5 ; i++){
59
           var  values = [];
60
           for(var j=0; j<10 ; j++){
61
             var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false}
62
             values.push(value);
63
           }
64
           values.sort((n2,n1) => {
65
              if (n1.number > n2.number) {
66
                  return 1;
67
              }
68

  
69
              if (n1.number < n2.number) {
70
                  return -1;
71
              }
72

  
73
              return 0;
74
          });
75
          var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'}
76
          if(i==0) {
77
              var  values = [];
78
              for(var j=0; j<10 ; j++){
79
                var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false}
80
                values.push(value);
81
              }
82
              values.sort((n2,n1) => {
83
                 if (n1.number > n2.number) {
84
                     return 1;
85
                 }
86

  
87
                 if (n1.number < n2.number) {
88
                     return -1;
89
                 }
90

  
91
                 return 0;
92
              });
93
              var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'}
94
              this.filters.push(filter1);
95
              this.getResults(this.keyword, true, this.page, this.size);
96

  
97
          }
98

  
99
           console.info(params);
100
          if(params[filter.filterId] != undefined) {
101
              let values = params[filter.filterId].split(",");
102
              for(let value of values) {
103
                  for(let filterValue of filter.values) {
104
                      if(filterValue.id == value) {
105
                          filterValue.selected = true;
106
                          filter.countSelectedValues++;
107
                      }
108
                  }
109
              }
110
          }
111
      }
112

  
59
    var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
60
     this._getResults(queryParameters, true, this.page, this.size);
61
 
113 62
    });
114 63
  }
115 64

  
116 65
  private ngOnDestroy() {
117
    this.sub.unsubscribe();
66
    if(this.sub){
67
      this.sub.unsubscribe();
68
    }
69
    if(this.subResults){
70
      this.subResults.unsubscribe();
71
    }
118 72
  }
119
/*
120
  public getResults(parameters:string, page: number, size: number, flag: string){
121
    console.info("getResults: Execute search query "+parameters);
122 73

  
123
    this._searchPublicationsService.searchPublications(parameters, page, size, flag).subscribe(
124
        data => {
125
            this.totalResults = data[0];
126
            console.info("searchPubl total="+this.totalResults);
127
            this.results = data[1];
128
            var errorCodes:ErrorCodes = new ErrorCodes();
129
             this.status = errorCodes.DONE;
130
            if(this.totalResults == 0 ){
131
              this.status = errorCodes.NONE;
132
            }
133
        },
134
        err => {
135
            console.error(err);
136
            console.info("error");
137
            //TODO check erros (service not available, bad request)
138
            // if( ){
139
            //   this.status = ErrorCodes.ERROR;
140
            // }
141
            var errorCodes:ErrorCodes = new ErrorCodes();
142
            this.status = errorCodes.NOT_AVAILABLE;
143
        }
144
    );
145
  }
146
*/
147

  
148 74
public getCSVResultsForEntity(entity:string, id:string): any {
149 75
    let exportPublications = [];
150 76
    exportPublications.push(//[exportPublications.length] =
......
247 173
  this._getResults(parameters,refine,page,size);
248 174
}
249 175
private _getResults(parameters:string,refine:boolean, page: number, size: number){
250

  
251
  this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
176
  if(!refine && !this.searchPage){
177
      this.searchPage = new SearchPageComponent(this._location);
178
  }
179
  this.subResults = this._searchPublicationsService.searchPublications(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
252 180
      data => {
253 181
          this.totalResults = data[0];
254 182
          console.info("search Publications: [Parameters:"+parameters+" ]  [total results:"+this.totalResults+"]");
255 183
          this.results = data[1];
256
            this.filters = this.searchPage.checkSelectedFilters(data[2]);
257
            this.searchPage.updateBaseUrlWithParameters(this.filters);
184
          this.filters = data[2];
185
          this.searchPage.checkSelectedFilters(this.filters);
186
          this.searchPage.updateBaseUrlWithParameters(this.filters);
258 187
          var errorCodes:ErrorCodes = new ErrorCodes();
259 188
          this.status = errorCodes.DONE;
260 189
          if(this.totalResults == 0 ){
......
273 202
  );
274 203
}
275 204

  
276
  private setFilters(){
277
    //TODO set filters from
278
  }
279 205

  
206

  
280 207
  private queryChanged($event) {
281 208
    var parameters = $event.value;
282 209
    console.info("queryChanged: Execute search query "+parameters);
modules/uoa-services-portal/trunk/portal-2/src/app/landingPages/dataProvider/tabs.component.ts
5 5
import { SearchPublicationsService } from '../../services/searchPublications.service';
6 6
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
7 7
import { SearchDatasetsService } from '../../services/searchDatasets.service';
8
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
9 8

  
10 9
@Component({
11 10
    selector: 'tabs',
......
98 97

  
99 98
    constructor (private  route: ActivatedRoute,
100 99
        private _searchPublicationsService: SearchPublicationsService,
101
        private _searchDatasetsService: SearchDatasetsService,
102
        private _refineResultsService:RefineResultsService) {
100
        private _searchDatasetsService: SearchDatasetsService) {
103 101
            this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
104
            this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService);
102
            this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
105 103
    }
106 104

  
107 105
    ngOnInit() {
modules/uoa-services-portal/trunk/portal-2/src/app/landingPages/person/person.component.ts
8 8
import { SearchPublicationsService } from '../../services/searchPublications.service';
9 9
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
10 10
import { SearchDatasetsService } from '../../services/searchDatasets.service';
11
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
12 11
import { SearchResultComponent } from '../../searchPages/searchUtils/searchResult.component';
13 12

  
14 13
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
......
38 37
    constructor (private _personService: PersonService,
39 38
                 private  route: ActivatedRoute,
40 39
                 private _searchPublicationsService: SearchPublicationsService,
41
                 private _searchDatasetsService: SearchDatasetsService,
42
                 private _refineResultsService:RefineResultsService) {
40
                 private _searchDatasetsService: SearchDatasetsService) {
43 41
            console.info('person constructor');
44 42
            this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
45
            this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService);
43
            this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
46 44
        }
47 45

  
48 46
    ngOnInit() {
modules/uoa-services-portal/trunk/portal-2/src/app/landingPages/project/project.component.ts
9 9
import {SearchPublicationsService} from '../../services/searchPublications.service';
10 10
import { SearchDatasetsComponent } from '../../searchPages/searchDatasets.component';
11 11
import { SearchDatasetsService } from '../../services/searchDatasets.service';
12
import {RefineResultsService} from '../../services/servicesUtils/refineResuts.service';
13 12
import {SearchResultComponent} from '../../searchPages/searchUtils/searchResult.component';
14 13

  
15 14
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
......
45 44
  constructor (private _projectService: ProjectService,
46 45
      private  route: ActivatedRoute,
47 46
      private _searchPublicationsService: SearchPublicationsService,
48
      private _searchDatasetsService: SearchDatasetsService,
49
      private _refineResultsService:RefineResultsService) {
47
      private _searchDatasetsService: SearchDatasetsService) {
50 48
    console.info('project constructor');
51 49

  
52 50
    this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
53
    this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService, this._refineResultsService);
51
    this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
54 52
  }
55 53

  
56 54
  ngOnInit() {
modules/uoa-services-portal/trunk/portal-2/src/app/universal-cache.ts
1
import { Injectable, isDevMode } from '@angular/core';
2

  
3
@Injectable()
4
export class CacheService {
5
  static KEY = 'CacheService';
6
  _cache = new Map();
7

  
8
  /**
9
   * check if there is a value in our store
10
   */
11
  has(key: string | number): boolean {
12
    let _key = this.normalizeKey(key);
13
    return this._cache.has(_key);
14
  }
15

  
16
  /**
17
   * store our state
18
   */
19
  set(key: string | number, value: any): void {
20
    let _key = this.normalizeKey(key);
21
    this._cache.set(_key, value);
22
  }
23

  
24
  /**
25
   * get our cached value
26
   */
27
  get(key: string | number): any {
28
    let _key = this.normalizeKey(key);
29
    return this._cache.get(_key);
30
  }
31

  
32
  /**
33
   * release memory refs
34
   */
35
  clear(): void {
36
    this._cache.clear();
37
  }
38

  
39
  /**
40
   * convert to json for the client
41
   */
42
  dehydrate(): any {
43
    let json = {};
44
    this._cache.forEach((value: any, key: string) => json[key] = value);
45
    return json;
46
  }
47

  
48
  /**
49
   * convert server json into out initial state
50
   */
51
  rehydrate(json: any): void {
52
    Object.keys(json).forEach((key: string) => {
53
      let _key = this.normalizeKey(key);
54
      let value = json[_key];
55
      this._cache.set(_key, value);
56
    });
57
  }
58

  
59
  /**
60
   * allow JSON.stringify to work
61
   */
62
  toJSON(): any {
63
    return this.dehydrate();
64
  }
65

  
66
  /**
67
   * convert numbers into strings
68
   */
69
  normalizeKey(key: string | number): string {
70
    if (isDevMode() && this._isInvalidValue(key)) {
71
      throw new Error('Please provide a valid key to save in the CacheService');
72
    }
73

  
74
    return key + '';
75
  }
76

  
77
  _isInvalidValue(key): boolean {
78
    return key === null ||
79
      key === undefined ||
80
      key === 0 ||
81
      key === '' ||
82
      typeof key === 'boolean' ||
83
      Number.isNaN(<number>key);
84
  }
85
}
modules/uoa-services-portal/trunk/portal-2/src/app/api.ts
1
import { Injectable } from '@angular/core';
2
import { Http } from '@angular/http';
3
import { Observable } from 'rxjs/Observable';
4
import 'rxjs/add/observable/thorw';
5
import 'rxjs/add/observable/of';
6
import 'rxjs/add/operator/do';
7
import 'rxjs/add/operator/share';
8

  
9
import { CacheService  } from './universal-cache';
10

  
11
export function hashCode(str) {
12
  let hash = 0;
13
  if (str.length === 0) {
14
    return hash;
15
  }
16
  for (let i = 0; i < str.length; i++) {
17
    let char = str.charCodeAt(i);
18
    hash = ((hash << 5) - hash) + char;
19
    hash = hash & hash; // Convert to 32bit integer
20
  }
21
  return hash;
22
}
23

  
24
@Injectable()
25
export class ApiService {
26
  constructor(public _http: Http) {
27

  
28
  }
29

  
30
 /**
31
  * whatever domain/feature method name
32
  */
33
  get(url: string, options?: any) {
34
    return this._http.get(url, options)
35
      .map(res => res.json())
36
      .catch(err => {
37
        console.log('Error: ', err);
38
        return Observable.throw(err);
39
      });
40
  }
41

  
42
}
43

  
44
@Injectable()
45
export class ModelService {
46

  
47
  constructor(public _api: ApiService, public _cache: Cache) {
48

  
49
  }
50

  
51
 /**
52
  * whatever domain/feature method name
53
  */
54
  get(url) {
55
    // 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
56
    let key = url;
57

  
58
    if (this._cache.has(key)) {
59
      return Observable.of(this._cache.get(key));
60
    }
61
    // you probably shouldn't .share() and you should write the correct logic
62
    return this._api.get(url)
63
      .do(json => {
64
        this._cache.set(key, json);
65
      })
66
      .share();
67
  }
68

  
69
}
modules/uoa-services-portal/trunk/portal-2/src/app.browser.module.ts
1 1
import { NgModule } from '@angular/core';
2 2
import { FormsModule } from '@angular/forms';
3
import { UniversalModule } from 'angular2-universal';
3
import { UniversalModule, isBrowser, isNode } from 'angular2-universal/browser'; // for AoT we need to manually split universal packages
4 4
import { App } from './app/app';
5 5
//for routing:
6 6
import { routing } from './app/app.routing';
7 7
import { Routes, RouterModule } from "@angular/router";
8

  
8
import { CacheService } from './app/universal-cache';
9 9
// custom modules::
10 10
import {ClaimModule} from './app/claimPages/claim.module';
11 11
import {SearchModule} from './app/searchPages/search.module';
......
43 43
      TestComponent
44 44
  ],
45 45
    providers:    [
46
    
46
      { provide: 'isBrowser', useValue: isBrowser },
47
    { provide: 'isNode', useValue: isNode },
48
    CacheService
47 49
     ]
48 50
})
49 51
export class MainModule {
modules/uoa-services-portal/trunk/portal-2/src/server.ts
1
// the polyfills must be the first thing imported in node.js
1
// the polyfills must be one of the first things imported in node.js.
2
// The only modules to be imported higher - node modules with es6-promise 3.x or other Promise polyfill dependency
3
// (rule of thumb: do it if you have zone.js exception that it has been overwritten)
4
// if you are including modules that modify Promise, such as NewRelic,, you must include them before polyfills
2 5
import 'angular2-universal-polyfills';
3 6

  
7
// Fix Universal Style
8
import { NodeDomRootRenderer, NodeDomRenderer } from 'angular2-universal/node';
9
function renderComponentFix(componentProto: any) {
10
  return new NodeDomRenderer(this, componentProto, this._animationDriver);
11
}
12
NodeDomRootRenderer.prototype.renderComponent = renderComponentFix;
13
// End Fix Universal Style
14

  
4 15
import * as path from 'path';
5 16
import * as express from 'express';
6 17
import * as bodyParser from 'body-parser';
......
21 32
const ROOT = path.join(path.resolve(__dirname, '..'));
22 33

  
23 34
// Express View
24
app.engine('.html', createEngine({}));
35
app.engine('.html', createEngine({
36
  precompile: true,
37
  ngModule: MainModule,
38
  providers: [
39
    // stateless providers only since it's shared
40
  ]
41
}));
42
app.set('port', process.env.PORT || 3000);
25 43
app.set('views', __dirname);
26 44
app.set('view engine', 'html');
27 45

  
......
43 61
  res.render('index', {
44 62
    req,
45 63
    res,
46
    ngModule: MainModule,
47 64
    preboot: false,
48 65
    baseUrl: '/',
49 66
    requestUrl: req.originalUrl,
modules/uoa-services-portal/trunk/portal-2/README.md
14 14

  
15 15
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
16 16

  
17
## Universal "Gotchas"
18

  
19
 - To use `templateUrl` or `stylesUrl` you must use **`angular2-template-loader`** in your TS loaders.
20
    - 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.
21
 - **`window`** & **`document`** do not exist on the server - so using them, or any library that uses them (jQuery for example) will not work.
22
    - 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';
23
 - The application runs XHR requests on the server & once again on the Client-side (when the application bootstraps)
24
    - 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.
25
 
26
## Upcoming Universal features
27

  
28
 - SeoServices
29
 - Universal fixes for Angular Core 2.1.1
30
 - AoT funcionality is still a *work-in-progress*, but is available as of 2.1.0-rc1
31

  
17 32
## Installation
18 33

  
19 34
* `npm install`
......
29 44
## Watch files
30 45
* `npm run watch` to build your client app and start a web server
31 46

  
47
## Edge case of server compatibility with Promise polyfills
32 48

  
49
If you have node modules with promise polyfill dependency on server - there is chance to get the following exception:
50
```
51
Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
52
```
53
It occurs because [Zone.js](https://github.com/angular/zone.js/) Promise implementation is not 
54
detected as Promise by some polyfills (e.g. [es6-promise](https://github.com/stefanpenner/es6-promise) before 4.x).
33 55

  
56
To sort it out, you need such polyfills initialized before zone.js. Zone.js is initialized in 'angular2-universal-polyfills' 
57
import of [server.ts](https://github.com/angular/universal-starter/blob/master/src/server.ts#L4). So import problematic
58
modules before this line.
59

  
34 60
### Documentation
35 61
[Design Doc](https://docs.google.com/document/d/1q6g9UlmEZDXgrkY88AJZ6MUrUxcnwhBGS0EXbVlYicY)
36 62

  

Also available in: Unified diff