-
Notifications
You must be signed in to change notification settings - Fork 63
enabled arrow icons to jump to previous and next lessons #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
6b8794c
7798eb3
d3758f2
0667163
e3be024
bfc44b7
89831ea
e84f72b
caeb0bc
60f6141
5fe9484
52958ef
feb7744
ef0f7d5
e91ae03
d9ad958
f524ec9
28ddb49
4126829
65c6403
f5acd63
c9c3956
5bde57b
154b746
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import { Component, Input, OnInit } from '@angular/core'; | ||
| import { Component, Input, OnInit, Inject, Optional } from '@angular/core'; | ||
| import { SlidesDeckComponent } from '@codelab/slides/src/lib/deck/deck.component'; | ||
| import { MENU_ROUTES } from '../../../common'; | ||
| import { Router } from '@angular/router'; | ||
|
|
||
| @Component({ | ||
| selector: 'codelab-closing-slide', | ||
|
|
@@ -10,7 +13,37 @@ export class CodelabClosingSlideComponent implements OnInit { | |
| @Input() body: String; | ||
| @Input() footer: String; | ||
|
|
||
| constructor() {} | ||
| constructor( | ||
| private readonly router: Router, | ||
| private readonly presentation: SlidesDeckComponent, | ||
| @Optional() @Inject(MENU_ROUTES) readonly menuRoutes | ||
| ) { | ||
| if (this.presentation != null && this.menuRoutes != null) { | ||
| this.setupPreviousNext(); | ||
| } | ||
| } | ||
|
|
||
| private setupPreviousNext() { | ||
|
||
| let previousLink = ''; | ||
| let nextLink = ''; | ||
| let allRoutes = this.menuRoutes.map(p => p.path); | ||
| let currentUrl = this.router.url; | ||
| if (currentUrl.startsWith('/')) { | ||
| currentUrl = currentUrl.substr(1); | ||
| } | ||
|
||
| const urlPaths = currentUrl.split('/'); | ||
| if (urlPaths.length > 1) { | ||
| const idx = allRoutes.indexOf(urlPaths[1]); | ||
| if (idx > 0) { | ||
| previousLink = `/${urlPaths[0]}/${allRoutes[idx - 1]}`; | ||
| } | ||
| if (idx < allRoutes.length - 1) { | ||
| nextLink = `/${urlPaths[0]}/${allRoutes[idx + 1]}`; | ||
| } | ||
| } | ||
| this.presentation.setPrevious(previousLink); | ||
sunilj74 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.presentation.setNext(nextLink); | ||
| } | ||
|
|
||
| ngOnInit() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,53 @@ | ||
| import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { RouterTestingModule } from '@angular/router/testing'; | ||
| import { By } from '@angular/platform-browser'; | ||
|
|
||
| import { TitleSlideComponent } from './title-slide.component'; | ||
| import { CodelabRippleAnimationComponent } from './ripple-animation/codelab-ripple-animation.component'; | ||
| import { MenuRoutes, MENU_ROUTES } from '../../../common'; | ||
| import { Router } from '@angular/router'; | ||
| import { SlidesDeckComponent } from '@codelab/slides/src/lib/deck/deck.component'; | ||
|
|
||
| describe('TitleSlideComponent', () => { | ||
| let component: TitleSlideComponent; | ||
| let fixture: ComponentFixture<TitleSlideComponent>; | ||
| const routerStub = { | ||
| url: '/ngtest/currentlesson' | ||
| }; | ||
|
|
||
| const slidesDeckComponentStub = { | ||
| previousLink: '', | ||
| nextLink: '', | ||
|
|
||
| setPrevious(link) { | ||
|
||
| this.previousLink = link; | ||
|
||
| }, | ||
|
|
||
| setNext(link) { | ||
| this.nextLink = link; | ||
| } | ||
| }; | ||
|
|
||
| const menuRoutes: MenuRoutes = [ | ||
| { | ||
| path: 'previouslesson' | ||
| }, | ||
| { | ||
| path: 'currentlesson' | ||
| }, | ||
| { | ||
| path: 'nextlesson' | ||
| } | ||
| ]; | ||
|
|
||
| beforeEach(async(() => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| { provide: Router, useValue: routerStub }, | ||
| { provide: SlidesDeckComponent, useFactory: () => { return slidesDeckComponentStub; } }, | ||
| { provide: MENU_ROUTES, useValue: menuRoutes } | ||
| ], | ||
| imports: [RouterTestingModule], | ||
| declarations: [CodelabRippleAnimationComponent, TitleSlideComponent] | ||
| }).compileComponents(); | ||
| })); | ||
|
|
@@ -24,6 +62,14 @@ describe('TitleSlideComponent', () => { | |
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should set previousLink', () => { | ||
| expect(slidesDeckComponentStub.previousLink).not.toBe(''); | ||
| }); | ||
|
|
||
| it('should set nextLink', () => { | ||
| expect(slidesDeckComponentStub.nextLink).not.toBe(''); | ||
| }); | ||
|
|
||
| it('should render a title', () => { | ||
| component.title = 'awesome title'; | ||
| fixture.detectChanges(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import { Component, Input } from '@angular/core'; | ||
| import { Component, Input, Optional, Inject } from '@angular/core'; | ||
| import { SlidesDeckComponent } from '@codelab/slides/src/lib/deck/deck.component'; | ||
| import { MENU_ROUTES } from '../../../common'; | ||
| import { Router } from '@angular/router'; | ||
|
|
||
| @Component({ | ||
| selector: 'codelab-title-slide', | ||
|
|
@@ -9,4 +12,36 @@ export class TitleSlideComponent { | |
| @Input() title: string; | ||
| @Input() description: string; | ||
| @Input() prereqs: string; | ||
|
|
||
| constructor( | ||
| private readonly router: Router, | ||
| private readonly presentation: SlidesDeckComponent, | ||
| @Optional() @Inject(MENU_ROUTES) readonly menuRoutes | ||
| ) { | ||
| if (this.presentation != null) { | ||
sunilj74 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.setupPreviousNext(); | ||
| } | ||
| } | ||
|
|
||
| private setupPreviousNext() { | ||
sunilj74 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let previousLink = ''; | ||
| let nextLink = ''; | ||
| let allRoutes = this.menuRoutes.map(p => p.path); | ||
| let currentUrl = this.router.url; | ||
| if (currentUrl.startsWith('/')) { | ||
| currentUrl = currentUrl.substr(1); | ||
| } | ||
| const urlPaths = currentUrl.split('/'); | ||
| if (urlPaths.length > 1) { | ||
| const idx = allRoutes.indexOf(urlPaths[1]); | ||
| if (idx > 0) { | ||
| previousLink = `/${urlPaths[0]}/${allRoutes[idx - 1]}`; | ||
| } | ||
| if (idx < allRoutes.length - 1) { | ||
| nextLink = `/${urlPaths[0]}/${allRoutes[idx + 1]}`; | ||
| } | ||
|
||
| } | ||
| this.presentation.setPrevious(previousLink); | ||
| this.presentation.setNext(nextLink); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ import { | |
| TemplateRef | ||
| } from '@angular/core'; | ||
|
|
||
| import { ActivatedRoute } from '@angular/router'; | ||
| import { ActivatedRoute, Router } from '@angular/router'; | ||
|
|
||
| @Component({ | ||
| selector: 'slide-deck', | ||
|
|
@@ -27,10 +27,13 @@ export class SlidesDeckComponent { | |
| @Output() slideAdded = new EventEmitter<{ index: number; id: string }>(); | ||
| @HostBinding('class.has-milestone') hasMilestone = false; | ||
| private milestone = ''; | ||
| private previousLink: string; | ||
| private nextLink: string; | ||
|
|
||
| constructor( | ||
| private readonly cdr: ChangeDetectorRef, | ||
| @Optional() private readonly route: ActivatedRoute | ||
| private readonly router: Router, | ||
| @Optional() private readonly route: ActivatedRoute | ||
|
||
| ) { | ||
| if (route) { | ||
| this.milestone = route.snapshot.queryParams.milestone; | ||
|
|
@@ -51,18 +54,40 @@ export class SlidesDeckComponent { | |
| } | ||
|
|
||
| nextSlide() { | ||
| this.goToSlide(this.activeSlideIndex + 1); | ||
| if (this.activeSlideIndex + 1 < this.slides.length) { | ||
| this.goToSlide(this.activeSlideIndex + 1); | ||
| } else if (this.nextLink) { | ||
| this.router.navigateByUrl(this.nextLink); | ||
| } | ||
| } | ||
|
|
||
| previousSlide() { | ||
| this.goToSlide(this.activeSlideIndex - 1); | ||
| if (this.activeSlideIndex > 0) { | ||
| this.goToSlide(this.activeSlideIndex - 1); | ||
| } else if (this.previousLink) { | ||
| this.router.navigateByUrl(this.previousLink); | ||
| } | ||
| } | ||
|
|
||
| canGoNext(): boolean { | ||
| return this.activeSlideIndex + 1 < this.slides.length; | ||
| return ( | ||
| this.activeSlideIndex + 1 < this.slides.length || | ||
| (this.nextLink != null && this.nextLink !== '') | ||
| ); | ||
| } | ||
|
|
||
| canGoPrevious(): boolean { | ||
| return this.activeSlideIndex > 0; | ||
| return ( | ||
| this.activeSlideIndex > 0 || | ||
| (this.previousLink != null && this.previousLink !== '') | ||
sunilj74 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| public setPrevious(previousLink) { | ||
| this.previousLink = previousLink; | ||
| } | ||
|
|
||
| public setNext(nextLink) { | ||
| this.nextLink = nextLink; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.