Skip to content

Commit ea69790

Browse files
authored
fix(module:cron-expression): exception error & cancel format prompt copy (#8114)
1 parent 5ec22fc commit ea69790

File tree

11 files changed

+71
-115
lines changed

11 files changed

+71
-115
lines changed

components/cron-expression/cron-expression-label.component.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,27 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { Component, ViewEncapsulation, ChangeDetectionStrategy, Input, OnInit } from '@angular/core';
6+
import { Component, ViewEncapsulation, ChangeDetectionStrategy, Input } from '@angular/core';
77

88
import { NzCronExpressionLabelI18n } from 'ng-zorro-antd/i18n';
99

10-
import { TimeType, TimeTypeError } from './typings';
10+
import { TimeType } from './typings';
1111

1212
@Component({
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
encapsulation: ViewEncapsulation.None,
1515
selector: 'nz-cron-expression-label',
1616
exportAs: 'nzCronExpressionLabel',
1717
template: `
18-
<div
19-
class="ant-cron-expression-label"
20-
[class.ant-cron-expression-label-foucs]="labelFocus === type"
21-
[class.ant-cron-expression-error]="!valid"
22-
>
23-
<label nz-tooltip [nzTooltipTitle]="error" [nzTooltipVisible]="!valid" nzTooltipPlacement="bottom">
18+
<div class="ant-cron-expression-label" [class.ant-cron-expression-label-foucs]="labelFocus === type">
19+
<label>
2420
{{ locale[type] }}
2521
</label>
2622
</div>
27-
<ng-template #error>
28-
<div class="ant-cron-expression-hint" [innerHTML]="locale[labelError]"></div>
29-
</ng-template>
3023
`
3124
})
32-
export class NzCronExpressionLabelComponent implements OnInit {
25+
export class NzCronExpressionLabelComponent {
3326
@Input() type: TimeType = 'second';
34-
@Input() valid: boolean = true;
3527
@Input() locale!: NzCronExpressionLabelI18n;
3628
@Input() labelFocus: string | null = null;
37-
labelError: TimeTypeError = 'secondError';
38-
39-
constructor() {}
40-
41-
ngOnInit(): void {
42-
this.labelError = `${this.type}Error`;
43-
}
4429
}

components/cron-expression/cron-expression-preview.component.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,18 @@ import { NzCronExpressionCronErrorI18n } from 'ng-zorro-antd/i18n';
3232
</ng-container>
3333
<ng-template #cronError>{{ locale.cronError }}</ng-template>
3434
</div>
35-
<div *ngIf="visible" class="ant-cron-expression-preview-content">
36-
<div class="ant-cron-expression-preview-content-date">
37-
<ng-container *ngIf="!isExpand">
38-
<ul class="ant-cron-expression-preview-list">
39-
<li *ngFor="let item of TimeList">
40-
{{ item | date: 'YYYY-MM-dd HH:mm:ss' }}
41-
</li>
42-
<li><a (click)="loadMorePreview.emit()">···</a></li>
43-
</ul>
44-
</ng-container>
45-
</div>
46-
<ul class="ant-cron-expression-preview-icon">
47-
<li *ngIf="isExpand"><span nz-icon nzType="down" nzTheme="outline" (click)="setExpand()"></span></li>
48-
<li *ngIf="!isExpand"><span nz-icon nzType="up" nzTheme="outline" (click)="setExpand()"></span></li>
35+
<div *ngIf="visible && !isExpand" class="ant-cron-expression-preview-content">
36+
<ul class="ant-cron-expression-preview-list">
37+
<li *ngFor="let item of TimeList">
38+
{{ item | date: 'YYYY-MM-dd HH:mm:ss' }}
39+
</li>
40+
<li><a (click)="loadMorePreview.emit()">···</a></li>
4941
</ul>
5042
</div>
43+
<ul class="ant-cron-expression-preview-icon">
44+
<li *ngIf="isExpand"><span nz-icon nzType="down" nzTheme="outline" (click)="setExpand()"></span></li>
45+
<li *ngIf="!isExpand"><span nz-icon nzType="up" nzTheme="outline" (click)="setExpand()"></span></li>
46+
</ul>
5147
</div>`
5248
})
5349
export class NzCronExpressionPreviewComponent {

components/cron-expression/cron-expression.component.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import {
1919
import {
2020
AbstractControl,
2121
AsyncValidator,
22-
AsyncValidatorFn,
2322
ControlValueAccessor,
2423
FormBuilder,
2524
FormControl,
2625
FormGroup,
2726
NG_ASYNC_VALIDATORS,
2827
NG_VALUE_ACCESSOR,
2928
ValidationErrors,
29+
ValidatorFn,
3030
Validators
3131
} from '@angular/forms';
3232
import { Observable, of } from 'rxjs';
@@ -86,7 +86,6 @@ function labelsOfType(type: NzCronExpressionType): TimeType[] {
8686
<ng-container *ngFor="let label of labels">
8787
<nz-cron-expression-label
8888
[type]="label"
89-
[valid]="this.validateForm.controls[label].valid"
9089
[labelFocus]="labelFocus"
9190
[locale]="locale"
9291
></nz-cron-expression-label>
@@ -135,7 +134,6 @@ export class NzCronExpressionComponent implements OnInit, OnChanges, ControlValu
135134
locale!: NzCronExpressionI18nInterface;
136135
focus: boolean = false;
137136
labelFocus: TimeType | null = null;
138-
validLabel: string | null = null;
139137
labels: TimeType[] = labelsOfType(this.nzType);
140138
interval!: CronExpression<false>;
141139
nextTimeList: Date[] = [];
@@ -185,14 +183,17 @@ export class NzCronExpressionComponent implements OnInit, OnChanges, ControlValu
185183
}
186184

187185
constructor(private formBuilder: FormBuilder, private cdr: ChangeDetectorRef, private i18n: NzI18nService) {
188-
this.validateForm = this.formBuilder.nonNullable.group({
189-
second: ['0', Validators.required, this.checkValid],
190-
minute: ['*', Validators.required, this.checkValid],
191-
hour: ['*', Validators.required, this.checkValid],
192-
day: ['*', Validators.required, this.checkValid],
193-
month: ['*', Validators.required, this.checkValid],
194-
week: ['*', Validators.required, this.checkValid]
195-
});
186+
this.validateForm = this.formBuilder.nonNullable.group(
187+
{
188+
second: ['0', Validators.required],
189+
minute: ['*', Validators.required],
190+
hour: ['*', Validators.required],
191+
day: ['*', Validators.required],
192+
month: ['*', Validators.required],
193+
week: ['*', Validators.required]
194+
},
195+
{ validators: this.checkValid }
196+
);
196197
}
197198

198199
ngOnInit(): void {
@@ -264,23 +265,22 @@ export class NzCronExpressionComponent implements OnInit, OnChanges, ControlValu
264265
}
265266

266267
getValue(item: CronChangeType): void {
267-
this.validLabel = item.label;
268268
this.validateForm.controls[item.label].patchValue(item.value);
269269
this.cdr.markForCheck();
270270
}
271271

272-
checkValid: AsyncValidatorFn = (control: AbstractControl) => {
272+
checkValid: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
273273
if (control.value) {
274274
try {
275275
const cron: string[] = [];
276276
this.labels.forEach(label => {
277-
label === this.validLabel ? cron.push(control.value) : cron.push('*');
277+
cron.push(control.value[label]);
278278
});
279279
parseExpression(cron.join(' '));
280280
} catch (err: unknown) {
281-
return of({ error: true });
281+
return { error: true };
282282
}
283283
}
284-
return of(null);
284+
return null;
285285
};
286286
}

components/cron-expression/doc/index.en-US.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,20 @@ npm install cron-parser
4040
| `[nzSize]` | The size of the input box. | `'large'|'small'|'default'` | `default` |
4141
| `[nzCollapseDisable]` | Hide collapse | `boolean` | `false` |
4242
| `[nzExtra]` | Render the content on the right | `TemplateRef<void>` | - |
43-
| `[nzSemantic]` | Custom rendering next execution time | `TemplateRef<void>` | - |
43+
| `[nzSemantic]` | Custom rendering next execution time | `TemplateRef<void>` | - |
44+
45+
## Note
46+
47+
### Supported format
48+
49+
```text
50+
* * * * * *
51+
┬ ┬ ┬ ┬ ┬ ┬
52+
│ │ │ │ │ |
53+
│ │ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
54+
│ │ │ │ └───── month (1 - 12)
55+
│ │ │ └────────── day of month (1 - 31, L)
56+
│ │ └─────────────── hour (0 - 23)
57+
│ └──────────────────── minute (0 - 59)
58+
└───────────────────────── second (0 - 59, optional)
59+
```

components/cron-expression/doc/index.zh-CN.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,20 @@ npm install cron-parser
4040
| `[nzBorderless]` | 是否隐藏边框 | `boolean` | `false` |
4141
| `[nzCollapseDisable]` | 隐藏折叠面板 | `boolean` | `false` |
4242
| `[nzExtra]` | 自定义渲染右侧的内容 | `TemplateRef<void>` | - |
43-
| `[nzSemantic]` | 自定义渲染下次执行时间 | `TemplateRef<void>` | - |
43+
| `[nzSemantic]` | 自定义渲染下次执行时间 | `TemplateRef<void>` | - |
44+
45+
## 注意
46+
47+
### 支持格式
48+
49+
```text
50+
* * * * * *
51+
┬ ┬ ┬ ┬ ┬ ┬
52+
│ │ │ │ │ |
53+
│ │ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
54+
│ │ │ │ └───── month (1 - 12)
55+
│ │ │ └────────── day of month (1 - 31, L)
56+
│ │ └─────────────── hour (0 - 23)
57+
│ └──────────────────── minute (0 - 59)
58+
└───────────────────────── second (0 - 59, optional)
59+
```

components/cron-expression/style/index.less

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@
8383
display: flex;
8484
align-items: center;
8585
padding-left: @padding-md;
86-
87-
&-date {
88-
flex: 1 1 auto;
89-
}
9086
}
9187

9288
&-list, &-icon {
@@ -106,21 +102,13 @@
106102
}
107103

108104
&-icon {
109-
height: 100%;
105+
flex: 0 0 16px;
106+
display: flex;
107+
justify-content: center;
110108
}
111109
}
112110

113111
&-error {
114112
color: @error-color;
115113
}
116-
117-
&-hint {
118-
p {
119-
display: flex;
120-
}
121-
span {
122-
display: inline-block;
123-
min-width: 40px;
124-
}
125-
}
126114
}

components/cron-expression/typings.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
export type TimeType = keyof Cron;
77

8-
export type TimeTypeError = 'secondError' | 'minuteError' | 'hourError' | 'dayError' | 'monthError' | 'weekError';
9-
108
export interface Cron {
119
second?: CronValue;
1210
minute?: CronValue;

components/i18n/languages/en_US.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,7 @@ export default {
185185
hour: 'hour',
186186
day: 'day',
187187
month: 'month',
188-
week: 'week',
189-
secondError:
190-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><p><span>0-59</span>Allowable range</p>',
191-
minuteError:
192-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><p><span>0-59</span>Allowable range</p>',
193-
hourError:
194-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><p><span>0-23</span>Allowable range</p>',
195-
dayError:
196-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><p><span>1-31</span>Allowable range</p>',
197-
monthError:
198-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><p><span>1-12</span>Allowable range</p>',
199-
weekError:
200-
'<p><span>*</span>Any value</p><p><span>,</span>Separator between multiple values</p><p><span>-</span>Connector for interval values</p><p><span>/</span>Equally distributed</p><span>?</span> Not specify</p><p><p><span>0-7</span>Allowable range (0 represents Sunday, 1-7 are Monday to Sunday)</p>'
188+
week: 'week'
201189
},
202190
QRCode: {
203191
expired: 'QR code expired',

components/i18n/languages/fa_IR.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,7 @@ export default {
185185
hour: 'ساعت',
186186
day: 'روز',
187187
month: 'ماه',
188-
week: 'هفته',
189-
secondError:
190-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><p><span>0-59</span>بازه مجاز</p>',
191-
minuteError:
192-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><p><span>0-59</span>بازه مجاز</p>',
193-
hourError:
194-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><p><span>0-23</span>بازه مجاز</p>',
195-
dayError:
196-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><p><span>1-31</span>بازه مجاز</p>',
197-
monthError:
198-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><p><span>1-12</span>بازه مجاز</p>',
199-
weekError:
200-
'<p><span>*</span>هر مقداری</p><p><span>,</span>جداکندده بین مقادیر متفاوت</p><p><span>-</span>وصل کننده مقادیر داخلی</p><p><span>/</span>به طور مساوی توزیع شده است</p><span>?</span>مشخص نیست</p><p><p><span>0-7</span>بازه مجاز (0 برای یک شنبه، از 1 تا 7 برای دوشنبه تا شنبه)</p>'
188+
week: 'هفته'
201189
},
202190
QRCode: {
203191
expired: 'کد QR منقضی شده است',

components/i18n/languages/zh_CN.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,7 @@ export default {
181181
hour: '小时',
182182
day: '日',
183183
month: '月',
184-
week: '周',
185-
secondError:
186-
'<p><span>*</span>任意值</p><p><span>,</span>多个值之间的分隔符</p><p><span>-</span>区间值的连接符</p><p><span>/</span>平均分配</p><p><span>0-59</span>允许范围</p>',
187-
minuteError:
188-
'<p><span>*</span>任意值</p><p><span>,</span>多个值之间的分隔符</p><p><span>-</span>区间值的连接符</p><p><span>/</span>平均分配</p><p><span>0-59</span>允许范围</p>',
189-
hourError:
190-
'<p><span>*</span> 任意值</p><p><span>,</span> 多个值之间的分隔符</p><p><span>-</span> 区间值的连接符</p><p><span>/</span> 平均分配</p><p><span>0-23</span> 允许范围</p>',
191-
dayError:
192-
'<p><span>*</span> 任意值</p><p><span>,</span> 多个值之间的分隔符</p><p><span>-</span> 区间值的连接符</p><p><span>/</span> 平均分配</p><p><span>1-31</span> 允许范围</p>',
193-
monthError:
194-
'<p><span>*</span> 任意值</p><p><span>,</span> 多个值之间的分隔符</p><p><span>-</span> 区间值的连接符</p><p><span>/</span> 平均分配</p><p><span>1-12</span> 允许范围</p>',
195-
weekError:
196-
'<p><span>*</span> 任意值</p><p><span>,</span> 多个值之间的分隔符</p><p><span>-</span> 区间值的连接符</p><p><span>/</span> 平均分配</p><p><span>?</span> 不指定</p><p><span>0-7</span> 允许范围(0代表周日,1-7依次为周一到周日)</p>'
184+
week: '周'
197185
},
198186
QRCode: {
199187
expired: '二维码过期',

0 commit comments

Comments
 (0)