Skip to content

Commit be82425

Browse files
committed
feat(header): integrate version info display and update logic
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent 632401f commit be82425

3 files changed

Lines changed: 37 additions & 43 deletions

File tree

frontend/src/app/shared/components/layout/header/header.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<div class="navbar-img mr-3 d-flex justify-content-start align-items-center">
88
<img *ngIf="logoImage" [alt]="altImage" [src]="sanitizer.bypassSecurityTrustUrl(logoImage)"
99
class="cursor-pointer" routerLink="/dashboard/overview">
10-
<app-utm-version-info></app-utm-version-info>
10+
<app-utm-version-info [version]="versionInfo"
11+
></app-utm-version-info>
1112

1213
<!--<app-utm-license-info class="ml-4"></app-utm-license-info>-->
1314
<app-utm-vault-status class="ml-4"></app-utm-vault-status>

frontend/src/app/shared/components/layout/header/header.component.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {DomSanitizer} from '@angular/platform-browser';
3-
import {Subject} from 'rxjs';
4-
import {filter, takeUntil} from 'rxjs/operators';
3+
import {EMPTY, Subject} from 'rxjs';
4+
import {catchError, filter, map, takeUntil, tap} from 'rxjs/operators';
55
import {AccountService} from '../../../../core/auth/account.service';
66
import {User} from '../../../../core/user/user.model';
77
import {ThemeChangeBehavior} from '../../../behaviors/theme-change.behavior';
88
import {ADMIN_ROLE} from '../../../constants/global.constant';
99
import {AppThemeLocationEnum} from '../../../enums/app-theme-location.enum';
10+
import {VersionType, VersionTypeService} from "../../../services/util/version-type.service";
11+
import {AppVersionInfo} from "../../../types/updates/updates.type";
12+
import {CheckForUpdatesService} from "../../../services/updates/check-for-updates.service";
1013

1114
@Component({
1215
selector: 'app-header',
@@ -20,11 +23,14 @@ export class HeaderComponent implements OnInit, OnDestroy {
2023
place = AppThemeLocationEnum;
2124
logoImage: string;
2225
altImage: string;
26+
versionInfo: AppVersionInfo;
2327
destroy$: Subject<void> = new Subject();
2428

2529
constructor(private accountService: AccountService,
2630
public sanitizer: DomSanitizer,
27-
private themeChangeBehavior: ThemeChangeBehavior) {
31+
private themeChangeBehavior: ThemeChangeBehavior,
32+
private versionTypeService: VersionTypeService,
33+
private checkForUpdatesService: CheckForUpdatesService) {
2834
}
2935

3036
ngOnInit() {
@@ -37,6 +43,27 @@ export class HeaderComponent implements OnInit, OnDestroy {
3743
this.accountService.identity().then(account => {
3844
this.user = account;
3945
});
46+
47+
this.checkForUpdatesService.getVersion()
48+
.pipe(
49+
map(response => response.body || null),
50+
tap((versionInfo: AppVersionInfo) => {
51+
const version = versionInfo && versionInfo.version || '';
52+
const versionType = versionInfo.edition.includes('community') || version === ''
53+
? VersionType.COMMUNITY
54+
: VersionType.ENTERPRISE;
55+
56+
if (versionType !== this.versionTypeService.versionType()) {
57+
this.versionTypeService.changeVersionType(versionType);
58+
}
59+
}),
60+
catchError(() => {
61+
return EMPTY;
62+
})
63+
)
64+
.subscribe(versionInfo => {
65+
this.versionInfo = versionInfo;
66+
});
4067
}
4168

4269
ngOnDestroy() {
Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,15 @@
1-
import {Component, OnDestroy, OnInit} from '@angular/core';
2-
import {EMPTY, Observable, Subject} from 'rxjs';
3-
import {catchError, map, tap} from 'rxjs/operators';
1+
import {Component, Input, OnInit} from '@angular/core';
42
import {UtmToastService} from '../../../../../../alert/utm-toast.service';
53
import {CheckForUpdatesService} from '../../../../../../services/updates/check-for-updates.service';
6-
import {VersionType, VersionTypeService} from '../../../../../../services/util/version-type.service';
7-
import {AppVersionInfo, VersionInfo} from '../../../../../../types/updates/updates.type';
4+
import {AppVersionInfo} from '../../../../../../types/updates/updates.type';
85

96
@Component({
107
selector: 'app-utm-version-info',
118
templateUrl: './utm-version-info.component.html',
129
styleUrls: ['./utm-version-info.component.css']
1310
})
14-
export class UtmVersionInfoComponent implements OnInit {
15-
versionInfo: AppVersionInfo;
16-
17-
constructor(private checkForUpdatesService: CheckForUpdatesService,
18-
private utmToastService: UtmToastService,
19-
private versionTypeService: VersionTypeService) {
20-
}
21-
22-
ngOnInit() {
23-
this.checkForUpdatesService.getVersion()
24-
.pipe(
25-
map(response => response.body || null),
26-
tap((versionInfo: AppVersionInfo) => {
27-
const version = versionInfo && versionInfo.version || '';
28-
const versionType = versionInfo.edition.includes('community') || version === ''
29-
? VersionType.COMMUNITY
30-
: VersionType.ENTERPRISE;
31-
32-
if (versionType !== this.versionTypeService.versionType()) {
33-
this.versionTypeService.changeVersionType(versionType);
34-
}
35-
}),
36-
catchError(() => {
37-
this.utmToastService.showError(
38-
'Error fetching version info',
39-
'An error occurred while fetching version info.'
40-
);
41-
return EMPTY;
42-
})
43-
)
44-
.subscribe(versionInfo => {
45-
this.versionInfo = versionInfo;
46-
});
47-
}
11+
export class UtmVersionInfoComponent {
12+
@Input('version') versionInfo: AppVersionInfo;
4813

14+
constructor() {}
4915
}

0 commit comments

Comments
 (0)