feat: edit user properties (#1435)

This commit is contained in:
Yaodong Yu
2022-12-31 15:27:53 +08:00
committed by GitHub
parent 7bbe1e38c1
commit d498bc60ce
9 changed files with 155 additions and 10 deletions

View File

@ -28,11 +28,7 @@ import SamlWidget from "./common/SamlWidget";
import SelectRegionBox from "./SelectRegionBox";
import WebAuthnCredentialTable from "./WebauthnCredentialTable";
import ManagedAccountTable from "./ManagedAccountTable";
import {Controlled as CodeMirror} from "react-codemirror2";
import "codemirror/lib/codemirror.css";
require("codemirror/theme/material-darker.css");
require("codemirror/mode/javascript/javascript");
import PropertyTable from "./propertyTable";
const {Option} = Select;
@ -490,13 +486,10 @@ class UserEditPage extends React.Component {
return (
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
{i18next.t("user:Properties")}:
{Setting.getLabel(i18next.t("user:Properties"), i18next.t("user:Properties - Tooltip"))} :
</Col>
<Col span={22} >
<CodeMirror
value={JSON.stringify(this.state.user.properties, null, 4)}
options={{mode: "javascript", theme: "material-darker"}}
/>
<PropertyTable properties={this.state.user.properties} onUpdateTable={(value) => {this.updateUserField("properties", value);}} />
</Col>
</Row>
);

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Whether the account is disabled",
"Is global admin": "Ist globaler Admin",
"Is global admin - Tooltip": "Is the application global administrator",
"Keys": "Keys",
"Link": "Link",
"Location": "Standort",
"Location - Tooltip": "Standort - Tooltip",
@ -741,6 +742,7 @@
"Password Set": "Passwort setzen",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "Eigenschaften",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "Neu erneut eingeben",
"Reset Email...": "Reset Email...",
"Reset Phone...": "Telefon zurücksetzen...",
@ -756,6 +758,7 @@
"Unlink": "Link aufheben",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Foto hochladen",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "Passwort eingeben"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Is forbidden - Tooltip",
"Is global admin": "Is global admin",
"Is global admin - Tooltip": "Is global admin - Tooltip",
"Keys": "Keys",
"Link": "Link",
"Location": "Location",
"Location - Tooltip": "Location - Tooltip",
@ -741,6 +742,7 @@
"Password Set": "Password Set",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "Properties",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "Re-enter New",
"Reset Email...": "Reset Email...",
"Reset Phone...": "Reset Phone...",
@ -756,6 +758,7 @@
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "input password"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Whether the account is disabled",
"Is global admin": "Est un administrateur global",
"Is global admin - Tooltip": "Is the application global administrator",
"Keys": "Keys",
"Link": "Lier",
"Location": "Localisation",
"Location - Tooltip": "Localisation - Infobulle",
@ -741,6 +742,7 @@
"Password Set": "Mot de passe défini",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "Propriétés",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "Nouvelle entrée",
"Reset Email...": "Reset Email...",
"Reset Phone...": "Réinitialiser le téléphone...",
@ -756,6 +758,7 @@
"Unlink": "Délier",
"Upload (.xlsx)": "Télécharger (.xlsx)",
"Upload a photo": "Télécharger une photo",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "saisir le mot de passe"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Whether the account is disabled",
"Is global admin": "グローバル管理者",
"Is global admin - Tooltip": "Is the application global administrator",
"Keys": "Keys",
"Link": "リンク",
"Location": "場所",
"Location - Tooltip": "場所 → ツールチップ",
@ -741,6 +742,7 @@
"Password Set": "パスワード設定",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "プロパティー",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "新しい入力",
"Reset Email...": "Reset Email...",
"Reset Phone...": "電話番号をリセット...",
@ -756,6 +758,7 @@
"Unlink": "リンクを解除",
"Upload (.xlsx)": "アップロード (.xlsx)",
"Upload a photo": "写真をアップロード",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "パスワードを入力"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Whether the account is disabled",
"Is global admin": "Is global admin",
"Is global admin - Tooltip": "Is the application global administrator",
"Keys": "Keys",
"Link": "Link",
"Location": "Location",
"Location - Tooltip": "Location - Tooltip",
@ -741,6 +742,7 @@
"Password Set": "Password Set",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "Properties",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "Re-enter New",
"Reset Email...": "Reset Email...",
"Reset Phone...": "Reset Phone...",
@ -756,6 +758,7 @@
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "input password"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "Whether the account is disabled",
"Is global admin": "Глобальный администратор",
"Is global admin - Tooltip": "Is the application global administrator",
"Keys": "Keys",
"Link": "Ссылка",
"Location": "Местоположение",
"Location - Tooltip": "Расположение - Подсказка",
@ -741,6 +742,7 @@
"Password Set": "Пароль установлен",
"Please select avatar from resources": "Please select avatar from resources",
"Properties": "Свойства",
"Properties - Tooltip": "Properties - Tooltip",
"Re-enter New": "Введите еще раз",
"Reset Email...": "Reset Email...",
"Reset Phone...": "Сбросить телефон...",
@ -756,6 +758,7 @@
"Unlink": "Отвязать",
"Upload (.xlsx)": "Загрузить (.xlsx)",
"Upload a photo": "Загрузить фото",
"Values": "Values",
"WebAuthn credentials": "WebAuthn credentials",
"input password": "пароль для ввода"
},

View File

@ -726,6 +726,7 @@
"Is forbidden - Tooltip": "账户是否已被禁用",
"Is global admin": "是全局管理员",
"Is global admin - Tooltip": "是应用程序管理员",
"Keys": "键",
"Link": "绑定",
"Location": "城市",
"Location - Tooltip": "居住地址所在的城市",
@ -741,6 +742,7 @@
"Password Set": "密码已设置",
"Please select avatar from resources": "从资源中选择...",
"Properties": "属性",
"Properties - Tooltip": "属性",
"Re-enter New": "重复新密码",
"Reset Email...": "重置邮箱...",
"Reset Phone...": "重置手机号...",
@ -756,6 +758,7 @@
"Unlink": "解绑",
"Upload (.xlsx)": "上传(.xlsx",
"Upload a photo": "上传头像",
"Values": "值",
"WebAuthn credentials": "WebAuthn凭据",
"input password": "输入密码"
},

