Project

General

Profile

1
import {Component, Input, ViewChild} from '@angular/core';
2
import { ActivatedRoute} from '@angular/router';
3

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

    
6
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
7
import {SearchResult}     from '../../utils/entities/searchResult';
8
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
9
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
10
import {SearchPageComponent } from '../searchUtils/searchPage.component';
11
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
12

    
13
@Component({
14
    selector: 'search-journals',
15
    template: `
16

    
17
    <search-page    pageTitle="OpenAIRE Journals"
18
                    formPlaceholderText = "Search for OpenAIRE Journals"
19
                    type="content providers" entityType="dataprovider" [(filters)] = "filters"
20
                    [(results)] = "results"  [(searchUtils)] = "searchUtils"
21
                    [baseUrl] = "baseUrl" [showResultCount]=false
22
                    (queryChange)="queryChanged($event)"
23
                    [csvParams]="csvParams" csvPath="resources"
24
                    [disableForms]="disableForms"
25
                    [tableViewLink]="'/search/journals-table'"
26
                    searchFormClass="journalsSearchForm">
27
    </search-page>
28
    `
29

    
30
})
31
export class SearchJournalsComponent {
32
  private errorCodes: ErrorCodes;
33

    
34
  public results =[];
35
  public filters =[];
36
  public baseUrl:string;
37
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
38
  public sub: any; public subResults: any;
39
  public _location:Location;
40
  public searchFields:SearchFields = new SearchFields();
41
  public refineFields: string[] =  this.searchFields.JOURNAL_FIELDS;
42
  public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
43
  public _prefixQueryFields: {field:string,opName:string,opValue:string,values:string[]}[] =[{field:"compatibility",opName:"cm",opValue:"not", values:["UNKNOWN","hostedBy","notCompatible"]},{field:"type",opName:"tp",opValue:"not",values: ["other"]}];
44
  // ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
45
  public _prefixQuery: string = "";
46

    
47
  public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
48
                        "export":[]
49
                     };
50
  public CSVDownloaded = false;
51
  public resourcesQuery = '&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) and (datasourcetypeuiid exact "pubsrepository::journal" or datasourcetypeuiid exact "aggregator::pubsrepository::journals" ))';
52
  //"&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))";
53
  public csvParams: string;
54
  public disableForms: boolean = false;
55

    
56
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
57

    
58
  constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
59
    this.errorCodes = new ErrorCodes();
60
    this.searchUtils.status = this.errorCodes.LOADING;
61
    this.baseUrl = OpenaireProperties.getLinkToSearchJournals();
62
    for(var i = 0; i < this._prefixQueryFields.length; i++ ){
63
      for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
64
        this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
65
        + this._prefixQueryFields[i].values[j] + "&" +
66
        this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
67
      }
68
    }
69
    this._prefixQuery+="&";
70
  }
71

    
72
  public ngOnInit() {
73
    this.searchPage.refineFields = this.refineFields;
74
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
75
    this.sub =  this.route.queryParams.subscribe(params => {
76
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
77
      this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
78
      this.filters = this.createFilters();
79
      var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
80
      console.info("|"+queryParameters+"|");
81
      this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
82
    });
83
  }
84

    
85
  public ngOnDestroy() {
86
    if(this.sub){
87
      this.sub.unsubscribe();
88
    }
89
    if(this.subResults){
90
      this.subResults.unsubscribe();
91
    }  }
92
    private _getResults(parameters:string,refine:boolean, page: number, size: number){
93
        this.csvParams = parameters+this.resourcesQuery+"&type=datasources";
94

    
95
      //var errorCodes:ErrorCodes = new ErrorCodes();
96
      this.searchUtils.status = this.errorCodes.LOADING;
97
      //this.searchPage.openLoading();
98
      this.disableForms = true;
99
      this.results = [];
100
      this.searchUtils.totalResults = 0;
101

    
102
      this.subResults = this._searchDataprovidersService.searchJournals(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
103
          data => {
104
              this.searchUtils.totalResults = data[0];
105
              console.info("search Journals: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
106
              this.results = data[1];
107
              this.searchPage.checkSelectedFilters(this.filters);
108
              this.searchPage.updateBaseUrlWithParameters(this.filters);
109
              //var errorCodes:ErrorCodes = new ErrorCodes();
110
              this.searchUtils.status = this.errorCodes.DONE;
111
              if(this.searchUtils.totalResults == 0 ){
112
                this.searchUtils.status = this.errorCodes.NONE;
113
              }
114
              //this.searchPage.closeLoading();
115
              this.disableForms = false;
116

    
117
          },
118
          err => {
119
              console.log(err);
120
               //TODO check erros (service not available, bad request)
121
              // if( ){
122
              //   this.searchUtils.status = ErrorCodes.ERROR;
123
              // }
124
              //var errorCodes:ErrorCodes = new ErrorCodes();
125
              //this.searchUtils.status = errorCodes.ERROR;
126
              if(err.status == '404') {
127
                this.searchUtils.status = this.errorCodes.NOT_FOUND;
128
              } else if(err.status == '500') {
129
                this.searchUtils.status = this.errorCodes.ERROR;
130
              } else {
131
                this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
132
              }
133

    
134
              //this.searchPage.closeLoading();
135
              this.disableForms = false;
136

    
137
          }
138
      );
139
    }
140
  private setFilters(){
141
    //TODO set filters from
142
  }
143

    
144
  public queryChanged($event) {
145
    var parameters = $event.index;
146
    console.info("queryChanged: Execute search query "+parameters);
147

    
148
    this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
149
  }
150
  private createFilters():Filter[] {
151
    var filter_names=["Type","Compatibility Level"];
152
    var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
153
    var searchFields = new SearchFields();
154
    var filter_original_ids = searchFields.JOURNAL_FIELDS;
155
    var value_names=[
156
      /*[
157
      "Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
158
     "Institutional Repositories Aggregators",
159
     "Thematic Repositories Aggregators", "Other Repositories Aggregators",
160
      "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
161
      */
162
      ["Journal", "Journal Aggregator\/Publisher"],
163
      ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]];
164

    
165
    var value_original_ids=[
166
      ["pubsrepository::journal", "aggregator::pubsrepository::journals"],
167
      //["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
168
    ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]];
169
    var filters: Filter[] =[];
170
    for(var i =0 ; i < filter_names.length;i++){
171
      var values:Value[] = [];
172
      for(var j =0 ; j < value_names[i].length;j++){
173
        var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
174
        values.push(value);
175
      }
176
       var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId:  filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
177
       filters.push(filter);
178
    }
179
    return filters;
180
    }
181
}
(9-9/12)