Project

General

Profile

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

    
8
import {OrganizationService} from '../services/organization.service';
9
import { Meta} from '../sharedComponents/metaService';
10

    
11
import {RouterHelper} from '../utils/routerHelper.class';
12
import {PiwikService} from '../utils/piwik/piwik.service';
13
import{EnvProperties} from '../utils/properties/env-properties';
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 custom-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  uk-margin-top">
36
                  <h3>See if your institution has a repository </h3>
37

    
38
                  <form class= "uk-grid">
39
                      <div class="uk-width-1-2 ">
40
                      <entities-autocomplete [(properties)]=properties fieldId="organization" (click)="warningMessage = ''" [entityType]="'organization'"
41
                        [depositType]=compatibility  [showSelected]=true [placeHolderMessage] = "'Organization name'"
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" class="organization">
55
                        <a *ngIf="organization['url']!=''" href="{{organization.url}}" target="_blank">
56
                            <span><i class="custom-external"></i>{{organization['name']}}</span>
57
                        </a>
58
                        <span *ngIf="organization['url']==''">{{organization['name']}}</span>
59
                    </h2>
60

    
61

    
62
                </div>
63

    
64
                <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
65
                    <p class="uk-text-meta">Please use the information below and contact your repository to deposit your <span class="uk-text-lowercase">{{requestFor}}</span>.</p>
66
                    <!--showDataProviders [dataProviders]=dataProviders></showDataProviders-->
67
                    <div class = "uk-text-right" *ngIf = "fetchDataproviders.searchUtils.totalResults > 10">
68
    					<!--a [href] = "linkToSearchDataproviders">
69
    						View all {{fetchDataproviders.searchUtils.totalResults}} results <span class="uk-icon">
70
    <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>
71
    </span>
72
    					</a-->
73

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

    
86

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

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

    
129
    `
130
})
131

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

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

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

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

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

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

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

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

    
156
  sub: any; piwiksub: any;
157
  properties:EnvProperties;
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.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
166

    
167
      this.status = this.errorCodes.LOADING;
168
      this.updateTitle("Deposit "+this.requestFor);
169
      this.updateDescription("Openaire,  repositories, open access,  content provider, compatibility, organization, deposit "+ this.requestFor);
170

    
171
    }
172
    ngOnInit() {
173
      this.route.data
174
        .subscribe((data: { envSpecific: EnvProperties }) => {
175
           this.properties = data.envSpecific;
176
           this.zenodo = this.properties.zenodo;
177
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
178

    
179
           if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
180
             this.piwiksub = this._piwikService.trackView("Deposit "+this.requestFor).subscribe();
181
           }
182
        });
183

    
184
        console.info('depositResult init');
185

    
186
        this.sub =  this.route.queryParams.subscribe(params => {
187
            this.organizationId = params['organizationId'];
188
            console.info("Id is :"+this.organizationId);
189
            if(this.organizationId){
190
                this.getOrganizationInfo();
191
            }
192
            this.selectedId = "";
193
        });
194
    }
195

    
196
    ngDoCheck() {
197
        if(this.organizationId == "" || this.organizationId == undefined) {
198
            this.organizationId = "";
199
            this.status = this.errorCodes.ERROR;
200
        }
201
    }
202

    
203
    ngOnDestroy() {
204
      this.sub.unsubscribe();
205
      if(this.piwiksub){
206
        this.piwiksub.unsubscribe();
207
      }
208
    }
209

    
210
    private searchDataproviders() {
211
        // if(this.organization != undefined) {
212
        //     this.fetchDataproviders.getResults(this.organization.name, false, 1, 10);
213
        // } else if(this.organizationId != undefined) {
214
            this.fetchDataproviders.getResultsForDeposit( this.organizationId,this.requestFor, 1, 10, this.properties);
215
        //}
216
        this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;
217
    }
218

    
219
    private getOrganizationInfo ()  {
220
        console.info("inside getOrganizationInfo of component");
221

    
222
        this._organizationService.getOrganizationInfo(this.organizationId,this.properties).subscribe(
223
            data => {
224
                if(data == null) {
225
                  this.status = this.errorCodes.NOT_FOUND;
226
                } else {
227
                  this.organization = data.title;
228
                  this.status = this.errorCodes.DONE;
229
                  this.searchDataproviders();
230
                }
231
            },
232
            err => {
233
                //console.log(err)
234

    
235
                if(err.status == '404') {
236
                  this.status = this.errorCodes.NOT_FOUND;
237
                  console.info("not found");
238
                } else if(err.status == '500') {
239
                  this.status = this.errorCodes.ERROR;
240
                  console.info("error");
241
                } else {
242
                  this.status = this.errorCodes.NOT_AVAILABLE;
243
                  console.info("not available");
244
                }
245
            }
246
        );
247
    }
248

    
249
    public goToDeposit() {
250
        if(this.requestFor == "Publications") {
251
            this._router.navigate( ['participate/deposit-publications'] );
252
        } else if(this.requestFor == "Research Data") {
253
            this._router.navigate( ['participate/deposit-datasets'] );
254
        }
255
    }
256

    
257
    public valueChanged($event){
258
      this.selectedId = $event.value;
259
    }
260

    
261
    public organizationSelected(id: string) {
262
        console.info("organization selected");
263
        if(id && id.length > 0 && id != this.organizationId){
264
            this.organization = null;
265
            this.status = this.errorCodes.LOADING;
266

    
267
            if(this.requestFor == "Publications") {
268
                this._router.navigate( ['participate/deposit-publications-result'], { queryParams: { "organizationId": id } } );
269
            } else if(this.requestFor == "Research Data") {
270
                this._router.navigate( ['participate/deposit-datasets-result'], { queryParams: { "organizationId": id } } );
271
            }
272
        } else {
273
            this.warningMessage = "No new organization selected";
274
        }
275
    }
276

    
277
    private updateDescription(description:string){
278
      this._meta.updateMeta("description", description);
279
      this._meta.updateProperty("og:description", description);
280
    }
281
    private updateTitle(title:string){
282
      var _prefix ="OpenAIRE | ";
283
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
284
      this._meta.setTitle(_title );
285
      this._meta.updateProperty("og:title",_title);
286
    }
287
    private updateUrl(url:string){
288
      this._meta.updateProperty("og:url", url);
289
    }
290
}
(4-4/4)