diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e53cb8c2..32a4253d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -37,6 +37,8 @@ import { AdminSystemInformationModule } from "./features/admin-system-informatio import { HyDialogBoxModule, HyDialogModule } from "@hyland/ui"; import { MatCheckboxModule } from "@angular/material/checkbox"; import { MatListModule } from "@angular/material/list"; +import { adminHomeReducer } from "../app/features/admin-home/store/reducers"; +import * as AdminEffects from "../app/features/admin-home/store/effects"; @NgModule({ declarations: [ @@ -59,9 +61,10 @@ import { MatListModule } from "@angular/material/list"; StoreModule.forRoot({ router: routerReducer, auth: authReducer, + admin: adminHomeReducer, }), StoreRouterConnectingModule.forRoot(), - EffectsModule.forRoot(authEffects), + EffectsModule.forRoot(authEffects, AdminEffects), MatIconModule, MatToolbarModule, MatButtonModule, diff --git a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.html b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.html index 05b1cb80..fc1cd2db 100644 --- a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.html +++ b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.html @@ -1,4 +1,13 @@ - Registration and Version Info - - \ No newline at end of file + Registration and Version Info + +

+ Server Version: {{ probesInfo.version }} +

+

+ Cluster Enabled: + {{ probesInfo.clusterEnabled }} +

