Project

General

Profile

1
import {Component, Input, Output, EventEmitter} from '@angular/core';
2
import {Metrics} from '../utils/entities/metrics';
3
import {MetricsService } from '../services/metrics.service';
4
import {ErrorCodes} from '../utils/properties/openaireProperties';
5

    
6
import { Subscription }   from 'rxjs/Subscription';
7

    
8
@Component({
9
    selector: 'metrics',
10
    template: `
11
    <!--div *ngIf="i>0 && tab.content=='metricsTab' && metrics != undefined" class="uk-panel uk-padding uk-background-muted"-->
12
    <!--/div-->
13

    
14
    <!--dl *ngIf="metrics != undefined"
15
        class="uk-description-list-horizontal uk-panel uk-padding uk-background-muted">
16
        <dt *ngIf="type=='results'">Total Downloads: </dt>
17
        <dt *ngIf="type!='results'" class="uk-text-break">
18
            Total <span [innerHTML]="name"></span> Publication Downloads:
19
        </dt>
20
        <dd>{{metrics.totalDownloads}}</dd>
21
        <dt>Total Views: </dt>
22
        <dd>{{metrics.totalViews}}</dd>
23
    </dl-->
24

    
25
    <!--div *ngIf="metrics == undefined" class="uk-alert uk-alert-warning">
26
        Metrics are currently unavailable
27
    </div-->
28

    
29
    <div *ngIf="status == errorCodes.LOADING" class="uk-animation-fade uk-margin-top  uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading"></div>
30
    <div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary" role="alert">No Results found</div>
31
    <div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning" role="alert">An Error Occured</div>
32
    <div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger" role="alert">Service not available</div>
33
    <div *ngIf="metrics != undefined" class="uk-child-width-1-3@m uk-grid-small uk-grid-match uk-grid" uk-grid="">
34
      <div class="uk-first-column">
35
          <div class="uk-tile uk-tile-default uk-padding-small">
36
            <!--div class="uk-clearfix">
37
                <div class="uk-float-left  " uk-tooltip="pos:right; delay:5"
38
                      title='<div    class= "uk-margin uk-padding-small">
39
                        <p>Info about the value....</p>
40
                      </div>'><span class="uk-icon">
41
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
42
</span>
43
                </div>
44
            </div-->
45
              <div *ngIf="entityType=='results'" class="uk-text-center">Page views</div>
46
              <div  *ngIf="entityType!='results'" class="uk-text-center">Research results page views</div>
47
              <div class="uk-text-center">{{pageViews}}</div>
48
              <div class="uk-margin-top uk-article-meta">
49
                <div *ngIf="entityType != 'results'">Research results page views in OpenAIRE</div>
50
                <div *ngIf="entityType == 'results'">{{entity}} page views in OpenAIRE</div>
51
              </div>
52

    
53
          </div>
54
      </div>
55
      <div>
56
          <div class="uk-tile uk-tile-muted uk-padding-small">
57
              <!--div class="uk-clearfix">
58
                  <div class="uk-float-left  " uk-tooltip="pos:right; delay:5"
59
                        title='<div    class= "uk-margin uk-padding-small">
60
                          <p>Info about the value....</p>
61
                        </div>'><span class="uk-icon">
62
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
63
</span>
64
                  </div>
65
              </div-->
66
              <div *ngIf="entityType=='results'" class="uk-text-center">Total views</div>
67
              <div  *ngIf="entityType!='results'" class="uk-text-center">  Total research results views</div>
68
              <!--div  *ngIf="type!='results'" class="uk-text-center">  Total <span [innerHTML]="name"></span> Research Results Views</div-->
69

    
70
              <div class="uk-text-center">  {{metrics.totalViews}}
71
                <span *ngIf="metrics.totalViews > 0 && metrics.totalOpenaireViews > 0">
72
                  ( {{metrics.totalOpenaireViews}} from OpenAIRE )
73
                </span></div>
74

    
75
                <div class="uk-margin-top uk-article-meta">
76
                  <div *ngIf="entityType == 'projects'">Research results page views in Repositories</div>
77
                  <div *ngIf="entityType == 'datasources'">Research results page views in Repository</div>
78
                  <div *ngIf="entityType == 'results'">{{entity}} page views in Repositories</div>
79
                  <div *ngIf="entityType!='datasources' && metrics.totalOpenaireViews > 0">
80
                    Of the {{metrics.totalViews}} views, repositories accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
81
                  </div>
82
                  <div *ngIf="entityType=='datasources' && metrics.totalOpenaireViews > 0">
83
                    Of the {{metrics.totalViews}} views, repository accessed {{metrics.totalOpenaireViews}} time(s) from OpenAIRE
84
                  </div>
85
                </div>
86
          </div>
87
      </div>
88
      <div>
89
          <div class="uk-tile uk-tile-primary uk-padding-small">
90
              <!--div class="uk-clearfix">
91
                  <div class="uk-float-left  " uk-tooltip="pos:right; delay:5"
92
                        title='<div    class= "uk-margin uk-padding-small">
93
                          <p>Info about the value....</p>
94
                        </div>'><span class="uk-icon">
95
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg>
96
</span>
97
                  </div>
98
              </div-->
99
              <div *ngIf="entityType=='results'" class="uk-text-center">Total downloads</div>
100
              <div  *ngIf="entityType!='results'" class="uk-text-center">  Total research results downloads</div>
101
              <!--div *ngIf="type!='results'" class="uk-text-center">Total <span [innerHTML]="name"></span> Research Results Downloads</div-->
102

    
103
              <div class="uk-text-center">  {{metrics.totalDownloads}}
104
                <span *ngIf="metrics.totalDownloads > 0 && metrics.totalOpenaireDownloads > 0">
105
                  ( {{metrics.totalOpenaireDownloads}} from OpenAIRE )
106
                </span></div>
107

    
108
                <div class="uk-margin-top uk-article-meta">
109
                  <div *ngIf="entityType == 'projects'">Research results page downloads in Repositories</div>
110
                  <div *ngIf="entityType == 'datasources'">Research results page downloads in Repository</div>
111
                  <div *ngIf="entityType == 'results'">{{entity}} page downloads in Repositories</div>
112
                  <div *ngIf="entityType!='datasources' && metrics.totalOpenaireDownloads > 0">
113
                    Of the {{metrics.totalDownloads}} downloads, repositories accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
114
                  </div>
115
                  <div *ngIf="entityType=='datasources' && metrics.totalOpenaireDownloads > 0">
116
                    Of the {{metrics.totalDownloads}} downloads, repository accessed {{metrics.totalOpenaireDownloads}} time(s) from OpenAIRE
117
                  </div>
118
                </div>
119

    
120
          </div>
121
      </div>
122

    
123
  </div>
124

    
125
<p *ngIf="metrics != undefined && metrics.infos.size > 0" >The information is available from the following content providers: </p>
126
    <table *ngIf="metrics != undefined && metrics.infos.size > 0"
127
            class="uk-table uk-table-striped">
128
        <thead>
129
            <tr>
130
                <th class="uk-text-center uk-text-bold">From</th>
131
                <th class="uk-text-center  uk-text-bold">Number Of Views</th>
132
                <th class="uk-text-center  uk-text-bold">Number Of Downloads</th>
133
            </tr>
134
        </thead>
135
        <tbody>
136
            <tr *ngFor="let key of metrics.infos.keys()">
137
                <td class="uk-text-center">
138
                    <a href="{{metrics.infos.get(key).url}}">
139
                        {{metrics.infos.get(key).name}}
140
                    </a>
141
                </td>
142
                <td class="uk-text-center">
143
                    {{metrics.infos.get(key).numOfViews}}
144
                    <span *ngIf="metrics.infos.get(key).numOfViews > 0 && metrics.infos.get(key).openaireViews > 0">
145
                      ( {{metrics.infos.get(key).openaireViews}} from OpenAIRE )
146
                    </span>
147
                </td>
148
                <td class="uk-text-center">
149
                    {{metrics.infos.get(key).numOfDownloads}}
150
                    <span *ngIf="metrics.infos.get(key).numOfDownloads > 0 && metrics.infos.get(key).openaireDownloads > 0">
151
                      ( {{metrics.infos.get(key).openaireDownloads}} from OpenAIRE )
152
                    </span>
153
                </td>
154
            </tr>
155
        </tbody>
156
    </table>
157
    `
158
    })
