Add version handling
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
<div class="footer-wrapper" *ngIf="userLoggedIn">
|
||||
<div class="version-web" *ngIf="versionWeb">
|
||||
Web: v{{versionWeb}}
|
||||
<span class="label">
|
||||
Web:
|
||||
</span>
|
||||
<span class="version">
|
||||
v.{{versionWeb}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="version-api" *ngIf="versionApi">
|
||||
API: v{{versionApi}}
|
||||
<span class="label">
|
||||
API:
|
||||
</span>
|
||||
<span class="version">
|
||||
v.{{versionApi}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -5,4 +5,17 @@ div.footer-wrapper {
|
||||
justify-content: flex-end;
|
||||
padding-right: 16px;
|
||||
align-items: center;
|
||||
|
||||
div.version-api {
|
||||
margin-left: 16px;
|
||||
}
|
||||
span.version {
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
span.label {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { LoaderService } from '../loader/loader.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from 'src/app/auth/auth.service';
|
||||
import { DatabaseService } from 'src/app/core/services/database.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-footer',
|
||||
@@ -14,11 +15,12 @@ import { AuthService } from 'src/app/auth/auth.service';
|
||||
})
|
||||
export class FooterComponent implements OnInit {
|
||||
versionWeb: number | undefined = environment.version;
|
||||
versionApi: number | undefined;
|
||||
versionApi: string | undefined;
|
||||
userLoggedIn: Boolean = false;
|
||||
|
||||
//injects
|
||||
private authService: AuthService = inject(AuthService);
|
||||
private databaseService: DatabaseService = inject(DatabaseService);
|
||||
// private loaderService: LoaderService = inject(LoaderService);
|
||||
|
||||
constructor() {}
|
||||
@@ -27,5 +29,18 @@ export class FooterComponent implements OnInit {
|
||||
this.authService.isLoggedIn.subscribe((res) => {
|
||||
this.userLoggedIn = res;
|
||||
});
|
||||
this.getApiVersion();
|
||||
|
||||
if (this.userLoggedIn) {
|
||||
this.databaseService.getApiVersion();
|
||||
}
|
||||
}
|
||||
|
||||
getApiVersion(): void {
|
||||
this.databaseService.apiVersion.subscribe({
|
||||
next: (value) => {
|
||||
this.versionApi = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { LoaderService } from '../loader/loader.service';
|
||||
import { FormsService } from 'src/app/core/services/forms.service';
|
||||
import { NotificationService } from 'src/app/core/services/notification.service';
|
||||
import { DatabaseService } from 'src/app/core/services/database.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -29,6 +30,7 @@ export class LoginComponent implements OnInit {
|
||||
private notificationService: NotificationService =
|
||||
inject(NotificationService);
|
||||
private router: Router = inject(Router);
|
||||
private dataBaseService: DatabaseService = inject(DatabaseService);
|
||||
|
||||
constructor() {}
|
||||
|
||||
@@ -65,6 +67,7 @@ export class LoginComponent implements OnInit {
|
||||
resp.tokenValue.trim() !== ''
|
||||
) {
|
||||
this.loginService.setSessionCurrentUser(resp);
|
||||
this.dataBaseService.getApiVersion();
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
HttpErrorResponse,
|
||||
HttpHeaders,
|
||||
} from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Meter, MeterData } from '../dataModels/Meterdata';
|
||||
@@ -15,7 +15,13 @@ import { Meter, MeterData } from '../dataModels/Meterdata';
|
||||
export class DatabaseService {
|
||||
private baseUrl = environment.apiBaseUrl;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
private apiVersionSubject: BehaviorSubject<string> =
|
||||
new BehaviorSubject<string>('');
|
||||
public apiVersion: Observable<string>;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.apiVersion = this.apiVersionSubject.asObservable();
|
||||
}
|
||||
|
||||
getMeterData(): Observable<MeterData[]> {
|
||||
const url = `${this.baseUrl}/meter-data`;
|
||||
@@ -55,4 +61,16 @@ export class DatabaseService {
|
||||
// Return an observable with a user-facing error message.
|
||||
return throwError(() => error);
|
||||
}
|
||||
|
||||
public getApiVersion(): void {
|
||||
const url = `${this.baseUrl}/version`;
|
||||
this.http
|
||||
.get<string>(url)
|
||||
.pipe(catchError(this.handleError))
|
||||
.subscribe({
|
||||
next: (value) => {
|
||||
this.apiVersionSubject.next(value);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ export const environment = {
|
||||
production: true,
|
||||
env: 'prod',
|
||||
apiBaseUrl: 'http://192.168.178.21:8182/api',
|
||||
version: 0.2,
|
||||
version: 0.3,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ export const environment = {
|
||||
production: false,
|
||||
env: 'local',
|
||||
apiBaseUrl: 'http://localhost:8080',
|
||||
version: 0.2,
|
||||
version: 0.4,
|
||||
// apiBaseUrl: 'http://192.168.178.21:8182/api',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user