Skip to content

Commit 50db861

Browse files
committed
Add test code for MSC2184 - <details> tags
1 parent 4f3bdfd commit 50db861

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

config.yml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rules:
2828
# The following values are optional:
2929
#image: true # Attach image to the notification?
3030
#embed_image: true # Upload and embed the image into the message?
31+
#details_tag: false # Use a <details> tag to include image (MSC2184)
3132
#templates:
3233
# Templates to use when rendering the notification, available placeholders:
3334
# %TEMPLATES% - lib/grafana_matrix/templates

lib/grafana_matrix/config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def embed_image?
4949
data.fetch(:embed_image, true)
5050
end
5151

52+
def details?
53+
data.fetch(:details_tag, false)
54+
end
55+
5256
def msgtype
5357
data.fetch(:msgtype, config.default_msgtype)
5458
end

lib/grafana_matrix/templates/html.erb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<h4><a href="<%= data['ruleUrl'] %>" style="font-weight: bold; font-style: italic"><font color="<%= SEVERITY_COLOURS[data['state'].to_sym] %>"><%= data['title'] %></font></a></h4>
2-
<%- unless data.fetch('message', '').empty? -%>
2+
<%- if data['imageUrl'] && rule.details? && data['state'] != 'ok' -%>
3+
<details><summary>
4+
<%- unless data.fetch('message', '').empty? -%>
5+
<%= data['message'] %>
6+
<%- end -%>
7+
<%- else -%>
8+
<%- unless data.fetch('message', '').empty? -%>
39
<p><%= data['message'] %></p>
10+
<%- end -%>
411
<%- end -%>
512
<%- if data.key? 'error' -%>
613
<h5>Error:</h5>
@@ -12,12 +19,20 @@
1219
<b><%= match['metric'] %></b>: <%= match['value'] %><br/>
1320
<%- end -%>
1421
<%- end -%>
22+
<%- if data['imageUrl'] && rule.details? -%>
23+
</summary>
24+
<%- end -%>
1525
<%- if data['imageUrl'] && rule.image? -%>
26+
<%- if !rule.details? -%>
1627
<br/>
28+
<%- end -%>
1729
<%- if rule.embed_image? -%>
1830
<a href="<%= data['ruleUrl'] %>"><img src="<%= data['imageUrl'] %>" alt="<%= data['ruleName'] %>" /></a>
1931
<%- else -%>
2032
<a href="<%= data['imageUrl'] %>">Alert image</a>
2133
<%- end -%>
2234
<%- end -%>
2335
<%- end -%>
36+
<%- if data['imageUrl'] && rule.details? -%>
37+
</details>
38+
<%- end -%>

0 commit comments

Comments
 (0)