Project

General

Profile

1 43967 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
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
9 44048 argiro.kok
import {SearchFields} from '../../utils/properties/searchFields';
10 44374 argiro.kok
import {SearchPageComponent } from '../searchUtils/searchPage.component';
11 44587 argiro.kok
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
12 44732 konstantin
import {ExportCSVComponent} from '../../utils/exportCSV.component';
13 43967 argiro.kok
14
@Component({
15
    selector: 'search-dataproviders',
16
    template: `
17
18
    <search-page pageTitle="Compatible Dataproviders" type="datasource" [(filters)] = "filters"
19 44726 argiro.kok
                 [(results)] = "results"  [(searchUtils)] = "searchUtils"
20 44732 konstantin
                  [baseUrl] = "baseUrl" [showResultCount]=false (queryChange)="queryChanged($event)"
21
                  (downloadClick)="downloadClicked($event)">
22 43967 argiro.kok
    </search-page>
23 44433 argiro.kok
    <!--table-view  [(datasources)] = results></table-view-->
24 43967 argiro.kok
25
    `
26
27
})
28
export class SearchCompatibleDataprovidersComponent {
29
  public results =[];
30 44826 argiro.kok
  public filters =[];
31
  public baseUrl:string;
32
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
33
  public sub: any; public subResults: any;
34
  public _location:Location;
35
  public searchFields:SearchFields = new SearchFields();
36 44846 argiro.kok
  public refineFields: string[] =  this.searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
37
  public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
38 44826 argiro.kok
  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"]}];
39 44374 argiro.kok
  // ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
40 44826 argiro.kok
  public _prefixQuery: string = "";
41 44732 konstantin
42 44826 argiro.kok
  public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
43 44732 konstantin
                        "export":[]
44
                     };
45 44826 argiro.kok
  public CSVDownloaded = false;
46 44732 konstantin
47 44374 argiro.kok
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
48 43967 argiro.kok
49
  constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
50
    var errorCodes:ErrorCodes = new ErrorCodes();
51 44587 argiro.kok
    this.searchUtils.status =errorCodes.LOADING;
52 44778 argiro.kok
    this.baseUrl = OpenaireProperties.searchLinkToCompatibleDataProviders;
53 44374 argiro.kok
    for(var i = 0; i < this._prefixQueryFields.length; i++ ){
54
      for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
55
        this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
56
        + this._prefixQueryFields[i].values[j] + "&" +
57
        this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
58
      }
59
    }
60
    this._prefixQuery+="&";
61 43967 argiro.kok
  }
62
63 44826 argiro.kok
  public ngOnInit() {
64 44374 argiro.kok
    this.searchPage.refineFields = this.refineFields;
65
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
66 43967 argiro.kok
    this.sub =  this.route.queryParams.subscribe(params => {
67 44587 argiro.kok
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
68
      this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
69 44374 argiro.kok
      this.filters = this.createFilters();
70 44433 argiro.kok
      var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
71 44587 argiro.kok
      this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
72 43967 argiro.kok
    });
73
  }
74
75 44826 argiro.kok
  public ngOnDestroy() {
76 44374 argiro.kok
    if(this.sub){
77
      this.sub.unsubscribe();
78
    }
79
    if(this.subResults){
80
      this.subResults.unsubscribe();
81
    }  }
