From 7a075ca52a702bc5e26e3950a48e9462d5dd0b2d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 12 Jul 2013 12:02:51 +0200 Subject: [PATCH] Add link to csv output to tabs There is currently no controller implementing this output type but the monitoring module will provide that. --- library/Icinga/File/Csv.php | 46 ++++++++++++++++++++++++++++++ library/Icinga/File/Csv/Query.php | 0 library/Icinga/Web/Widget.php | 34 +++++----------------- library/Icinga/Web/Widget/Tabs.php | 36 ++++++++++++++--------- 4 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 library/Icinga/File/Csv.php create mode 100644 library/Icinga/File/Csv/Query.php diff --git a/library/Icinga/File/Csv.php b/library/Icinga/File/Csv.php new file mode 100644 index 000000000..b2efde401 --- /dev/null +++ b/library/Icinga/File/Csv.php @@ -0,0 +1,46 @@ +query = $query; + return $csv; + } + + public function dump() + { + header('Content-type: text/csv'); + echo (string) $this; + } + + public function __toString() + { + $first = true; + $csv = ''; + foreach ($this->query->fetchAll() as $row) { + if ($first) { + $csv .= implode(',', array_keys((array) $row)) . "\r\n"; + $first = false; + } + $out = array(); + foreach ($row as & $val) { + $out[] = '"' . $val . '"'; + } + $csv .= implode(',', $out) . "\r\n"; + } + return $csv; + } +} + diff --git a/library/Icinga/File/Csv/Query.php b/library/Icinga/File/Csv/Query.php new file mode 100644 index 000000000..e69de29bb diff --git a/library/Icinga/Web/Widget.php b/library/Icinga/Web/Widget.php index 8552f4396..43692d842 100644 --- a/library/Icinga/Web/Widget.php +++ b/library/Icinga/Web/Widget.php @@ -1,28 +1,8 @@ - * @author Icinga Development Team - */ -// {{{ICINGA_LICENSE_HEADER}}} +/** + * Web widget class + */ namespace Icinga\Web; use Icinga\Exception\ProgrammingError; @@ -45,16 +25,16 @@ use Icinga\Exception\ProgrammingError; */ class Widget { + /** * Create a new widget * * @param string $name Widget name - * @param array $options Widget constructor options + * @param array $options Widget constructor options * - * @throws \Icinga\Exception\ProgrammingError * @return Icinga\Web\Widget\AbstractWidget */ - public static function create($name, $options = array()) + public static function create($name, $options = array(), $module_name = null) { $class = 'Icinga\\Web\\Widget\\' . ucfirst($name); @@ -67,7 +47,7 @@ class Widget ); } - $widget = new $class($options); + $widget = new $class($options, $module_name); return $widget; } } diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index 6cdb43065..db568a277 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -8,6 +8,8 @@ namespace Icinga\Web\Widget; use Icinga\Exception\ProgrammingError; use Icinga\Web\Url; +use Countable; + /** * Navigation tab widget * @@ -17,7 +19,7 @@ use Icinga\Web\Url; * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ -class Tabs extends AbstractWidget implements \Countable +class Tabs extends AbstractWidget implements Countable { /** * This is where single tabs added to this container will be stored @@ -201,25 +203,37 @@ class Tabs extends AbstractWidget implements \Countable $special = array(); $special[] = $this->view()->qlink( - 'PDF', + $this->view()->img('img/classic/application-pdf.png') . ' PDF', Url::current(), array('filetype' => 'pdf'), - array('target' => '_blank') + array('target' => '_blank', 'quote' => false) + ); + $special[] = $this->view()->qlink( + $this->view()->img('img/classic/application-csv.png') . ' CSV', + Url::current(), + array('format' => 'csv'), + array('target' => '_blank', 'quote' => false) + ); + $special[] = $this->view()->qlink( + $this->view()->img('img/classic/application-json.png') . ' JSON', + Url::current(), + array('format' => 'json', 'quote' => false), + array('target' => '_blank', 'quote' => false) ); $special[] = $this->view()->qlink( - 'Basket', + $this->view()->img('img/classic/basket.png') . ' URL Basket', Url::create('basket/add'), - array('url' => Url::current()->getRelative()) + array('url' => Url::current()->getRelative()), + array('quote' => false) ); $special[] = $this->view()->qlink( - 'Dashboard', + $this->view()->img('img/classic/dashboard.png') . ' Dashboard', Url::create('dashboard/addurl'), - array('url' => Url::current()->getRelative()) + array('url' => Url::current()->getRelative()), + array('quote' => false) ); - - // @todo rework auth // $auth = Auth::getInstance(); // if ($this->specialActions && ! empty($special) && $auth->isAuthenticated() && $auth->getUsername() === 'admin') { if ($this->specialActions) { @@ -241,10 +255,6 @@ class Tabs extends AbstractWidget implements \Countable return $html; } - /** - * Counting registered tabs - * @return int - */ public function count() { return count($this->tabs);