-
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
Open
sunilj74
wants to merge
24
commits into
master
Choose a base branch
from
lesson_1024
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6b8794c
enabled arrow icons to jump to previous and next lessons
sunilj74 7798eb3
Merge branch 'master' into lesson_1024
sunilj74 d3758f2
Enabled next and previous buttons to navigate to different lessons on…
sunilj74 0667163
Merge branch 'lesson_1024' of https://github.com/codelab-fun/codelab …
sunilj74 e3be024
made presentation slide optional in constructor in title and closing …
sunilj74 bfc44b7
added tests to title and closing slides
sunilj74 89831ea
dropped calls to setPrevious from closing slide and calls to setNext …
sunilj74 e84f72b
merged with master
sunilj74 caeb0bc
fixed linting errors
sunilj74 60f6141
Changed to createSpy in tests. Also changed some method names to more…
sunilj74 5fe9484
Merge branch 'master' into lesson_1024
sunilj74 52958ef
removed complicated code from title and closing slides
sunilj74 feb7744
moved previous and next link features to a service
sunilj74 ef0f7d5
added commit logs
sunilj74 e91ae03
Merge branch 'master' into lesson_1024
sunilj74 d9ad958
Merge branch 'master' into lesson_1024
NothingEverHappens f524ec9
changed menu-route service to receive ActivatedRoute while getting ne…
sunilj74 28ddb49
Merge branch 'master' into lesson_1024
sunilj74 4126829
Merge branch 'lesson_1024' of https://github.com/codelab-fun/codelab …
sunilj74 65c6403
fixed tests for menu-route.service.ts
sunilj74 f5acd63
added more details to TODO action. moved redundant code into functions
sunilj74 c9c3956
Merge branch 'master' into lesson_1024
sunilj74 5bde57b
switched variables to direct returns. also removed an unecessary if c…
sunilj74 154b746
removed a wrong TODO
sunilj74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
apps/codelab/src/app/codelabs/angular/menu-route.service.spec.ts
This file contains hidden or 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,55 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { MenuRouteService } from './menu-route.service'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { MENU_ROUTES, MenuRoutes } from '../../common'; | ||
|
||
describe('MenuRouteService', () => { | ||
const menuRoutes: MenuRoutes = [ | ||
{ | ||
path: 'previouslesson', | ||
prod: true | ||
}, | ||
{ | ||
path: 'currentlesson', | ||
prod: true | ||
}, | ||
{ | ||
path: 'nextlesson', | ||
prod: true | ||
} | ||
]; | ||
|
||
const activatedRouteStub = { | ||
snapshot: { | ||
pathFromRoot: [ | ||
{ | ||
routeConfig: menuRoutes[1] | ||
} | ||
] | ||
} | ||
} as ActivatedRoute; | ||
|
||
beforeEach(() => | ||
TestBed.configureTestingModule({ | ||
providers: [{ provide: MENU_ROUTES, useValue: menuRoutes }] | ||
}) | ||
); | ||
|
||
it('should be created', () => { | ||
const service: MenuRouteService = TestBed.inject(MenuRouteService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('getPreviousLink should return previouslesson', () => { | ||
const service: MenuRouteService = TestBed.inject(MenuRouteService); | ||
const previousLink = service.getPreviousLink(activatedRouteStub); | ||
expect(previousLink).toEqual('../../' + menuRoutes[0].path); | ||
}); | ||
|
||
it('getNextLink should return nextlesson', () => { | ||
const service: MenuRouteService = TestBed.inject(MenuRouteService); | ||
const nextLink = service.getNextLink(activatedRouteStub); | ||
expect(nextLink).toEqual('../../' + menuRoutes[2].path); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
apps/codelab/src/app/codelabs/angular/menu-route.service.ts
This file contains hidden or 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,59 @@ | ||
import { Injectable, Inject } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { MENU_ROUTES, MenuRoute } from '../../common'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class MenuRouteService { | ||
constructor(@Inject(MENU_ROUTES) private readonly menuRoutes) {} | ||
|
||
getPreviousLink(activeRoute: ActivatedRoute): string { | ||
const index = this.getCurrentIndex(activeRoute); | ||
if (index > 0) { | ||
return this.getMenuRoutePathByIndex(index - 1); | ||
} | ||
return ''; | ||
} | ||
|
||
getNextLink(activeRoute: ActivatedRoute): string { | ||
const index = this.getCurrentIndex(activeRoute); | ||
if (index < this.menuRoutes.length - 1) { | ||
NothingEverHappens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this.getMenuRoutePathByIndex(index + 1); | ||
} | ||
return ''; | ||
} | ||
|
||
private getCurrentIndex(activeRoute: ActivatedRoute): number { | ||
// TODO: figure out a way to inject the ActivatedRoute instead of parameter | ||
// This method gets the index of the current menuRoute. Ideally we should be able | ||
// to inject in the ActivatedRoute in the constructor. However we noticed that | ||
// probably because this is a service, activatedRoute has the value when the | ||
// service is constructed and not the current activated route. We are using a | ||
// workaround now which expects the calling method to pass the current activated | ||
// route. Fix this to use DI. | ||
const config = activeRoute.snapshot.pathFromRoot | ||
.map(a => a.routeConfig) | ||
.find(r => r && (r as MenuRoute).prod); | ||
if (config == null) { | ||
return -1; | ||
} | ||
return this.menuRoutes.findIndex(c => c.path === config.path); | ||
} | ||
|
||
private getMenuRouteByIndex(index: number) { | ||
return this.menuRoutes[index]; | ||
} | ||
|
||
private getMenuRoutePathByIndex(index: number): string { | ||
const indexRoute = this.getMenuRouteByIndex(index); | ||
if (indexRoute != null) { | ||
let path = indexRoute.path; | ||
if (path) { | ||
path = '../../' + path; | ||
} | ||
return path; | ||
} | ||
return ''; | ||
} | ||
} |
This file contains hidden or 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
39 changes: 38 additions & 1 deletion
39
apps/codelab/src/app/components/slides/closing-slide/codelab-closing-slide.component.spec.ts
This file contains hidden or 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
18 changes: 14 additions & 4 deletions
18
apps/codelab/src/app/components/slides/closing-slide/codelab-closing-slide.component.ts
This file contains hidden or 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,16 +1,26 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { SlidesDeckComponent } from '@codelab/slides/src/lib/deck/deck.component'; | ||
import { MenuRouteService } from '../../../codelabs/angular/menu-route.service'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'codelab-closing-slide', | ||
templateUrl: './codelab-closing-slide.component.html', | ||
styleUrls: ['./codelab-closing-slide.component.css'] | ||
}) | ||
export class CodelabClosingSlideComponent implements OnInit { | ||
export class CodelabClosingSlideComponent { | ||
@Input() header: String; | ||
@Input() body: String; | ||
@Input() footer: String; | ||
|
||
constructor() {} | ||
|
||
ngOnInit() {} | ||
constructor( | ||
private readonly activeRoute: ActivatedRoute, | ||
private readonly menuRouteService: MenuRouteService, | ||
private readonly presentation: SlidesDeckComponent | ||
) { | ||
if (this.presentation != null) { | ||
const nextLink = this.menuRouteService.getNextLink(this.activeRoute); | ||
this.presentation.setNext(nextLink); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop empty ngOnInit while you're here? |
||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.