From f22ae527689cdeecd5adc2b14749a5b6d4f74ba9 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 27 Jun 2013 12:45:18 +0200 Subject: [PATCH] System settings Add new configuration controller for the configuration controllers later. refs #4299 --- .../controllers/ConfigurationController.php | 39 +++++ .../views/scripts/configuration/index.phtml | 11 ++ config/menu.ini | 2 +- library/Icinga/Web/Url.php | 154 ++++++++++++++++++ library/Icinga/Web/Widget/Tabs.php | 5 +- 5 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 application/controllers/ConfigurationController.php create mode 100644 application/views/scripts/configuration/index.phtml create mode 100644 library/Icinga/Web/Url.php diff --git a/application/controllers/ConfigurationController.php b/application/controllers/ConfigurationController.php new file mode 100644 index 000000000..534e7aefa --- /dev/null +++ b/application/controllers/ConfigurationController.php @@ -0,0 +1,39 @@ +view->tabs = $this->createTabs(); + } + + /** + * @return \Icinga\Web\Widget + */ + protected function createTabs() + { + $tabs = $this->widget('tabs')->add( + 'configuration', + array( + 'title' => $this->translate('Overview'), + 'url' => 'configuration/index', + ) + ); + + return $tabs; + } +} + +// @codingStandardsIgnoreEnd \ No newline at end of file diff --git a/application/views/scripts/configuration/index.phtml b/application/views/scripts/configuration/index.phtml new file mode 100644 index 000000000..537cb5fd7 --- /dev/null +++ b/application/views/scripts/configuration/index.phtml @@ -0,0 +1,11 @@ +tabs; ?> +

Configuration

+ +

+ This is the configuration over page. Modules can register their handler to + provide own controllers for configuration. +

+ +

+ Many thanks for your attention! +

\ No newline at end of file diff --git a/config/menu.ini b/config/menu.ini index c9a1f8f0d..21e230bcc 100644 --- a/config/menu.ini +++ b/config/menu.ini @@ -1,3 +1,3 @@ [menu] -Configuration = "/modules/overview" +Configuration = "/configuration/index" diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php new file mode 100644 index 000000000..1849fdd76 --- /dev/null +++ b/library/Icinga/Web/Url.php @@ -0,0 +1,154 @@ +url = $url; + if (! empty($params)) { + $this->params = $params; + } + } else { + $this->url = substr($url, 0, $split); + parse_str(substr($url, $split + 1), $urlParams); + $this->params = $urlParams; + if (! empty($params)) { + $this->params += $params; + // TODO: Test += behavior! + } + } + + } + + public static function create($url, $params = null) + { + $u = new Url($url, $params); + return $u; + } + + // For tests + public function setBaseUrl($baseUrl) + { + $this->baseUrl = $baseUrl; + return $this; + } + + public static function current() + { + $app = Icinga::app(); + $view = $app->getView()->view; + $request = $app->frontController()->getRequest(); + $parts = array(); + // TODO: getQuery! + $params = $request->getParams(); + foreach (array('module', 'controller', 'action') as $param) { + if ($view->{$param . '_name'} !== 'default') { + $parts[] = $view->{$param . '_name'}; + } + if (array_key_exists($param, $params)) { + unset($params[$param]); + } + } + $rel = implode('/', $parts); + $url = new Url($rel, $params); + return $url; + } + + public function getScript() + { + return $this->url; + } + + public function getRelative() + { + $params = $args = array(); + foreach ($this->params as $name => $value) { + if (is_int($name)) { + $params[] = rawurlencode($value); + } else { + $args[] = rawurlencode($name) . '=' . rawurlencode($value); + } + } + $url = vsprintf($this->url, $params); + if (! empty($args)) { + $url .= '?' . implode('&', $args); + } + return $url; + } + + public function addParams($params) + { + $this->params += $params; + return $this; + } + + public function setParams($params) + { + $this->params = $params; + return $this; + } + + public function set($key, $val) + { + $this->params[$key] = $val; + return $this; + } + + + public function hasParam($key) + { + return array_key_exists($key, $this->params); + } + + public function getParam($key, $default = null) + { + if ($this->hasParam($key)) { + return $this->params[$key]; + } + return $default; + } + + public function getParams() + { + return $this->params; + } + + public function without($keys) + { + if (! is_array($keys)) { + $keys = array($keys); + } + foreach ($keys as $key) { + if (array_key_exists($key, $this->params)) { + unset($this->params[$key]); + } + } + return $this; + } + + public function __toString() + { + $url = $this->getRelative(); + $base = is_null($this->baseUrl) + ? Icinga::app()->getView()->view->baseUrl() + : $this->baseUrl; + if ($base === '') { + // Otherwise all URLs would be relative to wherever you are + $base = '/'; + } + if (strlen($base) > 0 && strlen($url) > 0 && $url[0] !== '?') { + $base = rtrim($base, '/') . '/'; + } + return $base . $url; + } +} diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index 25e379688..8f4014fe8 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -7,7 +7,6 @@ namespace Icinga\Web\Widget; use Icinga\Exception\ProgrammingError; use Icinga\Web\Url; -use Icinga\Authentication\Auth; /** * Navigation tab widget @@ -219,7 +218,9 @@ class Tabs extends AbstractWidget Url::create('dashboard/addurl'), array('url' => Url::current()->getRelative()) ); - $auth = Auth::getInstance(); + + // @todo rework auth + // $auth = Auth::getInstance(); // if ($this->specialActions && ! empty($special) && $auth->isAuthenticated() && $auth->getUsername() === 'admin') { if ($this->specialActions) { $html .= '