Skip to content

Commit

Permalink
Merged in feature/SHIBUI-372 (pull request #25)
Browse files Browse the repository at this point in the history
Added version information, reorganized root level redux implementation

Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Mar 23, 2018
1 parent a157ad7 commit f733806
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 29 deletions.
5 changes: 3 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json --i18nFile=./src/locale/en.xlf --i18nFormat=xlf --locale=en --aot",
"start": "ng serve --proxy-config proxy.conf.json",
"startProd": "ng serve --proxy-config proxy.conf.json --i18nFile=./src/locale/en.xlf --i18nFormat=xlf --locale=en --aot --environment=prod",
"build": "ng build",
"test": "ng test --code-coverage",
"lint": "ng lint",
Expand All @@ -27,11 +28,11 @@
"@ngrx/effects": "^5.1.0",
"@ngrx/router-store": "^5.0.1",
"@ngrx/store": "^5.1.0",
"@reactivex/rxjs": "^5.5.6",
"bootstrap": "4.0.0",
"core-js": "^2.4.1",
"file-saver": "^1.3.3",
"font-awesome": "^4.7.0",
"@reactivex/rxjs": "^5.5.6",
"xml-formatter": "^1.0.1",
"zone.js": "^0.8.20"
},
Expand Down
5 changes: 5 additions & 0 deletions ui/proxy.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"secure": false,
"logLevel": "debug"
},
"/actuator": {
"target": "http://localhost:8080",
"secure": false,
"logLevel": "debug"
},
"/login": {
"target": "http://localhost:8080",
"secure": false,
Expand Down
8 changes: 7 additions & 1 deletion ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@
<li class="list-inline-item"><a href="https://issues.shibboleth.net/" target="_blank" i18n="@@link--issue-tracker" aria-label="Shibboleth.net open-source community issue tracker">Issue Tracker</a></li>
<li class="list-inline-item"><a href="https://www.shibboleth.net/community/lists/" target="_blank" i18n="@@link--mailing-list" aria-label="Shibboleth.net open-source community mailing list">Mailing List</a></li>
</ul>
<p><ng-container i18n="@@label--copyright">Copyright</ng-container> &copy; 2017 Internet2</p>
<p>
<ng-container *ngIf="version$ | async">
{{ version }}
&nbsp;|&nbsp;
</ng-container>
<ng-container i18n="@@label--copyright">Copyright</ng-container> &copy; {{ today | date:'yyyy' }} Internet2
</p>
</div>
<div class="col-md-4 logo">
<a href="https://www.shibboleth.net/" target="_blank"><img src="/assets/shibboleth_logowordmark_color.png" class="img-fluid float-right" alt="Shibboleth Logo - Click to be directed to www.shibboleth.net"></a>
Expand Down
19 changes: 17 additions & 2 deletions ui/src/app/app.component.ts
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}`;
}
});
}
}
13 changes: 6 additions & 7 deletions ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@ import { AppComponent } from './app.component';

import { CoreModule } from './core/core.module';
import { MetadataProviderModule } from './metadata-provider/metadata-provider.module';
import { reducers } from './core/reducer';
import { reducers, metaReducers } from './app.reducer';
import { CustomRouterStateSerializer } from './shared/util';

import { UserEffects } from './core/effect/user.effect';
import { CachingInterceptor } from './core/service/cache.interceptor';
import { AuthorizedInterceptor } from './core/service/authorized.interceptor';
import { NotificationModule } from './notification/notification.module';
import { ErrorInterceptor } from './core/service/error.interceptor';
import { NavigatorService } from './core/service/navigator.service';

import { environment } from '../environments/environment';

@NgModule({
declarations: [
AppComponent
],
imports: [
StoreModule.forRoot({
...reducers
StoreModule.forRoot(reducers, {
metaReducers
}),
EffectsModule.forRoot([
UserEffects
]),
EffectsModule.forRoot([]),
BrowserModule,
AppRoutingModule,
CoreModule.forRoot(),
Expand Down
15 changes: 15 additions & 0 deletions ui/src/app/app.reducer.ts
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>[] = [];
31 changes: 31 additions & 0 deletions ui/src/app/core/action/version.action.ts
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;
20 changes: 17 additions & 3 deletions ui/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';

import { UserService } from './service/user.service';
import { CanDeactivateGuard } from './service/can-deactivate.guard';
import { FileService } from './service/file.service';

import { reducers } from './reducer';
import { VersionEffects } from './effect/version.effect';
import { UserEffects } from './effect/user.effect';
import { HttpClientModule } from '@angular/common/http';

export const COMPONENTS = [];

@NgModule({
imports: [
CommonModule,
RouterModule,
HttpModule
HttpClientModule
],
declarations: COMPONENTS,
entryComponents: COMPONENTS,
Expand All @@ -22,7 +28,7 @@ export const COMPONENTS = [];
export class CoreModule {
static forRoot() {
return {
ngModule: CoreModule,
ngModule: RootCoreModule,
providers: [
UserService,
FileService,
Expand All @@ -31,3 +37,11 @@ export class CoreModule {
};
}
}

@NgModule({
imports: [
StoreModule.forFeature('core', reducers),
EffectsModule.forFeature([UserEffects, VersionEffects]),
],
})
export class RootCoreModule { }
34 changes: 34 additions & 0 deletions ui/src/app/core/effect/version.effect.ts
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 */
16 changes: 16 additions & 0 deletions ui/src/app/core/model/version.ts
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
};
}
32 changes: 21 additions & 11 deletions ui/src/app/core/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@ import {
ActionReducerMap,
createSelector,
createFeatureSelector,
createSelectorFactory,
ActionReducer,
MetaReducer,
combineReducers
} from '@ngrx/store';

import { routerReducer, RouterReducerState } from '@ngrx/router-store';
import * as fromRouter from '@ngrx/router-store';
import * as fromUser from './user.reducer';
import { RouterStateUrl } from '../../shared/util';
import * as fromVersion from './version.reducer';
import * as fromRoot from '../../app.reducer';

export interface State {
routerReducer: fromRouter.RouterReducerState<RouterStateUrl>;
export interface CoreState {
user: fromUser.UserState;
version: fromVersion.VersionState;
}

export const reducers: ActionReducerMap<State> = {
routerReducer: fromRouter.routerReducer,
user: fromUser.reducer
export interface State extends fromRoot.State {
core: CoreState;
}

export const reducers = {
user: fromUser.reducer,
version: fromVersion.reducer
};

export const getState = createFeatureSelector<State>('user');
export const getUserState = createSelector(getState, (state: State) => state.user);
export const getCoreFeature = createFeatureSelector<CoreState>('core');

export const getUserState = createSelector(getCoreFeature, (state: CoreState) => state.user);
export const getUser = createSelector(getUserState, fromUser.getUser);
export const isFetching = createSelector(getUserState, fromUser.isFetching);
export const getError = createSelector(getUserState, fromUser.getError);
export const getUserError = createSelector(getUserState, fromUser.getError);

export const getVersionState = createSelector(getCoreFeature, (state: CoreState) => state.version);
export const getVersionInfo = createSelector(getVersionState, fromVersion.getVersionInfo);
export const getVersionLoading = createSelector(getVersionState, fromVersion.getVersionIsLoading);
export const getVersionError = createSelector(getVersionState, fromVersion.getVersionError);
47 changes: 47 additions & 0 deletions ui/src/app/core/reducer/version.reducer.ts
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;
3 changes: 1 addition & 2 deletions ui/src/app/core/service/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'rxjs/add/observable/of';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { User } from '../model/user';

@Injectable()
export class UserService {

constructor(private http: Http) { }
constructor() { }

get(): Observable<User> {
const defUser = Object.assign({}, {
Expand Down
Loading

0 comments on commit f733806

Please sign in to comment.