-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:cron-expression): Optimize cron result display & support …
…custom rendering cron time (#7750) * feat(module:cron-expression): brand new cron result display * feat(module:cron-expression): delete CollapseModule Co-authored-by: Gyy <wb-gyy965916@alibaba-inc.com>
- Loading branch information
1 parent
ddd44d2
commit 1820da5
Showing
11 changed files
with
193 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
components/cron-expression/cron-expression-preview.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { | ||
Component, | ||
ViewEncapsulation, | ||
ChangeDetectionStrategy, | ||
Input, | ||
Output, | ||
EventEmitter, | ||
ChangeDetectorRef, | ||
TemplateRef | ||
} from '@angular/core'; | ||
|
||
import { InputBoolean } from 'ng-zorro-antd/core/util'; | ||
import { NzCronExpressionCronErrorI18n } from 'ng-zorro-antd/i18n'; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
selector: 'nz-cron-expression-preview', | ||
exportAs: 'nzCronExpressionPreview', | ||
template: `<div class="ant-collapse ant-collapse-borderless ant-cron-expression-preview"> | ||
<div class="ant-cron-expression-preview-dateTime" [class.ant-cron-expression-preview-dateTime-center]="!isExpand"> | ||
<ng-container *ngIf="visible; else cronError"> | ||
<ng-container *ngIf="!nzSemantic; else semanticTemplate"> | ||
{{ TimeList[0] | date: 'YYYY-MM-dd HH:mm:ss' }} | ||
</ng-container> | ||
<ng-template #semanticTemplate [ngTemplateOutlet]="nzSemantic"></ng-template> | ||
</ng-container> | ||
<ng-template #cronError>{{ locale.cronError }}</ng-template> | ||
</div> | ||
<div *ngIf="visible" class="ant-cron-expression-preview-content"> | ||
<div class="ant-cron-expression-preview-content-date"> | ||
<ng-container *ngIf="!isExpand"> | ||
<ul class="ant-cron-expression-preview-list"> | ||
<li *ngFor="let item of TimeList"> | ||
{{ item | date: 'YYYY-MM-dd HH:mm:ss' }} | ||
</li> | ||
<li><a (click)="loadMorePreview.emit()">···</a></li> | ||
</ul> | ||
</ng-container> | ||
</div> | ||
<ul class="ant-cron-expression-preview-icon"> | ||
<li *ngIf="isExpand"><span nz-icon nzType="down" nzTheme="outline" (click)="setExpand()"></span></li> | ||
<li *ngIf="!isExpand"><span nz-icon nzType="up" nzTheme="outline" (click)="setExpand()"></span></li> | ||
</ul> | ||
</div> | ||
</div>` | ||
}) | ||
export class NzCronExpressionPreviewComponent { | ||
@Input() TimeList: Date[] = []; | ||
@Input() @InputBoolean() visible: boolean = true; | ||
@Input() locale!: NzCronExpressionCronErrorI18n; | ||
@Input() nzSemantic: TemplateRef<void> | null = null; | ||
@Output() readonly loadMorePreview = new EventEmitter<void>(); | ||
|
||
isExpand: boolean = true; | ||
|
||
constructor(private cdr: ChangeDetectorRef) {} | ||
|
||
setExpand(): void { | ||
this.isExpand = !this.isExpand; | ||
this.cdr.markForCheck(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 5 | ||
title: | ||
zh-CN: 自定义渲染 cron 时间 | ||
en-US: Custom rendering cron time | ||
--- | ||
|
||
## zh-CN | ||
|
||
自定义渲染下次执行时间 | ||
|
||
## en-US | ||
|
||
Custom rendering next execution time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { parseExpression } from 'cron-parser'; | ||
|
||
import { NzSafeAny } from 'ng-zorro-antd/core/types'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-cron-expression-semantic', | ||
template: ` <nz-cron-expression | ||
[nzSemantic]="semanticTemplate" | ||
[(ngModel)]="value" | ||
(ngModelChange)="getValue($event)" | ||
></nz-cron-expression> | ||
<ng-template #semanticTemplate>Next Time: {{ semantic | date: 'YYYY-MM-dd HH:mm:ss' }}</ng-template>` | ||
}) | ||
export class NzDemoCronExpressionSemanticComponent { | ||
value: string = '10 * * * *'; | ||
semantic?: Date; | ||
|
||
getValue(value: string): void { | ||
try { | ||
const interval = parseExpression(value); | ||
this.semantic = interval.next().toDate(); | ||
} catch (err: NzSafeAny) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
order: 5 | ||
order: 6 | ||
title: | ||
zh-CN: 结合表单使用 | ||
en-US: Basic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.