Skip to content

Commit d9bb769

Browse files
hf-kkleinKonstantin
andauthored
feat: display version in footer (#421)
--------- Co-authored-by: Konstantin <[email protected]>
1 parent 44ebfc4 commit d9bb769

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed

src/app/core/api/api.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ApiConfiguration, ApiConfigurationParams } from './api-configuration';
88

99
import { AhbService } from './services/ahb.service';
1010
import { MaintenanceService } from './services/maintenance.service';
11-
11+
import { provideHttpClient } from '@angular/common/http';
1212
/**
1313
* Module that provides all services and configuration.
1414
*/
@@ -19,7 +19,8 @@ import { MaintenanceService } from './services/maintenance.service';
1919
providers: [
2020
AhbService,
2121
MaintenanceService,
22-
ApiConfiguration
22+
ApiConfiguration,
23+
provideHttpClient()
2324
],
2425
})
2526
export class ApiModule {
@@ -35,7 +36,7 @@ export class ApiModule {
3536
}
3637
}
3738

38-
constructor(
39+
constructor(
3940
@Optional() @SkipSelf() parentModule: ApiModule,
4041
@Optional() http: HttpClient
4142
) {

src/app/shared/components/footer/footer.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<div class="flex-1 flex justify-center">
1818
<div class="flex items-center text-sm text-black/70 space-x-1 text-center">
1919
<p class="flex items-center flex-wrap justify-center">
20-
© {{ currentYear }} - made with <i class="mdi mdi-heart-outline text-lg mx-1"></i> by
20+
© {{ currentYear }} - <app-version-display></app-version-display> - made with
21+
<i class="mdi mdi-heart-outline text-lg mx-1"></i> by
2122
<a
2223
class="ml-1 mr-2 hover:underline font-bold"
2324
target="_blank"

src/app/shared/components/footer/footer.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
32
import { FooterComponent } from './footer.component';
3+
import { provideHttpClient } from '@angular/common/http';
44

55
describe('FooterComponent', () => {
66
let component: FooterComponent;
@@ -9,6 +9,7 @@ describe('FooterComponent', () => {
99
beforeEach(async () => {
1010
await TestBed.configureTestingModule({
1111
imports: [FooterComponent],
12+
providers: [provideHttpClient()],
1213
}).compileComponents();
1314

1415
fixture = TestBed.createComponent(FooterComponent);

src/app/shared/components/footer/footer.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Component } from '@angular/core';
2+
import { VersionDisplayComponent } from '../version-display/version-display.component';
23

34
@Component({
45
selector: 'app-footer',
56
standalone: true,
6-
imports: [],
7+
imports: [VersionDisplayComponent],
78
templateUrl: './footer.component.html',
89
})
910
export class FooterComponent {

src/app/shared/components/version-display/version-display.component.css

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<a *ngIf="version" title="Commit {{ commitId }} built on {{ buildDate }}" href="/version">{{
2+
version
3+
}}</a>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Component, inject } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { HttpClient } from '@angular/common/http';
4+
import { catchError, map } from 'rxjs/operators';
5+
import { of } from 'rxjs';
6+
7+
interface VersionInfo {
8+
version: string;
9+
commitId: string;
10+
buildDate: string;
11+
}
12+
13+
@Component({
14+
selector: 'app-version-display',
15+
standalone: true,
16+
imports: [CommonModule],
17+
templateUrl: './version-display.component.html',
18+
styleUrls: ['./version-display.component.css'],
19+
})
20+
export class VersionDisplayComponent {
21+
version: string | null = null;
22+
commitId: string | null = null;
23+
buildDate: string | null = null;
24+
private http = inject(HttpClient);
25+
26+
constructor() {
27+
this.http
28+
.get('/version', { responseType: 'text' }) // we don't know the build date at compile time
29+
.pipe(
30+
map((response: string) => {
31+
try {
32+
const parsedData: VersionInfo = JSON.parse(response);
33+
if (parsedData.version && parsedData.commitId && parsedData.buildDate) {
34+
return parsedData;
35+
}
36+
throw new Error('Invalid JSON structure');
37+
} catch (error) {
38+
console.warn(
39+
'Response to /version endpoint is not valid JSON. This happens on localhost',
40+
error
41+
);
42+
return { version: 'v0.0.0', commitId: '0000000', buildDate: 'Unknown' };
43+
}
44+
}),
45+
catchError(error => {
46+
console.error('Failed to load version info:', error);
47+
return of({ version: 'Error', commitId: 'Unknown', buildDate: 'Unknown' });
48+
})
49+
)
50+
.subscribe(data => {
51+
this.version = data.version;
52+
this.commitId = data.commitId;
53+
this.buildDate = data.buildDate;
54+
});
55+
}
56+
}

0 commit comments

Comments
 (0)