Revision 59469
Added by Konstantinos Triantafyllou over 3 years ago
analytics.component.ts | ||
---|---|---|
8 | 8 |
import {DomSanitizer, SafeUrl, Title} from '@angular/platform-browser'; |
9 | 9 |
import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; |
10 | 10 |
import {ActivatedRoute} from '@angular/router'; |
11 |
import {NumberUtils} from '../openaireLibrary/utils/number-utils.class'; |
|
11 | 12 |
|
12 | 13 |
@Component({ |
13 | 14 |
selector: 'analytics', |
... | ... | |
74 | 75 |
this.iframeLoading = false; |
75 | 76 |
} |
76 | 77 |
|
78 |
roundUsageStat(stats: UsageStat) { |
|
79 |
if(stats) { |
|
80 |
stats.repositories = NumberUtils.roundNumber(Number.parseInt(stats.repositories)); |
|
81 |
stats.total_downloads = NumberUtils.roundNumber(Number.parseInt(stats.total_downloads)); |
|
82 |
stats.total_views = NumberUtils.roundNumber(Number.parseInt(stats.total_views)); |
|
83 |
} |
|
84 |
return stats; |
|
85 |
} |
|
86 |
|
|
87 |
roundCountryUsageStat(stats: CountryUsageStat) { |
|
88 |
if(stats) { |
|
89 |
stats.total_repos = NumberUtils.roundNumber(Number.parseInt(stats.total_repos)); |
|
90 |
stats.downloads = NumberUtils.roundNumber(Number.parseInt(stats.downloads)); |
|
91 |
stats.views = NumberUtils.roundNumber(Number.parseInt(stats.views)); |
|
92 |
} |
|
93 |
return stats; |
|
94 |
} |
|
95 |
|
|
77 | 96 |
public search() { |
78 | 97 |
this.country = this.countryFb.value.country; |
79 | 98 |
this.showSearch = false; |
... | ... | |
82 | 101 |
if (this.country && this.country.length > 0) { |
83 | 102 |
this.country = StringUtils.capitalize(this.country); |
84 | 103 |
this.usageStatsService.getCountryMetrics(this.country).subscribe(stats => { |
85 |
this.display = stats;
|
|
104 |
this.display = this.roundCountryUsageStat(stats);
|
|
86 | 105 |
this.loading = false; |
87 | 106 |
if (this.display) { |
88 | 107 |
this.state = 1; |
... | ... | |
94 | 113 |
}); |
95 | 114 |
} else { |
96 | 115 |
this.usageStatsService.getAllMetrics().subscribe(stats => { |
97 |
this.display = stats;
|
|
116 |
this.display = this.roundUsageStat(stats);
|
|
98 | 117 |
this.loading = false; |
99 | 118 |
if (this.display) { |
100 | 119 |
this.state = 1; |
... | ... | |
156 | 175 |
goTo(id: string) { |
157 | 176 |
const yOffset = -100; |
158 | 177 |
const element = document.getElementById(id); |
159 |
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset; |
|
160 |
window.scrollTo({top: y, behavior: 'smooth'}); |
|
178 |
if(element) { |
|
179 |
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset; |
|
180 |
window.scrollTo({top: y, behavior: 'smooth'}); |
|
181 |
} |
|
161 | 182 |
} |
162 | 183 |
|
163 | 184 |
public getSafeUrl(url: string): SafeUrl { |
Also available in: Unified diff
[Usage Counts | Trunk]: Round numbers on analytics. Fix error when a fragment does not exist