Skip to content

Commit 10d47be

Browse files
feat(frontend): make environment tag configurable (#135)
* feat(frontend): make environemt tag configurable resolves #100 * fix(build): fix build errors - Angular AoT needs variables in module to be foldable * test(frontend-unit): Fix Unit tests * chore(format): fix missing semicolon * chore(refactor): improve clarity of the statement * fix(frontend-navigation): add return statement
1 parent 594ce5e commit 10d47be

File tree

19 files changed

+106
-112
lines changed

19 files changed

+106
-112
lines changed

Phonebook.Demo/values.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ contactEmail: &contactEmail 'phonebook-t-systems-mms@mg.telekom.de'
1010
ravenUrl: 'undefined'
1111
employeePictureEndpoint: 'undefined'
1212
assetsEndpoint: 'https://demo-phonebook.me/assets'
13+
environment: 'preview'
14+
environmentTag: 'demo'
1315

1416
frontend:
1517
replicaCount: 1

Phonebook.Frontend/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ services:
1919
dockerfile: Dockerfile
2020
environment:
2121
DEBUG: 'true'
22+
ENVIRONMENT: 'development'
23+
ENVIRONMENT_TAG: 'docker'
2224
BASE_URL: 'http://localhost/'
2325
SERVER_NAME: 'localhost'
2426
CONTACT_URL: 'https://example.com'

Phonebook.Frontend/globals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
var ENV = {
2-
employeePicturesEndpoint: 'https://employee-pictures.example.com'
2+
employeePicturesEndpoint: 'https://employee-pictures.example.com',
3+
environment: 'production'
34
};

Phonebook.Frontend/src/app/app.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { DashboardComponent } from 'src/app/pages/dashboard/dashboard.component'
2323
import { SettingsModule } from 'src/app/pages/settings/settings.module';
2424
import { UserPagesModule } from 'src/app/pages/users/user-pages.module';
2525
import { ApiModule } from 'src/app/services/api/api.module';
26-
import { EnvironmentService } from 'src/app/services/environment.service';
2726
import { MailService } from 'src/app/services/mail.service';
2827
import { ReleaseInfoService } from 'src/app/services/release-info.service';
2928
import { ServiceWorkerService } from 'src/app/services/service-worker.service';
@@ -105,8 +104,7 @@ declare const require;
105104
ReleaseInfoService,
106105
ThemeService,
107106
I18n,
108-
ColumnTranslate,
109-
EnvironmentService
107+
ColumnTranslate
110108
],
111109
bootstrap: [AppComponent]
112110
})

Phonebook.Frontend/src/app/modules/feature-flag/feature-flag.service.spec.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Location } from '@angular/common';
22
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
33
import { NO_ERRORS_SCHEMA } from '@angular/core';
44
import { TestBed } from '@angular/core/testing';
5-
import { Environment, EnvironmentService } from 'src/app/services/environment.service';
65
import { FeatureFlagService } from './feature-flag.service';
76

