Skip to content

Commit

Permalink
NXP-32252: admin-console-nuxeo-server-information
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishant0928 committed May 27, 2024
1 parent fef5bc4 commit 6b1f3a4
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<mat-card role="region" aria-label="registration-version">
<mat-card-content>Registration and Version Info</mat-card-content>
<button mat-flat-button color="primary">Details</button>
</mat-card>
<mat-card-content>Registration and Version Info</mat-card-content>
<ng-container *ngIf="probesInfo$ | async as probesInfo">
<p class="version">
<span class="label">Server Version:</span> {{ probesInfo.version }}
</p>
<p class="cluster">
<span class="label">Cluster Enabled:</span>
{{ probesInfo.clusterEnabled }}
</p>
</ng-container>
<button mat-flat-button color="primary">Details</button>
</mat-card>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<boolean>;
error$: Observable<any>;

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());
}
}
18 changes: 18 additions & 0 deletions src/app/features/admin-home/services/admin-home-service.ts
Original file line number Diff line number Diff line change
@@ -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<VersionInfo> {
return this.http.get<VersionInfo>(this.jsonFilePath);
}
}
11 changes: 11 additions & 0 deletions src/app/features/admin-home/store/actions.ts
Original file line number Diff line number Diff line change
@@ -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 }>()
);
30 changes: 30 additions & 0 deletions src/app/features/admin-home/store/effects.ts
Original file line number Diff line number Diff line change
@@ -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 }
);
42 changes: 42 additions & 0 deletions src/app/features/admin-home/store/reducers.ts
Original file line number Diff line number Diff line change
@@ -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,
}))
);
4 changes: 4 additions & 0 deletions src/app/shared/types/versionInfo.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface VersionInfo {
version: string;
clusterEnabled: boolean;
}
4 changes: 4 additions & 0 deletions src/assets/version-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "Nuxeo Platform 2021.45.8",
"clusterEnabled": true
}

0 comments on commit 6b1f3a4

Please sign in to comment.