Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/current-tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export class ActivatedTutorial {
public tutorial: Subject<TutorialDefinition>;
public step: Subject<TutorialStep>;
public steps: Subject<TutorialStep[]>;
public branch: Subject<string>;

constructor() {
this.step = new Subject<TutorialStep>();
this.tutorial = new Subject<TutorialDefinition>();
this.steps = new Subject<TutorialStep[]>();
this.branch = new Subject<string>();
}

updateCurrentTutorial(tutorial: TutorialDefinition) {
Expand All @@ -23,4 +25,8 @@ export class ActivatedTutorial {
updateCurrentSteps(steps: TutorialStep[]) {
this.steps.next(steps);
}

updateCurrentBranch(branch: string) {
this.branch.next(branch);
}
}
2 changes: 1 addition & 1 deletion src/tutorial-code-diff.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class CodeDiffLink {
}

let compareEnd = 'step' + (index + 1);
let url = 'https://github.com/' + tutorial.gitHub + '/compare/' + compareStart + '...' + compareEnd;
let url = `https://github.com/${tutorial.gitHub}/compare/${compareStart}...${compareEnd}`;

renderer.setElementAttribute(el.nativeElement, 'href', url);
}
Expand Down
31 changes: 31 additions & 0 deletions src/tutorial-history.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Injectable, Directive, ElementRef, Renderer} from '@angular/core';
import {ActivatedTutorial} from './current-tutorial';
import {TutorialDefinition} from './tutorial-definition';
import {Observable} from 'rxjs';

@Directive({
selector: '[historyLink]'
})
@Injectable()
export class HistoryLink {
constructor(private activated: ActivatedTutorial, el: ElementRef, renderer: Renderer) {
Observable.zip(activated.tutorial, activated.branch, (tutorial, branch) => {
return {
tutorial,
branch
};
}).subscribe((data) => {
let tutorial: TutorialDefinition = data.tutorial;
let branch: string = data.branch;

let url = `https://github.com/${tutorial.gitHub}/tree/${branch}-history`;

renderer.setElementAttribute(el.nativeElement, 'href', url);
});
}

pad(n, width, z = '0') {
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
}
3 changes: 3 additions & 0 deletions src/tutorial-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class TutorialPage implements OnInit {
private tutorial: TutorialDefinition;
private step: TutorialStep;
private steps: TutorialStep[];
private branch: string;

constructor(private route: ActivatedRoute,
private compiler: Compiler,
Expand All @@ -37,9 +38,11 @@ export class TutorialPage implements OnInit {
this.tutorial = <TutorialDefinition>routeData.tutorialObject;
this.step = <TutorialStep>routeData.stepObject;
this.steps = <TutorialStep[]>routeData.steps;
this.branch = <string>routeData.gitTagRevision;
this.currentTutorial.updateCurrentTutorial(this.tutorial);
this.currentTutorial.updateCurrentStep(this.step);
this.currentTutorial.updateCurrentSteps(this.steps);
this.currentTutorial.updateCurrentBranch(this.branch);
let htmlContent = data.resolveData.step;

this.seo.setSeoDescription(htmlContent);
Expand Down
2 changes: 2 additions & 0 deletions src/tutorials-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {ApiLoadResolve} from './api-load-resolve';
import {ActivatedApi} from './current-api';
import {StepListComponent} from './steps-list.component';
import {CodeDiffLink} from './tutorial-code-diff.directive';
import {HistoryLink} from './tutorial-history.directive';
import {StepDownloadZipLink} from './tutorial-download-zip.directive';
import {PageTitleService} from './page-title.service';

Expand All @@ -34,6 +35,7 @@ const exportsAndDeclarations = [
ApiVersionsList,
ApiListItems,
CodeDiffLink,
HistoryLink,
StepDownloadZipLink
];

Expand Down