From 25d3583d3677ecfada67f973c32243c6849cf7cc Mon Sep 17 00:00:00 2001 From: Shijun Sun <30999793+AllForNothing@users.noreply.github.com> Date: Tue, 28 Jun 2022 14:41:55 +0800 Subject: [PATCH] Improve cron validator for replication rule (#17069) Signed-off-by: AllForNothing --- .../create-edit-rule.component.html | 4 ++- .../create-edit-rule.component.ts | 36 ++++++++++--------- src/portal/src/i18n/lang/de-de-lang.json | 3 +- src/portal/src/i18n/lang/en-us-lang.json | 3 +- src/portal/src/i18n/lang/es-es-lang.json | 3 +- src/portal/src/i18n/lang/fr-fr-lang.json | 3 +- src/portal/src/i18n/lang/pt-br-lang.json | 3 +- src/portal/src/i18n/lang/tr-tr-lang.json | 3 +- src/portal/src/i18n/lang/zh-cn-lang.json | 3 +- src/portal/src/i18n/lang/zh-tw-lang.json | 3 +- 10 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.html b/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.html index d107ca86c..cba4e461e 100644 --- a/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.html +++ b/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.html @@ -654,13 +654,15 @@ name="targetCron" id="targetCron" required + pattern="^0\s(?!(\*\s)).+$" class="form-control cron-input clr-input" formControlName="cron" /> {{ - 'TOOLTIP.CRON_REQUIRED' | translate + 'REPLICATION.CRON_ERROR_TIP' + | translate }} diff --git a/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.ts b/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.ts index b182c85be..eb406177a 100644 --- a/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.ts +++ b/src/portal/src/app/base/left-side-nav/replication/replication/create-edit-rule/create-edit-rule.component.ts @@ -710,22 +710,26 @@ export class CreateEditRuleComponent implements OnInit, OnDestroy { return filtersArray; } cronInputShouldShowError(): boolean { - return ( - this.ruleForm && - this.ruleForm.get('trigger') && - this.ruleForm.get('trigger').get('trigger_settings') && - this.ruleForm.get('trigger').get('trigger_settings').get('cron') && - (this.ruleForm.get('trigger').get('trigger_settings').get('cron') - .touched || - this.ruleForm.get('trigger').get('trigger_settings').get('cron') - .dirty) && - this.ruleForm.get('trigger').get('trigger_settings').get('cron') - .value && - !cronRegex( - this.ruleForm.get('trigger').get('trigger_settings').get('cron') - .value - ) - ); + if ( + this.ruleForm?.get('trigger')?.get('trigger_settings')?.get('cron') + ?.touched || + this.ruleForm?.get('trigger')?.get('trigger_settings')?.get('cron') + ?.dirty + ) { + return ( + this.ruleForm + ?.get('trigger') + ?.get('trigger_settings') + ?.get('cron')?.invalid || + !cronRegex( + this.ruleForm + .get('trigger') + .get('trigger_settings') + .get('cron').value + ) + ); + } + return false; } stickLabel(value, index) { value.select = !value.select; diff --git a/src/portal/src/i18n/lang/de-de-lang.json b/src/portal/src/i18n/lang/de-de-lang.json index 1a524dc4c..5a4289f88 100644 --- a/src/portal/src/i18n/lang/de-de-lang.json +++ b/src/portal/src/i18n/lang/de-de-lang.json @@ -658,7 +658,8 @@ "BANDWIDTH_ERROR_TIP": "Bitte -1 oder einen Integer-Wert größer als 0 eingeben", "BANDWIDTH_TOOLTIP": "Legt die maximale Netzwerkbandbreite für jede Ausführung fest. Bitte auf die Anzahl der parallelen Ausführungen achten. Für umbegrenzte Bandbreite, bitte -1 eingeben", "UNLIMITED": "Unbegrenzt", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "Neuer Endpunkt", diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index 2035c37d2..d6c2805e9 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -658,7 +658,8 @@ "BANDWIDTH_ERROR_TIP": "Please enter -1 or an integer greater than 0", "BANDWIDTH_TOOLTIP": "Set the maximum network bandwidth for each execution. Please pay attention to the number of concurrent executions. For unlimited bandwidth, please enter -1", "UNLIMITED": "Unlimited", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "New Endpoint", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index 246d77479..f79c71994 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -660,7 +660,8 @@ "BANDWIDTH_ERROR_TIP": "Please enter -1 or an integer greater than 0", "BANDWIDTH_TOOLTIP": "Set the maximum network bandwidth for each execution. Please pay attention to the number of concurrent executions. For unlimited bandwidth, please enter -1", "UNLIMITED": "Unlimited", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "Nuevo Endpoint", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 065968458..4c3b2ac3a 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -648,7 +648,8 @@ "BANDWIDTH_ERROR_TIP": "Veuillez saisir -1 ou un nombre entier supérieur à 0", "BANDWIDTH_TOOLTIP": "Définissez la bande passante réseau maximale pour chaque exécution. Veuillez faire attention au nombre d'exécutions simultanées. Pour une bande passante illimitée, veuillez entrer -1", "UNLIMITED": "Illimitée", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "Nouveau Endpoint", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index 7c8b2eaee..799510b57 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -658,7 +658,8 @@ "BANDWIDTH_ERROR_TIP": "Informe um número inteiro maior que 0 (zero) ou -1", "BANDWIDTH_TOOLTIP": "Informe o limite de banda para cada execução. Tome cuidado e observe a relação com o número de execuções simultâneas. Para remover qualquer limite, informe -1", "UNLIMITED": "Ilimitado", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\"is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "Novo Endereço", diff --git a/src/portal/src/i18n/lang/tr-tr-lang.json b/src/portal/src/i18n/lang/tr-tr-lang.json index 8b1d8f925..04408b387 100644 --- a/src/portal/src/i18n/lang/tr-tr-lang.json +++ b/src/portal/src/i18n/lang/tr-tr-lang.json @@ -658,7 +658,8 @@ "BANDWIDTH_ERROR_TIP": "Please enter -1 or an integer greater than 0", "BANDWIDTH_TOOLTIP": "Set the maximum network bandwidth for each execution. Please pay attention to the number of concurrent executions. For unlimited bandwidth, please enter -1", "UNLIMITED": "Unlimited", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION": { "NEW_ENDPOINT": "Yeni Uç Nokta", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index 6ac57050c..b25a7ef58 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -660,7 +660,8 @@ "BANDWIDTH_ERROR_TIP": "请输入-1或者大于0的整数", "BANDWIDTH_TOOLTIP": "设置执行该条同步规则时的最大网络带宽。实际总带宽需要考虑并发执行的情况。如无需限制,请输入-1", "UNLIMITED": "无限制", - "UNREACHABLE_SOURCE_REGISTRY": "连接源仓库失败,在编辑此规则前请先确保源仓库可用: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "连接源仓库失败,在编辑此规则前请先确保源仓库可用: {{error}}", + "CRON_ERROR_TIP": "此项必填且\"分钟\"项不能为\"*\"" }, "DESTINATION": { "NEW_ENDPOINT": "新建目标", diff --git a/src/portal/src/i18n/lang/zh-tw-lang.json b/src/portal/src/i18n/lang/zh-tw-lang.json index de40f64ea..484ade8b3 100644 --- a/src/portal/src/i18n/lang/zh-tw-lang.json +++ b/src/portal/src/i18n/lang/zh-tw-lang.json @@ -655,7 +655,8 @@ "BANDWIDTH_ERROR_TIP": "Please enter -1 or an integer greater than 0", "BANDWIDTH_TOOLTIP": "Set the maximum network bandwidth for each execution. Please pay attention to the number of concurrent executions. For unlimited bandwidth, please enter -1", "UNLIMITED": "Unlimited", - "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}" + "UNREACHABLE_SOURCE_REGISTRY": "Failed to connect to the source registry, please make sure the source registry is available before editing this rule: {{error}}", + "CRON_ERROR_TIP": "Field is required and \"*\" is not allowed for the \"Minutes\" field" }, "DESTINATION":{ "NEW_ENDPOINT": "新建目標",