From 32da02c16239ab8475e48e029d3c514e11742117 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 4 May 2015 14:30:25 +0200 Subject: [PATCH] Deduplicate comment views Move comment detail and description into separate partial to reduce code duplication --- .../views/scripts/list/comments.phtml | 36 ++----------- .../comment/comment-description.phtml | 27 ++++++++++ .../partials/comment/comment-detail.phtml | 18 +++++++ .../partials/comment/comment-header.phtml | 51 +------------------ 4 files changed, 52 insertions(+), 80 deletions(-) create mode 100644 modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml create mode 100644 modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index 8810c6e67..248c40490 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -18,40 +18,14 @@ if (count($comments) === 0) { + data-icinga-multiselect-data="comment_id"> - - type) { - case 'flapping': - $icon = 'flapping'; - $title = $this->translate('Flapping'); - $tooltip = $this->translate('Comment was caused by a flapping host or service.'); - break; - case 'comment': - $icon = 'user'; - $title = $this->translate('User Comment'); - $tooltip = $this->translate('Comment was created by an user.'); - break; - case 'downtime': - $icon = 'plug'; - $title = $this->translate('Downtime'); - $tooltip = $this->translate('Comment was caused by a downtime.'); - break; - case 'ack': - $icon = 'ok'; - $title = $this->translate('Acknowledgement'); - $tooltip = $this->translate('Comment was caused by an acknowledgement.'); - break; - } - ?> + comment = $comment; ?> +
- icon($icon, $tooltip) ?> -
- escape($title); ?> -
- prefixedTimeSince($comment->timestamp); ?> + render('partials/comment/comment-description.phtml'); ?>
objecttype === 'service'): ?> diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml new file mode 100644 index 000000000..2c5f07133 --- /dev/null +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml @@ -0,0 +1,27 @@ +type) { + case 'flapping': + $icon = 'flapping'; + $title = $this->translate('Flapping'); + $tooltip = $this->translate('Comment was caused by a flapping host or service.'); + break; + case 'comment': + $icon = 'user'; + $title = $this->translate('User Comment'); + $tooltip = $this->translate('Comment was created by an user.'); + break; + case 'downtime': + $icon = 'plug'; + $title = $this->translate('Downtime'); + $tooltip = $this->translate('Comment was caused by a downtime.'); + break; + case 'ack': + $icon = 'ok'; + $title = $this->translate('Acknowledgement'); + $tooltip = $this->translate('Comment was caused by an acknowledgement.'); + break; +} +?> +escape($title); ?>
+icon($icon, $tooltip) ?> +prefixedTimeSince($comment->timestamp); ?> diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml new file mode 100644 index 000000000..e31f1fdce --- /dev/null +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml @@ -0,0 +1,18 @@ +objecttype === 'service'): ?> + icon('service', $this->translate('Service')); ?> + link()->service( + $comment->service_description, + $comment->service_display_name, + $comment->host_name, + $comment->host_display_name + ); ?> + + icon('host', $this->translate('Host')); ?> + link()->host($comment->host_name, $comment->host_display_name); ?> + + +
+icon('comment', $this->translate('Comment')); ?> author) + ? '[' . $comment->author . '] ' + : ''; +?>escape($comment->comment); ?> diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-header.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-header.phtml index 6b9a5c53e..ce0eabe03 100644 --- a/modules/monitoring/application/views/scripts/partials/comment/comment-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-header.phtml @@ -1,57 +1,10 @@ -
- - type) { - case 'flapping': - $icon = 'flapping'; - $title = $this->translate('Flapping'); - $tooltip = $this->translate('Comment was caused by a flapping host or service.'); - break; - case 'comment': - $icon = 'user'; - $title = $this->translate('User Comment'); - $tooltip = $this->translate('Comment was created by an user.'); - break; - case 'downtime': - $icon = 'plug'; - $title = $this->translate('Downtime'); - $tooltip = $this->translate('Comment was caused by a downtime.'); - break; - case 'ack': - $icon = 'ok'; - $title = $this->translate('Acknowledgement'); - $tooltip = $this->translate('Comment was caused by an acknowledgement.'); - break; - } - ?> - - escape($title); ?> -
- icon($icon, $tooltip) ?> - prefixedTimeSince($comment->timestamp); ?> + render('partials/comment/comment-description.phtml'); ?>
- objecttype === 'service'): ?> - icon('service', $this->translate('Service')); ?> - link()->service( - $comment->service_description, - $comment->service_display_name, - $comment->host_name, - $comment->host_display_name - ); ?> - - icon('host', $this->translate('Host')); ?> - link()->host($comment->host_name, $comment->host_display_name); ?> - - -
- icon('comment', $this->translate('Comment')); ?> author) - ? '[' . $comment->author . '] ' - : ''; - ?>escape($comment->comment); ?> + render('partials/comment/comment-detail.phtml'); ?>