+
+ + diff --git a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.scss b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.scss index bcfba5fa..4657b7d7 100644 --- a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.scss +++ b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.scss @@ -14,6 +14,23 @@ mat-card.mat-mdc-card:not([class*="mat-elevation-z"]) { 0px 1px 5px rgba(0, 0, 0, 0.2); border-radius: 4px; } +.mat-mdc-card-content { + display: block; + padding: 0 0 !important; +} .mat-mdc-card-content:first-child { padding-top: 0; } + +.cluster { + margin-top: 6px; +} + +.version { + margin-top: 10px; +} + +.label { + font-weight: bold; + margin-right: 10px; +} diff --git a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.ts b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.ts index 99c1c599..f91a9d84 100644 --- a/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.ts +++ b/src/app/features/admin-home/components/admin-registration-version/admin-registration-version.component.ts @@ -1,8 +1,35 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; +import { Store, select } from "@ngrx/store"; +import { Observable } from "rxjs"; +import { AdminHomeService } from "../../services/admin-home-service"; +import * as AdminHomeActions from "../../store/actions"; +import { AdminState } from "../../store/reducers"; @Component({ selector: "admin-registration-version", templateUrl: "./admin-registration-version.component.html", styleUrls: ["./admin-registration-version.component.scss"], }) -export class AdminRegistrationVersionComponent {} +export class AdminRegistrationVersionComponent implements OnInit { + probesInfo$: Observable<{ + version: string | null; + clusterEnabled: boolean | null; + }>; + loading$: Observable; + error$: Observable; + + constructor( + private store: Store<{ admin: AdminState }>, + private adminHomeService: AdminHomeService + ) { + this.probesInfo$ = this.store.pipe( + select((state) => state.admin.probesInfo) + ); + this.loading$ = this.store.pipe(select((state) => state.admin.loading)); + this.error$ = this.store.pipe(select((state) => state.admin.error)); + } + + ngOnInit(): void { + this.store.dispatch(AdminHomeActions.fetchVersionInfo()); + } +} diff --git a/src/app/features/admin-home/services/admin-home-service.ts b/src/app/features/admin-home/services/admin-home-service.ts new file mode 100644 index 00000000..ed87e264 --- /dev/null +++ b/src/app/features/admin-home/services/admin-home-service.ts @@ -0,0 +1,18 @@ +import { Injectable } from "@angular/core"; +import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs"; +import { environment } from "../../../../environments/environment"; +import { VersionInfo } from "../../../shared/types/versionInfo.interface"; + +@Injectable({ + providedIn: "root", +}) +export class AdminHomeService { + private readonly jsonFilePath = environment.apiUrl + "/version-info.json"; + + constructor(private http: HttpClient) {} + + getVersionInfo(): Observable { + return this.http.get(this.jsonFilePath); + } +} diff --git a/src/app/features/admin-home/store/actions.ts b/src/app/features/admin-home/store/actions.ts new file mode 100644 index 00000000..123c275b --- /dev/null +++ b/src/app/features/admin-home/store/actions.ts @@ -0,0 +1,11 @@ +import { createAction, props } from "@ngrx/store"; + +export const fetchVersionInfo = createAction("[Admin] Fetch Version Info"); +export const fetchVersionInfoSuccess = createAction( + "[Admin] Fetch Version Info Success", + props<{ probesInfo: { version: string; clusterEnabled: boolean } }>() +); +export const fetchVersionInfoFailure = createAction( + "[Admin] Fetch Version Info Failure", + props<{ error: any }>() +); diff --git a/src/app/features/admin-home/store/effects.ts b/src/app/features/admin-home/store/effects.ts new file mode 100644 index 00000000..589b4148 --- /dev/null +++ b/src/app/features/admin-home/store/effects.ts @@ -0,0 +1,30 @@ +import { HttpErrorResponse } from "@angular/common/http"; +import { inject } from "@angular/core"; +import { Actions, createEffect, ofType } from "@ngrx/effects"; +import { catchError, map, of, switchMap } from "rxjs"; +import { AdminHomeService } from "../services/admin-home-service"; +import * as AdminHomeActions from "../store/actions"; + +export const loadVersionInfoEffect = createEffect( + (actions$ = inject(Actions), adminHomeService = inject(AdminHomeService)) => { + return actions$.pipe( + ofType(AdminHomeActions.fetchVersionInfo), + switchMap(() => { + return adminHomeService.getVersionInfo().pipe( + map((data) => { + return AdminHomeActions.fetchVersionInfoSuccess({ + probesInfo: { + version: data.version, + clusterEnabled: data.clusterEnabled, + }, + }); + }), + catchError((error: HttpErrorResponse) => { + return of(AdminHomeActions.fetchVersionInfoFailure({ error })); + }) + ); + }) + ); + }, + { functional: true } +); diff --git a/src/app/features/admin-home/store/reducers.ts b/src/app/features/admin-home/store/reducers.ts new file mode 100644 index 00000000..4666896f --- /dev/null +++ b/src/app/features/admin-home/store/reducers.ts @@ -0,0 +1,42 @@ +import { createReducer, on } from "@ngrx/store"; +import * as AdminHomeActions from "./actions"; //AdminHomeActions // ProbesInfo + +export interface AdminState { + probesInfo: { + version: string | null; + clusterEnabled: boolean | null; + }; + loading: boolean; + error: any; +} + +export const initialState: AdminState = { + probesInfo: { + version: null, + clusterEnabled: null, + }, + loading: false, + error: null, +}; + +export const adminHomeReducer = createReducer( + initialState, + on(AdminHomeActions.fetchVersionInfo, (state) => ({ + ...state, + loading: true, + error: null, + })), + on(AdminHomeActions.fetchVersionInfoSuccess, (state, { probesInfo }) => ({ + ...state, + probesInfo: { + version: probesInfo.version, + clusterEnabled: probesInfo.clusterEnabled, + }, + loading: false, + })), + on(AdminHomeActions.fetchVersionInfoFailure, (state, { error }) => ({ + ...state, + error, + loading: false, + })) +); diff --git a/src/app/shared/types/versionInfo.interface.ts b/src/app/shared/types/versionInfo.interface.ts new file mode 100644 index 00000000..d91f2c29 --- /dev/null +++ b/src/app/shared/types/versionInfo.interface.ts @@ -0,0 +1,4 @@ +export interface VersionInfo { + version: string; + clusterEnabled: boolean; +} diff --git a/src/assets/version-info.json b/src/assets/version-info.json new file mode 100644 index 00000000..f4ce8fce --- /dev/null +++ b/src/assets/version-info.json @@ -0,0 +1,4 @@ +{ + "version": "Nuxeo Platform 2021.45.8", + "clusterEnabled": true +}