diff --git a/src/app/core/api/api.module.ts b/src/app/core/api/api.module.ts index e392aadc..5115bcf9 100644 --- a/src/app/core/api/api.module.ts +++ b/src/app/core/api/api.module.ts @@ -8,7 +8,7 @@ import { ApiConfiguration, ApiConfigurationParams } from './api-configuration'; import { AhbService } from './services/ahb.service'; import { MaintenanceService } from './services/maintenance.service'; - +import { provideHttpClient } from '@angular/common/http'; /** * Module that provides all services and configuration. */ @@ -19,7 +19,8 @@ import { MaintenanceService } from './services/maintenance.service'; providers: [ AhbService, MaintenanceService, - ApiConfiguration + ApiConfiguration, + provideHttpClient() ], }) export class ApiModule { @@ -35,7 +36,7 @@ export class ApiModule { } } - constructor( + constructor( @Optional() @SkipSelf() parentModule: ApiModule, @Optional() http: HttpClient ) { diff --git a/src/app/shared/components/footer/footer.component.html b/src/app/shared/components/footer/footer.component.html index a9896676..68e53884 100644 --- a/src/app/shared/components/footer/footer.component.html +++ b/src/app/shared/components/footer/footer.component.html @@ -17,7 +17,7 @@

- © {{ currentYear }} - made with by + © {{ currentYear }} - - made with by {{ version }} diff --git a/src/app/shared/components/version-display/version-display.component.ts b/src/app/shared/components/version-display/version-display.component.ts new file mode 100644 index 00000000..fd91642c --- /dev/null +++ b/src/app/shared/components/version-display/version-display.component.ts @@ -0,0 +1,49 @@ +import { Component, inject } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpClient } from '@angular/common/http'; +import { catchError, map } from 'rxjs/operators'; +import { of } from 'rxjs'; + +interface VersionInfo { + version: string; + commitId: string; +} + +@Component({ + selector: 'app-version-display', + standalone: true, // ✅ Standalone component + imports: [CommonModule], // ✅ No need for HttpClientModule anymore + templateUrl: './version-display.component.html', + styleUrls: ['./version-display.component.css'], +}) +export class VersionDisplayComponent { + version: string | null = null; + commitId: string | null = null; + private http = inject(HttpClient); // ✅ Use `inject()` instead of constructor injection + + constructor() { + this.http.get('/version', { responseType: 'text' }) + .pipe( + map((response: string) => { + try { + const parsedData: VersionInfo = JSON.parse(response); + if (parsedData.version && parsedData.commitId) { + return parsedData; + } + throw new Error('Invalid JSON structure'); + } catch (error) { + console.warn('Response is not valid JSON, using dummy values.'); + return { version: 'v0.0.0', commitId: '0000000' }; + } + }), + catchError((error) => { + console.error('Failed to load version info:', error); + return of({ version: 'Error', commitId: 'Unknown' }); + }) + ) + .subscribe((data) => { + this.version = data.version; + this.commitId = data.commitId; + }); + } +}