131
web/src/propertyTable.js Normal file
View File

@ -0,0 +1,131 @@
// Copyright 2022 The Casdoor Authors. All Rights Reserved.
//
// 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.
import React from "react";
import {Button, Input, Table} from "antd";
import i18next from "i18next";
import {DeleteOutlined} from "@ant-design/icons";
import * as Setting from "./Setting";
class PropertyTable extends React.Component {
constructor(props) {
super(props);
this.state = {
properties: [],
count: Object.entries(this.props.properties).length,
};
// transfer the Object to object[]
Object.entries(this.props.properties).map((item, index) => {
this.state.properties.push({key: index, name: item[0], value: item[1]});
});
}
page = 1;
updateTable(table) {
this.setState({properties: table});
const properties = {};
table.map((item) => {
properties[item.name] = item.value;
});
this.props.onUpdateTable(properties);
}
addRow(table) {
const row = {key: this.state.count, name: "", value: ""};
if (table === undefined) {
table = [];
}
table = Setting.addRow(table, row);
this.setState({count: this.state.count + 1});
this.updateTable(table);
}
deleteRow(table, index) {
table = Setting.deleteRow(table, this.getIndex(index));
this.updateTable(table);
}
getIndex(index) {
// Parameter is the row index in table, need to calculate the index in dataSource. 10 is the pageSize.
return index + (this.page - 1) * 10;
}
updateField(table, index, key, value) {
table[this.getIndex(index)][key] = value;
this.updateTable(table);
}
renderTable(table) {
const columns = [
{
title: i18next.t("user:Keys"),
dataIndex: "name",
width: "200px",
render: (text, record, index) => {
return (
<Input value={text} onChange={e => {
this.updateField(table, index, "name", e.target.value);
}} />
);
},
},
{
title: i18next.t("user:Values"),
dataIndex: "value",
width: "200px",
render: (text, record, index) => {
return (
<Input value={text} onChange={e => {
this.updateField(table, index, "value", e.target.value);
}} />
);
},
},
{
title: i18next.t("general:Action"),
dataIndex: "operation",
width: "20px",
render: (text, record, index) => {
return (
<Button icon={<DeleteOutlined />} size="small" onClick={() => this.deleteRow(table, index)} />
);
},
},
];
return (
<Table title={() => (
<div>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
</div>
)}
pagination={{onChange: page => {this.page = page;}}}
columns={columns} dataSource={table} rowKey="key" size="middle" bordered
/>
);
}
render() {
return (
<React.Fragment>
{
this.renderTable(this.state.properties)
}
</React.Fragment>
);
}
}
export default PropertyTable;