[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: ActivityLogTable: friendlier layout, show days

git at icinga.org git at icinga.org
Thu May 19 16:46:15 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 102925ee845643f4b85cc77774a35ca740f11fe2
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=102925ee845643f4b85cc77774a35ca740f11fe2

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 18 21:49:20 2016 +0200

ActivityLogTable: friendlier layout, show days

---

 application/tables/ActivityLogTable.php |   72 +++++++++++++++++++++++++++++--
 public/css/module.less                  |    8 ++++
 2 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/application/tables/ActivityLogTable.php b/application/tables/ActivityLogTable.php
index 5845957..3e644b7 100644
--- a/application/tables/ActivityLogTable.php
+++ b/application/tables/ActivityLogTable.php
@@ -12,14 +12,22 @@ class ActivityLogTable extends QuickTable
 
     protected $extraParams = array();
 
+    protected $lastDay;
+
+    protected $columnCount;
+
+    protected $isUsEnglish;
+
     public function getColumns()
     {
         return array(
             'id'              => 'l.id',
             'change_time'     => 'l.change_time',
+            'ts_change_time'  => 'UNIX_TIMESTAMP(l.change_time)',
             'author'          => 'l.author',
-            'action'          => "CONCAT(l.action_name || ' ' || REPLACE(l.object_type, 'icinga_', '')"
-                               . " || ' \"' || l.object_name || '\"')",
+            'action'          => 'l.action_name',
+            'log_message'     => "'[' || l.author || '] ' || l.action_name || ' ' || REPLACE(l.object_type, 'icinga_', '')"
+                               . " || ' \"' || l.object_name || '\"'",
             'action_name'     => 'l.action_name',
         );
     }
@@ -35,6 +43,12 @@ class ActivityLogTable extends QuickTable
         return array_merge(array('activity-log'), parent::listTableClasses());
     }
 
+    protected function renderRow($row)
+    {
+        $row->change_time = strftime('%H:%M:%S', $row->ts_change_time);
+        return $this->renderDayIfNew($row) . parent::renderRow($row);
+    }
+
     protected function getRowClasses($row)
     {
         $action = 'action-' . $row->action_name . ' ';
@@ -58,12 +72,62 @@ class ActivityLogTable extends QuickTable
     {
         $view = $this->view();
         return array(
+            // 'author'      => $view->translate('Author'),
+            'log_message' => $view->translate('Action'),
             'change_time' => $view->translate('Timestamp'),
-            'author'      => $view->translate('Author'),
-            'action'      => $view->translate('Action'),
         );
     }
 
+    protected function renderTitles($row)
+    {
+        return '';
+    }
+
+    protected function isUsEnglish()
+    {
+        if ($this->isUsEnglish === null) {
+            $this->isUsEnglish = in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'));
+        }
+
+        return $this->isUsEnglish;
+    }
+
+    protected function renderDayIfNew($row)
+    {
+        $view = $this->view();
+
+        if ($this->isUsEnglish()) {
+            $day = date('l, jS F Y', (int) $row->ts_change_time);
+        } else {
+            $day = strftime('%A, %e. %B, %Y', (int) $row->ts_change_time);
+        }
+
+        if ($this->lastDay === $day) {
+            return;
+        }
+
+        if ($this->lastDay === null) {
+            $htm = "<thead>\n  <tr>\n";
+        } else {
+            $htm = "</tbody>\n<thead>\n  <tr>\n";
+        }
+
+        if ($this->columnCount === null) {
+            $this->columnCount = count($this->getTitles());
+        }
+
+        $htm .= '<th colspan="' . $this->columnCount . '">' . $this->view()->escape($day) . '</th>' . "\n";
+        if ($this->lastDay === null) {
+            $htm .= "  </tr>\n";
+        } else {
+            $htm .= "  </tr>\n</thead>\n";
+        }
+
+        $this->lastDay = $day;
+
+        return $htm . "<tbody>\n";
+    }
+
     public function filterObject($type, $name)
     {
         $this->filters[] = array('l.object_type = ?', $type);
diff --git a/public/css/module.less b/public/css/module.less
index fe062f3..39b4b04 100644
--- a/public/css/module.less
+++ b/public/css/module.less
@@ -942,11 +942,19 @@ table.endpoints {
 }
 
 table.activity-log {
+    thead th {
+        text-align: right;
+    }
 
     tr th:first-child {
         padding-left: 2em;
     }
 
+    tr td:last-child {
+        text-align: right;
+        white-space: nowrap;
+    }
+
     tr td:first-child {
         padding-left: 2em;
         &::before {



More information about the icinga-checkins mailing list