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
import {PiwikService} from '../utils/piwik/piwik.service';
14

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

    
22
        <div class="uk-container uk-margin-top">
23
            <div class="uk-article-title">
24
                Deposit {{requestFor}}
25
            </div>
26
            <helper position="top"></helper>
27
            <div class="uk-grid  helper-grid">
28
              <helper position="left" styleName=" uk-width-1-5 uk-padding-left"></helper>
29
              <div class="uk-width-expand">
30
                <div *ngIf="status == errorCodes.LOADING || (status == errorCodes.LOADING && fetchDataproviders.searchUtils.status == errorCodes.LOADING)"
31
                      class="uk-animation-fade uk-margin-top  uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading">
32
                </div>
33

    
34

    
35
                <div *ngIf="status != errorCodes.LOADING" class="uk-margin-bottom">
36
                  <h3>Locate repository via your institution</h3>
37

    
38
                  <form class= "uk-grid">
39
                      <div class="uk-width-1-2 ">
40
                      <entities-autocomplete fieldId="organization" (click)="warningMessage = ''" [entityType]="'organization'"
41
                        [depositType]=compatibility  [showSelected]=true [placeHolderMessage] = "'Search for Organizations'"
42
                        [title] = "'Organizations'"  [multipleSelections]=false (selectedValueChanged)="valueChanged($event)">
43
                      </entities-autocomplete>
44
                      </div>
45
                      <button class=" uk-button uk-button-default"  type="submit" (click)="organizationSelected(selectedId)" >
46
                          Locate
47
                      </button>
48
                      <div *ngIf="warningMessage.length > 0" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">{{warningMessage}}</div>
49
                  </form>
50
                </div>
51

    
52

    
53
                <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
54
                    <h2 *ngIf="organization">
55
                        <span>content providers for institution: </span>
56
                        <a *ngIf="organization['url']!=''" href="{{organization.url}}" target="_blank">
57
                            <span>{{organization['name']}} (<i class="custom-external"></i>)</span>
58
                        </a>
59
                        <span *ngIf="organization['url']==''">{{organization['name']}}</span>
60
                    </h2>
61

    
62

    
63
                </div>
64

    
65
                <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
66
                    <p>Please use the information/contacts shown below to deposit your {{requestFor}}.</p>
67
                    <!--showDataProviders [dataProviders]=dataProviders></showDataProviders-->
68
                    <div class = "uk-text-right" *ngIf = "fetchDataproviders.searchUtils.totalResults > 10">
69
    					<!--a [href] = "linkToSearchDataproviders">
70
    						View all {{fetchDataproviders.searchUtils.totalResults}} results <span class="uk-icon">
71
    <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
72
    </span>
73
    					</a-->
74

    
75
                        <a  [queryParams]="routerHelper.createQueryParams(['organizationId', 'or'], [organizationId, 'and'])"
76
                            routerLinkActive="router-link-active" [routerLink]="linkToSearchDataproviders" class="uk-button uk-button-text">
77
                            View all {{fetchDataproviders.searchUtils.totalResults}} results
78
                        </a>
79
    				</div>
80
                    <search-result  [(results)]="fetchDataproviders.results"
81
                                    [(status)]= "fetchDataproviders.searchUtils.status"
82
                                    type="dataprovider" urlParam="datasourceId"
83
                                    [custom_class]="'other-results'">
84
                    </search-result>
85
                </div>
86

    
87

    
88
                <div *ngIf="(fetchDataproviders.searchUtils.totalResults == 0 && status == errorCodes.DONE)
89
                            || status == errorCodes.NOT_FOUND || status == errorCodes.ERROR || status == errorCodes.NOT_AVAILABLE" class = "alert alert-warning">
90
                    <div *ngIf="organization">
91
                        <span *ngIf="fetchDataproviders.searchUtils.status == errorCodes.ERROR">
92
                            An error occured.
93
                        </span>
94
                        No content providers found for institution:
95
                        <a *ngIf="organization['url']!=''" target="_blank" href="{{organization.url}}">
96
                            <span>{{organization['name']}} (<i class="custom-external"></i>)</span>
97
                        </a>
98
                        <span *ngIf="organization['url']==''">{{organization['name']}}</span>
99
                        .
100
                    </div>
101
                    <div *ngIf="status == errorCodes.NOT_FOUND && organizationId != ''">
102
                        No organization with ID: {{organizationId}} found.
103
                    </div>
104
                    <div *ngIf="status == errorCodes.ERROR && organizationId != ''">
105
                        An error occured.
106
                    </div>
107
                    <span *ngIf="status == errorCodes.NOT_AVAILABLE && organizationId != ''">
108
                        Service temprorarily unavailable. Please try again later.
109
                    </span>
110
                    <div *ngIf="organizationId == ''">
111
                        No ID for organization.
112
                    </div>
113

    
114
                    You can still deposit your {{requestFor}} in
115
                    <a href="{{zenodo}}" target="_blank">OpenAIRE's Zenodo catch-all repository (<i class="custom-external"></i>)</a>
116
                    hosted by CERN.
117
                </div>
118
              </div>
119
              <helper position="right" styleName=" uk-width-1-5"></helper>
120
            </div>
121
            <button class=" uk-button uk-button-default uk-margin-small-top"  type="submit" (click)="goToDeposit()">
122
                <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
123
            </button>
124
            <helper position="bottom"></helper>
125
        </div>
126
        </div>
