Add more fields to syncer.

This commit is contained in:
Gucheng Wang
2021-12-17 20:33:03 +08:00
parent c2110ef59d
commit 07f9a9ee96
4 changed files with 84 additions and 21 deletions

View File

@ -39,7 +39,7 @@ func (c *ApiController) GetSyncers() {
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetSyncerCount(owner))) paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetSyncerCount(owner)))
syncers := object.GetPaginationSyncers(owner, paginator.Offset(), limit) syncers := object.GetMaskedSyncers(object.GetPaginationSyncers(owner, paginator.Offset(), limit))
c.ResponseOk(syncers, paginator.Nums()) c.ResponseOk(syncers, paginator.Nums())
} }
} }
@ -53,7 +53,7 @@ func (c *ApiController) GetSyncers() {
func (c *ApiController) GetSyncer() { func (c *ApiController) GetSyncer() {
id := c.Input().Get("id") id := c.Input().Get("id")
c.Data["json"] = object.GetSyncer(id) c.Data["json"] = object.GetMaskedSyncer(object.GetSyncer(id))
c.ServeJSON() c.ServeJSON()
} }

View File

@ -35,8 +35,10 @@ type Syncer struct {
Password string `xorm:"varchar(100)" json:"password"` Password string `xorm:"varchar(100)" json:"password"`
Database string `xorm:"varchar(100)" json:"database"` Database string `xorm:"varchar(100)" json:"database"`
Table string `xorm:"varchar(100)" json:"table"` Table string `xorm:"varchar(100)" json:"table"`
AffiliationTable string `xorm:"varchar(100)" json:"affiliationTable"`
AvatarBaseUrl string `xorm:"varchar(100)" json:"avatarBaseUrl"`
SyncInterval int `json:"syncInterval"` SyncInterval int `json:"syncInterval"`
IsEnabled bool `json:"isEnabled"`
} }
func GetSyncerCount(owner string) int { func GetSyncerCount(owner string) int {
@ -91,6 +93,24 @@ func GetSyncer(id string) *Syncer {
return getSyncer(owner, name) return getSyncer(owner, name)
} }
func GetMaskedSyncer(syncer *Syncer) *Syncer {
if syncer == nil {
return nil
}
if syncer.Password != "" {
syncer.Password = "***"
}
return syncer
}
func GetMaskedSyncers(syncers []*Syncer) []*Syncer {
for _, syncer := range syncers {
syncer = GetMaskedSyncer(syncer)
}
return syncers
}
func UpdateSyncer(id string, syncer *Syncer) bool { func UpdateSyncer(id string, syncer *Syncer) bool {
owner, name := util.GetOwnerAndNameFromId(id) owner, name := util.GetOwnerAndNameFromId(id)
if getSyncer(owner, name) == nil { if getSyncer(owner, name) == nil {

View File

@ -13,7 +13,8 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Button, Card, Col, Input, InputNumber, Row, Select} from 'antd'; import {Button, Card, Col, Input, InputNumber, Row, Select, Switch} from 'antd';
import {LinkOutlined} from "@ant-design/icons";
import * as SyncerBackend from "./backend/SyncerBackend"; import * as SyncerBackend from "./backend/SyncerBackend";
import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
@ -176,6 +177,26 @@ class SyncerEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("syncer:Affiliation table"), i18next.t("syncer:Affiliation table - Tooltip"))} :
</Col>
<Col span={22} >
<Input value={this.state.syncer.affiliationTable} onChange={e => {
this.updateSyncerField('affiliationTable', e.target.value);
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("syncer:Avatar base URL"), i18next.t("syncer:Avatar base URL - Tooltip"))} :
</Col>
<Col span={22} >
<Input prefix={<LinkOutlined/>} value={this.state.syncer.avatarBaseUrl} onChange={e => {
this.updateSyncerField('avatarBaseUrl', e.target.value);
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}> <Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("syncer:Sync interval"), i18next.t("syncer:Sync interval - Tooltip"))} : {Setting.getLabel(i18next.t("syncer:Sync interval"), i18next.t("syncer:Sync interval - Tooltip"))} :
@ -186,6 +207,16 @@ class SyncerEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("syncer:Is enabled"), i18next.t("syncer:Is enabled - Tooltip"))} :
</Col>
<Col span={1} >
<Switch checked={this.state.syncer.isEnabled} onChange={checked => {
this.updateSyncerField('isEnabled', checked);
}} />
</Col>
</Row>
</Card> </Card>
) )
} }