159

    
160
export class MetricsComponent {
161
    @Output() metricsResults = new EventEmitter();
162
    @Input() id: string;
163
    @Input() entityType: string;
164
    @Input() entity: string;
165
    //@Input() name: string = "";
166
    @Input() pageViews: number = 0;
167
    public metrics: Metrics;
168
    public errorCodes:ErrorCodes;
169
    public status: number;
170
    private sub: Subscription;
171

    
172
    constructor (private _metricsService: MetricsService) {}
173

    
174
    ngOnInit() {
175
        this.errorCodes = new ErrorCodes();
176
        this.status = this.errorCodes.LOADING;
177
        this.getMetrics();
178
    }
179

    
180
    ngOnDestroy() {
181
        this.sub.unsubscribe();
182
    }
183

    
184
    getMetrics() {
185
        //if(this.id == undefined || this.id == "") {
186
        //    console.log("supplied id in metrics is not acceptable");
187
        //}
188
        //if(this.type == undefined || this.type == "") {
189
        //    console.log("supplied id in metrics is not acceptable");
190
        //}
191

    
192
        this.sub = this._metricsService.getMetrics(this.id, this.entityType).subscribe(
193
         data => {
194
             this.metrics = data;
195
             this.status = this.errorCodes.DONE;
196
             this.metricsResults.emit({
197
                 totalViews: this.metrics.totalViews,
198
                 totalDownloads: this.metrics.totalDownloads,
199
                 pageViews: this.metrics.pageViews
200
             });
201
         },
202
         err => {
203
           console.log(err);
204
           this.status = this.errorCodes.ERROR;
205
           if(err.status == '404') {
206
               this.status = this.errorCodes.NOT_AVAILABLE;
207
           }
208
           this.metricsResults.emit({
209
               totalViews: 0,
210
               totalDownloads: 0
211
           });
212
         }
213
       );
214
    }
215
}
(3-3/13)