From dde12182426a1c4ae90f34b2956ff35a10a20a0b Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 8 Jun 2022 15:20:23 +0800 Subject: [PATCH] fix: i18n and validator for zun 1. Add Chinese translation in zun 2. Add validator for template file in zun capsule Change-Id: Icb4bb98978e1a74a22f347e7f6b471ed0266fec8 --- src/locales/en.json | 1 + src/locales/zh.json | 15 ++++---- .../containers/Capsules/Detail/BaseDetail.jsx | 4 ++- .../containers/Capsules/actions/Create.jsx | 35 ++++++++----------- src/resources/zun/capsule.js | 14 ++++++++ src/resources/zun/container.js | 14 ++++++++ 6 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index f866d52d..2ddb347f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1668,6 +1668,7 @@ "Please input key size": "Please input key size", "Please input metadata": "Please input metadata", "Please input name": "Please input name", + "Please input or load Template from a file": "Please input or load Template from a file", "Please input port range": "Please input port range", "Please input prefix": "Please input prefix", "Please input protocol number if it absent in select list.": "Please input protocol number if it absent in select list.", diff --git a/src/locales/zh.json b/src/locales/zh.json index 0dd66c9c..9a984d52 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -292,9 +292,9 @@ "Cancel upload successfully.": "取消上传成功。", "Capacity (GiB)": "容量(GiB)", "Cape Verde": "佛得角", - "Capsule Detail": "Capsule 详情", - "Capsule Type": "Capsule 类型", - "Capsules": "Capsules", + "Capsule Detail": "集合详情", + "Capsule Type": "集合类型", + "Capsules": "集合", "Cast Rules To Read Only": "规则强制只读", "Category": "类别", "Cayman Islands": "开曼群岛", @@ -449,7 +449,7 @@ "Create Backups": "创建备份", "Create Bandwidth Limit Rule": "创建带宽限制规则", "Create Bare Metal Node": "创建裸机节点", - "Create Capsule": "创建 Capsule", + "Create Capsule": "创建集合", "Create Certificate": "创建证书", "Create Cluster": "创建集群", "Create Cluster Template": "创建集群模板", @@ -603,7 +603,7 @@ "Delete Backup": "删除备份", "Delete Bandwidth Egress Rules": "删除带宽出方向限制", "Delete Bandwidth Ingress Rules": "删除带宽入方向限制", - "Delete Capsule": "删除 Capsule", + "Delete Capsule": "删除集合", "Delete Certificate": "删除证书", "Delete Clusters": "删除集群", "Delete Clusters Templates": "删除集群模板", @@ -1410,7 +1410,7 @@ "Min. Disk": "最小硬盘大小", "Min. RAM": "最小内存", "Minimum value is 68 for IPv4, and 1280 for IPv6.": "对于IPv4,最小值是68,对于IPv6,最小值是1280。", - "Miscellaneous": "Miscellaneous", + "Miscellaneous": "杂项", "Missing IP Address": "缺少IP地址", "Missing Port": "未填写端口号", "Missing Subnet": "未填写子网", @@ -1668,6 +1668,7 @@ "Please input key size": "请输入密钥大小", "Please input metadata": "请输入元数据", "Please input name": "请输入名称", + "Please input or load Template from a file": "请输入或者从文件加载模板", "Please input port range": "请输入端口范围", "Please input prefix": "请输入前缀", "Please input protocol number if it absent in select list.": "如果选择列表中没有,请输入协议号。", @@ -2526,7 +2527,7 @@ "be soft rebooted": "软重启", "be started": "启动", "be stopped": "关闭", - "capsules": "capsules", + "capsules": "集合", "certificate": "证书", "cidr": "CIDR", "cinder services": "存储服务", diff --git a/src/pages/container-service/containers/Capsules/Detail/BaseDetail.jsx b/src/pages/container-service/containers/Capsules/Detail/BaseDetail.jsx index ac07b14c..f43706c7 100644 --- a/src/pages/container-service/containers/Capsules/Detail/BaseDetail.jsx +++ b/src/pages/container-service/containers/Capsules/Detail/BaseDetail.jsx @@ -55,7 +55,7 @@ export class BaseDetail extends Base { value.map((it) => { return (
- {t('Name')} : {it.name} + {t('Container Name')} : {it.name}
{t('Container ID')}: {it.uuid}
@@ -67,6 +67,8 @@ export class BaseDetail extends Base { return { title: t('Containers'), options, + labelCol: 0, + contentCol: 24, }; } diff --git a/src/pages/container-service/containers/Capsules/actions/Create.jsx b/src/pages/container-service/containers/Capsules/actions/Create.jsx index fe0b1072..abaf3117 100644 --- a/src/pages/container-service/containers/Capsules/actions/Create.jsx +++ b/src/pages/container-service/containers/Capsules/actions/Create.jsx @@ -1,4 +1,4 @@ -// Copyright 2021 99cloud +// Copyright 2022 99cloud // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ export class Create extends ModalAction { init() { this.store = globalCapsulesStore; - this.maxSize = 1; } static allowed = () => Promise.resolve(true); @@ -41,37 +40,33 @@ export class Create extends ModalAction { static policy = 'container:capsule:create'; - sizeValidate = (rule, value) => { - if (!value) { - return Promise.reject(t('Please select a file')); - } - const { size } = value; - if (size <= this.maxSize * 1024 * 1024 * 1024) { - return Promise.resolve(); - } - return Promise.reject( - t( - 'Please upload files smaller than { size }G on the page. It is recommended to upload files over { size }G using API.', - { size: this.maxSize } - ) - ); - }; - get formItems() { return [ { name: 'template_file', label: t('Load Template from a file'), type: 'textarea-from-file', + rows: 6, + required: true, + accept: '.yaml', + validator: (rule, value) => { + if (!value) { + // eslint-disable-next-line prefer-promise-reject-errors + return Promise.reject( + t('Please input or load Template from a file') + ); + } + return Promise.resolve(); + }, }, ]; } onSubmit = (values) => { - const y = getYaml(values.template_file); + const template = getYaml(values.template_file); return this.store.create({ - template: y, + template, }); }; } diff --git a/src/resources/zun/capsule.js b/src/resources/zun/capsule.js index 6ea24e54..a6c22d3e 100644 --- a/src/resources/zun/capsule.js +++ b/src/resources/zun/capsule.js @@ -1,3 +1,17 @@ +// Copyright 2022 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + export const capsuleStatus = { Creating: t('Creating'), Pending: t('Pending'), diff --git a/src/resources/zun/container.js b/src/resources/zun/container.js index 5c9b662f..609a9ed6 100644 --- a/src/resources/zun/container.js +++ b/src/resources/zun/container.js @@ -1,3 +1,17 @@ +// Copyright 2022 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + export const containerStatus = { Creating: t('Creating'), Created: t('Created'),