From: Marcin Haba Date: Sun, 19 Nov 2017 14:04:46 +0000 (+0100) Subject: baculum: Add removing single resource X-Git-Tag: Release-9.0.6~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=db165207d0859d009abc07a9847b63e53d90b4c3;p=bacula%2Fbacula baculum: Add removing single resource --- diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index 3d7319622b..523418c02e 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index b588d8968e..b9d0409fd1 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -1420,3 +1420,19 @@ msgstr "Field required." msgid "Invalid value. Integer value required." msgstr "Invalid value. Integer value required." + +msgid "Resource %s \"%s\" is used in the following resources:" +msgstr "Resource %s \"%s\" is used in the following resources:" + +msgid "Component: %s, Resource: %s \"%s\", Directive: %s" +msgstr "Component: %s, Resource: %s \"%s\", Directive: %s" + +msgid "Are you sure that you want to remove %s resource \"%s\"?" +msgstr "Are you sure that you want to remove %s resource \"%s\"?" + +msgid "Resource %s \"%s\" removed successfully." +msgstr "Resource %s \"%s\" removed successfully." + +msgid "Please unassign resource %s \"%s\" from these resources and try again." +msgstr "Please unassign resource %s \"%s\" from these resources and try again." + diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index 02a0e29f7d..4454027436 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index a4eab462d5..1d460895ec 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -1171,3 +1171,19 @@ msgstr "Field required." msgid "Invalid value. Integer value required." msgstr "Invalid value. Integer value required." + +msgid "Resource %s \"%s\" is used in the following resources:" +msgstr "Resource %s \"%s\" is used in the following resources:" + +msgid "Component: %s, Resource: %s \"%s\", Directive: %s" +msgstr "Component: %s, Resource: %s \"%s\", Directive: %s" + +msgid "Are you sure that you want to remove %s resource \"%s\"?" +msgstr "Are you sure that you want to remove %s resource \"%s\"?" + +msgid "Resource %s \"%s\" removed successfully." +msgstr "Resource %s \"%s\" removed successfully." + +msgid "Please unassign resource %s \"%s\" from these resources and try again." +msgstr "Please unassign resource %s \"%s\" from these resources and try again." + diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index 15040e0681..054235dd35 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index 84f967b446..9c5eae621f 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -1427,3 +1427,19 @@ msgstr "Pole wymagane." msgid "Invalid value. Integer value required." msgstr "Niepoprawna wartość. Wymagane jest podanie liczby całkowitej." + +msgid "Resource %s \"%s\" is used in the following resources:" +msgstr "Zasób %s \"%s\" jest użyty w następujących zasobach:" + +msgid "Component: %s, Resource: %s \"%s\", Directive: %s" +msgstr "Komponent: %s, Zasób: %s \"%s\", Dyrektywa: %s" + +msgid "Are you sure that you want to remove %s resource \"%s\"?" +msgstr "Czy jesteś pewien, że chcesz usunąć zasób %s \"%s\"?" + +msgid "Resource %s \"%s\" removed successfully." +msgstr "Zasób %s \"%s\" został usunięty pomyślnie." + +msgid "Please unassign resource %s \"%s\" from these resources and try again." +msgstr "Proszę wypisać zasób %s \"%s\" z tych zasobów i spróbować ponownie." + diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index 2b901fd01c..a4e3dcdf01 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index 09cb86ec7e..9cbacbd9ae 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -1435,3 +1435,19 @@ msgstr "Field required." msgid "Invalid value. Integer value required." msgstr "Invalid value. Integer value required." + +msgid "Resource %s \"%s\" is used in the following resources:" +msgstr "Resource %s \"%s\" is used in the following resources:" + +msgid "Component: %s, Resource: %s \"%s\", Directive: %s" +msgstr "Component: %s, Resource: %s \"%s\", Directive: %s" + +msgid "Are you sure that you want to remove %s resource \"%s\"?" +msgstr "Are you sure that you want to remove %s resource \"%s\"?" + +msgid "Resource %s \"%s\" removed successfully." +msgstr "Resource %s \"%s\" removed successfully." + +msgid "Please unassign resource %s \"%s\" from these resources and try again." +msgstr "Please unassign resource %s \"%s\" from these resources and try again." + diff --git a/gui/baculum/protected/Web/Pages/config.xml b/gui/baculum/protected/Web/Pages/config.xml index dbd439b9fe..2b82047688 100644 --- a/gui/baculum/protected/Web/Pages/config.xml +++ b/gui/baculum/protected/Web/Pages/config.xml @@ -9,6 +9,7 @@ + diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigResources.php b/gui/baculum/protected/Web/Portlets/BaculaConfigResources.php index b24db49975..5083f58fc1 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigResources.php +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigResources.php @@ -77,6 +77,7 @@ class BaculaConfigResources extends ResourceListTemplate { $control->setResourceName($param->Item->DataItem['resource_name']); $control->setResourceNames($this->resource_names); } + $param->Item->RemoveResource->setCommandParameter($param->Item->DataItem); } public function getDirectives($sender, $param) { @@ -85,5 +86,144 @@ class BaculaConfigResources extends ResourceListTemplate { $control->raiseEvent('OnDirectiveListLoad', $this, null); } } + + /** + * Remove resource callback method. + * + * @return object $sender sender instance + * @return mixed $param additional parameters + * @return none + */ + public function removeResource($sender, $param) { + if (!$this->getPage()->IsCallback) { + // removing resource available only by callback + return; + } + $host_params = $param->getCommandParameter(); + if (!is_array($host_params) || count($host_params) === 0) { + return; + } + $host = $this->getHost(); + $config = $this->getConfigData($host, $host_params['component_type']); + $deps = $this->getModule('data_deps')->checkDependencies( + $host_params['component_type'], + $host_params['resource_type'], + $host_params['resource_name'], + $config + ); + if (count($deps) === 0) { + // NO DEPENDENCY. Ready to remove. + $this->removeResourceFromConfig( + $config, + $host_params['resource_type'], + $host_params['resource_name'] + ); + $result = $this->getModule('api')->set( + array('config', $host_params['component_type']), + array('config' => json_encode($config)), + $host, + false + ); + if ($result->error === 0) { + $this->showRemovedResourceInfo( + $host_params['resource_type'], + $host_params['resource_name'] + ); + } else { + $this->showRemovedResourceError($result->output); + } + } else { + // DEPENDENCIES EXIST. List them on the interface. + $this->showDependenciesError( + $deps, + $host_params['resource_type'], + $host_params['resource_name'] + ); + } + } + + /** + * Show removed resource information. + * + * @param string $resource_type removed resource type + * @param string $resource_name removed resource name + * @return none + */ + private function showRemovedResourceInfo($resource_type, $resource_name) { + $msg = Prado::localize('Resource %s "%s" removed successfully.'); + $msg = sprintf( + $msg, + $resource_type, + $resource_name + ); + $this->RemoveResourceOk->Text = $msg; + $this->getPage()->getCallbackClient()->hide($this->RemoveResourceError); + $this->getPage()->getCallbackClient()->show($this->RemoveResourceOk); + } + + /** + * Show removed resource error message. + * + * @param string $error_message error message + * @return none + */ + private function showRemovedResourceError($error_message) { + $this->RemoveResourceError->Text = $error_message; + $this->getPage()->getCallbackClient()->hide($this->RemoveResourceOk); + $this->getPage()->getCallbackClient()->show($this->RemoveResourceError); + } + + /** + * Show dependencies error message. + * + * @param array $deps list dependencies for the removing resource + * @param string $resource_type resource type of the removing resource + * @param string $resource_name resource name of the removing resource + * @return none + */ + private function showDependenciesError($deps, $resource_type, $resource_name) { + $emsg = Prado::localize('Resource %s "%s" is used in the following resources:'); + $emsg = sprintf($emsg, $resource_type, $resource_name); + $emsg_deps = Prado::localize('Component: %s, Resource: %s "%s", Directive: %s'); + $dependencies = array(); + for ($i = 0; $i < count($deps); $i++) { + $dependencies[] = sprintf( + $emsg_deps, + $deps[$i]['component_type'], + $deps[$i]['resource_type'], + $deps[$i]['resource_name'], + $deps[$i]['directive_name'] + ); + } + $emsg_sum = Prado::localize('Please unassign resource %s "%s" from these resources and try again.'); + $emsg_sum = sprintf($emsg_sum, $resource_type, $resource_name); + $error = array($emsg, implode('
', $dependencies), $emsg_sum); + $error_message = implode('

', $error); + $this->showRemovedResourceError($error_message); + } + + /** + * Remove resource from config. + * Note, passing config by reference. + * + * @param array $config entire config + * @param string $resource_type resource type to remove + * @param string $resource_name resource name to remove + * @return none + */ + private function removeResourceFromConfig(&$config, $resource_type, $resource_name) { + for ($i = 0; $i < count($config); $i++) { + foreach ($config[$i] as $rtype => $resource) { + if (!property_exists($resource, 'Name')) { + continue; + } + if ($rtype === $resource_type && $resource->Name === $resource_name) { + // remove resource + array_splice($config, $i, 1); + break; + } + } + } + } } ?> diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigResources.tpl b/gui/baculum/protected/Web/Portlets/BaculaConfigResources.tpl index 303d8329b6..1d2090f071 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigResources.tpl +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigResources.tpl @@ -1,8 +1,30 @@