From 1ac60c21537cfc0fb9eac1a4ab1eb589dfc00656 Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Thu, 1 Aug 2019 11:38:40 +0800 Subject: [PATCH] Add download button that it can download the message of robot to local file when click it Signed-off-by: Yogi_Wang --- .../add-robot/add-robot.component.html | 1 + .../robot-account/add-robot/add-robot.component.ts | 14 +++++++++++++- 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/zh-cn-lang.json | 3 ++- 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.html b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.html index 248631225..4019db7f4 100644 --- a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.html +++ b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.html @@ -128,6 +128,7 @@ (onCopyError)="onCpError($event)" inputSize="50" headerTitle="" defaultValue="{{robotToken}}" class="copy-input"> + \ No newline at end of file diff --git a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.ts b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.ts index 805ad4e91..eb007d9ea 100644 --- a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.ts +++ b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.ts @@ -17,6 +17,7 @@ import { TranslateService } from "@ngx-translate/core"; import { ErrorHandler } from "@harbor/ui"; import { MessageHandlerService } from "../../../shared/message-handler/message-handler.service"; import { InlineAlertComponent } from "../../../shared/inline-alert/inline-alert.component"; +import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; @Component({ selector: "add-robot", @@ -28,6 +29,8 @@ export class AddRobotComponent implements OnInit, OnDestroy { copyToken: boolean; robotToken: string; robotAccount: string; + downLoadFileName: string = ''; + downLoadHref: SafeUrl = ''; isSubmitOnGoing = false; closable: boolean = false; staticBackdrop: boolean = true; @@ -50,7 +53,8 @@ export class AddRobotComponent implements OnInit, OnDestroy { private translate: TranslateService, private errorHandler: ErrorHandler, private cdr: ChangeDetectorRef, - private messageHandlerService: MessageHandlerService + private messageHandlerService: MessageHandlerService, + private sanitizer: DomSanitizer ) {} ngOnInit(): void { @@ -148,6 +152,10 @@ export class AddRobotComponent implements OnInit, OnDestroy { this.createSuccess = res; }); this.addRobotOpened = false; + // export to token file + const downLoadUrl = `data:text/json;charset=utf-8, ${encodeURIComponent(JSON.stringify(response))}`; + this.downLoadHref = this.sanitizer.bypassSecurityTrustUrl(downLoadUrl); + this.downLoadFileName = `${response.name}.json`; }, error => { this.isSubmitOnGoing = false; @@ -197,4 +205,8 @@ export class AddRobotComponent implements OnInit, OnDestroy { this.messageHandlerService.showSuccess(res); }); } + + closeModal() { + this.copyToken = false; + } } diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index 72666fab0..91c8c70c3 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -332,7 +332,8 @@ "COPY_SUCCESS": "Copy token successfully of '{{param}}'", "DELETION_TITLE": "Confirm removal of robot accounts", "DELETION_SUMMARY": "Do you want to delete robot accounts {{param}}?", - "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified." + "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified.", + "EXPORT_TO_FILE" : "export to file" }, "GROUP": { "GROUP": "Group", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index fb785fe88..ec333735c 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -333,7 +333,8 @@ "COPY_SUCCESS": "Copy token successfully of '{{param}}'", "DELETION_TITLE": "Confirm removal of robot accounts", "DELETION_SUMMARY": "Do you want to delete robot accounts {{param}}?", - "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified." + "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified.", + "EXPORT_TO_FILE" : "export to file" }, "GROUP": { "GROUP": "Group", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 0924dd8f2..356d623a6 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -325,7 +325,8 @@ "COPY_SUCCESS": "Copy token successfully of '{{param}}'", "DELETION_TITLE": "confirmer l'enlèvement des comptes du robot ", "DELETION_SUMMARY": "Voulez-vous supprimer la règle {{param}}?", - "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified." + "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified.", + "EXPORT_TO_FILE" : "export to file" }, "GROUP": { "Group": "Group", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index 715192fc7..73b3ff8bb 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -330,7 +330,8 @@ "COPY_SUCCESS": "Copy token successfully of '{{param}}'", "DELETION_TITLE": "Confirmar a remoção do robô Contas", "DELETION_SUMMARY": "Você quer remover a regra {{param}}?", - "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified." + "PULL_IS_MUST" : "Pull permission is checked by default and can not be modified.", + "EXPORT_TO_FILE" : "export to file" }, "GROUP": { "GROUP": "Grupo", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index ecba805d2..c0354d493 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -331,7 +331,8 @@ "COPY_SUCCESS": "成功复制 '{{param}}' 的令牌", "DELETION_TITLE": "删除账户确认", "DELETION_SUMMARY": "你确认删除机器人账户 {{param}}?", - "PULL_IS_MUST" : "拉取权限默认选中且不可修改。" + "PULL_IS_MUST" : "拉取权限默认选中且不可修改。", + "EXPORT_TO_FILE" : "导出到文件中" }, "GROUP": { "GROUP": "组",