-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtutorial-history.directive.ts
More file actions
31 lines (27 loc) · 950 Bytes
/
tutorial-history.directive.ts
File metadata and controls
31 lines (27 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}
}