2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { compose } from "redux";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2020-02-26 15:45:24 +01:00
|
|
|
import { Redirect, Route, RouteComponentProps, Switch } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { Links } from "@scm-manager/ui-types";
|
2020-02-26 15:45:24 +01:00
|
|
|
import {
|
|
|
|
|
Navigation,
|
|
|
|
|
NavLink,
|
|
|
|
|
Page,
|
|
|
|
|
Section,
|
|
|
|
|
SubNavigation,
|
|
|
|
|
isMenuCollapsed,
|
2020-03-02 14:13:51 +01:00
|
|
|
MenuContext,
|
|
|
|
|
storeMenuCollapsed
|
2020-02-26 15:45:24 +01:00
|
|
|
} from "@scm-manager/ui-components";
|
2020-01-08 15:57:13 +01:00
|
|
|
import { getAvailablePluginsLink, getInstalledPluginsLink, getLinks } from "../../modules/indexResource";
|
2019-10-20 18:02:52 +02:00
|
|
|
import AdminDetails from "./AdminDetails";
|
|
|
|
|
import PluginsOverview from "../plugins/containers/PluginsOverview";
|
|
|
|
|
import GlobalConfig from "./GlobalConfig";
|
|
|
|
|
import RepositoryRoles from "../roles/containers/RepositoryRoles";
|
|
|
|
|
import SingleRepositoryRole from "../roles/containers/SingleRepositoryRole";
|
|
|
|
|
import CreateRepositoryRole from "../roles/containers/CreateRepositoryRole";
|
2019-01-18 10:10:03 +01:00
|
|
|
|
2020-02-26 15:45:24 +01:00
|
|
|
type Props = RouteComponentProps &
|
|
|
|
|
WithTranslation & {
|
|
|
|
|
links: Links;
|
|
|
|
|
availablePluginsLink: string;
|
|
|
|
|
installedPluginsLink: string;
|
|
|
|
|
};
|
2019-01-18 10:10:03 +01:00
|
|
|
|
2020-02-26 15:45:24 +01:00
|
|
|
type State = {
|
|
|
|
|
menuCollapsed: boolean;
|
2019-01-18 10:10:03 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-26 15:45:24 +01:00
|
|
|
class Admin extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2020-03-02 14:13:51 +01:00
|
|
|
menuCollapsed: isMenuCollapsed()
|
2020-02-26 15:45:24 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onCollapseAdminMenu = (collapsed: boolean) => {
|
|
|
|
|
this.setState({ menuCollapsed: collapsed }, () => storeMenuCollapsed(collapsed));
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-18 10:10:03 +01:00
|
|
|
stripEndingSlash = (url: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
if (url.includes("role")) {
|
2019-06-24 15:13:04 +02:00
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url.substring(0, url.length - 1);
|
2019-01-18 10:10:03 +01:00
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-09 16:57:13 +02:00
|
|
|
matchesRoles = (route: any) => {
|
|
|
|
|
const url = this.matchedUrl();
|
2019-05-15 14:06:40 +02:00
|
|
|
const regex = new RegExp(`${url}/role/`);
|
2019-05-09 16:57:13 +02:00
|
|
|
return route.location.pathname.match(regex);
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-18 10:10:03 +01:00
|
|
|
render() {
|
2019-07-31 15:40:35 +02:00
|
|
|
const { links, availablePluginsLink, installedPluginsLink, t } = this.props;
|
2020-02-26 15:45:24 +01:00
|
|
|
const { menuCollapsed } = this.state;
|
2019-01-18 10:10:03 +01:00
|
|
|
|
|
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
const extensionProps = {
|
|
|
|
|
links,
|
2019-10-20 18:02:52 +02:00
|
|
|
url
|
2019-01-18 10:10:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2020-03-02 14:13:51 +01:00
|
|
|
<MenuContext.Provider
|
|
|
|
|
value={{ menuCollapsed, setMenuCollapsed: (collapsed: boolean) => this.setState({ menuCollapsed: collapsed }) }}
|
|
|
|
|
>
|
2020-02-26 15:45:24 +01:00
|
|
|
<Page>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Switch>
|
|
|
|
|
<Redirect exact from={url} to={`${url}/info`} />
|
|
|
|
|
<Route path={`${url}/info`} exact component={AdminDetails} />
|
|
|
|
|
<Route path={`${url}/settings/general`} exact component={GlobalConfig} />
|
|
|
|
|
<Redirect exact from={`${url}/plugins`} to={`${url}/plugins/installed/`} />
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/installed`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => <PluginsOverview baseUrl={`${url}/plugins/installed`} installed={true} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/installed/:page`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => <PluginsOverview baseUrl={`${url}/plugins/installed`} installed={true} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/available`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => <PluginsOverview baseUrl={`${url}/plugins/available`} installed={false} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/available/:page`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => <PluginsOverview baseUrl={`${url}/plugins/available`} installed={false} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/role/:role`}
|
|
|
|
|
render={() => <SingleRepositoryRole baseUrl={`${url}/roles`} history={this.props.history} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route path={`${url}/roles`} exact render={() => <RepositoryRoles baseUrl={`${url}/roles`} />} />
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/roles/create`}
|
|
|
|
|
render={() => <CreateRepositoryRole history={this.props.history} />}
|
|
|
|
|
/>
|
|
|
|
|
<Route path={`${url}/roles/:page`} exact render={() => <RepositoryRoles baseUrl={`${url}/roles`} />} />
|
|
|
|
|
<ExtensionPoint name="admin.route" props={extensionProps} renderAll={true} />
|
|
|
|
|
</Switch>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={menuCollapsed ? "column is-1" : "column is-3"}>
|
2020-03-10 10:45:37 +01:00
|
|
|
<Section
|
|
|
|
|
label={t("admin.menu.navigationLabel")}
|
|
|
|
|
onCollapse={() => this.onCollapseAdminMenu(!menuCollapsed)}
|
|
|
|
|
collapsed={menuCollapsed}
|
|
|
|
|
>
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/info`}
|
|
|
|
|
icon="fas fa-info-circle"
|
|
|
|
|
label={t("admin.menu.informationNavLink")}
|
|
|
|
|
title={t("admin.menu.informationNavLink")}
|
|
|
|
|
/>
|
|
|
|
|
{(availablePluginsLink || installedPluginsLink) && (
|
2019-07-31 15:40:35 +02:00
|
|
|
<SubNavigation
|
2020-03-10 10:45:37 +01:00
|
|
|
to={`${url}/plugins/`}
|
|
|
|
|
icon="fas fa-puzzle-piece"
|
|
|
|
|
label={t("plugins.menu.pluginsNavLink")}
|
|
|
|
|
title={t("plugins.menu.pluginsNavLink")}
|
2019-07-31 15:40:35 +02:00
|
|
|
>
|
2020-03-10 10:45:37 +01:00
|
|
|
{installedPluginsLink && (
|
|
|
|
|
<NavLink to={`${url}/plugins/installed/`} label={t("plugins.menu.installedNavLink")} />
|
|
|
|
|
)}
|
|
|
|
|
{availablePluginsLink && (
|
|
|
|
|
<NavLink to={`${url}/plugins/available/`} label={t("plugins.menu.availableNavLink")} />
|
|
|
|
|
)}
|
2019-07-31 15:40:35 +02:00
|
|
|
</SubNavigation>
|
2020-03-10 10:45:37 +01:00
|
|
|
)}
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/roles/`}
|
|
|
|
|
icon="fas fa-user-shield"
|
|
|
|
|
label={t("repositoryRole.navLink")}
|
|
|
|
|
title={t("repositoryRole.navLink")}
|
|
|
|
|
activeWhenMatch={this.matchesRoles}
|
|
|
|
|
activeOnlyWhenExact={false}
|
|
|
|
|
/>
|
|
|
|
|
<ExtensionPoint name="admin.navigation" props={extensionProps} renderAll={true} />
|
|
|
|
|
<SubNavigation
|
|
|
|
|
to={`${url}/settings/general`}
|
|
|
|
|
label={t("admin.menu.settingsNavLink")}
|
|
|
|
|
title={t("admin.menu.settingsNavLink")}
|
|
|
|
|
>
|
|
|
|
|
<NavLink to={`${url}/settings/general`} label={t("admin.menu.generalNavLink")} />
|
|
|
|
|
<ExtensionPoint name="admin.setting" props={extensionProps} renderAll={true} />
|
|
|
|
|
</SubNavigation>
|
|
|
|
|
</Section>
|
2020-02-26 15:45:24 +01:00
|
|
|
</div>
|
2019-01-18 10:10:03 +01:00
|
|
|
</div>
|
2020-02-26 15:45:24 +01:00
|
|
|
</Page>
|
|
|
|
|
</MenuContext.Provider>
|
2019-01-18 10:10:03 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: any) => {
|
|
|
|
|
const links = getLinks(state);
|
2019-07-31 15:40:35 +02:00
|
|
|
const availablePluginsLink = getAvailablePluginsLink(state);
|
|
|
|
|
const installedPluginsLink = getInstalledPluginsLink(state);
|
2019-01-18 10:10:03 +01:00
|
|
|
return {
|
2019-07-31 15:40:35 +02:00
|
|
|
links,
|
|
|
|
|
availablePluginsLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
installedPluginsLink
|
2019-01-18 10:10:03 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
export default compose(connect(mapStateToProps), withTranslation("admin"))(Admin);
|