Skip to content

Commit

Permalink
fix: set tab index value (#22)
Browse files Browse the repository at this point in the history
Sets the correct tab index from the selected cron type. This allows the correct tab to be opened on initialization.
  • Loading branch information
Dioltas95 authored Dec 11, 2023
1 parent 355c5cf commit 80c613e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions libs/ngx-cron-editor/src/cron-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function* range(start: number, end: number) {
providers: [CRON_VALUE_ACCESSOR]
})
export class CronGenComponent implements OnInit, OnDestroy, ControlValueAccessor {

public tabIndex = 0;
public seconds = [...range(0, 59)];
public minutes = [...range(0, 59)];
public hours = [...range(0, 23)];
Expand Down Expand Up @@ -214,21 +214,27 @@ export class CronGenComponent implements OnInit, OnDestroy, ControlValueAccessor
break;
case 'hourly':
cron = this.computeHourlyCron();
this.tabIndex = 1;
break;
case 'daily':
cron = this.computeDailyCron();
this.tabIndex = 2;
break;
case 'weekly':
cron = this.computeWeeklyCron();
this.tabIndex = 3;
break;
case 'monthly':
cron = this.computeMonthlyCron();
this.tabIndex = 4;
break;
case 'yearly':
cron = this.computeYearlyCron();
this.tabIndex = 5;
break;
case 'unknown':
cron = this.computeAdvancedExpression();
this.tabIndex = 6;
break;
default:
throw Error('Unknown cron type ' + this.allForm.value.cronType);
Expand Down Expand Up @@ -395,7 +401,7 @@ export class CronGenComponent implements OnInit, OnDestroy, ControlValueAccessor
// Month
x = parseCronNumberToken(t[4])
this.allForm.controls.months.setValue(x.val, {emitEvent: false});
this.allForm.controls.monthsInc.setValue(x.inc, {emitEvent: false});
this.allForm.controls.monthsInc.setValue(x.inc, { emitEvent: false });

// Day of Week
this.allForm.controls.day.setValue(t[5]);
Expand Down Expand Up @@ -429,7 +435,7 @@ export class CronGenComponent implements OnInit, OnDestroy, ControlValueAccessor
this.allForm.controls.FRI.setValue(false, {emitEvent: false});
}

if (t[5].match('SAT')) {
if (t[5].match('SAT')) {
this.allForm.controls.SAT.setValue(true, {emitEvent: false});
} else {
this.allForm.controls.SAT.setValue(false, {emitEvent: false});
Expand Down
2 changes: 1 addition & 1 deletion libs/ngx-cron-editor/src/cron-editor.template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<section class="cron-editor-main">
<mat-tab-group class="cron-editor-container" (selectedTabChange)="onTabChange($event)" [backgroundColor]="backgroundColor" [color]="color">
<mat-tab-group class="cron-editor-container" (selectedTabChange)="onTabChange($event)" [backgroundColor]="backgroundColor" [color]="color" [(selectedIndex)]="tabIndex">

<!-- Minute -->
<mat-tab [formGroup]="allForm" class="cron-editor-tab" label="Minutely" *ngIf="!options.hideMinutesTab" #minutesTab>
Expand Down

0 comments on commit 80c613e

Please sign in to comment.