Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
</header>
<main>
<mat-sidenav-container>
<mat-sidenav #sidenav role="navigation">
<mat-sidenav #sidenav
role="navigation">
<mat-nav-list (click)="sidenav.toggle()">
<a *ngFor="let menu of menus" mat-list-item routerLinkActive="active" [routerLinkActiveOptions]="menu.options" [routerLink]="menu.link">
<a *ngFor="let menu of menus"
mat-list-item
routerLinkActive="active"
[routerLinkActiveOptions]="menu.options"
[routerLink]="menu.link"
(click)="shouldOpenChildMenu(menu.title)">
{{menu.title}}
</a>
</mat-nav-list>
Expand Down
11 changes: 10 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@angular/router';
import { filter, map, mergeMap } from 'rxjs/operators';
import { SeoService, SeoData } from './core/services/seo.service';
import { OperatorMenuService } from './core/services/operator-menu.service';

interface Menu {
title: string;
Expand Down Expand Up @@ -46,7 +47,8 @@ export class AppComponent implements OnInit {
constructor(
private _router: Router,
private _activatedRoute: ActivatedRoute,
private _seo: SeoService
private _seo: SeoService,
private _operatorMenuService: OperatorMenuService
) {}

ngOnInit() {
Expand All @@ -66,4 +68,11 @@ export class AppComponent implements OnInit {
)
.subscribe((data: SeoData) => this._seo.setHeaders(data));
}

shouldOpenChildMenu(title: string) {
// for accessibility we need to ensure child menu is open when clicked
if (title === 'Operators') {
this._operatorMenuService.openOperatorMenu();
}
}
}
3 changes: 2 additions & 1 deletion src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FlexLayoutModule } from '@angular/flex-layout';

import { CopierService } from './services/copier.service';
import { SeoService } from './services/seo.service';
import { OperatorMenuService } from './services/operator-menu.service';
import { ToolbarComponent } from './components/toolbar/toolbar.component';
import { MaterialModule } from '../material/material.module';

Expand All @@ -17,7 +18,7 @@ export class CoreModule {
static forRoot() {
return {
ngModule: CoreModule,
providers: [CopierService, SeoService]
providers: [CopierService, SeoService, OperatorMenuService]
};
}
}
19 changes: 19 additions & 0 deletions src/app/core/services/operator-menu.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class OperatorMenuService {
private _operatorMenuStatus = new Subject<boolean>();

openOperatorMenu() {
this._operatorMenuStatus.next(true);
}

closeOperatorMenu() {
this._operatorMenuStatus.next(false);
}

menuStatus() {
return this._operatorMenuStatus.asObservable();
}
}
42 changes: 20 additions & 22 deletions src/app/operators/operators.component.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<mat-sidenav-container
class="operator-container">
<mat-sidenav
[mode]="sidenavMode"
[opened]="!smallScreen"
[fixedTopGap]="operatorMenuGap"
[fixedInViewport]="true"
class="operator-list-sidenav"
#operatorSidenav>
<mat-nav-list *ngFor="let category of categories" class="operator-list">
<h3 mat-subheader class="category-subheader">{{ category }}</h3>
<mat-sidenav-container class="operator-container">
<mat-sidenav [mode]="sidenavMode"
[opened]="!smallScreen"
[fixedTopGap]="operatorMenuGap"
[fixedInViewport]="true"
class="operator-list-sidenav"
#operatorSidenav>
<mat-nav-list *ngFor="let category of categories"
class="operator-list">
<h3 mat-subheader
class="category-subheader">{{ category }}</h3>
<a mat-list-item
*ngFor="let operator of groupedOperators[category]"
[routerLink]="['/operators', operator.name]"
routerLinkActive="active">
*ngFor="let operator of groupedOperators[category]"
[routerLink]="['/operators', operator.name]"
routerLinkActive="active">
{{ operator.name }}
</a>
</mat-nav-list>
</mat-sidenav>
<router-outlet></router-outlet>
</mat-sidenav-container>
<button
*ngIf="smallScreen"
mat-mini-fab
color="primary"
class="sidenav-toggle"
[@growInOut]="'in'"
(click)="operatorSidenav.toggle()">
<button *ngIf="smallScreen"
mat-mini-fab
color="primary"
class="sidenav-toggle"
[@growInOut]="'in'"
(click)="operatorSidenav.toggle()">
<mat-icon>view_list</mat-icon>
</button>

25 changes: 23 additions & 2 deletions src/app/operators/operators.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
Inject,
InjectionToken,
OnInit,
ChangeDetectionStrategy
OnDestroy,
AfterContentInit,
ChangeDetectionStrategy,
ViewChild
} from '@angular/core';
import {
trigger,
Expand All @@ -14,9 +17,13 @@ import {
} from '@angular/animations';
import { Router, ActivatedRoute } from '@angular/router';
import { BreakpointObserver } from '@angular/cdk/layout';
import { MatSidenav } from '@angular/material';
import { Subscription } from 'rxjs/Subscription';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { filter, takeUntil } from 'rxjs/operators';
import { OperatorDoc } from '../../operator-docs/operator.model';
import { OperatorMenuService } from '../core/services/operator-menu.service';

const OPERATOR_MENU_GAP_LARGE = 64;
const OPERATOR_MENU_GAP_SMALL = 54;
Expand Down Expand Up @@ -53,12 +60,15 @@ interface OperatorDocMap {
])
]
})
export class OperatorsComponent implements OnInit {
export class OperatorsComponent implements OnInit, AfterContentInit, OnDestroy {
@ViewChild(MatSidenav) _sidenav: MatSidenav;
public groupedOperators: OperatorDocMap;
public categories: string[];
private _onDestroy = new Subject();

constructor(
private _breakpointObserver: BreakpointObserver,
private _operatorMenuService: OperatorMenuService,
@Inject(OPERATORS_TOKEN) public operators: OperatorDoc[]
) {}

Expand All @@ -67,6 +77,13 @@ export class OperatorsComponent implements OnInit {
this.categories = Object.keys(this.groupedOperators);
}

ngAfterContentInit() {
this._operatorMenuService
.menuStatus()
.pipe(filter(s => !!s), takeUntil(this._onDestroy))
.subscribe(_ => this._sidenav.open());
}

get extraSmallScreen() {
return this._breakpointObserver.isMatched('(max-width: 601px)');
}
Expand All @@ -84,6 +101,10 @@ export class OperatorsComponent implements OnInit {
get sidenavMode() {
return this.smallScreen ? 'over' : 'side';
}

ngOnDestroy() {
this._onDestroy.next();
}
}

export function groupOperatorsByType(operators: OperatorDoc[]): OperatorDocMap {
Expand Down
2 changes: 2 additions & 0 deletions src/app/operators/specs/operators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
groupOperatorsByType
} from '../operators.component';
import { OperatorDoc } from '../../../operator-docs';
import { OperatorMenuService } from '../../core/services/operator-menu.service';

const mockActivatedRoute = {
snapshot: {},
Expand Down Expand Up @@ -41,6 +42,7 @@ describe('Operators', () => {
imports: [RouterTestingModule, LayoutModule],
declarations: [OperatorsComponent],
providers: [
OperatorMenuService,
{ provide: OPERATORS_TOKEN, useValue: mockOperators },
{ provide: ActivatedRoute, useValue: mockActivatedRoute }
],
Expand Down