mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-08 00:50:28 +08:00
refactor: improve code reuse rate (#1515)
This commit is contained in:
@ -109,7 +109,10 @@ class AdapterEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select virtual={false} style={{width: "100%"}} value={this.state.adapter.organization} onChange={(value => {this.updateAdapterField("organization", value);})}>
|
<Select virtual={false} style={{width: "100%"}} value={this.state.adapter.organization} onChange={(value => {
|
||||||
|
this.getModels(value);
|
||||||
|
this.updateAdapterField("organization", value);
|
||||||
|
})}>
|
||||||
{
|
{
|
||||||
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ class App extends Component {
|
|||||||
menuVisible: false,
|
menuVisible: false,
|
||||||
themeAlgorithm: ["default"],
|
themeAlgorithm: ["default"],
|
||||||
themeData: Setting.ThemeDefault,
|
themeData: Setting.ThemeDefault,
|
||||||
|
logo: this.getLogo(Setting.getAlgorithmNames(Setting.ThemeDefault)),
|
||||||
};
|
};
|
||||||
|
|
||||||
Setting.initServerUrl();
|
Setting.initServerUrl();
|
||||||
@ -330,12 +331,12 @@ class App extends Component {
|
|||||||
{
|
{
|
||||||
this.renderAvatar()
|
this.renderAvatar()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{Setting.isMobile() ? null : Setting.getShortName(this.state.account.displayName)} <DownOutlined />
|
{Setting.isMobile() ? null : Setting.getShortName(this.state.account.displayName)} <DownOutlined />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
@ -484,8 +485,8 @@ class App extends Component {
|
|||||||
|
|
||||||
isStartPages() {
|
isStartPages() {
|
||||||
return window.location.pathname.startsWith("/login") ||
|
return window.location.pathname.startsWith("/login") ||
|
||||||
window.location.pathname.startsWith("/signup") ||
|
window.location.pathname.startsWith("/signup") ||
|
||||||
window.location.pathname === "/";
|
window.location.pathname === "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
renderRouter() {
|
renderRouter() {
|
||||||
@ -559,7 +560,7 @@ class App extends Component {
|
|||||||
<Header style={{padding: "0", marginBottom: "3px", backgroundColor: this.state.themeAlgorithm.includes("dark") ? "black" : "white"}}>
|
<Header style={{padding: "0", marginBottom: "3px", backgroundColor: this.state.themeAlgorithm.includes("dark") ? "black" : "white"}}>
|
||||||
{Setting.isMobile() ? null : (
|
{Setting.isMobile() ? null : (
|
||||||
<Link to={"/"}>
|
<Link to={"/"}>
|
||||||
<div className="logo" style={{background: `url(${this.getLogo(Setting.getAlgorithmNames(this.state.themeData))})`}} />
|
<div className="logo" style={{background: `url(${this.state.logo})`}} />
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
{Setting.isMobile() ?
|
{Setting.isMobile() ?
|
||||||
@ -611,7 +612,7 @@ class App extends Component {
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
}
|
}
|
||||||
}>
|
}>
|
||||||
Powered by <a target="_blank" href="https://casdoor.org" rel="noreferrer"><img style={{paddingBottom: "3px"}} height={"20px"} alt={"Casdoor"} src={this.getLogo(Setting.getAlgorithmNames(this.state.themeData))} /></a>
|
Powered by <a target="_blank" href="https://casdoor.org" rel="noreferrer"><img style={{paddingBottom: "3px"}} height={"20px"} alt={"Casdoor"} src={this.state.logo} /></a>
|
||||||
</Footer>
|
</Footer>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
@ -623,11 +624,11 @@ class App extends Component {
|
|||||||
|
|
||||||
isEntryPages() {
|
isEntryPages() {
|
||||||
return window.location.pathname.startsWith("/signup") ||
|
return window.location.pathname.startsWith("/signup") ||
|
||||||
window.location.pathname.startsWith("/login") ||
|
window.location.pathname.startsWith("/login") ||
|
||||||
window.location.pathname.startsWith("/forget") ||
|
window.location.pathname.startsWith("/forget") ||
|
||||||
window.location.pathname.startsWith("/prompt") ||
|
window.location.pathname.startsWith("/prompt") ||
|
||||||
window.location.pathname.startsWith("/cas") ||
|
window.location.pathname.startsWith("/cas") ||
|
||||||
window.location.pathname.startsWith("/auto-signup");
|
window.location.pathname.startsWith("/auto-signup");
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPage() {
|
renderPage() {
|
||||||
@ -643,12 +644,7 @@ class App extends Component {
|
|||||||
onUpdateAccount={(account) => {
|
onUpdateAccount={(account) => {
|
||||||
this.onUpdateAccount(account);
|
this.onUpdateAccount(account);
|
||||||
}}
|
}}
|
||||||
updataThemeData={(nextThemeData) => {
|
updataThemeData={this.setTheme}
|
||||||
this.setState({
|
|
||||||
themeData: nextThemeData,
|
|
||||||
});
|
|
||||||
localStorage.setItem("themeAlgorithm", Setting.getAlgorithmNames(nextThemeData).toString());
|
|
||||||
}}
|
|
||||||
/> :
|
/> :
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/callback" component={AuthCallback} />
|
<Route exact path="/callback" component={AuthCallback} />
|
||||||
|
@ -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, Col, List, Popconfirm, Result, Row, Table, Tooltip} from "antd";
|
import {Button, Col, List, Popconfirm, Row, Table, Tooltip} from "antd";
|
||||||
import {EditOutlined} from "@ant-design/icons";
|
import {EditOutlined} from "@ant-design/icons";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
@ -25,19 +25,12 @@ import BaseListPage from "./BaseListPage";
|
|||||||
class ApplicationListPage extends BaseListPage {
|
class ApplicationListPage extends BaseListPage {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
}
|
||||||
classes: props,
|
|
||||||
organizationName: props.account.owner,
|
componentDidMount() {
|
||||||
data: [],
|
this.setState({
|
||||||
pagination: {
|
organizationName: this.props.account.owner,
|
||||||
current: 1,
|
});
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
loading: false,
|
|
||||||
searchText: "",
|
|
||||||
searchedColumn: "",
|
|
||||||
isAuthorized: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newApplication() {
|
newApplication() {
|
||||||
@ -259,17 +252,6 @@ class ApplicationListPage extends BaseListPage {
|
|||||||
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.state.isAuthorized) {
|
|
||||||
return (
|
|
||||||
<Result
|
|
||||||
status="403"
|
|
||||||
title="403 Unauthorized"
|
|
||||||
subTitle={i18next.t("general:Sorry, you do not have permission to access this page or logged in status invalid.")}
|
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={applications} rowKey="name" size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={applications} rowKey="name" size="middle" bordered pagination={paginationProps}
|
||||||
|
@ -25,16 +25,14 @@ class ManagedAccountTable extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
managedAccounts: [],
|
managedAccounts: this.props.table !== null ? this.props.table.map((item, index) => {
|
||||||
|
item.key = index;
|
||||||
|
return item;
|
||||||
|
}) : [],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.state.managedAccounts = this.props.table.map((item, index) => {
|
|
||||||
item.key = index;
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
count = this.props.table.length;
|
count = this.props.table?.length ?? 0;
|
||||||
|
|
||||||
updateTable(table) {
|
updateTable(table) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -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, Result, Switch, 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 OrganizationBackend from "./backend/OrganizationBackend";
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
||||||
@ -246,17 +246,6 @@ class OrganizationListPage extends BaseListPage {
|
|||||||
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.state.isAuthorized) {
|
|
||||||
return (
|
|
||||||
<Result
|
|
||||||
status="403"
|
|
||||||
title="403 Unauthorized"
|
|
||||||
subTitle={i18next.t("general:Sorry, you do not have permission to access this page or logged in status invalid.")}
|
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={organizations} rowKey="name" size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={organizations} rowKey="name" size="middle" bordered pagination={paginationProps}
|
||||||
|
@ -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, Result, Table} from "antd";
|
import {Button, Popconfirm, Table} from "antd";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
import * as ProviderBackend from "./backend/ProviderBackend";
|
import * as ProviderBackend from "./backend/ProviderBackend";
|
||||||
@ -25,20 +25,14 @@ import BaseListPage from "./BaseListPage";
|
|||||||
class ProviderListPage extends BaseListPage {
|
class ProviderListPage extends BaseListPage {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
|
||||||
classes: props,
|
|
||||||
owner: Setting.isAdminUser(props.account) ? "admin" : props.account.owner,
|
|
||||||
data: [],
|
|
||||||
pagination: {
|
|
||||||
current: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
loading: false,
|
|
||||||
searchText: "",
|
|
||||||
searchedColumn: "",
|
|
||||||
isAuthorized: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.setState({
|
||||||
|
owner: Setting.isAdminUser(this.props.account) ? "admin" : this.props.account.owner,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
newProvider() {
|
newProvider() {
|
||||||
const randomName = Setting.getRandomName();
|
const randomName = Setting.getRandomName();
|
||||||
return {
|
return {
|
||||||
@ -228,17 +222,6 @@ class ProviderListPage extends BaseListPage {
|
|||||||
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.state.isAuthorized) {
|
|
||||||
return (
|
|
||||||
<Result
|
|
||||||
status="403"
|
|
||||||
title="403 Unauthorized"
|
|
||||||
subTitle={i18next.t("general:Sorry, you do not have permission to access this page or logged in status invalid.")}
|
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={providers} rowKey="name" size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={providers} rowKey="name" size="middle" bordered pagination={paginationProps}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {Button, Popconfirm, Result, Table, Upload} from "antd";
|
import {Button, Popconfirm, Table, Upload} from "antd";
|
||||||
import {UploadOutlined} from "@ant-design/icons";
|
import {UploadOutlined} from "@ant-design/icons";
|
||||||
import copy from "copy-to-clipboard";
|
import copy from "copy-to-clipboard";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
@ -25,20 +25,13 @@ import BaseListPage from "./BaseListPage";
|
|||||||
class ResourceListPage extends BaseListPage {
|
class ResourceListPage extends BaseListPage {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
}
|
||||||
classes: props,
|
|
||||||
data: [],
|
componentDidMount() {
|
||||||
pagination: {
|
this.setState({
|
||||||
current: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
loading: false,
|
|
||||||
searchText: "",
|
|
||||||
searchedColumn: "",
|
|
||||||
fileList: [],
|
fileList: [],
|
||||||
uploading: false,
|
uploading: false,
|
||||||
isAuthorized: true,
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteResource(i) {
|
deleteResource(i) {
|
||||||
@ -273,17 +266,6 @@ class ResourceListPage extends BaseListPage {
|
|||||||
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.state.isAuthorized) {
|
|
||||||
return (
|
|
||||||
<Result
|
|
||||||
status="403"
|
|
||||||
title="403 Unauthorized"
|
|
||||||
subTitle={i18next.t("general:Sorry, you do not have permission to access this page or logged in status invalid.")}
|
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={resources} rowKey="name" size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={resources} rowKey="name" size="middle" bordered pagination={paginationProps}
|
||||||
|
@ -182,7 +182,10 @@ class UserEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select virtual={false} style={{width: "100%"}} disabled={disabled} value={this.state.user.owner} onChange={(value => {this.updateUserField("owner", value);})}>
|
<Select virtual={false} style={{width: "100%"}} disabled={disabled} value={this.state.user.owner} onChange={(value => {
|
||||||
|
this.getApplicationsByOrganization(value);
|
||||||
|
this.updateUserField("owner", value);
|
||||||
|
})}>
|
||||||
{
|
{
|
||||||
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
||||||
}
|
}
|
||||||
|
@ -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, Result, Switch, Table, Upload} from "antd";
|
import {Button, Popconfirm, Switch, Table, Upload} from "antd";
|
||||||
import {UploadOutlined} from "@ant-design/icons";
|
import {UploadOutlined} from "@ant-design/icons";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
||||||
@ -26,20 +26,13 @@ import BaseListPage from "./BaseListPage";
|
|||||||
class UserListPage extends BaseListPage {
|
class UserListPage extends BaseListPage {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
}
|
||||||
classes: props,
|
|
||||||
organizationName: props.match.params.organizationName,
|
componentDidMount() {
|
||||||
|
this.setState({
|
||||||
|
organizationName: this.props.match.params.organizationName,
|
||||||
organization: null,
|
organization: null,
|
||||||
data: [],
|
});
|
||||||
pagination: {
|
|
||||||
current: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
loading: false,
|
|
||||||
searchText: "",
|
|
||||||
searchedColumn: "",
|
|
||||||
isAuthorized: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newUser() {
|
newUser() {
|
||||||
@ -371,17 +364,6 @@ class UserListPage extends BaseListPage {
|
|||||||
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.state.isAuthorized) {
|
|
||||||
return (
|
|
||||||
<Result
|
|
||||||
status="403"
|
|
||||||
title="403 Unauthorized"
|
|
||||||
subTitle={i18next.t("general:Sorry, you do not have permission to access this page or logged in status invalid.")}
|
|
||||||
extra={<a href="/"><Button type="primary">{i18next.t("general:Back Home")}</Button></a>}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table scroll={{x: "max-content"}} columns={columns} dataSource={users} rowKey={(record) => `${record.owner}/${record.name}`} size="middle" bordered pagination={paginationProps}
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={users} rowKey={(record) => `${record.owner}/${record.name}`} size="middle" bordered pagination={paginationProps}
|
||||||
|
Reference in New Issue
Block a user