-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/SHIBUI-372 (pull request #25)
Added version information, reorganized root level redux implementation Approved-by: Ryan Mathis <rmathis@unicon.net>
- Loading branch information
Showing
14 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Store } from '@ngrx/store'; | ||
import 'rxjs/add/operator/takeWhile'; | ||
|
||
import * as fromUser from './core/reducer/user.reducer'; | ||
import * as fromRoot from './core/reducer'; | ||
import { VersionInfo } from './core/model/version'; | ||
import { LoadProviderRequest } from './metadata-provider/action/provider.action'; | ||
import { LoadDraftRequest } from './metadata-provider/action/draft.action'; | ||
import { VersionInfoLoadRequestAction } from './core/action/version.action'; | ||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'] | ||
}) | ||
export class AppComponent implements OnInit { | ||
title = 'Shib UI'; | ||
version$: Observable<VersionInfo>; | ||
version: string; | ||
today = new Date(); | ||
|
||
constructor(private store: Store<fromUser.UserState>) { } | ||
constructor(private store: Store<fromRoot.State>) { | ||
this.version$ = this.store.select(fromRoot.getVersionInfo); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.store.dispatch(new LoadProviderRequest()); | ||
this.store.dispatch(new LoadDraftRequest()); | ||
this.store.dispatch(new VersionInfoLoadRequestAction()); | ||
|
||
this.version$.subscribe(v => { | ||
if (v && v.build) { | ||
this.version = `${v.build.version}-${v.git.commit.id}`; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ActionReducerMap, MetaReducer, ActionReducer } from '@ngrx/store'; | ||
import { routerReducer, RouterReducerState } from '@ngrx/router-store'; | ||
import * as fromRouter from '@ngrx/router-store'; | ||
|
||
import { RouterStateUrl } from './shared/util'; | ||
|
||
export interface State { | ||
router: fromRouter.RouterReducerState<RouterStateUrl>; | ||
} | ||
|
||
export const reducers: ActionReducerMap<State> = { | ||
router: fromRouter.routerReducer, | ||
}; | ||
|
||
export const metaReducers: MetaReducer<State>[] = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
import { VersionInfo } from '../model/version'; | ||
|
||
export const VERSION_LOAD_REQUEST = '[Version] Load REQUEST'; | ||
export const VERSION_LOAD_SUCCESS = '[Version] Load SUCCESS'; | ||
export const VERSION_LOAD_ERROR = '[Version] Load ERROR'; | ||
|
||
/** | ||
* Add User to Collection Actions | ||
*/ | ||
export class VersionInfoLoadRequestAction implements Action { | ||
readonly type = VERSION_LOAD_REQUEST; | ||
} | ||
|
||
export class VersionInfoLoadSuccessAction implements Action { | ||
readonly type = VERSION_LOAD_SUCCESS; | ||
|
||
constructor (public payload: VersionInfo) { } | ||
} | ||
|
||
export class VersionInfoLoadErrorAction implements Action { | ||
readonly type = VERSION_LOAD_ERROR; | ||
|
||
constructor(public payload: Error) { } | ||
} | ||
|
||
export type Actions = | ||
| VersionInfoLoadRequestAction | ||
| VersionInfoLoadSuccessAction | ||
| VersionInfoLoadErrorAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'rxjs/add/operator/switchMap'; | ||
import 'rxjs/add/operator/map'; | ||
import 'rxjs/add/operator/catch'; | ||
import 'rxjs/add/operator/do'; | ||
import { of } from 'rxjs/observable/of'; | ||
import { Injectable } from '@angular/core'; | ||
import { Effect, Actions } from '@ngrx/effects'; | ||
import { Location } from '@angular/common'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
import * as version from '../action/version.action'; | ||
import { VersionInfo } from '../model/version'; | ||
|
||
@Injectable() | ||
export class VersionEffects { | ||
|
||
private endpoint = '/info'; | ||
private base = '/actuator'; | ||
|
||
@Effect() | ||
loadVersionInfo$ = this.actions$ | ||
.ofType(version.VERSION_LOAD_REQUEST) | ||
.switchMap(() => | ||
this.http | ||
.get<VersionInfo>(`${this.base}${this.endpoint}`) | ||
.map(info => new version.VersionInfoLoadSuccessAction(info) ) | ||
.catch(error => of(new version.VersionInfoLoadErrorAction(error))) | ||
); | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private actions$: Actions | ||
) { } | ||
} /* istanbul ignore next */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface VersionInfo { | ||
git: { | ||
commit: { | ||
time: string, | ||
id: string | ||
}, | ||
branch: string | ||
}; | ||
build: { | ||
version: string, | ||
artifact: string, | ||
name: string, | ||
group: string, | ||
time: string | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSelector, createFeatureSelector } from '@ngrx/store'; | ||
import * as version from '../action/version.action'; | ||
import * as fromRoot from '../../core/reducer'; | ||
|
||
export interface VersionState { | ||
info: any; | ||
loading: boolean; | ||
error: Error | null; | ||
} | ||
|
||
export const initialState: VersionState = { | ||
info: {}, | ||
loading: false, | ||
error: null | ||
}; | ||
|
||
export function reducer(state = initialState, action: version.Actions): VersionState { | ||
switch (action.type) { | ||
case version.VERSION_LOAD_REQUEST: { | ||
return { | ||
...state, | ||
loading: true | ||
}; | ||
} | ||
case version.VERSION_LOAD_SUCCESS: { | ||
return { | ||
...state, | ||
loading: false, | ||
info: action.payload | ||
}; | ||
} | ||
case version.VERSION_LOAD_ERROR: { | ||
return { | ||
...state, | ||
loading: false, | ||
error: action.payload | ||
}; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
export const getVersionInfo = (state: VersionState) => state.info; | ||
export const getVersionIsLoading = (state: VersionState) => state.loading; | ||
export const getVersionError = (state: VersionState) => state.error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.