@ -12,6 +12,7 @@ import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component' ;
import { UntypedFormControl , UntypedFormGroup , Validators } from '@angular/forms' ;
import { MatStepper } from '@angular/material/stepper' ;
import { StepperSelectionEvent } from '@angular/cdk/stepper' ;
import { firstValueFrom } from 'rxjs' ;
import { TranslateService } from '@ngx-translate/core' ;
import { PageLink } from '@shared/models/page/page-link' ;
@ -261,10 +262,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
connectivityStep . completed = true ;
this . cdr . detectChanges ( ) ;
// Wait for new mat-step children to register before advancing.
setTimeout ( ( ) = > {
this . stepper ? . next ( ) ;
this . onStepActivated ( ) ;
} , 0 ) ;
setTimeout ( ( ) = > this . stepper ? . next ( ) , 0 ) ;
return ;
}
this . startWizard ( ) ;
@ -315,12 +313,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
if ( ! step ) {
return ;
}
if ( step . type === 'form' ) {
if ( step . formGroup ? . invalid ) {
step . formGroup . markAllAsTouched ( ) ;
return ;
}
Object . assign ( this . formValues , step . formGroup . getRawValue ( ) ) ;
if ( step . type === 'form' && step . formGroup ? . invalid ) {
step . formGroup . markAllAsTouched ( ) ;
return ;
}
if ( this . isLastWizardStep ) {
this . done ( ) ;
@ -329,7 +324,22 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
step . completed = true ;
this . cdr . detectChanges ( ) ;
this . stepper . next ( ) ;
this . onStepActivated ( ) ;
}
onStepSelectionChange ( event : StepperSelectionEvent ) : void {
if ( event . selectedIndex <= event . previouslySelectedIndex ) {
return ;
}
// Forward moves can come from the stepper header, which bypasses nextStep(),
// so commit every step being passed over here.
for ( let i = event . previouslySelectedIndex ; i < event . selectedIndex ; i ++ ) {
const ws = this . wizardSteps [ i ] ;
if ( ws . type === 'form' ) {
Object . assign ( this . formValues , ws . formGroup . getRawValue ( ) ) ;
}
ws . completed = true ;
}
this . onStepActivated ( this . wizardSteps [ event . selectedIndex ] ) ;
}
get primaryEntityAction ( ) : { url : string ; label : string } | null {
@ -704,13 +714,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
return field . defaultValue ? ? ( field . type === FormFieldType . BOOLEAN ? false : '' ) ;
}
private onStepActivated ( ) : void {
const step = this . currentWizardStep ;
private onStepActivated ( step = this . currentWizardStep ) : void {
if ( ! step ) {
return ;
}
if ( step . type === 'instruction' ) {
step . markdown = this . zipFiles . get ( step . rawSteps [ 0 ] . file ) || '' ;
// Nothing to validate here, so the linear stepper header may move past it right away.
step . completed = true ;
} else if ( step . type === 'progress' && ! step . progressDone ) {
if ( this . reviewMode ) {
this . showCompletedEntitySteps ( step ) ;
@ -826,7 +837,6 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
await this . delay ( 500 ) ;
this . stepper . next ( ) ;
this . cdr . detectChanges ( ) ;
this . onStepActivated ( ) ;
}
}