11import { Component , OnDestroy , OnInit } from '@angular/core' ;
22import { 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' ;
55import { AccountService } from '../../../../core/auth/account.service' ;
66import { User } from '../../../../core/user/user.model' ;
77import { ThemeChangeBehavior } from '../../../behaviors/theme-change.behavior' ;
88import { ADMIN_ROLE } from '../../../constants/global.constant' ;
99import { 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 ( ) {
0 commit comments