Project

General

Profile

1 50169 argiro.kok
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 50761 argiro.kok
import {ErrorCodes} from '../../utils/properties/errorCodes';
9 50169 argiro.kok
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
10
import {SearchPageTableViewComponent } from '../searchUtils/searchPageTableView.component';
11
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
12 50586 argiro.kok
import{EnvProperties} from '../../utils/properties/env-properties';
13 50169 argiro.kok
14
@Component({
15
    selector: 'search-journals-table',
16
    template: `
17
18
    <search-page-table    pageTitle="OpenAIRE Journals Table"
19
                          type="content providers" entityType="dataprovider" [(filters)] = "filters"
20
                          [(results)] = "results"  [(searchUtils)] = "searchUtils"
21 50991 konstantin
                          [columnNames]="columnNames"
22 50169 argiro.kok
                          [showResultCount]=false
23
                          [disableForms]="disableForms"
24 52163 konstantin
                          [enableSearchView]="enableSearchView"
25 50169 argiro.kok
                          [searchViewLink]="'/search/journals'"
26
                          searchFormClass="journalsTableSearchForm"
27 54614 konstantin
                          formPlaceholderText="Search for Journals"
28
                          [mapUrl]="mapUrl" [mapTooltipType]="'journals'">
29 50169 argiro.kok
    </search-page-table>
30
    `
31
32
})
33
export class SearchJournalsTableComponent {
34
  private errorCodes: ErrorCodes;
35
36
  public results =[];
37
  public filters =[];
38 50991 konstantin
  public columnNames = ["Name", "Type", "Country", "Institution", "Compatibility"];
39 50169 argiro.kok
  public baseUrl:string;
40
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
41
  public sub: any; public subResults: any;
42
  public _location:Location;
43
  public searchFields:SearchFields = new SearchFields();
44
  public refineFields: string[] =  this.searchFields.JOURNAL_FIELDS;
45 54614 konstantin
  public mapUrl: string;
46 50586 argiro.kok
properties:EnvProperties;
47 50169 argiro.kok
  /*public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
48
                        "export":[]
49
                     };
50
  public CSVDownloaded = false;
51
  public csvParams: string;
52
  public resourcesQuery = "&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))";*/
53
54
  public disableForms: boolean = false;
55 52163 konstantin
  public enableSearchView: boolean = true;
56 50169 argiro.kok
57
  @ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
58
59
  constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
60
    this.errorCodes = new ErrorCodes();
61
    this.searchUtils.status = this.errorCodes.LOADING;
62
  }
63
64
  public ngOnInit() {
65 50586 argiro.kok
    this.route.data
66
      .subscribe((data: { envSpecific: EnvProperties }) => {
67
        this.properties = data.envSpecific;
68
        this.baseUrl = data.envSpecific.searchLinkToJournalsTable;
69 54614 konstantin
        this.mapUrl = this.properties.statisticsFrameAPIURL+"markers-test.html?show=journals";
70 50586 argiro.kok
      });
71 50169 argiro.kok
    this.searchPage.refineFields = this.refineFields;
72
    this.sub =  this.route.queryParams.subscribe(params => {
73
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
74
      //this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
75
      this.filters = this.createFilters();
76
      this.searchPage.getParametersFromUrl(params);
77
      this._getResults();
78
    });
79
  }
80
81
  public ngOnDestroy() {
82
    if(this.sub){
83
      this.sub.unsubscribe();
84
    }
85
    if(this.subResults){
86
      this.subResults.unsubscribe();
87 50586 argiro.kok
    }
88
  }
