Skip to content

Commit 49d3588

Browse files
committed
- added a new goToStep directive that let's you navigate to a given step either by its index or by the step object itself
- changed the click listener in the wizard navigation bar to the new goToStep directive - modified the tests to work with the new directive and its corresponding changes
1 parent 68b04d2 commit 49d3588

File tree

8 files changed

+48
-10
lines changed

8 files changed

+48
-10
lines changed

src/components/components/wizard-navigation-bar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
editing: step.selected && step.completed,
88
optional: step.optional && !step.completed && !step.selected
99
}">
10-
<a (click)="goToStep(step)">{{step.title}}</a>
10+
<a [goToStep]="step">{{step.title}}</a>
1111
</li>
1212
</ul>

src/components/components/wizard-navigation-bar.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {DebugElement, QueryList} from '@angular/core';
66
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
77
import {WizardComponent} from "./wizard.component";
88
import {WizardStepComponent} from "./wizard-step.component";
9+
import {GoToStepDirective} from "../directives/go-to-step.directive";
910

1011
describe('WizardNavigationBarComponent', () => {
1112
let component: WizardNavigationBarComponent;
@@ -17,7 +18,7 @@ describe('WizardNavigationBarComponent', () => {
1718
wizard.wizardSteps = new QueryList<WizardStepComponent>();
1819

1920
TestBed.configureTestingModule({
20-
declarations: [WizardNavigationBarComponent, WizardComponent, WizardStepComponent],
21+
declarations: [WizardNavigationBarComponent, WizardComponent, WizardStepComponent, GoToStepDirective],
2122
providers: [{ provide: WizardComponent, useValue: wizard }]
2223
})
2324
.compileComponents();

src/components/components/wizard-navigation-bar.component.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,4 @@ export class WizardNavigationBarComponent {
1818
numberOfWizardSteps(): number {
1919
return this.wizard.wizardSteps.length;
2020
}
21-
22-
goToStep(nextStep: WizardStepComponent): void {
23-
if (this.wizard.canGoToStep(nextStep)) {
24-
// If the next step is enterable, then enter it
25-
this.wizard.goToStep(nextStep);
26-
}
27-
}
2821
}

src/components/components/wizard.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {QueryList, Component, ViewChild} from "@angular/core";
44
import {WizardComponent} from "./wizard.component";
55
import {WizardStepComponent} from "./wizard-step.component";
66
import {WizardNavigationBarComponent} from "./wizard-navigation-bar.component";
7+
import {GoToStepDirective} from "../directives/go-to-step.directive";
78

89
@Component({
910
selector: "test-wizard",
@@ -44,7 +45,7 @@ describe('WizardComponent', () => {
4445

4546
beforeEach(async(() => {
4647
TestBed.configureTestingModule({
47-
declarations: [ WizardComponent, WizardStepComponent, WizardNavigationBarComponent, WizardTestComponent ]
48+
declarations: [ WizardComponent, WizardStepComponent, WizardNavigationBarComponent, WizardTestComponent, GoToStepDirective ]
4849
})
4950
.compileComponents();
5051
}));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Created by marc on 09.01.17.
3+
*/
4+
import {GoToStepDirective} from "./go-to-step.directive";
5+
6+
describe('GoToStepDirective', () => {
7+
it('should create an instance', () => {
8+
let directive = new GoToStepDirective(null);
9+
expect(directive).toBeTruthy();
10+
});
11+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Created by marc on 09.01.17.
3+
*/
4+
5+
import {Directive, Output, HostListener, EventEmitter, Input} from '@angular/core';
6+
import {WizardComponent} from "../components/wizard.component";
7+
import {WizardStepComponent} from "../components/wizard-step.component";
8+
9+
@Directive({
10+
selector: '[goToStep]'
11+
})
12+
export class GoToStepDirective {
13+
@Output()
14+
public finalize = new EventEmitter();
15+
16+
@Input('goToStep')
17+
public destinationStep: WizardStepComponent | number;
18+
19+
constructor(private wizard: WizardComponent) { }
20+
21+
@HostListener('click', ['$event']) onClick(): void {
22+
if (this.wizard.canGoToStep(this.destinationStep)) {
23+
this.finalize.emit();
24+
25+
this.wizard.goToStep(this.destinationStep);
26+
}
27+
}
28+
}

src/components/directives/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Created by marc on 29.12.16.
33
*/
44

5+
export {GoToStepDirective} from "./go-to-step.directive";
56
export {NextStepDirective} from './next-step.directive';
67
export {PreviousStepDirective} from './previous-step.directive';
78
export {OptionalStepDirective} from './optional-step.directive';

src/components/wizard.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {NextStepDirective} from './directives/next-step.directive';
77
import {PreviousStepDirective} from './directives/previous-step.directive';
88
import {OptionalStepDirective} from './directives/optional-step.directive';
99
import {WizardNavigationBarComponent} from './components/wizard-navigation-bar.component';
10+
import {GoToStepDirective} from "./directives/go-to-step.directive";
1011

1112

1213
@NgModule({
1314
declarations: [
1415
WizardComponent,
1516
WizardStepComponent,
1617
WizardNavigationBarComponent,
18+
GoToStepDirective,
1719
NextStepDirective,
1820
PreviousStepDirective,
1921
OptionalStepDirective,
@@ -25,6 +27,7 @@ import {WizardNavigationBarComponent} from './components/wizard-navigation-bar.c
2527
WizardComponent,
2628
WizardStepComponent,
2729
WizardNavigationBarComponent,
30+
GoToStepDirective,
2831
NextStepDirective,
2932
PreviousStepDirective,
3033
OptionalStepDirective,

0 commit comments

Comments
 (0)