87
describe('FeatureFlagService', () => {
@@ -14,11 +13,7 @@ describe('FeatureFlagService', () => {
1413
TestBed.configureTestingModule({
1514
schemas: [NO_ERRORS_SCHEMA],
1615
imports: [HttpClientTestingModule],
17-
providers: [
18-
FeatureFlagService,
19-
{ provide: Location, useClass: LocationMock },
20-
{ provide: EnvironmentService, useClass: MockEnviromentService }
21-
]
16+
providers: [FeatureFlagService, { provide: Location, useClass: LocationMock }]
2217
}).compileComponents();
2318
httpMock = TestBed.get(HttpTestingController);
2419
featureFlagServiceTest = TestBed.get(FeatureFlagService);
@@ -103,9 +98,3 @@ class LocationMock {
10398
return '/' + url;
10499
}
105100
}
106-
107-
class MockEnviromentService {
108-
public getEnvironment(): Environment {
109-
return Environment.production;
110-
}
111-
}

Phonebook.Frontend/src/app/modules/feature-flag/feature-flag.service.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { HttpClient } from '@angular/common/http';
33
import { EventEmitter, Injectable } from '@angular/core';
44
import { combineLatest, ConnectableObservable, Observable, of } from 'rxjs';
55
import { catchError, map, publishReplay, startWith } from 'rxjs/operators';
6-
import { Environment, EnvironmentService } from 'src/app/services/environment.service';
6+
import { Environment } from 'src/environments/EnvironmentInterfaces';
7+
import { runtimeEnvironment } from 'src/environments/runtime-environment';
78

89
@Injectable()
910
export class FeatureFlagService {
@@ -13,11 +14,7 @@ export class FeatureFlagService {
1314
};
1415
private flagOverwriteEmitter: EventEmitter<any> = new EventEmitter<any>();
1516

16-
constructor(
17-
private httpClient: HttpClient,
18-
private location: Location,
19-
private environmentService: EnvironmentService
20-
) {}
17+
constructor(private httpClient: HttpClient, private location: Location) {}
2118

2219
/**
2320
* Returns the Feature Flags.
@@ -69,7 +66,7 @@ export class FeatureFlagService {
6966
}
7067
// Flags with 0 are disabled by default, but can be enabled by the user
7168
if (value === 0) {
72-
if (this.environmentService.getEnvironment() === Environment.production) {
69+
if (runtimeEnvironment.environment === Environment.production) {
7370
return false;
7471
} else {
7572
return true;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { Environment, EnvironmentService } from 'src/app/services/environment.service';
3-
import { RuntimeEnvironmentInterface } from 'src/environments/EnvironmentInterfaces';
2+
import { Environment, RuntimeEnvironmentInterface } from 'src/environments/EnvironmentInterfaces';
43
import { runtimeEnvironment } from 'src/environments/runtime-environment';
54

65
@Component({
@@ -11,9 +10,9 @@ import { runtimeEnvironment } from 'src/environments/runtime-environment';
1110
export class PageInformationComponent implements OnInit {
1211
public isPreview: boolean = true;
1312
public runtimeEnvironment: RuntimeEnvironmentInterface = runtimeEnvironment;
14-
constructor(private environmentService: EnvironmentService) {}
13+
constructor() {}
1514

1615
public ngOnInit() {
17-
this.isPreview = this.environmentService.getEnvironment() === Environment.production ? false : true;
16+
this.isPreview = runtimeEnvironment.environment === Environment.production ? false : true;
1817
}
1918
}

Phonebook.Frontend/src/app/pages/page-information/page-information.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { MatCardModule } from '@angular/material/card';
55
import { MatListModule } from '@angular/material/list';
66
import { RouterModule, Routes } from '@angular/router';
77
import { PageInformationComponent } from 'src/app/pages/page-information/page-information.component';
8-
import { EnvironmentService } from 'src/app/services/environment.service';
98
import { FeedbackDrawerModule } from 'src/app/shared/directives/feedback-drawer/feedback-drawer.module';
109

1110
const routes: Routes = [
@@ -25,6 +24,6 @@ const routes: Routes = [
2524
MatListModule,
2625
FeedbackDrawerModule
2726
],
28-
providers: [EnvironmentService]
27+
providers: []
2928
})
3029
export class PageInformationModule {}

Phonebook.Frontend/src/app/services/environment.service.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

Phonebook.Frontend/src/app/shared/components/navigation/navigation.component.html

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,10 @@
8282
>
8383
<span
8484
class="beta-tag mat-headline pb-hide-below-small"
85-
*ngIf="environmentService.getEnvironment() == Environment.preview"
86-
i18n="NavigationBar|Tag on Application Name@@navigationBarApplicationNameTag"
87-
>Preview</span
88-
>
89-
<span
90-
class="beta-tag mat-headline pb-hide-below-small"
91-
*ngIf="environmentService.getEnvironment() == Environment.local"
92-
>Dev</span
93-
>
94-
<span
95-
class="version pb-hide-below-small"
96-
*ngIf="environmentService.getEnvironment() != Environment.local"
85+
*ngIf="currentEnvironment != Environment.production"
86+
>{{ getEnvironmentTag() }}</span
9787
>
88+
<span class="version pb-hide-below-small" *ngIf="currentEnvironment != Environment.development">
9889
v{{ version }}</span
9990
>
10091
</button>
@@ -172,10 +163,8 @@
172163
<!-- Dummy for Layout -->
173164
</div>
174165
<div>
175-
<span *ngIf="environmentService.getEnvironment() != Environment.local">
176-
<span *ngIf="environment.production">Prod</span><span *ngIf="!environment.production">Dev</span> - v{{
177-
version
178-
}}
166+
<span *ngIf="currentEnvironment != Environment.development">
167+
<span>{{ getEnvironmentTag() }}</span> - v{{ version }}
179168
-
180169
<a href="https://github.com/T-Systems-MMS/phonebook/commit/{{ versionHashLong }}">{{ versionHashShort }}</a>
181170
</span>

0 commit comments

Comments
 (0)