From 131683b4ef645fbad34ff87358d88fc2cb44db9f Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Fri, 10 May 2019 18:28:34 +0800 Subject: [PATCH] Fix_cron schedule bug when call api ' get/schedule ' error Signed-off-by: Yogi_Wang --- src/portal/lib/src/config/gc/gc.component.ts | 10 ++++---- .../vulnerability-config.component.ts | 24 ++++++++++--------- .../cron-schedule/cron-schedule.component.ts | 7 ++++++ src/portal/src/i18n/lang/en-us-lang.json | 4 +++- src/portal/src/i18n/lang/es-es-lang.json | 4 +++- src/portal/src/i18n/lang/fr-fr-lang.json | 4 +++- src/portal/src/i18n/lang/pt-br-lang.json | 4 +++- src/portal/src/i18n/lang/zh-cn-lang.json | 4 +++- 8 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/portal/lib/src/config/gc/gc.component.ts b/src/portal/lib/src/config/gc/gc.component.ts index 7d0e104f4..44d805d92 100644 --- a/src/portal/lib/src/config/gc/gc.component.ts +++ b/src/portal/lib/src/config/gc/gc.component.ts @@ -18,7 +18,7 @@ import { import { ErrorHandler } from "../../error-handler/index"; import { CronScheduleComponent } from "../../cron-schedule/cron-schedule.component"; import { OriginCron } from '../../service/interface'; - +import { finalize } from "rxjs/operators"; @Component({ selector: "gc-config", templateUrl: "./gc.component.html", @@ -50,12 +50,14 @@ export class GcComponent implements OnInit { getCurrentSchedule() { this.loadingGcStatus.emit(true); - this.gcRepoService.getSchedule().subscribe(schedule => { - this.initSchedule(schedule); + this.gcRepoService.getSchedule() + .pipe(finalize(() => { this.loadingGcStatus.emit(false); + })) + .subscribe(schedule => { + this.initSchedule(schedule); }, error => { this.errorHandler.error(error); - this.loadingGcStatus.emit(false); }); } diff --git a/src/portal/lib/src/config/vulnerability/vulnerability-config.component.ts b/src/portal/lib/src/config/vulnerability/vulnerability-config.component.ts index 4de6733b5..69d3af918 100644 --- a/src/portal/lib/src/config/vulnerability/vulnerability-config.component.ts +++ b/src/portal/lib/src/config/vulnerability/vulnerability-config.component.ts @@ -1,6 +1,6 @@ import { Component, Input, Output, EventEmitter, ViewChild, OnInit } from '@angular/core'; import { NgForm } from '@angular/forms'; -import { map, catchError } from "rxjs/operators"; +import { map, catchError, finalize } from "rxjs/operators"; import { Observable, throwError as observableThrowError, of } from "rxjs"; import { Configuration } from '../config'; import { @@ -85,16 +85,18 @@ export class VulnerabilityConfigComponent implements OnInit { } getSchedule() { - this.onGoing = true; - this.scanningService.getSchedule().subscribe(schedule => { - this.initSchedule(schedule); - this.onGoing = false; - this.loadingStatus.emit(this.onGoing); - }, error => { - this.errorHandler.error(error); - this.loadingStatus.emit(this.onGoing); - }); - } + this.onGoing = true; + this.scanningService.getSchedule() + .pipe(finalize(() => { + this.onGoing = false; + this.loadingStatus.emit(this.onGoing); + })) + .subscribe(schedule => { + this.initSchedule(schedule); + }, error => { + this.errorHandler.error(error); + }); + } public initSchedule(schedule: any) { if (schedule && schedule.schedule !== null) { diff --git a/src/portal/lib/src/cron-schedule/cron-schedule.component.ts b/src/portal/lib/src/cron-schedule/cron-schedule.component.ts index f3d91ff2a..ba9abae5b 100644 --- a/src/portal/lib/src/cron-schedule/cron-schedule.component.ts +++ b/src/portal/lib/src/cron-schedule/cron-schedule.component.ts @@ -9,6 +9,8 @@ import { } from "@angular/core"; import { OriginCron } from "../service/interface"; import { cronRegex } from "../utils"; +import { TranslateService } from "@ngx-translate/core"; +import { ErrorHandler } from "../error-handler/error-handler"; const SCHEDULE_TYPE = { NONE: "None", DAILY: "Daily", @@ -33,6 +35,10 @@ export class CronScheduleComponent implements OnChanges { SCHEDULE_TYPE = SCHEDULE_TYPE; scheduleType: string; @Output() inputvalue = new EventEmitter(); + constructor( + private translate: TranslateService, + private errorHandler: ErrorHandler, + ) { } ngOnChanges(changes: SimpleChanges): void { let cronChange: SimpleChange = changes["originCron"]; @@ -43,6 +49,7 @@ export class CronScheduleComponent implements OnChanges { } editSchedule() { if (!this.originScheduleType) { + this.translate.get('SCHEDULE.NOSCHEDULE').subscribe(res => this.errorHandler.error(res)); return; } this.isEditMode = true; diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index 9e554af1b..9c3ca475f 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -991,7 +991,9 @@ "MANUAL": "Manual", "CRON": "cron", "ON": "on", - "AT": "at" + "AT": "at", + "NOSCHEDULE": "An error occurred in Get schedule" + }, "GC": { "CURRENT_SCHEDULE": "Current Schedule", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index d2a9897a6..0b8de5893 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -989,7 +989,9 @@ "MANUAL": "Manual", "CRON": "cron", "ON": "on", - "AT": "at" + "AT": "at", + "NOSCHEDULE": "An error occurred in Get schedule" + }, "GC": { "CURRENT_SCHEDULE": "Current Schedule", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 6e8514074..05e8a111d 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -960,7 +960,9 @@ "MANUAL": "Manual", "CRON": "cron", "ON": "on", - "AT": "at" + "AT": "at", + "NOSCHEDULE": "An error occurred in Get schedule" + }, "GC": { "CURRENT_SCHEDULE": "Current Schedule", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index 870686a4c..0cafa5f3d 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -981,7 +981,9 @@ "MANUAL": "Manual", "CRON": "cron", "ON": "on", - "AT": "at" + "AT": "at", + "NOSCHEDULE": "An error occurred in Get schedule" + }, "GC": { "CURRENT_SCHEDULE": "Agendamento atual", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index 5e6cede7f..1681641b7 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -987,7 +987,9 @@ "CRON": "cron", "MANUAL": "手动", "ON": " ", - "AT": " " + "AT": " ", + "NOSCHEDULE": "获取schedule时出现错误" + }, "GC": { "CURRENT_SCHEDULE": "当前定时任务",