Revision 58098
Added by Stefania Martziou about 4 years ago
dashboard.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import { AuthenticationService } from '../../services/authentication.service'; |
|
3 |
import { RepositoryService } from '../../services/repository.service'; |
|
2 |
import { AuthenticationService } from '../../../services/authentication.service';
|
|
3 |
import { RepositoryService } from '../../../services/repository.service';
|
|
4 | 4 |
import { |
5 | 5 |
AggregationDetails, BrokerSummary, BrowseEntry, CollectionMonitorSummary, |
6 | 6 |
MetricsInfo, PiwikInfo, |
7 |
Repository, |
|
8 |
RepositorySnippet, |
|
9 |
RepositorySummaryInfo, StoredJob, UsageSummary |
|
10 |
} from '../../domain/typeScriptClasses'; |
|
7 |
Repository, StoredJob, UsageSummary |
|
8 |
} from '../../../domain/typeScriptClasses'; |
|
11 | 9 |
import { |
12 |
loadingAggregationHistory, loadingAggregationHistoryError, loadingMetrics, loadingMetricsError,
|
|
13 |
loadingReposMessage, loadingSubscriptions, loadingTopics, loadingTopicsError,
|
|
14 |
loadingUserRepoInfoEmpty, noAggregationHistory, noSubscriptionsFound, noTopicsFound, reposRetrievalError,
|
|
10 |
loadingAggregationHistory, loadingAggregationHistoryError, loadingMetrics, |
|
11 |
loadingMetricsError, loadingSubscriptions, loadingTopics, loadingTopicsError,
|
|
12 |
noAggregationHistory, noSubscriptionsFound, noTopicsFound,
|
|
15 | 13 |
loadingJobSummary, loadingJobSummaryError |
16 |
} from '../../domain/shared-messages'; |
|
17 |
import {DashboardService} from '../../services/dashboard.service'; |
|
14 |
} from '../../../domain/shared-messages';
|
|
15 |
import {DashboardService} from '../../../services/dashboard.service';
|
|
18 | 16 |
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser'; |
19 |
import {PiwikService} from '../../services/piwik.service'; |
|
20 |
import {ValidatorService} from '../../services/validator.service'; |
|
17 |
import {PiwikService} from '../../../services/piwik.service'; |
|
18 |
import {ValidatorService} from '../../../services/validator.service'; |
|
19 |
import {ActivatedRoute} from "@angular/router"; |
|
20 |
import {SharedService} from "../../../services/shared.service"; |
|
21 | 21 |
|
22 | 22 |
@Component ({ |
23 | 23 |
selector: 'app-dashboard', |
... | ... | |
26 | 26 |
|
27 | 27 |
export class DashboardComponent implements OnInit { |
28 | 28 |
|
29 |
reposOfUser: RepositorySnippet[] = []; |
|
30 |
selectedRepo: RepositorySnippet = null; |
|
31 |
// tilesView: boolean; |
|
29 |
repository: Repository = null; |
|
32 | 30 |
errorMessage: string; |
33 |
noRepos: string; |
|
34 | 31 |
loadingMessage: string; |
35 | 32 |
|
36 | 33 |
constructor(private authService: AuthenticationService, |
37 | 34 |
private repositoryService: RepositoryService, |
35 |
private sharedService: SharedService, |
|
38 | 36 |
private dashboardService: DashboardService, |
39 | 37 |
private piwikService: PiwikService, |
40 | 38 |
private validatorService: ValidatorService, |
41 |
private sanitizer: DomSanitizer) { } |
|
39 |
private sanitizer: DomSanitizer, |
|
40 |
private route: ActivatedRoute) { |
|
41 |
} |
|
42 | 42 |
|
43 |
repositories: RepositorySummaryInfo[] = []; |
|
44 |
userEmail: string; |
|
45 |
|
|
46 | 43 |
loading: boolean = true; |
47 | 44 |
|
48 | 45 |
|
... | ... | |
66 | 63 |
totalDownloads = '--'; |
67 | 64 |
viewsUrl: SafeResourceUrl; |
68 | 65 |
downloadsUrl: SafeResourceUrl; |
69 |
shortSelectedRepoId: string;
|
|
66 |
shortRepositoryId: string;
|
|
70 | 67 |
currentDate: string; |
71 | 68 |
|
72 | 69 |
// Broker |
... | ... | |
90 | 87 |
loadingJobSummaryMessage: string; |
91 | 88 |
|
92 | 89 |
ngOnInit() { |
93 |
// this.getUserEmail(); |
|
94 |
this.userEmail = sessionStorage.getItem('email'); |
|
95 |
if (this.userEmail) { |
|
96 |
this.getReposOfUser(); |
|
97 |
// this.getRepositoriesSummaryInfo(this.userEmail); |
|
90 |
|
|
91 |
if(this.sharedService.getRepository()) { |
|
92 |
this.repository = this.sharedService.getRepository(); |
|
93 |
this.getSelectedRepositorySummaryInfo(this.repository); |
|
98 | 94 |
} |
95 |
|
|
96 |
this.sharedService.repository$.subscribe( |
|
97 |
r => { |
|
98 |
this.repository = r; |
|
99 |
// console.log("RepositoryID: ", this.repository.id); |
|
100 |
this.getSelectedRepositorySummaryInfo(this.repository); |
|
101 |
} |
|
102 |
); |
|
103 |
|
|
99 | 104 |
let body = document.getElementsByTagName('body')[0]; |
100 | 105 |
body.classList.remove("top_bar_active"); |
101 | 106 |
body.classList.remove("page_heading_active"); |
... | ... | |
106 | 111 |
this.currentDate = currentTime.getFullYear() + '-' + (currentTime.getMonth() + 1); |
107 | 112 |
} |
108 | 113 |
|
109 |
getReposOfUser(): void { |
|
110 |
this.loadingMessage = loadingReposMessage; |
|
111 |
this.repositoryService.getRepositoriesOfUser() |
|
112 |
.subscribe( |
|
113 |
repos => { |
|
114 |
this.sortRepositoriesByName(repos); |
|
115 |
if (this.reposOfUser && this.reposOfUser.length > 0) { |
|
116 |
this.selectedRepo = this.reposOfUser[0]; |
|
117 |
this.getSelectedRepositorySummaryInfo(this.reposOfUser[0]); |
|
118 |
} |
|
119 |
}, |
|
120 |
error => { |
|
121 |
console.log(error); |
|
122 |
this.loadingMessage = ''; |
|
123 |
this.errorMessage = reposRetrievalError; |
|
124 |
}, |
|
125 |
() => { |
|
126 |
this.loadingMessage = ''; |
|
127 |
if (!this.reposOfUser || !this.reposOfUser.length) { |
|
128 |
this.noRepos = loadingUserRepoInfoEmpty; |
|
129 |
} |
|
130 |
} |
|
131 |
); |
|
132 |
} |
|
114 |
getSelectedRepositorySummaryInfo(repository: Repository) { |
|
133 | 115 |
|
134 |
sortRepositoriesByName(repos: RepositorySnippet[]) { |
|
135 |
this.reposOfUser = repos.sort( function(a, b) { |
|
136 |
if (a.officialname < b.officialname) { |
|
137 |
return -1; |
|
138 |
} else if (a.officialname > b.officialname) { |
|
139 |
return 1; |
|
140 |
} else { |
|
141 |
return 0; |
|
142 |
} |
|
143 |
}); |
|
144 |
} |
|
145 |
|
|
146 |
changeSelectedRepository(repoId: string) { |
|
147 |
this.selectedRepo = this.reposOfUser.find(x => x.id == repoId); |
|
148 |
console.log('selectedRepo ' + this.selectedRepo.id); |
|
149 |
this.getSelectedRepositorySummaryInfo(this.selectedRepo); |
|
150 |
} |
|
151 |
|
|
152 |
getSelectedRepositorySummaryInfo(selectedRepo: RepositorySnippet) { |
|
153 |
|
|
154 | 116 |
// Aggregations |
155 | 117 |
this.loadingAggregationsMessage = loadingAggregationHistory; |
156 | 118 |
this.latestAggregations = []; |
157 | 119 |
this.lastIndexedVersion = null; |
158 |
this.dashboardService.getCollectionMonitorSummary(selectedRepo.id, 5).subscribe(
|
|
120 |
this.dashboardService.getCollectionMonitorSummary(repository.id, 5).subscribe(
|
|
159 | 121 |
collectionMonitorSummary => this.getCollectionMonitorSummary(collectionMonitorSummary), |
160 | 122 |
error => { |
161 | 123 |
this.loadingAggregationsMessage = ''; |
... | ... | |
177 | 139 |
this.totalDownloads = '--'; |
178 | 140 |
this.viewsUrl = null; |
179 | 141 |
this.downloadsUrl = null; |
180 |
this.shortSelectedRepoId = null;
|
|
181 |
this.dashboardService.getUsageSummary(selectedRepo.id).subscribe(
|
|
142 |
this.shortRepositoryId = null;
|
|
143 |
this.dashboardService.getUsageSummary(repository.id).subscribe(
|
|
182 | 144 |
usageSummary => this.getUsageSummary(usageSummary), |
183 | 145 |
error => { |
184 | 146 |
this.loadingUsageStatsMessage = ''; |
... | ... | |
186 | 148 |
console.log(error); |
187 | 149 |
} , |
188 | 150 |
() => { |
189 |
this.shortSelectedRepoId = selectedRepo.id.replace(/_/g, '').replace('::', ':');
|
|
151 |
this.shortRepositoryId = repository.id.replace(/_/g, '').replace('::', ':');
|
|
190 | 152 |
this.loadingUsageStatsMessage = ''; |
191 | 153 |
this.errorUsageStatsMessage = ''; |
192 | 154 |
} |
... | ... | |
222 | 184 |
this.loadingJobSummaryMessage = loadingJobSummary; |
223 | 185 |
this.noValidationsMessage = ''; |
224 | 186 |
this.errorValidationsMessage = ''; |
225 |
this.validatorService.getValidationSummary(selectedRepo.id).subscribe(
|
|
187 |
this.validatorService.getValidationSummary(repository.id).subscribe(
|
|
226 | 188 |
validationSummary => { |
227 | 189 |
this.storedJob = validationSummary; |
228 | 190 |
console.log(validationSummary); |
... | ... | |
345 | 307 |
} |
346 | 308 |
|
347 | 309 |
getCorrectName() { |
348 |
const temp = this.selectedRepo.officialname.split('|');
|
|
310 |
const temp = this.repository.officialName.split('|');
|
|
349 | 311 |
let correctName = temp[0]; |
350 | 312 |
let repoName = temp[0]; |
351 | 313 |
for (let i = 1; i < temp.length; i++) { |
... | ... | |
355 | 317 |
|
356 | 318 |
return correctName; |
357 | 319 |
} |
358 |
|
|
359 |
getIsUserLoggedIn() { |
|
360 |
return this.authService.getIsUserLoggedIn(); |
|
361 |
} |
|
362 |
|
|
363 |
getUserEmail() { |
|
364 |
this.userEmail = this.authService.getUserEmail(); |
|
365 |
} |
|
366 |
|
|
367 |
getRepos() { |
|
368 |
console.log('in getRepos'); |
|
369 |
this.getRepositoriesSummaryInfo(this.userEmail); |
|
370 |
} |
|
371 |
|
|
372 |
getRepositoriesSummaryInfo(userEmail: string) { |
|
373 |
this.repositoryService.getRepositoriesSummaryInfo().subscribe( |
|
374 |
repositories => { this.repositories = repositories; this.loading=false }, |
|
375 |
error => { console.log('getRepSumError'); this.loading=false }, |
|
376 |
() => { console.log(this.repositories); this.loading=false } |
|
377 |
); |
|
378 |
} |
|
379 | 320 |
} |
Also available in: Unified diff
Second commit for the new layout provided by the UX team