Browse Source

Style tweaks for PushOver integration

pull/15/head
Pēteris Caune 9 years ago
parent
commit
3ba47b1a67
6 changed files with 82 additions and 34 deletions
  1. +10
    -2
      hc/api/models.py
  2. +8
    -11
      hc/front/views.py
  3. +8
    -0
      static/css/add_pushover.css
  4. +1
    -0
      templates/base.html
  5. +3
    -2
      templates/front/channels.html
  6. +52
    -19
      templates/integrations/add_pushover.html

+ 10
- 2
hc/api/models.py View File

@ -26,6 +26,14 @@ CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"),
("hipchat", "HipChat"), ("hipchat", "HipChat"),
("slack", "Slack"), ("pd", "PagerDuty"), ("po", "Pushover")) ("slack", "Slack"), ("pd", "PagerDuty"), ("po", "Pushover"))
PO_PRIORITIES = {
-2: "lowest",
-1: "low",
0: "normal",
1: "high",
2: "emergency"
}
class Check(models.Model): class Check(models.Model):
@ -195,7 +203,7 @@ class Channel(models.Model):
else: else:
title = "%s is now UP" % check.name_then_code() title = "%s is now UP" % check.name_then_code()
user_key, priority = self.po_value
user_key, priority, _ = self.po_value
payload = { payload = {
"token": settings.PUSHOVER_API_TOKEN, "token": settings.PUSHOVER_API_TOKEN,
"user": user_key, "user": user_key,
@ -219,7 +227,7 @@ class Channel(models.Model):
assert self.kind == "po" assert self.kind == "po"
user_key, prio = self.value.split("|") user_key, prio = self.value.split("|")
prio = int(prio) prio = int(prio)
return user_key, prio
return user_key, prio, PO_PRIORITIES[prio]
class Notification(models.Model): class Notification(models.Model):


+ 8
- 11
hc/front/views.py View File

@ -358,11 +358,8 @@ def add_pushover(request):
if request.GET.get("pushover_unsubscribed", "0") == "1": if request.GET.get("pushover_unsubscribed", "0") == "1":
# Unsubscription: delete all Pushover channels for this user # Unsubscription: delete all Pushover channels for this user
for channel in Channel.objects.filter(user=request.user, kind="po"):
channel.delete()
Channel.objects.filter(user=request.user, kind="po").delete()
return redirect("hc-channels") return redirect("hc-channels")
else: else:
# Subscription # Subscription
user_key = request.GET["pushover_user_key"] user_key = request.GET["pushover_user_key"]
@ -373,10 +370,10 @@ def add_pushover(request):
"value": "%s|%d" % (user_key, priority), "value": "%s|%d" % (user_key, priority),
}) })
else:
ctx = {
"page": "channels",
"po_retry_delay": td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY),
"po_expiration": td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION),
}
return render(request, "integrations/add_pushover.html", ctx)
# Integration Settings form
ctx = {
"page": "channels",
"po_retry_delay": td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY),
"po_expiration": td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION),
}
return render(request, "integrations/add_pushover.html", ctx)

+ 8
- 0
static/css/add_pushover.css View File

@ -0,0 +1,8 @@
#add-pushover .radio {
margin-bottom: 1em;
}
#add-pushover .help {
display: block;
color: #888;
}

+ 1
- 0
templates/base.html View File

@ -27,6 +27,7 @@
<link rel="stylesheet" href="{% static 'css/channels.css' %}" type="text/css"> <link rel="stylesheet" href="{% static 'css/channels.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/channel_checks.css' %}" type="text/css"> <link rel="stylesheet" href="{% static 'css/channel_checks.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/log.css' %}" type="text/css"> <link rel="stylesheet" href="{% static 'css/log.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/add_pushover.css' %}" type="text/css">
{% endcompress %} {% endcompress %}
</head> </head>
<body class="page-{{ page }}"> <body class="page-{{ page }}">


+ 3
- 2
templates/front/channels.html View File

@ -29,11 +29,12 @@
<span class="preposition"> <span class="preposition">
{% if ch.kind == "email" %} to {% endif %} {% if ch.kind == "email" %} to {% endif %}
{% if ch.kind == "pd" %} API key {% endif %} {% if ch.kind == "pd" %} API key {% endif %}
{% if ch.kind == "po" %} User key / priority {% endif %}
{% if ch.kind == "po" %} user key {% endif %}
</span> </span>
{% if ch.kind == "po" %} {% if ch.kind == "po" %}
{{ ch.po_value|join:" / " }}
{{ ch.po_value|first }}
({{ ch.po_value|last }} priority)
{% else %} {% else %}
{{ ch.value }} {{ ch.value }}
{% endif %} {% endif %}


+ 52
- 19
templates/integrations/add_pushover.html View File

@ -16,25 +16,61 @@
<h2>Integration Settings</h2> <h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-pushover' %}">
<form method="post" id="add-pushover" class="form-horizontal" action="{% url 'hc-add-pushover' %}">
{% csrf_token %} {% csrf_token %}
<div class="form-group"> <div class="form-group">
<label for="po_priority" class="col-sm-2 control-label">Notification priority</label> <label for="po_priority" class="col-sm-2 control-label">Notification priority</label>
<div class="col-sm-3">
<select class="form-control" id="po_priority" name="po_priority">
<option value="-2">Lowest</option>
<option value="-1">Low</option>
<option value="0" selected>Normal</option>
<option value="1">High</option>
<option value="2"
data-toggle="tooltip" data-placement="right"
title="Emergency notifications will be repeated every
{{po_retry_delay|hc_duration }} for at most
{{ po_expiration|hc_duration }} until you
acknowledge them.">
Emergency
</option>
</select>
<div class="col-sm-6">
<div class="radio">
<label>
<input type="radio" name="po_priority" value="-2">
Lowest Priority.
<span class="help">
Generates no notification/alert on your device.
On iOS, the application badge number will be increased.
</span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="po_priority" value="-1">
Low Priority.
<span class="help">
Sends a quiet notification.
</span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="po_priority" value="0" checked>
Normal Priority.
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="po_priority" value="1">
<span class="text-warning">High Priority.</span>
<span class="help">
Bypasses user's quiet hours.
</span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="po_priority" value="-2">
<span class="text-danger">Emergency Priority.</span>
<span class="help">
The notification is repeated every
{{po_retry_delay|hc_duration }} for at most
{{ po_expiration|hc_duration }} until you
acknowledge them.
</span>
</label>
</div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -55,7 +91,4 @@
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script> <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script> <script src="{% static 'js/bootstrap.min.js' %}"></script>
{% endcompress %} {% endcompress %}
<script>$(function() {
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
})</script>
{% endblock %} {% endblock %}

Loading…
Cancel
Save