89 50169 argiro.kok
    private _getResults(){
90
        //this.csvParams = this.resourcesQuery+"&type=datasources";
91
92
      //var errorCodes:ErrorCodes = new ErrorCodes();
93
      this.searchUtils.status = this.errorCodes.LOADING;
94
      this.disableForms = true;
95 52163 konstantin
      this.enableSearchView = false;
96 50169 argiro.kok
      this.results = [];
97
      this.searchUtils.totalResults = 0;
98
99
      let size: number = 0;
100 50586 argiro.kok
      this.subResults = this._searchDataprovidersService.searchJournalsTable(this.properties).subscribe(
101 50169 argiro.kok
          data => {
102
              size = data;
103
              if(size > 0) {
104 50586 argiro.kok
                this.subResults = this._searchDataprovidersService.searchJournals("", null, 1, size, [],this.properties).subscribe(
105 50169 argiro.kok
                    data => {
106
                        this.searchUtils.totalResults = data[0];
107
                        console.info("search Journals [total results:"+this.searchUtils.totalResults+"]");
108
                        this.results = data[1];
109
110
                        this.searchPage.checkSelectedFilters(this.filters);
111
112
                        //var errorCodes:ErrorCodes = new ErrorCodes();
113
                        this.searchUtils.status = this.errorCodes.DONE;
114
                        if(this.searchUtils.totalResults == 0 ){
115
                          this.searchUtils.status = this.errorCodes.NONE;
116 52163 konstantin
                        } else {
117
                          this.searchPage.triggerInitialLoad();
118
                          this.searchPage.transform(this.results);
119
                          this.disableForms = false;
120 50169 argiro.kok
                        }
121 52163 konstantin
                        this.enableSearchView = true;
122 50169 argiro.kok
                    },
123
                    err => {
124
                        console.log(err);
125
                         //TODO check erros (service not available, bad request)
126
                        // if( ){
127
                        //   this.searchUtils.status = ErrorCodes.ERROR;
128
                        // }
129
                        //var errorCodes:ErrorCodes = new ErrorCodes();
130
                        //this.searchUtils.status = errorCodes.ERROR;
131
                        if(err.status == '404') {
132
                          this.searchUtils.status = this.errorCodes.NOT_FOUND;
133
                        } else if(err.status == '500') {
134
                          this.searchUtils.status = this.errorCodes.ERROR;
135
                        } else {
136
                          this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
137
                        }
138
139 52163 konstantin
                        this.enableSearchView = true;
140 50169 argiro.kok
                    }
141
                );
142
              } else {
143
                this.searchPage.checkSelectedFilters(this.filters);
144
145
                //var errorCodes:ErrorCodes = new ErrorCodes();
146
                this.searchUtils.status = this.errorCodes.NONE;
147 52163 konstantin
                this.enableSearchView = true;
148 50169 argiro.kok
              }
149
          },
150
          err => {
151
              console.log(err);
152
               //TODO check erros (service not available, bad request)
153
              // if( ){
154
              //   this.searchUtils.status = ErrorCodes.ERROR;
155
              // }
156
              //var errorCodes:ErrorCodes = new ErrorCodes();
157
              //this.searchUtils.status = errorCodes.ERROR;
158
              if(err.status == '404') {
159
                this.searchUtils.status = this.errorCodes.NOT_FOUND;
160
              } else if(err.status == '500') {
161
                this.searchUtils.status = this.errorCodes.ERROR;
162
              } else {
163
                this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
164
              }
165 52163 konstantin
              this.enableSearchView = true;
166 50169 argiro.kok
          }
167
      );
168
169
    }
170
  private setFilters(){
171
    //TODO set filters from
172
  }
173
174
  private createFilters():Filter[] {
175
    var filter_names=["Type","Compatibility Level"];
176
    var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
177
    var searchFields = new SearchFields();
178
    var filter_original_ids = searchFields.JOURNAL_FIELDS;
179
    var value_names=[
180
      /*[
181
      "Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
182
     "Institutional Repositories Aggregators",
183
     "Thematic Repositories Aggregators", "Other Repositories Aggregators",
184
      "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
185
      */
186
      ["Journal", "Journal Aggregator\/Publisher"],
187
188
189
190
191 52692 konstantin
      ["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)",
192
       "collected from a compatible aggregator", "proprietary", "under validation"]];
193 50169 argiro.kok
194
    var value_original_ids=[
195
      ["pubsrepository::journal", "aggregator::pubsrepository::journals"],
196
      //["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
197 52692 konstantin
    ["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)",
198
     "collected from a compatible aggregator", "proprietary", "under validation"]];
199 50169 argiro.kok
    var filters: Filter[] =[];
200
    for(var i =0 ; i < filter_names.length;i++){
201
      var values:Value[] = [];
202
      for(var j =0 ; j < value_names[i].length;j++){
203
        var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
204
        values.push(value);
205
      }
206 54614 konstantin
       var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId:  filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or', valueIsExact: true };
207 50169 argiro.kok
       filters.push(filter);
208
    }
209
    return filters;
210
    }
211
}