127
      </div>
128
    </div>
129

    
130
    `
131
})
132

    
133
export class DepositResultComponent {
134
  @Input() compatibility: string = '';
135

    
136
  // Type of entity: Publication or Research Data
137
  @Input() requestFor: string = "Publications";
138

    
139
  public organization: {"name": string, "url": string};
140
  public organizationId: string = "";
141

    
142
  // Id of the new selected organization to be searched
143
  public selectedId: string = "";
144

    
145
  public status: number;
146
  public warningMessage: string = "";
147

    
148
  public fetchDataproviders : FetchDataproviders;
149
  public linkToSearchDataproviders: string = "";
150

    
151
  // url of Zenodo
152
  public zenodo: string;
153

    
154
  public routerHelper:RouterHelper = new RouterHelper();
155
  public errorCodes:ErrorCodes = new ErrorCodes();
156

    
157
  sub: any; piwiksub: any;
158

    
159
  constructor ( private _router: Router,
160
                private  route: ActivatedRoute,
161
                private _searchDataprovidersService: SearchDataprovidersService,
162
                private _organizationService: OrganizationService,
163
                private _meta: Meta, private _piwikService:PiwikService) {
164

    
165
      this.zenodo = OpenaireProperties.getZenodoURL();
166
      this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
167

    
168
      this.status = this.errorCodes.LOADING;
169
      this.updateTitle("Deposit "+this.requestFor);
170
      this.updateDescription("Openaire,  repositories, open access,  content provider, compatibility, organization, deposit "+ this.requestFor);
171
      this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
172
      if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
173
        this.piwiksub = this._piwikService.trackView("Deposit "+this.requestFor).subscribe();
174
      }
175
    }
176

    
177
    ngOnInit() {
178
        console.info('depositResult init');
179

    
180
        this.sub =  this.route.queryParams.subscribe(params => {
181
            this.organizationId = params['organizationId'];
182
            console.info("Id is :"+this.organizationId);
183
            if(this.organizationId){
184
                this.getOrganizationInfo();
185
            }
186
            this.selectedId = "";
187
        });
188
    }
189

    
190
    ngDoCheck() {
191
        if(this.organizationId == "" || this.organizationId == undefined) {
192
            this.organizationId = "";
193
            this.status = this.errorCodes.ERROR;
194
        }
195
    }
196

    
197
    ngOnDestroy() {
198
      this.sub.unsubscribe();
199
      if(this.piwiksub){
200
        this.piwiksub.unsubscribe();
201
      }
202
    }
203

    
204
    private searchDataproviders() {
205
        // if(this.organization != undefined) {
206
        //     this.fetchDataproviders.getResults(this.organization.name, false, 1, 10);
207
        // } else if(this.organizationId != undefined) {
208
            this.fetchDataproviders.getResultsForDeposit( this.organizationId,this.requestFor, 1, 10);
209
        //}
210
        this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders();
211
    }
212

    
213
    private getOrganizationInfo ()  {
214
        console.info("inside getOrganizationInfo of component");
215

    
216
        this._organizationService.getOrganizationInfo(this.organizationId).subscribe(
217
            data => {
218
                if(data == null) {
219
                  this.status = this.errorCodes.NOT_FOUND;
220
                } else {
221
                  this.organization = data.title;
222
                  this.status = this.errorCodes.DONE;
223
                  this.searchDataproviders();
224
                }
225
            },
226
            err => {
227
                //console.log(err)
228

    
229
                if(err.status == '404') {
230
                  this.status = this.errorCodes.NOT_FOUND;
231
                  console.info("not found");
232
                } else if(err.status == '500') {
233
                  this.status = this.errorCodes.ERROR;
234
                  console.info("error");
235
                } else {
236
                  this.status = this.errorCodes.NOT_AVAILABLE;
237
                  console.info("not available");
238
                }
239
            }
240
        );
241
    }
242

    
243
    public goToDeposit() {
244
        if(this.requestFor == "Publications") {
245
            this._router.navigate( ['participate/deposit-publications'] );
246
        } else if(this.requestFor == "Research Data") {
247
            this._router.navigate( ['participate/deposit-datasets'] );
248
        }
249
    }
250

    
251
    public valueChanged($event){
252
      this.selectedId = $event.value;
253
    }
254

    
255
    public organizationSelected(id: string) {
256
        console.info("organization selected");
257
        if(id && id.length > 0 && id != this.organizationId){
258
            this.organization = null;
259
            this.status = this.errorCodes.LOADING;
260

    
261
            if(this.requestFor == "Publications") {
262
                this._router.navigate( ['participate/deposit-publications-result'], { queryParams: { "organizationId": id } } );
263
            } else if(this.requestFor == "Research Data") {
264
                this._router.navigate( ['participate/deposit-datasets-result'], { queryParams: { "organizationId": id } } );
265
            }
266
        } else {
267
            this.warningMessage = "No new organization selected";
268
        }
269
    }
270

    
271
    private updateDescription(description:string){
272
      this._meta.updateMeta("description", description);
273
      this._meta.updateProperty("og:description", description);
274
    }
275
    private updateTitle(title:string){
276
      var _prefix ="OpenAIRE | ";
277
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
278
      this._meta.setTitle(_title );
279
      this._meta.updateProperty("og:title",_title);
280
    }
281
    private updateUrl(url:string){
282
      this._meta.updateProperty("og:url", url);
283
    }
284
}
(4-4/4)