From 5e34cd3cf9d3623df100c8221652e030c9432032 Mon Sep 17 00:00:00 2001 From: FangyuanCheng Date: Thu, 25 Apr 2019 14:39:20 +0800 Subject: [PATCH] Fix some issues of replication Signed-off-by: FangyuanCheng --- .../create-edit-rule.component.html | 10 +-- .../lib/src/endpoint/endpoint.component.ts | 14 ++-- .../list-replication-rule.component.ts | 73 ++++--------------- .../replication-tasks.component.html | 10 +-- .../src/replication/replication.component.ts | 43 +++++++---- src/portal/src/i18n/lang/en-us-lang.json | 7 +- src/portal/src/i18n/lang/es-es-lang.json | 8 +- src/portal/src/i18n/lang/fr-fr-lang.json | 14 +++- src/portal/src/i18n/lang/pt-br-lang.json | 8 +- src/portal/src/i18n/lang/zh-cn-lang.json | 6 +- 10 files changed, 90 insertions(+), 103 deletions(-) diff --git a/src/portal/lib/src/create-edit-rule/create-edit-rule.component.html b/src/portal/lib/src/create-edit-rule/create-edit-rule.component.html index 80f22ae21..a422fd678 100644 --- a/src/portal/lib/src/create-edit-rule/create-edit-rule.component.html +++ b/src/portal/lib/src/create-edit-rule/create-edit-rule.component.html @@ -66,12 +66,12 @@
- +
@@ -156,11 +156,11 @@
- + - + {{'TOOLTIP.OVERRIDE' | translate}} diff --git a/src/portal/lib/src/endpoint/endpoint.component.ts b/src/portal/lib/src/endpoint/endpoint.component.ts index 44edf5d44..15ab9a8db 100644 --- a/src/portal/lib/src/endpoint/endpoint.component.ts +++ b/src/portal/lib/src/endpoint/endpoint.component.ts @@ -19,7 +19,7 @@ import { ChangeDetectionStrategy, ChangeDetectorRef } from "@angular/core"; -import { Subscription, Observable, forkJoin } from "rxjs"; +import { Subscription, Observable, forkJoin, throwError as observableThrowError } from "rxjs"; import { TranslateService } from "@ngx-translate/core"; import { Comparator } from "../service/interface"; @@ -210,19 +210,17 @@ export class EndpointComponent implements OnInit, OnDestroy { }); }) , catchError(error => { - if (error && error.status === 412) { - return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'), - this.translateService.get('DESTINATION.FAILED_TO_DELETE_TARGET_IN_USED')).pipe(map(res => { - operateChanges(operMessage, OperationState.failure, res[1]); - })); + if (error && error._body) { + const message = JSON.parse(error._body).message; + operateChanges(operMessage, OperationState.failure, message); + return observableThrowError(message); } else { return this.translateService.get('BATCH.DELETED_FAILURE').pipe(map(res => { operateChanges(operMessage, OperationState.failure, res); })); } - } - )); + )); } // Forcely refresh the view diff --git a/src/portal/lib/src/list-replication-rule/list-replication-rule.component.ts b/src/portal/lib/src/list-replication-rule/list-replication-rule.component.ts index 91834463d..18d2ec493 100644 --- a/src/portal/lib/src/list-replication-rule/list-replication-rule.component.ts +++ b/src/portal/lib/src/list-replication-rule/list-replication-rule.component.ts @@ -80,7 +80,6 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { rules: ReplicationRule[]; changedRules: ReplicationRule[]; ruleName: string; - canDeleteRule: boolean; selectedRow: ReplicationRule; @@ -149,21 +148,6 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { this.replicateManual.emit(rule); } - hasDeletedLabel(rule: any) { - if (rule.filters) { - let count = 0; - rule.filters.forEach((data: any) => { - if (data.kind === 'label' && data.value.deleted) { - count++; - } - }); - if (count === 0) { - return 'enabled'; - } else { return 'disabled'; } - } - return 'enabled'; - } - deletionConfirm(message: ConfirmationAcknowledgement) { if ( message && @@ -193,27 +177,6 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { this.editOne.emit(rule); } - jobList(id: string | number): Observable { - let ruleData: ReplicationJobItem[]; - this.canDeleteRule = true; - let count = 0; - - return this.replicationService.getExecutions(id) - .pipe(map(response => { - ruleData = response.data; - if (ruleData.length) { - ruleData.forEach(job => { - if ( - job.status === jobstatus - ) { - count++; - } - }); - } - this.canDeleteRule = count > 0 ? false : true; - }), catchError(error => observableThrowError(error))); - } - deleteRule(rule: ReplicationRule) { if (rule) { let deletionMessage = new ConfirmationMessage( @@ -231,15 +194,13 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { deleteOpe(rule: ReplicationRule) { if (rule) { let observableLists: any[] = []; - this.jobList(rule.id).subscribe(items => { - observableLists.push(this.delOperate(rule)); + observableLists.push(this.delOperate(rule)); - forkJoin(...observableLists).subscribe(item => { - this.selectedRow = null; - this.reload.emit(true); - let hnd = setInterval(() => this.ref.markForCheck(), 200); - setTimeout(() => clearInterval(hnd), 2000); - }); + forkJoin(...observableLists).subscribe(item => { + this.selectedRow = null; + this.reload.emit(true); + let hnd = setInterval(() => this.ref.markForCheck(), 200); + setTimeout(() => clearInterval(hnd), 2000); }); } } @@ -253,13 +214,6 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { operMessage.data.name = rule.name; this.operationService.publishInfo(operMessage); - if (!this.canDeleteRule) { - return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'), - this.translateService.get('REPLICATION.DELETION_SUMMARY_FAILURE')).pipe(map(res => { - operateChanges(operMessage, OperationState.failure, res[1]); - })); - } - return this.replicationService .deleteReplicationRule(+rule.id) .pipe(map(() => { @@ -267,15 +221,16 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges { .subscribe(res => operateChanges(operMessage, OperationState.success)); }) , catchError(error => { - if (error && error.status === 412) { - return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'), - this.translateService.get('REPLICATION.FAILED_TO_DELETE_POLICY_ENABLED')).pipe(map(res => { - operateChanges(operMessage, OperationState.failure, res[1]); - })); + if (error && error._body) { + const message = JSON.parse(error._body).message; + operateChanges(operMessage, OperationState.failure, message); + return observableThrowError(message); } else { - return this.translateService.get('BATCH.DELETED_FAILURE').pipe(map(res => { + return this.translateService.get("BATCH.DELETED_FAILURE").pipe( + map(res => { operateChanges(operMessage, OperationState.failure, res); - })); + }) + ); } })); } diff --git a/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.html b/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.html index 2d5e5cd23..920b4e084 100644 --- a/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.html +++ b/src/portal/lib/src/replication/replication-tasks/replication-tasks.component.html @@ -111,13 +111,9 @@ {{t.start_time | date: 'short'}} {{t.end_time | date: 'short'}} - {{'REPLICATION.NO_LOGS' - | translate}} - - - - - + + + diff --git a/src/portal/lib/src/replication/replication.component.ts b/src/portal/lib/src/replication/replication.component.ts index 4ee6a6496..a238f6ea8 100644 --- a/src/portal/lib/src/replication/replication.component.ts +++ b/src/portal/lib/src/replication/replication.component.ts @@ -22,7 +22,7 @@ import { } from "@angular/core"; import { Comparator, State } from "../service/interface"; import { finalize, catchError, map } from "rxjs/operators"; -import { Subscription, forkJoin, timer, Observable, throwError } from "rxjs"; +import { Subscription, forkJoin, timer, Observable, throwError as observableThrowError, observable } from "rxjs"; import { TranslateService } from "@ngx-translate/core"; import { ListReplicationRuleComponent } from "../list-replication-rule/list-replication-rule.component"; @@ -327,19 +327,14 @@ export class ReplicationComponent implements OnInit, OnDestroy { ); }), catchError(error => { - if (error && error.status === 412) { - return forkJoin( - this.translateService.get("BATCH.REPLICATE_FAILURE"), - this.translateService.get("REPLICATION.REPLICATE_SUMMARY_FAILURE") - ).pipe( - map(function(res) { - operateChanges(operMessage, OperationState.failure, res[1]); - }) - ); + if (error && error._body) { + const message = JSON.parse(error._body).message; + operateChanges(operMessage, OperationState.failure, message); + return observableThrowError(message); } else { return this.translateService.get("BATCH.REPLICATE_FAILURE").pipe( map(res => { - operateChanges(operMessage, OperationState.failure, res); + operateChanges(operMessage, OperationState.failure, res); }) ); } @@ -409,7 +404,7 @@ export class ReplicationComponent implements OnInit, OnDestroy { let ExecutionsStop$ = targets.map(target => this.StopOperate(target)); forkJoin(ExecutionsStop$) .pipe( - catchError(err => throwError(err)), + catchError(err => observableThrowError(err)), finalize(() => { this.refreshJobs(); this.isStopOnGoing = false; @@ -431,10 +426,26 @@ export class ReplicationComponent implements OnInit, OnDestroy { return this.replicationService .stopJobs(targets.id) .pipe( - map( - () => operateChanges(operMessage, OperationState.success), - err => operateChanges(operMessage, OperationState.failure, err) - ) + map(response => { + this.translateService + .get("BATCH.STOP_SUCCESS") + .subscribe(res => + operateChanges(operMessage, OperationState.success) + ); + }), + catchError(error => { + if (error && error._body) { + const message = JSON.parse(error._body).message; + operateChanges(operMessage, OperationState.failure, message); + return observableThrowError(message); + } else { + return this.translateService.get("BATCH.STOP_FAILURE").pipe( + map(res => { + operateChanges(operMessage, OperationState.failure, res); + }) + ); + } + }) ); } diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index f4b46a863..b1816987d 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -50,7 +50,9 @@ "SWITCH_SUCCESS": "Switch successfully", "SWITCH_FAILURE": "Switch failed", "REPLICATE_SUCCESS": "Started successfully", - "REPLICATE_FAILURE": "Started failed" + "REPLICATE_FAILURE": "Started failed", + "STOP_SUCCESS": "Stop successfully", + "STOP_FAILURE": "Stop execution failed" }, "TOOLTIP": { "NAME_FILTER": "Filter the name part of the resources. Leaving empty or '**' matches all; 'library/**' only matches the resources under 'library'. For more patterns please refer to the user guide.", @@ -358,11 +360,12 @@ "REPLICATION": { "TOTAL": "Total", "OVERRIDE": "Override", + "OVERRIDE_INFO": "Override the destination resources if name conflicts", "OPERATION": "Operation", "CURRENT": "current", "FILTER_PLACEHOLDER": "Filter Tasks", "STOP_TITLE": "Confirm Stop Executions", - "PLEASE_SELECT": "select an option", + "BOTH": "both", "STOP_SUCCESS": "Stop Execution {{param}} Successful", "STOP_SUMMARY": "Do you want to stop the executions {{param}}?", "TASK_ID":"Task ID", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index f00d7c029..d05dce0c5 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -50,7 +50,9 @@ "SWITCH_SUCCESS": "Switch successfully", "SWITCH_FAILURE": "Switch failed", "REPLICATE_SUCCESS": "Started successfully", - "REPLICATE_FAILURE": "Started failed" + "REPLICATE_FAILURE": "Started failed", + "STOP_SUCCESS": "Stop successfully", + "STOP_FAILURE": "Stop execution failed" }, "TOOLTIP": { "NAME_FILTER": "Filter the name part of the resources. Leaving empty or '**' matches all; 'library/**' only matches the resources under 'library'. For more patterns please refer to the user guide.", @@ -356,10 +358,12 @@ }, "REPLICATION": { "TOTAL": "Total", - "OVERRIDE": "Anular", + "OVERRIDE": "Override", + "OVERRIDE_INFO": "Override the destination resources if name conflicts", "CURRENT": "current", "FILTER_PLACEHOLDER": "Filter Tasks", "STOP_TITLE": "Confirme Stop Executions", + "BOTH": "both", "PLEASE_SELECT": "select an option", "STOP_SUCCESS": "Stop Execution {{param}} Successful", "STOP_SUMMARY": "De que desea detener las ejecuciones {{param}}?", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 5ad5e14d5..6aee1f37d 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -41,6 +41,16 @@ "UPLOAD": "Upload", "NO_FILE": "No file selected" }, + "BATCH": { + "DELETED_SUCCESS": "Deleted successfully", + "DELETED_FAILURE": "Deleted failed", + "SWITCH_SUCCESS": "Switch successfully", + "SWITCH_FAILURE": "Switch failed", + "REPLICATE_SUCCESS": "Started successfully", + "REPLICATE_FAILURE": "Started failed", + "STOP_SUCCESS": "Stop successfully", + "STOP_FAILURE": "Stop execution failed" + }, "TOOLTIP": { "NAME_FILTER": "Filter the name part of the resources. Leaving empty or '**' matches all; 'library/**' only matches the resources under 'library'. For more patterns please refer to the user guide.", "TAG_FILTER": "Filter the tag/version part of the resources. Leaving empty or '**' matches all; '1.0*' only matches the tags that starts with '1.0'. For more patterns please refer to the user guide.", @@ -341,10 +351,12 @@ }, "REPLICATION": { "TOTAL": "Total", - "OVERRIDE": "Passer outre", + "OVERRIDE": "Override", + "OVERRIDE_INFO": "Override the destination resources if name conflicts", "CURRENT": "current", "FILTER_PLACEHOLDER": "Filter Tasks", "STOP_TITLE": "Confirmer arrêter les exécutions", + "BOTH": "both", "PLEASE_SELECT": "select an option", "STOP_SUCCESS": "Stop Execution {{param}} Successful", "STOP_SUMMARY": "Voulez-vous arrêter les exécutions {{param}}?", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index be3e2804b..32e9fa4f7 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -50,7 +50,9 @@ "SWITCH_SUCCESS": "Alterado com sucesso", "SWITCH_FAILURE": "Falha ao alterar", "REPLICATE_SUCCESS": "Iniciado com sucesso", - "REPLICATE_FAILURE": "Falha ao iniciar" + "REPLICATE_FAILURE": "Falha ao iniciar", + "STOP_SUCCESS": "Stop successfully", + "STOP_FAILURE": "Stop execution failed" }, "TOOLTIP": { "NAME_FILTER": "Filter the name part of the resources. Leaving empty or '**' matches all; 'library/**' only matches the resources under 'library'. For more patterns please refer to the user guide.", @@ -355,10 +357,12 @@ }, "REPLICATION": { "TOTAL": "Total", - "OVERRIDE": "Substituir", + "OVERRIDE": "Override", + "OVERRIDE_INFO": "Override the destination resources if name conflicts", "CURRENT": "current", "FILTER_PLACEHOLDER": "Filter Tasks", "STOP_TITLE": "Confirme as execuções de parada", + "BOTH": "both", "PLEASE_SELECT": "select an option", "STOP_SUCCESS": "Stop Execution {{param}} Successful", "STOP_SUMMARY": "Você quer parar as execuções? {{param}}?", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index d0ada2514..1fa548f58 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -50,7 +50,9 @@ "SWITCH_SUCCESS": "切换成功", "SWITCH_FAILURE": "切换失败", "REPLICATE_SUCCESS": "开始成功", - "REPLICATE_FAILURE": "开始失败" + "REPLICATE_FAILURE": "开始失败", + "STOP_SUCCESS": "停止任务成功", + "STOP_FAILURE": "停止任务失败" }, "TOOLTIP": { "NAME_FILTER": "过滤资源的名字。不填或者“”匹配所有资源;“library/”只匹配“library”下的资源。更多的匹配模式请参考用户手册。", @@ -357,9 +359,11 @@ "REPLICATION": { "TOTAL": "总数", "OVERRIDE": "覆盖", + "OVERRIDE_INFO": "如果名称冲突则覆盖目标资源", "CURRENT": "当前仓库", "FILTER_PLACEHOLDER": "过滤任务", "STOP_TITLE": "确认停止任务", + "BOTH": "全部", "PLEASE_SELECT": "请选择", "STOP_SUCCESS": "停止任务 {{param}} 成功", "STOP_SUMMARY": "确认停止任务{{param}}?",