2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import * as React from "react";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { PendingPlugins, PluginCollection } from "@scm-manager/ui-types";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { Button, ButtonGroup, ErrorNotification, Modal } from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import SuccessNotification from "./SuccessNotification";
|
2019-08-21 14:54:01 +02:00
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
type Props = WithTranslation & {
|
2019-10-19 16:38:07 +02:00
|
|
|
onClose: () => void;
|
|
|
|
|
pendingPlugins?: PendingPlugins;
|
|
|
|
|
installedPlugins?: PluginCollection;
|
2021-02-24 08:17:40 +01:00
|
|
|
execute: () => void;
|
2019-10-19 16:38:07 +02:00
|
|
|
description: string;
|
|
|
|
|
label: string;
|
|
|
|
|
loading: boolean;
|
2021-02-24 08:17:40 +01:00
|
|
|
error?: Error | null;
|
2019-10-19 16:38:07 +02:00
|
|
|
success: boolean;
|
2021-02-24 08:17:40 +01:00
|
|
|
children?: React.Node;
|
2019-08-21 14:54:01 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
class PluginActionModal extends React.Component<Props> {
|
2019-08-21 14:54:01 +02:00
|
|
|
renderNotifications = () => {
|
2021-02-24 08:17:40 +01:00
|
|
|
const { children, error, success } = this.props;
|
2019-08-21 14:54:01 +02:00
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
} else if (success) {
|
2019-09-16 18:51:00 +02:00
|
|
|
return <SuccessNotification />;
|
2019-08-21 14:54:01 +02:00
|
|
|
} else {
|
2019-10-01 17:03:27 +02:00
|
|
|
return children;
|
2019-08-21 14:54:01 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-27 14:05:19 +02:00
|
|
|
renderModalContent = () => {
|
2019-10-01 13:21:08 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{this.renderUpdatable()}
|
|
|
|
|
{this.renderInstallQueue()}
|
|
|
|
|
{this.renderUpdateQueue()}
|
|
|
|
|
{this.renderUninstallQueue()}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2019-09-27 14:05:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUpdatable = () => {
|
2019-09-28 15:28:40 +02:00
|
|
|
const { installedPlugins, t } = this.props;
|
2019-09-27 14:05:19 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-21 10:57:56 +02:00
|
|
|
{installedPlugins && installedPlugins._embedded && installedPlugins._embedded.plugins && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.updateQueue")}</strong>
|
|
|
|
|
<ul>
|
|
|
|
|
{installedPlugins._embedded.plugins
|
2021-12-09 09:12:02 +01:00
|
|
|
.filter(plugin => plugin._links && plugin._links.update)
|
|
|
|
|
.map(plugin => (
|
2019-10-21 10:57:56 +02:00
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-09-27 14:05:19 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-16 14:31:55 +02:00
|
|
|
renderInstallQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-21 10:57:56 +02:00
|
|
|
{pendingPlugins && pendingPlugins._embedded && pendingPlugins._embedded.new.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.installQueue")}</strong>
|
|
|
|
|
<ul>
|
2021-12-09 09:12:02 +01:00
|
|
|
{pendingPlugins._embedded.new.map(plugin => (
|
2019-10-21 10:57:56 +02:00
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-09-16 14:31:55 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUpdateQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-21 10:57:56 +02:00
|
|
|
{pendingPlugins && pendingPlugins._embedded && pendingPlugins._embedded.update.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.updateQueue")}</strong>
|
|
|
|
|
<ul>
|
2021-12-09 09:12:02 +01:00
|
|
|
{pendingPlugins._embedded.update.map(plugin => (
|
2019-10-21 10:57:56 +02:00
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-09-17 16:25:24 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUninstallQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-21 10:57:56 +02:00
|
|
|
{pendingPlugins && pendingPlugins._embedded && pendingPlugins._embedded.uninstall.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.uninstallQueue")}</strong>
|
|
|
|
|
<ul>
|
2021-12-09 09:12:02 +01:00
|
|
|
{pendingPlugins._embedded.uninstall.map(plugin => (
|
2019-10-21 10:57:56 +02:00
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-09-16 14:31:55 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-21 14:54:01 +02:00
|
|
|
renderBody = () => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="media">
|
|
|
|
|
<div className="content">
|
2019-10-01 17:03:27 +02:00
|
|
|
<p>{this.props.description}</p>
|
2019-09-27 14:05:19 +02:00
|
|
|
{this.renderModalContent()}
|
2019-08-21 14:54:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-10-01 17:03:27 +02:00
|
|
|
<div className="media">{this.renderNotifications()}</div>
|
2019-08-21 14:54:01 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderFooter = () => {
|
2021-02-24 08:17:40 +01:00
|
|
|
const { onClose, t, loading, error, success } = this.props;
|
2019-08-21 14:54:01 +02:00
|
|
|
return (
|
|
|
|
|
<ButtonGroup>
|
|
|
|
|
<Button
|
|
|
|
|
color="warning"
|
2019-10-01 17:03:27 +02:00
|
|
|
label={this.props.label}
|
2019-08-21 14:54:01 +02:00
|
|
|
loading={loading}
|
2021-02-24 08:17:40 +01:00
|
|
|
action={this.props.execute}
|
|
|
|
|
disabled={!!error || success}
|
2019-08-21 14:54:01 +02:00
|
|
|
/>
|
2019-10-20 18:02:52 +02:00
|
|
|
<Button label={t("plugins.modal.abort")} action={onClose} />
|
2019-08-21 14:54:01 +02:00
|
|
|
</ButtonGroup>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-09-28 15:28:40 +02:00
|
|
|
const { onClose } = this.props;
|
2019-08-21 14:54:01 +02:00
|
|
|
return (
|
|
|
|
|
<Modal
|
2019-10-01 17:03:27 +02:00
|
|
|
title={this.props.label}
|
2019-08-21 14:54:01 +02:00
|
|
|
closeFunction={onClose}
|
|
|
|
|
body={this.renderBody()}
|
|
|
|
|
footer={this.renderFooter()}
|
|
|
|
|
active={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
export default withTranslation("admin")(PluginActionModal);
|