2021-07-07 14:59:03 +08:00
|
|
|
// Copyright 2021 The casbin 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 {Link} from "react-router-dom";
|
2021-07-25 11:10:45 +08:00
|
|
|
import {Table} from 'antd';
|
2021-07-07 14:59:03 +08:00
|
|
|
import * as Setting from "./Setting";
|
|
|
|
import * as RecordBackend from "./backend/RecordBackend";
|
|
|
|
import i18next from "i18next";
|
|
|
|
|
|
|
|
class RecordListPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
classes: props,
|
|
|
|
records: null,
|
2021-11-06 11:32:22 +08:00
|
|
|
total: 0,
|
2021-07-07 14:59:03 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
UNSAFE_componentWillMount() {
|
2021-11-06 11:32:22 +08:00
|
|
|
this.getRecords(1, 10);
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-06 11:32:22 +08:00
|
|
|
getRecords(page, pageSize) {
|
|
|
|
RecordBackend.getRecords(page, pageSize)
|
2021-07-07 14:59:03 +08:00
|
|
|
.then((res) => {
|
2021-11-06 11:32:22 +08:00
|
|
|
if (res.status === "ok") {
|
|
|
|
this.setState({
|
|
|
|
records: res.data,
|
|
|
|
total: res.data2
|
|
|
|
});
|
|
|
|
}
|
2021-07-07 14:59:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
newRecord() {
|
|
|
|
return {
|
|
|
|
id : "",
|
|
|
|
Record:{
|
|
|
|
clientIp:"",
|
|
|
|
timestamp:"",
|
|
|
|
organization:"",
|
|
|
|
username:"",
|
|
|
|
requestUri:"",
|
|
|
|
action:"login",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTable(records) {
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Client ip"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'clientIp'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '120px',
|
2021-07-23 09:46:01 +08:00
|
|
|
fixed: 'left',
|
2021-07-07 14:59:03 +08:00
|
|
|
sorter: (a, b) => a.Record.clientIp.localeCompare(b.Record.clientIp),
|
|
|
|
render: (text, record, index) => {
|
2021-07-16 17:04:16 +08:00
|
|
|
return text;
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Timestamp"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'timestamp'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '160px',
|
|
|
|
sorter: (a, b) => a.Record.timestamp.localeCompare(b.Record.timestamp),
|
|
|
|
render: (text, record, index) => {
|
2021-07-16 17:04:16 +08:00
|
|
|
return Setting.getFormattedDate(text);
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Organization"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'organization'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '120px',
|
|
|
|
sorter: (a, b) => a.Record.organization.localeCompare(b.Record.organization),
|
|
|
|
render: (text, record, index) => {
|
|
|
|
return (
|
2021-07-16 17:04:16 +08:00
|
|
|
<Link to={`/organizations/${text}`}>
|
|
|
|
{text}
|
2021-07-07 14:59:03 +08:00
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Username"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'username'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '160px',
|
|
|
|
sorter: (a, b) => a.Record.username.localeCompare(b.Record.username),
|
|
|
|
render: (text, record, index) => {
|
2021-07-16 17:04:16 +08:00
|
|
|
return text;
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Request uri"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'requestUri'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '160px',
|
|
|
|
sorter: (a, b) => a.Record.requestUri.localeCompare(b.Record.requestUri),
|
|
|
|
render: (text, record, index) => {
|
2021-07-16 17:04:16 +08:00
|
|
|
return text;
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: i18next.t("general:Action"),
|
2021-07-16 17:04:16 +08:00
|
|
|
dataIndex: ['Record', 'action'],
|
|
|
|
key: 'id',
|
2021-07-07 14:59:03 +08:00
|
|
|
width: '160px',
|
|
|
|
sorter: (a, b) => a.Record.action.localeCompare(b.Record.action),
|
|
|
|
render: (text, record, index) => {
|
2021-07-16 17:04:16 +08:00
|
|
|
return text;
|
2021-07-07 14:59:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-11-06 11:32:22 +08:00
|
|
|
const paginationProps = {
|
|
|
|
total: this.state.total,
|
|
|
|
showQuickJumper: true,
|
|
|
|
showSizeChanger: true,
|
|
|
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.total),
|
|
|
|
onChange: (page, pageSize) => this.getRecords(page, pageSize),
|
|
|
|
onShowSizeChange: (current, size) => this.getRecords(current, size),
|
|
|
|
};
|
|
|
|
|
2021-07-07 14:59:03 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2021-11-06 11:32:22 +08:00
|
|
|
<Table scroll={{x: 'max-content'}} columns={columns} dataSource={records} rowKey="id" size="middle" bordered pagination={paginationProps}
|
2021-07-07 14:59:03 +08:00
|
|
|
title={() => (
|
|
|
|
<div>
|
|
|
|
{i18next.t("general:Records")}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
loading={records === null}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2021-07-23 09:46:01 +08:00
|
|
|
{
|
|
|
|
this.renderTable(this.state.records)
|
|
|
|
}
|
2021-07-07 14:59:03 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RecordListPage;
|