From 2fdb01ef1a1addfb556eb01a7481243218e1d9b7 Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Wed, 11 Mar 2020 15:24:12 +0800 Subject: [PATCH] Improve UI for add robot page Signed-off-by: AllForNothing --- .../add-robot/add-robot.component.html | 26 ++++++++++-- .../add-robot/add-robot.component.scss | 8 +++- .../add-robot/add-robot.component.ts | 40 ++++++++++++++++++- .../robot-account.component.html | 2 +- .../robot-account/robot-account.service.ts | 1 + .../src/app/project/robot-account/robot.ts | 1 + src/portal/src/i18n/lang/en-us-lang.json | 6 ++- src/portal/src/i18n/lang/es-es-lang.json | 6 ++- src/portal/src/i18n/lang/fr-fr-lang.json | 6 ++- src/portal/src/i18n/lang/pt-br-lang.json | 6 ++- src/portal/src/i18n/lang/tr-tr-lang.json | 6 ++- src/portal/src/i18n/lang/zh-cn-lang.json | 6 ++- 12 files changed, 102 insertions(+), 12 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 dfa7bf680..25df44ad1 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 @@ -6,7 +6,7 @@
-
+
@@ -34,7 +34,27 @@
-
+
+ +
+
+ + + + + +
+
+
+
@@ -48,7 +68,7 @@
-
+
diff --git a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.scss b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.scss index df3f83daa..9ecf12db1 100644 --- a/src/portal/src/app/project/robot-account/add-robot/add-robot.component.scss +++ b/src/portal/src/app/project/robot-account/add-robot/add-robot.component.scss @@ -37,7 +37,7 @@ } .permission{ - padding-top: 5px; + padding-top: 0.1rem; color: #000000; } @@ -46,4 +46,10 @@ } .w-90{ width: 90%; +} +.date { + margin-top: -0.9rem; +} +.input-width-date { + width: 265px; } \ 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 65bb9dc13..bcf8dbdf4 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 @@ -19,7 +19,8 @@ import { InlineAlertComponent } from "../../../shared/inline-alert/inline-alert. import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; import { AppConfigService } from "../../../app-config.service"; import { ErrorHandler } from "../../../../lib/utils/error-handler"; - +const ONE_THOUSAND: number = 1000; +const NEVER_EXPIRED: number = -1; @Component({ selector: "add-robot", templateUrl: "./add-robot.component.html", @@ -50,6 +51,9 @@ export class AddRobotComponent implements OnInit, OnDestroy { @Output() create = new EventEmitter(); @ViewChild("robotForm", {static: true}) currentForm: NgForm; @ViewChild("copyAlert", {static: false}) copyAlert: InlineAlertComponent; + private _expiresDate: Date; + isNeverExpired: boolean = false; + expiresDatePlaceholder: string = ' '; constructor( private robotService: RobotService, private translate: TranslateService, @@ -114,6 +118,9 @@ export class AddRobotComponent implements OnInit, OnDestroy { this.isRobotNameValid = true; this.robot = new Robot(); this.nameTooltipText = "ROBOT_ACCOUNT.ROBOT_NAME"; + this.isNeverExpired = false; + this.expiresDate = null; + this.expiresDatePlaceholder = ' '; this.copyAlert.close(); } @@ -137,6 +144,18 @@ export class AddRobotComponent implements OnInit, OnDestroy { this.robot.access.isPullImage = true; this.robot.access.isPushOrPullImage = false; } + if (this.isNeverExpired) { + this.robot.expires_at = NEVER_EXPIRED; + } else { + if (this.expiresDate) { + if (this.expiresDate <= new Date()) { + this.copyAlert.showInlineError("ROBOT_ACCOUNT.INVALID_VALUE"); + return; + } else { + this.robot.expires_at = Math.floor(this.expiresDate.getTime() / ONE_THOUSAND); + } + } + } this.isSubmitOnGoing = true; this.robotService .addRobotAccount( @@ -214,4 +233,23 @@ export class AddRobotComponent implements OnInit, OnDestroy { closeModal() { this.copyToken = false; } + switch() { + if (this.isNeverExpired) { + this.expiresDate = null; + this.translate.get('ROBOT_ACCOUNT.NEVER_EXPIRED').subscribe(value => { + this.expiresDatePlaceholder = value; + }); + } else { + this.expiresDatePlaceholder = ' '; + } + } + get expiresDate(): Date { + return this._expiresDate; + } + set expiresDate(date: Date) { + if (date) { + this.isNeverExpired = false; + } + this._expiresDate = date; + } } diff --git a/src/portal/src/app/project/robot-account/robot-account.component.html b/src/portal/src/app/project/robot-account/robot-account.component.html index 86662c32c..807606220 100644 --- a/src/portal/src/app/project/robot-account/robot-account.component.html +++ b/src/portal/src/app/project/robot-account/robot-account.component.html @@ -54,7 +54,7 @@ {{r.description}} {{r.creation_time | date: 'short'}} - {{r.expires_at * 1000 | date: 'short'}} + {{r.expires_at === -1?("ROBOT_ACCOUNT.NEVER_EXPIRED" | translate):(r.expires_at * 1000 | date: 'short')}} {{pagination.firstItem + 1}} diff --git a/src/portal/src/app/project/robot-account/robot-account.service.ts b/src/portal/src/app/project/robot-account/robot-account.service.ts index 4438a4b27..0ed252511 100644 --- a/src/portal/src/app/project/robot-account/robot-account.service.ts +++ b/src/portal/src/app/project/robot-account/robot-account.service.ts @@ -47,6 +47,7 @@ export class RobotService { let param = { name: robot.name, + expires_at: +robot.expires_at, description: robot.description, access }; diff --git a/src/portal/src/app/project/robot-account/robot.ts b/src/portal/src/app/project/robot-account/robot.ts index 5e859430b..aac69f54f 100644 --- a/src/portal/src/app/project/robot-account/robot.ts +++ b/src/portal/src/app/project/robot-account/robot.ts @@ -5,6 +5,7 @@ export class Robot { description: string; expires_at: number; disabled: boolean; + creation_time?: Date; access: { isPullImage: boolean; isPushOrPullImage: boolean; diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index 065d3bc65..c75c9d377 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -349,7 +349,11 @@ "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.", - "EXPORT_TO_FILE": "export to file" + "EXPORT_TO_FILE": "export to file", + "EXPIRES_AT": "Expires At", + "EXPIRATION_TOOLTIP": "If not set, the expiration time of system configuration will be used", + "INVALID_VALUE": "The value of the expiration time is invalid", + "NEVER_EXPIRED": "Never Expired" }, "WEBHOOK": { "EDIT_BUTTON": "EDIT", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index 47a1a3d53..cda216321 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -350,7 +350,11 @@ "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.", - "EXPORT_TO_FILE": "export to file" + "EXPORT_TO_FILE": "export to file", + "EXPIRES_AT": "Expires At", + "EXPIRATION_TOOLTIP": "If not set, the expiration time of system configuration will be used", + "INVALID_VALUE": "The value of the expiration time is invalid", + "NEVER_EXPIRED": "Never Expired" }, "WEBHOOK": { "EDIT_BUTTON": "EDIT", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 8e33f5312..a75708b73 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -341,7 +341,11 @@ "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.", - "EXPORT_TO_FILE": "export to file" + "EXPORT_TO_FILE": "export to file", + "EXPIRES_AT": "Expires At", + "EXPIRATION_TOOLTIP": "If not set, the expiration time of system configuration will be used", + "INVALID_VALUE": "The value of the expiration time is invalid", + "NEVER_EXPIRED": "Never Expired" }, "WEBHOOK": { "EDIT_BUTTON": "EDIT", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index aebbd34dc..fa8e195c1 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -347,7 +347,11 @@ "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.", - "EXPORT_TO_FILE": "export to file" + "EXPORT_TO_FILE": "export to file", + "EXPIRES_AT": "Expires At", + "EXPIRATION_TOOLTIP": "If not set, the expiration time of system configuration will be used", + "INVALID_VALUE": "The value of the expiration time is invalid", + "NEVER_EXPIRED": "Never Expired" }, "GROUP": { "GROUP": "Grupo", diff --git a/src/portal/src/i18n/lang/tr-tr-lang.json b/src/portal/src/i18n/lang/tr-tr-lang.json index 750f366c5..35eecb3d2 100644 --- a/src/portal/src/i18n/lang/tr-tr-lang.json +++ b/src/portal/src/i18n/lang/tr-tr-lang.json @@ -349,7 +349,11 @@ "DELETION_TITLE": "Robot hesaplarının kaldırılmasını onaylayın", "DELETION_SUMMARY": "Robot hesaplarını silmek istiyor musunuz {{param}}?", "PULL_IS_MUST": "Çekme izni varsayılan olarak kontrol edilir ve değiştirilemez.", - "EXPORT_TO_FILE": "dosyayı dışarı aktar" + "EXPORT_TO_FILE": "dosyayı dışarı aktar", + "EXPIRES_AT": "Expires At", + "EXPIRATION_TOOLTIP": "If not set, the expiration time of system configuration will be used", + "INVALID_VALUE": "The value of the expiration time is invalid", + "NEVER_EXPIRED": "Never Expired" }, "WEBHOOK": { "EDIT_BUTTON": "DÜZENLE", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index f35b0692d..47ebcadae 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -348,7 +348,11 @@ "DELETION_TITLE": "删除账户确认", "DELETION_SUMMARY": "你确认删除机器人账户 {{param}}?", "PULL_IS_MUST": "拉取权限默认选中且不可修改。", - "EXPORT_TO_FILE": "导出到文件中" + "EXPORT_TO_FILE": "导出到文件中", + "EXPIRES_AT": "到期日", + "EXPIRATION_TOOLTIP": "如不设置,将会使用系统设置中的过期时间。", + "INVALID_VALUE": "无效的过期日期", + "NEVER_EXPIRED": "永不过期" }, "WEBHOOK": { "EDIT_BUTTON": "编辑",