View File

@ -14,7 +14,7 @@
import React from "react"; import React from "react";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Button, Popconfirm, Table} from 'antd'; import {Button, Popconfirm, Switch, Table} from 'antd';
import moment from "moment"; import moment from "moment";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
import * as SyncerBackend from "./backend/SyncerBackend"; import * as SyncerBackend from "./backend/SyncerBackend";
@ -102,7 +102,7 @@ class SyncerListPage extends React.Component {
title: i18next.t("general:Organization"), title: i18next.t("general:Organization"),
dataIndex: 'organization', dataIndex: 'organization',
key: 'organization', key: 'organization',
width: '80px', width: '120px',
sorter: (a, b) => a.organization.localeCompare(b.organization), sorter: (a, b) => a.organization.localeCompare(b.organization),
render: (text, record, index) => { render: (text, record, index) => {
return ( return (
@ -141,58 +141,70 @@ class SyncerListPage extends React.Component {
title: i18next.t("provider:Type"), title: i18next.t("provider:Type"),
dataIndex: 'type', dataIndex: 'type',
key: 'type', key: 'type',
width: '150px', width: '100px',
sorter: (a, b) => a.type.localeCompare(b.type), sorter: (a, b) => a.type.localeCompare(b.type),
}, },
{ {
title: i18next.t("provider:Host"), title: i18next.t("provider:Host"),
dataIndex: 'host', dataIndex: 'host',
key: 'host', key: 'host',
width: '150px', width: '120px',
sorter: (a, b) => a.host.localeCompare(b.host), sorter: (a, b) => a.host.localeCompare(b.host),
}, },
{ {
title: i18next.t("provider:Port"), title: i18next.t("provider:Port"),
dataIndex: 'port', dataIndex: 'port',
key: 'port', key: 'port',
width: '150px', width: '100px',
sorter: (a, b) => a.port - b.port, sorter: (a, b) => a.port - b.port,
}, },
{ {
title: i18next.t("general:User"), title: i18next.t("general:User"),
dataIndex: 'user', dataIndex: 'user',
key: 'user', key: 'user',
width: '150px', width: '120px',
sorter: (a, b) => a.user.localeCompare(b.user), sorter: (a, b) => a.user.localeCompare(b.user),
}, },
{ {
title: i18next.t("general:Password"), title: i18next.t("general:Password"),
dataIndex: 'password', dataIndex: 'password',
key: 'password', key: 'password',
width: '150px', width: '120px',
sorter: (a, b) => a.password.localeCompare(b.password), sorter: (a, b) => a.password.localeCompare(b.password),
}, },
{ {
title: i18next.t("syncer:Database"), title: i18next.t("syncer:Database"),
dataIndex: 'database', dataIndex: 'database',
key: 'database', key: 'database',
width: '150px', width: '120px',
sorter: (a, b) => a.database.localeCompare(b.database), sorter: (a, b) => a.database.localeCompare(b.database),
}, },
{ {
title: i18next.t("syncer:Table"), title: i18next.t("syncer:Table"),
dataIndex: 'table', dataIndex: 'table',
key: 'table', key: 'table',
width: '150px', width: '120px',
sorter: (a, b) => a.table.localeCompare(b.table), sorter: (a, b) => a.table.localeCompare(b.table),
}, },
{ {
title: i18next.t("syncer:Sync interval"), title: i18next.t("syncer:Sync interval"),
dataIndex: 'syncInterval', dataIndex: 'syncInterval',
key: 'syncInterval', key: 'syncInterval',
width: '150px', width: '120px',
sorter: (a, b) => a.syncInterval.localeCompare(b.syncInterval), sorter: (a, b) => a.syncInterval.localeCompare(b.syncInterval),
}, },
{
title: i18next.t("record:Is Enabled"),
dataIndex: 'isEnabled',
key: 'isEnabled',
width: '120px',
sorter: (a, b) => a.isEnabled - b.isEnabled,
render: (text, record, index) => {
return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} />
)
}
},
{ {
title: i18next.t("general:Action"), title: i18next.t("general:Action"),
dataIndex: '', dataIndex: '',