From 25cb0d6a258b84008ad6a94b05f3ce9e2fe7c662 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 21 Aug 2019 11:22:49 +0200 Subject: [PATCH] implemented restart after installation --- .../java/sonia/scm/plugin/PluginManager.java | 3 +- scm-ui/public/locales/de/admin.json | 6 +- scm-ui/public/locales/en/admin.json | 6 +- .../admin/plugins/components/PluginModal.js | 158 +++++++++++------- .../v2/resources/AvailablePluginResource.java | 5 +- .../scm/plugin/DefaultPluginManager.java | 11 +- .../AvailablePluginResourceTest.java | 2 +- .../scm/plugin/DefaultPluginManagerTest.java | 29 +++- 8 files changed, 143 insertions(+), 77 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/plugin/PluginManager.java b/scm-core/src/main/java/sonia/scm/plugin/PluginManager.java index ad9045544c..235e360547 100644 --- a/scm-core/src/main/java/sonia/scm/plugin/PluginManager.java +++ b/scm-core/src/main/java/sonia/scm/plugin/PluginManager.java @@ -77,6 +77,7 @@ public interface PluginManager { * Installs the plugin with the given name from the list of available plugins. * * @param name plugin name + * @param restartAfterInstallation restart context after plugin installation */ - void install(String name); + void install(String name, boolean restartAfterInstallation); } diff --git a/scm-ui/public/locales/de/admin.json b/scm-ui/public/locales/de/admin.json index df01dd8dbb..19e8a07751 100644 --- a/scm-ui/public/locales/de/admin.json +++ b/scm-ui/public/locales/de/admin.json @@ -34,11 +34,15 @@ "title": "{{name}} Plugin installieren", "restart": "Neustarten um Plugin zu aktivieren", "install": "Installieren", + "installAndRestart": "Installieren und Neustarten", "abort": "Abbrechen", "author": "Autor", "version": "Version", "dependencyNotification": "Mit diesem Plugin werden folgende Abhängigkeiten mit installieren wenn sie noch nicht vorhanden sind!", - "dependencies": "Abhängigkeiten" + "dependencies": "Abhängigkeiten", + "successNotification": "Das Plugin wurde erfolgreich installiert. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:", + "reload": "jetzt new laden", + "restartNotification": "Der SCM-Manager Kontext sollte nur neu gestartet werden, wenn aktuell niemand damit arbeitet." } }, "repositoryRole": { diff --git a/scm-ui/public/locales/en/admin.json b/scm-ui/public/locales/en/admin.json index 8c920c0df3..afdc75585a 100644 --- a/scm-ui/public/locales/en/admin.json +++ b/scm-ui/public/locales/en/admin.json @@ -34,11 +34,15 @@ "title": "Install {{name}} Plugin", "restart": "Restart to activate", "install": "Install", + "installAndRestart": "Install and Restart", "abort": "Abort", "author": "Author", "version": "Version", "dependencyNotification": "With this plugin, the following dependencies are installed if they are not available yet!", - "dependencies": "Dependencies" + "dependencies": "Dependencies", + "successNotification": "Successful installed plugin. You have to reload the page, to see ui changes:", + "reload": "reload now", + "restartNotification": "Restarting the scm-manager context, should only be done if no one else is currently working with it." } }, "repositoryRole": { diff --git a/scm-ui/src/admin/plugins/components/PluginModal.js b/scm-ui/src/admin/plugins/components/PluginModal.js index f09f252cc5..78af2d8bec 100644 --- a/scm-ui/src/admin/plugins/components/PluginModal.js +++ b/scm-ui/src/admin/plugins/components/PluginModal.js @@ -8,9 +8,10 @@ import { apiClient, Button, ButtonGroup, - Checkbox, ErrorNotification, + Checkbox, + ErrorNotification, Modal, - SubmitButton + Notification } from "@scm-manager/ui-components"; import classNames from "classnames"; @@ -25,14 +26,13 @@ type Props = { }; type State = { + success: boolean, + restart: boolean, loading: boolean, error?: Error }; const styles = { - titleVersion: { - marginLeft: "0.75rem" - }, userLabelAlignment: { textAlign: "left", marginRight: 0, @@ -40,37 +40,48 @@ const styles = { }, userFieldFlex: { flexGrow: 4 - }, - listSpacing: { - marginTop: "0 !important" - }, - error: { - marginTop: "1em" } }; -class PluginModal extends React.Component { - +class PluginModal extends React.Component { constructor(props: Props) { super(props); this.state = { - loading: false + loading: false, + restart: false, + success: false }; } + onInstallSuccess = () => { + const { restart } = this.state; + const { onClose } = this.props; + + const newState = { + loading: false, + error: undefined + }; + + if (restart) { + this.setState({ + ...newState, + success: true + }); + } else { + this.setState(newState, onClose); + } + }; + install = (e: Event) => { - const { plugin, onClose } = this.props; + const { restart } = this.state; + const { plugin } = this.props; this.setState({ loading: true }); e.preventDefault(); - apiClient.post(plugin._links.install.href) - .then(() => { - this.setState({ - loading: false, - error: undefined - }, onClose); - }) + apiClient + .post(plugin._links.install.href + "?restart=" + restart.toString()) + .then(this.onInstallSuccess) .catch(error => { this.setState({ loading: false, @@ -81,14 +92,25 @@ class PluginModal extends React.Component { footer = () => { const { onClose, t } = this.props; - const { loading, error } = this.state; + const { loading, error, restart, success } = this.state; + + let color = "primary"; + let label = "plugins.modal.install"; + if (restart) { + color = "warning"; + label = "plugins.modal.installAndRestart"; + } return ( -
- - -