82
    private _getResults(parameters:string,refine:boolean, page: number, size: number){
83 44433 argiro.kok
84
      this.subResults = this._searchDataprovidersService.searchCompatibleDataproviders(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
85 44374 argiro.kok
          data => {
86 44726 argiro.kok
              this.searchUtils.totalResults = data[0];
87
              console.info("search Data Providers: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
88 44374 argiro.kok
              this.results = data[1];
89
              this.searchPage.checkSelectedFilters(this.filters);
90
              this.searchPage.updateBaseUrlWithParameters(this.filters);
91
              var errorCodes:ErrorCodes = new ErrorCodes();
92 44587 argiro.kok
              this.searchUtils.status = errorCodes.DONE;
93 44726 argiro.kok
              if(this.searchUtils.totalResults == 0 ){
94 44587 argiro.kok
                this.searchUtils.status = errorCodes.NONE;
95 44374 argiro.kok
              }
96
          },
97
          err => {
98
              console.error(err);
99
               //TODO check erros (service not available, bad request)
100
              // if( ){
101 44587 argiro.kok
              //   this.searchUtils.status = ErrorCodes.ERROR;
102 44374 argiro.kok
              // }
103
              var errorCodes:ErrorCodes = new ErrorCodes();
104 44587 argiro.kok
              this.searchUtils.status = errorCodes.ERROR;
105 44374 argiro.kok
          }
106
      );
107
    }
108 43967 argiro.kok
  private setFilters(){
109
    //TODO set filters from
110
  }
111
112 44826 argiro.kok
  public queryChanged($event) {
113 44433 argiro.kok
    var parameters = $event.index;
114 43967 argiro.kok
    console.info("queryChanged: Execute search query "+parameters);
115 44433 argiro.kok
116 44587 argiro.kok
    this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
117 43967 argiro.kok
  }
118
  private createFilters():Filter[] {
119
    var filter_names=["Type","Compatibility Level"];
120 44374 argiro.kok
    var filter_ids=["datasourcetypeuiid","datasourcecompatibilityid"];
121 44048 argiro.kok
    var searchFields = new SearchFields();
122 44374 argiro.kok
    var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
123 43967 argiro.kok
    var value_names=[
124 44433 argiro.kok
      [
125 44374 argiro.kok
      "Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
126 44433 argiro.kok
     "Institutional Repositories Aggregators",
127
     "Thematic Repositories Aggregators", "Other Repositories Aggregators",
128 43967 argiro.kok
      "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
129
      ["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)"]];
130 44433 argiro.kok
131 44048 argiro.kok
    var value_original_ids=[
132 44433 argiro.kok
      ["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::thematic","aggregator::pubsrepository::institutional","aggregator::pubsrepository::unknown",
133 44048 argiro.kok
      "datarepository::unknown", "aggregator::datarepository", "pubsrepository::journal", "aggregator::pubsrepository::journals", "cris", "pubscatalogue::unknown"],
134
      ["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]];
135 43967 argiro.kok
    var filters: Filter[] =[];
136
    for(var i =0 ; i < filter_names.length;i++){
137
      var values:Value[] = [];
138
      for(var j =0 ; j < value_names[i].length;j++){
139 44374 argiro.kok
        var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
140 43967 argiro.kok
        values.push(value);
141
      }
142
       var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId:  filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or'}
143
       filters.push(filter);
144
    }
145
    return filters;
146
    }
147
148 44826 argiro.kok
    public downloadClicked($event) {
149 44732 konstantin
        if(!this.CSVDownloaded) {
150
            this.CSVDownloaded = false;
151
152
            var parameters = $event.value;
153
154
            //this.getResultsCSV(parameters, false, 1, 1000);
155
156
            this._searchDataprovidersService.searchCompatibleDataprovidersCSV(parameters,this.searchPage.getRefineFieldsQuery(), 1, 1000).subscribe(
157
                data => {
158
                      this.CSV.export = data;
159
                      ExportCSVComponent.downloadCSV(this.CSV, "compatibleDataproviders.csv");
160
161
                      var errorCodes:ErrorCodes = new ErrorCodes();
162
                      this.searchUtils.status = errorCodes.DONE;
163
                },
164
                err => {
165
                    console.error(err);
166
                     //TODO check erros (service not available, bad request)
167
                    // if( ){
168
                    //   this.searchUtils.status = ErrorCodes.ERROR;
169
                    // }
170
                    var errorCodes:ErrorCodes = new ErrorCodes();
171
                    this.searchUtils.status = errorCodes.ERROR;
172
                }
173
            );
174
        }
175
    }
176
177 43967 argiro.kok
}