Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
4
import { Router } from '@angular/router';
5
import { ActivatedRoute } from '@angular/router';
6
import { FetchDataproviders } from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
7
import { SearchDataprovidersService } from '../../services/searchDataproviders.service';
8

    
9
import {OrganizationService} from '../../services/organization.service';
10
import { Meta} from '../../../angular2-meta';
11

    
12
import {RouterHelper} from '../../utils/routerHelper.class';
13

    
14
@Component({
15
    selector: 'deposit-by-subject-result',
16
    template: `
17
    <div id="tm-main" class=" uk-section  uk-margin-small-top tm-middle"   >
18
      <div uk-grid uk-grid>
19
       <div class="tm-main uk-width-1-1@s uk-width-1-1@m  uk-width-1-1@l uk-row-first ">
20

    
21
        <div class="uk-container uk-margin-top">
22
            <div class="page-header" >
23
                <h2>Deposit {{requestFor}}</h2>
24
            </div>
25

    
26
                        <div class="uk-width-1-1  uk-margin uk-padding uk-panel  uk-background-muted">
27
                          <form class= "uk-margin uk-text-center uk-margin-top">
28
                              <input type="text"  [(ngModel)]="subject"  class=" uk-input uk-width-1-2" name="subject" placeholder="Search for classifications..."   />
29

    
30
                              <button class=" uk-button uk-button-default"  type="submit" (click)="searchDataproviders()" >
31
                                  Search
32
                              </button>
33
                          </form>
34
                          <div *ngIf="subject.length > 0" class=" uk-text-center ">
35
                              <span>Keywords: {{subject}}<span><a class="uk-icon-button" (click) = "subject = ''"><span aria-hidden="true" class=" clickable "><span class="clickable uk-icon">
36
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="close" ratio="1"><path fill="none" stroke="#000" stroke-width="1.06" d="M16,16 L4,4"></path><path fill="none" stroke="#000" stroke-width="1.06" d="M16,4 L4,16"></path></svg>
37
</span></span></a></span>
38
                            </span>
39
                          </div>
40
                        </div>
41
            <div *ngIf="fetchDataproviders.searchUtils.status == errorCodes.LOADING"
42
                  class="uk-alert uk-alert-primary" role="alert">
43
                    Loading...
44
            </div>
45

    
46

    
47

    
48
            <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
49
                <p>Please use the information/contacts shown below to deposit your {{requestFor}}.</p>
50
                <!--showDataProviders [dataProviders]=dataProviders></showDataProviders-->
51
                <div *ngIf="fetchDataproviders.searchUtils.totalResults" class="">
52
                    <paging-no-load [currentPage]="page" [totalResults]="fetchDataproviders.searchUtils.totalResults"    size=10  (pageChange)="pageChange($event)"> </paging-no-load>
53
                 </div>
54
                 <div class="" *ngIf="fetchDataproviders.results  && fetchDataproviders.searchUtils.totalResults > 0">
55
                       {{fetchDataproviders.searchUtils.totalResults}} data providers, page {{fetchDataproviders.searchUtils.page}} of {{(totalPages())}}
56
                 </div>
57

    
58
                <search-result  [(results)]="fetchDataproviders.results"
59
                                type="dataprovider" urlParam="datasourceId" [showSubjects]=true
60
                                [custom_class]="'other-results'">
61
                </search-result>
62
            </div>
63

    
64
            <div *ngIf="fetchDataproviders.searchUtils.status == errorCodes.NONE && subject != ''" class = "uk-alert uk-alert-primary">
65
                No Data providers found with classification "{{subject}}".
66
            </div>
67
            <div *ngIf="fetchDataproviders.searchUtils.status == errorCodes.ERROR && subject != ''" class = "uk-alert uk-alert-danger">
68
                An error occured.
69
            </div>
70

    
71
            <div *ngIf="(fetchDataproviders.searchUtils.totalResults == 0 && fetchDataproviders.searchUtils.status == errorCodes.DONE)
72
                        || fetchDataproviders.searchUtils.status == errorCodes.NONE || fetchDataproviders.searchUtils.status == errorCodes.ERROR" class = "uk-alert  ">
73

    
74
                You can still deposit your {{requestFor}} in
75
                <a href="{{zenodo}}" target="_blank">OpenAIRE's Zenodo catch-all repository (<i class="custom-external"></i>)</a>
76
                hosted by CERN.
77
            </div>
78

    
79
            <button class=" uk-button uk-button-default"  type="submit" (click)="goToDeposit()">
80
                <span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-left" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="13 16 7 10 13 4"></polyline></svg></span> Back
81
            </button>
82
        </div>
83
        </div>
84
      </div>
85
    </div>
86
    `
87
})
88

    
89
export class DepositBySubjectResultComponent {
90

    
91

    
92
    public status: number;
93
    public errorCodes:ErrorCodes = new ErrorCodes();
94

    
95
    sub: any;
96
    subDataproviders: any;
97
    public fetchDataproviders : FetchDataproviders;
98

    
99
    public routerHelper:RouterHelper = new RouterHelper();
100
     public linkToSearchDataproviders = "";
101
    public zenodo: string;
102
    public page: number = 1;
103
    @Input() compatibility: string = '';
104
    @Input() requestFor: string = "Research Data";
105
    @Input() subject: string = "";
106

    
107
    constructor (private _router: Router,
108
        private  route: ActivatedRoute,
109
        private _searchDataprovidersService: SearchDataprovidersService,  private _meta: Meta) {
110

    
111
            this.zenodo = OpenaireProperties.getZenodoURL();
112
            this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
113

    
114
            this.status = this.errorCodes.LOADING;
115
            this.updateTitle("Deposit "+this.requestFor);
116
            this.updateDescription("Openaire,  repositories, open access,  data provider, compatibility, organization, deposit "+ this.requestFor);
117
            this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
118
        }
119
        updateDescription(description:string){
120
          this._meta.updateMeta("description", description);
121
          this._meta.updateProperty("og:description", description);
122
        }
123
        updateTitle(title:string){
124
          var _suffix ="| OpenAIRE";
125
          var _title = ((title.length> 50 ) ?title.substring(0,50):title) + _suffix;
126
          this._meta.setTitle(_title );
127
          this._meta.updateProperty("og:title",_title);
128
        }
129
        updateUrl(url:string){
130
          this._meta.updateProperty("og:url", url);
131
        }
132

    
133

    
134
    ngOnInit() {
135
        console.info('depositResult init');
136

    
137
        this.sub =  this.route.queryParams.subscribe(params => {
138
            this.subject = params['q'];
139
                this.searchDataproviders();
140

    
141
        });
142
    }
143
    totalPages(): number {
144
        let totalPages:any = this.fetchDataproviders.searchUtils.totalResults/(this.fetchDataproviders.searchUtils.size);
145
        if(!(Number.isInteger(totalPages))) {
146
            totalPages = (parseInt(totalPages, 10) + 1);
147
        }
148
        return totalPages;
149
    }
150

    
151
    // ngDoCheck() {
152
    //     if(this.organizationId == "" || this.organizationId == undefined) {
153
    //         this.organizationId = "";
154
    //         this.status = this.errorCodes.ERROR;
155
    //     }
156
    // }
157

    
158
    ngOnDestroy() {
159
      this.sub.unsubscribe();
160
      if(this.subDataproviders != undefined) {
161
          this.subDataproviders.unsubscribe();
162
      }
163
    }
164

    
165
    public searchDataproviders() {
166
        this.fetchDataproviders.getResultsBySubjectsForDeposit( (this.subject =="")?"*":this.subject, this.requestFor, this.page, 10);
167
        this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders();
168
    }
169

    
170

    
171

    
172
    goToDeposit() {
173
        if(this.requestFor == "Publications") {
174
            this._router.navigate( ['participate/deposit-publications'] );
175
        } else if(this.requestFor == "Research Data") {
176
            this._router.navigate( ['participate/deposit-datasets'] );
177
        }
178
    }
179
    pageChange($event) {
180
      this.page = +$event.value;
181
      this.searchDataproviders();
182
     }
183
}
(3-3/10)