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
import { SearchResultComponent } from '../searchPages/searchUtils/searchResult.component';
9

    
10
import {OrganizationService} from '../landingPages/organization/organization.service';
11

    
12
@Component({
13
    selector: 'deposit-result',
14
    template: `
15
        <div class="container uk-margin-top">
16
            <div class="page-header" >
17
                <h2>Deposit {{requestFor}}</h2>
18
            </div>
19

    
20
            <div *ngIf="status == errorCodes.LOADING || (status == errorCodes.LOADING && fetchDataproviders.searchUtils.status == errorCodes.LOADING)"
21
                  class="uk-alert uk-alert-primary" role="alert">
22
                    Loading...
23
            </div>
24

    
25
            <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
26
                <h2 *ngIf="organization != undefined">
27
                    <span>Data providers for institution: </span>
28
                    <a *ngIf="organization['url']!=''" href="{{organization.url}}" target="_blank">
29
                        <span>{{organization['name']}} (<i class="uk-icon-external-link"></i>)</span>
30
                    </a>
31
                    <span *ngIf="organization['url']==''">{{organization['name']}}</span>
32
                </h2>
33

    
34
            </div>
35

    
36
            <div *ngIf="fetchDataproviders.searchUtils.totalResults > 0">
37
                <p>Please use the information/contacts shown below to deposit your {{requestFor}}.</p>
38
                <!--showDataProviders [dataProviders]=dataProviders></showDataProviders-->
39
                <div class = "uk-text-right" *ngIf = "fetchDataproviders.searchUtils.totalResults > 10" ><a [href] = "linkToSearchDataproviders" >View all {{fetchDataproviders.searchUtils.totalResults}} results</a></div>
40
                <!--search-result [(results)]="fetchDataproviders.results" [(status)]= "fetchDataproviders.searchUtils.status"></search-result-->
41
            </div>
42

    
43
            <div *ngIf="(fetchDataproviders.searchUtils.totalResults == 0 && status == errorCodes.DONE)
44
                        || status == errorCodes.NONE || status == errorCodes.ERROR" class = "alert alert-warning">
45
                <div *ngIf="organization != undefined">
46
                    No data providers found
47
                    <span *ngIf="organization != undefined">
48
                        for institution:
49
                        <a *ngIf="organization['url']!=''" href="{{organization.url}}">
50
                            <span>{{organization['name']}}</span>
51
                        </a>
52
                        <span *ngIf="organization['url']==''">{{organization['name']}}</span>
53
                    </span>
54
                    .
55
                </div>
56
                <div *ngIf="organization == undefined && organizationId != ''">
57
                    No organization with ID: {{organizationId}} found.
58
                </div>
59
                <div *ngIf="organizationId == ''">
60
                    No ID for organization.
61
                </div>
62

    
63
                You can still deposit your {{requestFor}} in
64
                <a href="{{zenodo}}" target="_blank">OpenAIRE's Zenodo catch-all repository (<i class="uk-icon-external-link"></i>)</a>
65
                hosted by CERN.
66
            </div>
67

    
68
            <button class="uk-button"  type="submit" (click)="goToDeposit()">
69
                <i class="uk-icon-arrow-circle-left"></i> Back
70
            </button>
71
        </div>
72
    `
73
})
74

    
75
export class DepositResultComponent {
76
    public organization: {"name": string, "url": string};
77
    public organizationId: string = "";
78

    
79
    public status: number;
80
    public errorCodes:ErrorCodes = new ErrorCodes();
81

    
82
    sub: any;
83
    subDataproviders: any;
84

    
85
    public fetchDataproviders : FetchDataproviders;
86
    public linkToSearchDataproviders = "";
87
    public zenodo: string;
88
    @Input() compatibility: string = '';
89
    @Input() requestFor: string = "Publications";
90

    
91
    constructor (private _router: Router,
92
        private  route: ActivatedRoute,
93
        private _searchDataprovidersService: SearchDataprovidersService,
94
        private _organizationService: OrganizationService) {
95
            console.info("depositResult constructor");
96

    
97
            this.zenodo = OpenaireProperties.getZenodoURL();
98
            this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
99

    
100
            this.status = this.errorCodes.LOADING;
101
            console.info("loading");
102
    }
103

    
104
    ngOnInit() {
105
        console.info('depositResult init');
106

    
107
        this.sub =  this.route.queryParams.subscribe(params => {
108
            this.organizationId = params['organizationId'];
109
            console.info("Id is :"+this.organizationId);
110
            if(this.organizationId){
111
                this.getOrganizationInfo();
112
            }
113
        });
114
    }
115

    
116
    ngDoCheck() {
117
        if(this.organizationId == "" || this.organizationId == undefined) {
118
            this.organizationId = "";
119
            this.status = this.errorCodes.ERROR;
120
        }
121
    }
122

    
123
    ngOnDestroy() {
124
      this.sub.unsubscribe();
125
      if(this.subDataproviders != undefined) {
126
          this.subDataproviders.unsubscribe();
127
      }
128
    }
129

    
130
    private searchDataproviders() {
131
        // if(this.organization != undefined) {
132
        //     this.fetchDataproviders.getResults(this.organization.name, false, 1, 10);
133
        // } else if(this.organizationId != undefined) {
134
            this.fetchDataproviders.getResultsForDeposit( this.organizationId,this.requestFor, 1, 10);
135
        //}
136
        this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders();
137
    }
138

    
139
    private getOrganizationInfo ()  {
140
        console.info("inside getOrganizationInfo of component");
141

    
142
        this._organizationService.getOrganizationInfo(this.organizationId).subscribe(
143
            data => {
144
                this.organization = data.title;
145
                this.status = this.errorCodes.DONE;
146
                this.subDataproviders =  this.route.queryParams.subscribe(params => {
147
                      this.searchDataproviders();
148
                });
149
            },
150
            err => {
151
                //console.log(err)
152

    
153
                if(err.status == '404') {
154
                    this.status = this.errorCodes.NONE;
155
                    console.info("none");
156
                } else {
157
                    this.status = this.errorCodes.ERROR;
158
                    console.info("error");
159
                }
160
            }
161
        );
162
    }
163

    
164
    goToDeposit() {
165
        if(this.requestFor == "Publications") {
166
            this._router.navigate( ['deposit-publications'] );
167
        } else if(this.requestFor == "Research Data") {
168
            this._router.navigate( ['deposit-datasets'] );
169
        }
170
    }
171
}
(13-13/13)