-
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 bugfix/SHIBUI-1673 (pull request #450)
SHIBUI-1673 Added page headings for all routes
- Loading branch information
Showing
22 changed files
with
271 additions
and
46 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
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,14 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export enum LocationActionTypes { | ||
SET_TITLE = '[Location] Set Title' | ||
} | ||
|
||
export class SetTitle implements Action { | ||
readonly type = LocationActionTypes.SET_TITLE; | ||
|
||
constructor(public payload: string) { } | ||
} | ||
|
||
export type LocationActionUnion = | ||
| SetTitle; |
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,65 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { StoreModule, Store, combineReducers } from '@ngrx/store'; | ||
|
||
import * as fromWizard from '../../wizard/reducer'; | ||
import * as fromI18n from '../../i18n/reducer'; | ||
import * as fromCore from '../reducer'; | ||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { PageTitleComponent } from './page-title.component'; | ||
import { MockI18nModule, MockI18nService } from '../../../testing/i18n.stub'; | ||
import { I18nService } from '../../i18n/service/i18n.service'; | ||
|
||
@Component({ | ||
template: `<page-title></page-title>` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(PageTitleComponent, { static: true }) | ||
public componentUnderTest: PageTitleComponent; | ||
} | ||
|
||
describe('Page Title Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: PageTitleComponent; | ||
let store: Store<fromWizard.State>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbDropdownModule, | ||
RouterTestingModule, | ||
StoreModule.forRoot({ | ||
wizard: combineReducers(fromWizard.reducers), | ||
core: combineReducers(fromCore.reducers), | ||
i18n: combineReducers(fromI18n.reducers) | ||
}), | ||
MockI18nModule | ||
], | ||
declarations: [ | ||
PageTitleComponent, | ||
TestHostComponent | ||
], | ||
providers: [ | ||
{ | ||
provide: I18nService, | ||
useClass: MockI18nService | ||
} | ||
] | ||
}).compileComponents(); | ||
|
||
store = TestBed.get(Store); | ||
spyOn(store, 'dispatch'); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should compile without error', () => { | ||
expect(app).toBeTruthy(); | ||
}); | ||
}); |
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,80 @@ | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
|
||
import { Store } from '@ngrx/store'; | ||
|
||
import * as fromRoot from '../reducer'; | ||
import { Observable, Subscription } from 'rxjs'; | ||
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router'; | ||
import { I18nService } from '../../i18n/service/i18n.service'; | ||
import { filter, map, mergeMap, startWith, combineLatest } from 'rxjs/operators'; | ||
import { getCurrent } from '../../wizard/reducer'; | ||
import { getMessages } from '../../i18n/reducer'; | ||
import { SetTitle } from '../action/location.action'; | ||
|
||
@Component({ | ||
selector: 'page-title', | ||
template: `<h2 tabindex="0" id="main-page-title" class="m-0">{{ pageTitle$ | async }}</h2>`, | ||
styleUrls: [] | ||
}) | ||
export class PageTitleComponent implements OnInit, OnDestroy { | ||
|
||
pageTitle$: Observable<string> = this.store.select(fromRoot.getLocationTitle); | ||
|
||
initial = true; | ||
sub: Subscription; | ||
|
||
constructor( | ||
private store: Store<fromRoot.State>, | ||
private router: Router, | ||
private activatedRoute: ActivatedRoute, | ||
private translateService: I18nService | ||
) { | ||
this.pageTitle$.subscribe(title => { | ||
const heading = document.getElementById('main-page-title'); | ||
if (heading && title) { | ||
if (!this.initial) { | ||
heading.focus(); | ||
} | ||
this.initial = false; | ||
} | ||
if (title) { | ||
document.title = `Shibboleth IDP UI | ${title}`; | ||
} | ||
}); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.sub = this.router.events.pipe( | ||
filter(e => e instanceof NavigationEnd), | ||
map(() => this.activatedRoute), | ||
map((route) => { | ||
while (route.firstChild) { | ||
route = route.firstChild; | ||
} | ||
return route; | ||
}), | ||
filter((route) => route.outlet === 'primary'), | ||
mergeMap((route) => route.data), | ||
combineLatest( | ||
this.store.select(getCurrent).pipe( | ||
filter(c => !!c), | ||
startWith({ label: '' }) | ||
), | ||
this.store.select(getMessages).pipe( | ||
startWith({}) | ||
) | ||
), | ||
map(([data, currentWizardPage, messages]) => { | ||
const title = data.subtitle && currentWizardPage ? | ||
`${data.title} - ${this.translateService.translate(currentWizardPage.label, null, messages)}` | ||
: | ||
data.title; | ||
return new SetTitle(title); | ||
}) | ||
).subscribe(this.store); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.sub.unsubscribe(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { LocationActionUnion, LocationActionTypes } from '../action/location.action'; | ||
|
||
export interface LocationState { | ||
title: string; | ||
} | ||
|
||
export const initialState: LocationState = { | ||
title: '' | ||
}; | ||
|
||
export function reducer(state = initialState, action: LocationActionUnion): LocationState { | ||
switch (action.type) { | ||
case LocationActionTypes.SET_TITLE: | ||
return { | ||
...state, | ||
title: action.payload | ||
}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export const getTitle = (state: LocationState) => state.title; |
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
Oops, something went wrong.