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 { type Record struct {
Id int `xorm:"int notnull pk autoincr" json:"id"` Id int `xorm:"int notnull pk autoincr" json:"id"`
ClientIp string `xorm:"varchar(100)" json:"clientIp"` Owner string `xorm:"varchar(100) index" json:"owner"`
Timestamp string `xorm:"varchar(100)" json:"timestamp"` Name string `xorm:"varchar(100) index" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
Organization string `xorm:"varchar(100)" json:"organization"` Organization string `xorm:"varchar(100)" json:"organization"`
ClientIp string `xorm:"varchar(100)" json:"clientIp"`
User string `xorm:"varchar(100)" json:"user"` User string `xorm:"varchar(100)" json:"user"`
RequestUri string `xorm:"varchar(1000)" json:"requestUri"` RequestUri string `xorm:"varchar(1000)" json:"requestUri"`
Action string `xorm:"varchar(1000)" json:"action"` 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) action := strings.Replace(ctx.Request.URL.Path, "/api/", "", -1)
record := Record{ record := Record{
ClientIp: ip, Name: util.GenerateId(),
Timestamp: util.GetCurrentTime(), CreatedTime: util.GetCurrentTime(),
RequestUri: ctx.Request.RequestURI, ClientIp: ip,
User: "", RequestUri: ctx.Request.RequestURI,
Organization: "", User: "",
Action: action, Action: action,
} }
return &record return &record
} }
func AddRecord(record *Record) bool { func AddRecord(record *Record) bool {
record.Owner = record.Organization
affected, err := adapter.Engine.Insert(record) affected, err := adapter.Engine.Insert(record)
if err != nil { if err != nil {
panic(err) panic(err)

View File

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