2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { Redirect, Route, Switch } from "react-router-dom";
|
|
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { History } from "history";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { compose } from "redux";
|
|
|
|
|
import { Links } from "@scm-manager/ui-types";
|
2019-07-31 15:40:35 +02:00
|
|
|
import {
|
|
|
|
|
Page,
|
|
|
|
|
Navigation,
|
|
|
|
|
NavLink,
|
|
|
|
|
Section,
|
2019-10-20 18:02:52 +02:00
|
|
|
SubNavigation
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-07-31 15:40:35 +02:00
|
|
|
import {
|
|
|
|
|
getLinks,
|
|
|
|
|
getAvailablePluginsLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
getInstalledPluginsLink
|
|
|
|
|
} from "../../modules/indexResource";
|
|
|
|
|
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
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
links: Links;
|
|
|
|
|
availablePluginsLink: string;
|
|
|
|
|
installedPluginsLink: string;
|
2019-01-18 10:10:03 +01:00
|
|
|
|
|
|
|
|
// context objects
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
match: any;
|
|
|
|
|
history: History;
|
2019-01-18 10:10:03 +01:00
|
|
|
};
|
|
|
|
|
|
2019-06-19 09:58:17 +02:00
|
|
|
class Admin extends React.Component<Props> {
|
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;
|
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 (
|
|
|
|
|
<Page>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-three-quarters">
|
2019-05-16 10:01:33 +02:00
|
|
|
<Switch>
|
2019-06-19 09:58:17 +02:00
|
|
|
<Redirect exact from={url} to={`${url}/info`} />
|
|
|
|
|
<Route path={`${url}/info`} exact component={AdminDetails} />
|
2019-07-31 15:40:35 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/settings/general`}
|
|
|
|
|
exact
|
|
|
|
|
component={GlobalConfig}
|
|
|
|
|
/>
|
|
|
|
|
<Redirect
|
|
|
|
|
exact
|
|
|
|
|
from={`${url}/plugins`}
|
|
|
|
|
to={`${url}/plugins/installed/`}
|
|
|
|
|
/>
|
2019-07-03 09:02:44 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/installed`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => (
|
2019-07-31 15:40:35 +02:00
|
|
|
<PluginsOverview
|
|
|
|
|
baseUrl={`${url}/plugins/installed`}
|
|
|
|
|
installed={true}
|
|
|
|
|
/>
|
2019-07-03 09:02:44 +02:00
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/installed/:page`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => (
|
2019-07-31 15:40:35 +02:00
|
|
|
<PluginsOverview
|
|
|
|
|
baseUrl={`${url}/plugins/installed`}
|
|
|
|
|
installed={true}
|
|
|
|
|
/>
|
2019-07-03 09:02:44 +02:00
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/available`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => (
|
2019-07-31 15:40:35 +02:00
|
|
|
<PluginsOverview
|
|
|
|
|
baseUrl={`${url}/plugins/available`}
|
|
|
|
|
installed={false}
|
|
|
|
|
/>
|
2019-07-03 09:02:44 +02:00
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/plugins/available/:page`}
|
|
|
|
|
exact
|
|
|
|
|
render={() => (
|
2019-07-31 15:40:35 +02:00
|
|
|
<PluginsOverview
|
|
|
|
|
baseUrl={`${url}/plugins/available`}
|
|
|
|
|
installed={false}
|
|
|
|
|
/>
|
2019-07-03 09:02:44 +02:00
|
|
|
)}
|
|
|
|
|
/>
|
2019-05-16 10:04:57 +02:00
|
|
|
<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={() => (
|
2019-07-31 15:40:35 +02:00
|
|
|
<CreateRepositoryRole history={this.props.history} />
|
2019-05-16 10:04:57 +02:00
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/roles/:page`}
|
|
|
|
|
exact
|
2019-07-31 15:40:35 +02:00
|
|
|
render={() => <RepositoryRoles baseUrl={`${url}/roles`} />}
|
2019-05-16 10:04:57 +02:00
|
|
|
/>
|
|
|
|
|
<ExtensionPoint
|
2019-06-19 09:58:17 +02:00
|
|
|
name="admin.route"
|
2019-05-16 10:04:57 +02:00
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-05-16 10:01:33 +02:00
|
|
|
</Switch>
|
2019-01-18 10:10:03 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="column is-one-quarter">
|
|
|
|
|
<Navigation>
|
2019-10-20 18:02:52 +02:00
|
|
|
<Section label={t("admin.menu.navigationLabel")}>
|
2019-01-18 10:10:03 +01:00
|
|
|
<NavLink
|
2019-06-19 09:58:17 +02:00
|
|
|
to={`${url}/info`}
|
|
|
|
|
icon="fas fa-info-circle"
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("admin.menu.informationNavLink")}
|
2019-01-18 10:10:03 +01:00
|
|
|
/>
|
2019-07-31 15:40:35 +02:00
|
|
|
{(availablePluginsLink || installedPluginsLink) && (
|
|
|
|
|
<SubNavigation
|
|
|
|
|
to={`${url}/plugins/`}
|
|
|
|
|
icon="fas fa-puzzle-piece"
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("plugins.menu.pluginsNavLink")}
|
2019-07-31 15:40:35 +02:00
|
|
|
>
|
|
|
|
|
{installedPluginsLink && (
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/plugins/installed/`}
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("plugins.menu.installedNavLink")}
|
2019-07-31 15:40:35 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{availablePluginsLink && (
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/plugins/available/`}
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("plugins.menu.availableNavLink")}
|
2019-07-31 15:40:35 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</SubNavigation>
|
|
|
|
|
)}
|
2019-05-08 09:32:51 +02:00
|
|
|
<NavLink
|
2019-05-16 10:01:33 +02:00
|
|
|
to={`${url}/roles/`}
|
2019-06-19 09:58:17 +02:00
|
|
|
icon="fas fa-user-shield"
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("repositoryRole.navLink")}
|
2019-05-09 16:57:13 +02:00
|
|
|
activeWhenMatch={this.matchesRoles}
|
2019-05-17 17:04:40 +02:00
|
|
|
activeOnlyWhenExact={false}
|
2019-05-08 09:32:51 +02:00
|
|
|
/>
|
2019-01-18 10:10:03 +01:00
|
|
|
<ExtensionPoint
|
2019-06-19 09:58:17 +02:00
|
|
|
name="admin.navigation"
|
2019-01-18 10:10:03 +01:00
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-06-19 09:58:17 +02:00
|
|
|
<SubNavigation
|
|
|
|
|
to={`${url}/settings/general`}
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("admin.menu.settingsNavLink")}
|
2019-06-19 09:58:17 +02:00
|
|
|
>
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/settings/general`}
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("admin.menu.generalNavLink")}
|
2019-06-19 09:58:17 +02:00
|
|
|
/>
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="admin.setting"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
|
|
|
|
</SubNavigation>
|
2019-01-18 10:10:03 +01:00
|
|
|
</Section>
|
|
|
|
|
</Navigation>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
|
connect(mapStateToProps),
|
2019-10-20 18:02:52 +02:00
|
|
|
translate("admin")
|
2019-06-19 09:58:17 +02:00
|
|
|
)(Admin);
|