From 8037f19e13c6b85c3798f1fde32f030d49d334c2 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 1 Jun 2015 14:33:07 +0200 Subject: [PATCH] show/activitylog: first simple visualization --- application/controllers/ShowController.php | 14 ++++++++ .../scripts/show/activitylog-create.phtml | 24 +++++++++++++ .../scripts/show/activitylog-delete.phtml | 8 +++++ .../scripts/show/activitylog-modify.phtml | 34 +++++++++++++++++++ .../views/scripts/show/activitylog.phtml | 23 +++++++++++++ library/Director/Db.php | 7 ++++ public/css/module.less | 28 +++++++++++++++ 7 files changed, 138 insertions(+) create mode 100644 application/controllers/ShowController.php create mode 100644 application/views/scripts/show/activitylog-create.phtml create mode 100644 application/views/scripts/show/activitylog-delete.phtml create mode 100644 application/views/scripts/show/activitylog-modify.phtml create mode 100644 application/views/scripts/show/activitylog.phtml diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php new file mode 100644 index 00000000..786cd901 --- /dev/null +++ b/application/controllers/ShowController.php @@ -0,0 +1,14 @@ +params->get('id')) { + $this->view->entry = $this->db()->fetchActivityLogEntry($id); + $this->view->title = $this->translate('Activity'); + } + } +} diff --git a/application/views/scripts/show/activitylog-create.phtml b/application/views/scripts/show/activitylog-create.phtml new file mode 100644 index 00000000..67efbc6a --- /dev/null +++ b/application/views/scripts/show/activitylog-create.phtml @@ -0,0 +1,24 @@ +

object_type)), + $entry->object_name +) ?>

+ +

translate('Properties') ?>

+ + +new_properties); + +foreach ($new as $key => $value) { + if ($key === 'id') continue; + + if ($value === null) continue; + + echo ' \n"; +} +?> +
' . $this->escape($key) . ''; + echo $this->escape($value); + echo "
+ diff --git a/application/views/scripts/show/activitylog-delete.phtml b/application/views/scripts/show/activitylog-delete.phtml new file mode 100644 index 00000000..58d973ea --- /dev/null +++ b/application/views/scripts/show/activitylog-delete.phtml @@ -0,0 +1,8 @@ +

object_type)), + $entry->object_name +) ?>

+
+escape(print_r($entry, 1)) ?>
+
diff --git a/application/views/scripts/show/activitylog-modify.phtml b/application/views/scripts/show/activitylog-modify.phtml new file mode 100644 index 00000000..f9388df4 --- /dev/null +++ b/application/views/scripts/show/activitylog-modify.phtml @@ -0,0 +1,34 @@ +

object_type)), + $entry->object_name +) ?>

+ +

translate('Properties') ?>

+ + +old_properties); +$new = json_decode($entry->new_properties); + +foreach ($old as $key => $value) { + if ($key === 'id') continue; + + $modified = array_key_exists($key, $new); + + if ($value === null && ! $modified) continue; + echo ' \n"; +} +?> +
' . $this->escape($key) . ''; + if ($modified) { + printf( + '%s %s', + $this->escape($value), + $this->escape($new->$key) + ); + } else { + echo $this->escape($value); + } + echo "
+ diff --git a/application/views/scripts/show/activitylog.phtml b/application/views/scripts/show/activitylog.phtml new file mode 100644 index 00000000..55b39e34 --- /dev/null +++ b/application/views/scripts/show/activitylog.phtml @@ -0,0 +1,23 @@ +
+tabs ?> +
+ +
+action_name) { +case 'create': + echo $this->render('show/activitylog-create.phtml'); + break; +case 'modify': + echo $this->render('show/activitylog-modify.phtml'); + break; +case 'delete': + echo $this->render('show/activitylog-delete.phtml'); + break; +default: + echo 'Invalid action'; +} + +?> +
diff --git a/library/Director/Db.php b/library/Director/Db.php index 98639b75..42d15ddc 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -13,6 +13,13 @@ class Db extends DbConnection return $this->getDbAdapter(); } + public function fetchActivityLogEntry($id) + { + $sql = 'SELECT * FROM director_activity_log WHERE id = ' . (int) $id; + + return $this->db()->fetchRow($sql); + } + public function getLastActivityChecksum() { $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(HEX(checksum)) AS checksum FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; diff --git a/public/css/module.less b/public/css/module.less index 30aa2e37..192b7e25 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -28,3 +28,31 @@ table.simple { text-align: right; } } + +table.log-properties { + + width: 100%; + th { + width: 12em; + text-align: left; + } + + td { + font-family: monospace; + } + + span { + padding: 0.3em 1em; + } + + .old { + background-color: @colorCriticalHandled; + color: white; + text-decoration: stroken; + } + + .new { + background-color: @colorOk; + color: white; + } +}