Add missing fields for record.

This commit is contained in:
Gucheng Wang 2021-11-07 17:36:52 +08:00
parent 5ec678fa28
commit e9e0721b34
2 changed files with 37 additions and 22 deletions

View File

@ -24,9 +24,12 @@ import (
type Record struct {
Id int `xorm:"int notnull pk autoincr" json:"id"`
ClientIp string `xorm:"varchar(100)" json:"clientIp"`
Timestamp string `xorm:"varchar(100)" json:"timestamp"`
Owner string `xorm:"varchar(100) index" json:"owner"`
Name string `xorm:"varchar(100) index" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
Organization string `xorm:"varchar(100)" json:"organization"`
ClientIp string `xorm:"varchar(100)" json:"clientIp"`
User string `xorm:"varchar(100)" json:"user"`
RequestUri string `xorm:"varchar(1000)" json:"requestUri"`
Action string `xorm:"varchar(1000)" json:"action"`
@ -37,17 +40,19 @@ func NewRecord(ctx *context.Context) *Record {
action := strings.Replace(ctx.Request.URL.Path, "/api/", "", -1)
record := Record{
ClientIp: ip,
Timestamp: util.GetCurrentTime(),
RequestUri: ctx.Request.RequestURI,
User: "",
Organization: "",
Action: action,
Name: util.GenerateId(),
CreatedTime: util.GetCurrentTime(),
ClientIp: ip,
RequestUri: ctx.Request.RequestURI,
User: "",
Action: action,
}
return &record
}
func AddRecord(record *Record) bool {
record.Owner = record.Organization
affected, err := adapter.Engine.Insert(record)
if err != nil {
panic(err)

View File

@ -18,6 +18,7 @@ import {Table} from 'antd';
import * as Setting from "./Setting";
import * as RecordBackend from "./backend/RecordBackend";
import i18next from "i18next";
import moment from "moment";
class RecordListPage extends React.Component {
constructor(props) {
@ -47,38 +48,47 @@ class RecordListPage extends React.Component {
newRecord() {
return {
id : "",
clientIp: "",
timestamp: "",
organization: "",
username: "",
requestUri: "",
owner: "built-in",
name: "1234",
id : "1234",
clientIp: "::1",
timestamp: moment().format(),
organization: "built-in",
username: "admin",
requestUri: "/api/get-account",
action: "login",
}
}
renderTable(records) {
const columns = [
{
title: i18next.t("general:Name"),
dataIndex: 'name',
key: 'name',
width: '220px',
sorter: (a, b) => a.name.localeCompare(b.name),
},
{
title: i18next.t("general:ID"),
dataIndex: 'id',
key: 'id',
width: '120px',
width: '100px',
sorter: (a, b) => a.id - b.id,
},
{
title: i18next.t("general:Client IP"),
dataIndex: 'clientIp',
key: 'clientIp',
width: '120px',
width: '100px',
sorter: (a, b) => a.clientIp.localeCompare(b.clientIp),
},
{
title: i18next.t("general:Timestamp"),
dataIndex: 'timestamp',
key: 'timestamp',
width: '160px',
sorter: (a, b) => a.timestamp.localeCompare(b.timestamp),
dataIndex: 'createdTime',
key: 'createdTime',
width: '120px',
sorter: (a, b) => a.createdTime.localeCompare(b.createdTime),
render: (text, record, index) => {
return Setting.getFormattedDate(text);
}
@ -101,14 +111,14 @@ class RecordListPage extends React.Component {
title: i18next.t("general:User"),
dataIndex: 'user',
key: 'user',
width: '160px',
width: '120px',
sorter: (a, b) => a.user.localeCompare(b.user),
},
{
title: i18next.t("general:Request URI"),
dataIndex: 'requestUri',
key: 'requestUri',
width: '160px',
width: '250px',
sorter: (a, b) => a.requestUri.localeCompare(b.requestUri),
},
{