Browse Source

Can remove channels

pull/7/head
Pēteris Caune 9 years ago
parent
commit
058101b941
6 changed files with 74 additions and 5 deletions
  1. +2
    -1
      hc/front/urls.py
  2. +15
    -1
      hc/front/views.py
  3. +8
    -0
      static/css/channels.css
  4. +11
    -1
      static/js/channels.js
  5. +37
    -1
      templates/front/channels.html
  6. +1
    -1
      templates/front/my_checks_desktop.html

+ 2
- 1
hc/front/urls.py View File

@ -8,7 +8,7 @@ urlpatterns = [
url(r'^checks/([\w-]+)/name/$', views.update_name, name="hc-update-name"),
url(r'^checks/([\w-]+)/timeout/$', views.update_timeout, name="hc-update-timeout"),
url(r'^checks/([\w-]+)/email/$', views.email_preview),
url(r'^checks/([\w-]+)/remove/$', views.remove, name="hc-remove-check"),
url(r'^checks/([\w-]+)/remove/$', views.remove_check, name="hc-remove-check"),
url(r'^checks/([\w-]+)/log/$', views.log, name="hc-log"),
url(r'^pricing/$', views.pricing, name="hc-pricing"),
url(r'^docs/$', views.docs, name="hc-docs"),
@ -16,6 +16,7 @@ urlpatterns = [
url(r'^channels/$', views.channels, name="hc-channels"),
url(r'^channels/add/$', views.add_channel, name="hc-add-channel"),
url(r'^channels/([\w-]+)/checks/$', views.channel_checks, name="hc-channel-checks"),
url(r'^channels/([\w-]+)/remove/$', views.remove_channel, name="hc-remove-channel"),
url(r'^channels/([\w-]+)/verify/([\w-]+)/$',
views.verify_email, name="hc-verify-email"),


+ 15
- 1
hc/front/views.py View File

@ -144,7 +144,7 @@ def email_preview(request, code):
@login_required
@uuid_or_400
def remove(request, code):
def remove_check(request, code):
assert request.method == "POST"
check = Check.objects.get(code=code)
@ -251,3 +251,17 @@ def verify_email(request, code, token):
return render(request, "front/verify_email_success.html")
return render(request, "bad_link.html")
@login_required
@uuid_or_400
def remove_channel(request, code):
assert request.method == "POST"
channel = Channel.objects.get(code=code)
if channel.user != request.user:
return HttpResponseForbidden()
channel.delete()
return redirect("hc-channels")

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

@ -67,3 +67,11 @@ table.channels-table > tbody > tr > th {
.channel-row:hover .edit-checks {
border: 1px dotted #AAA;
}
.channel-remove {
visibility: hidden;
}
.channel-row:hover .channel-remove {
visibility: visible;
}

+ 11
- 1
static/js/channels.js View File

@ -26,7 +26,6 @@ $(function() {
return false;
});
var $cm = $("#checks-modal");
$cm.on("click", "#toggle-all", function() {
var value = $(this).prop("checked");
@ -35,4 +34,15 @@ $(function() {
});
$(".channel-remove").click(function() {
var $this = $(this);
$("#remove-channel-form").attr("action", $this.data("url"));
$(".remove-channel-name").text($this.data("name"));
$('#remove-channel-modal').modal("show");
return false;
});
});

+ 37
- 1
templates/front/channels.html View File

@ -9,6 +9,7 @@
<div class="col-sm-12">
<h1>Notification Channels</h1>
<table class="table channels-table">
{% if channels %}
<tr>
<th>Type</th>
<th>Value</th>
@ -41,11 +42,21 @@
{{ ch.checks.count }} of {{ num_checks }}
</a>
</td>
<td>
<button
data-name="{{ ch.value }}"
data-url="{% url 'hc-remove-channel' ch.code %}"
class="btn btn-sm btn-default channel-remove"
type="button">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
<td>
</td>
</tr>
{% endfor %}
{% endif %}
<tr>
<th colspan="2" class="channels-add-title">
Add Notification Channel
@ -71,7 +82,6 @@
<button type="submit" class="btn btn-success">Add</button>
</td>
<td>
</td>
</form>
</tr>
@ -109,6 +119,32 @@
</div>
</div>
<div id="remove-channel-modal" class="modal">
<div class="modal-dialog">
<form id="remove-channel-form" method="post">
{% csrf_token %}
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</span></button>
<h4 class="remove-check-title">Remove Channel <span class="remove-channel-name"></h4>
</div>
<div class="modal-body">
<p>You are about to remove channel
<strong class="remove-channel-name">---</strong>.
</p>
<p>Once it's gone it's gone. But, if you change your
mind later, you can create a similar channel again.</p>
<p>Do you want to continue?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Remove</button>
</div>
</div>
</form>
</div>
</div>
{% endblock %}
{% block scripts %}


+ 1
- 1
templates/front/my_checks_desktop.html View File

@ -79,7 +79,7 @@
<li role="separator" class="divider"></li>
<li>
<a href="#" class="check-menu-remove"
data-name="{{ check.name|default:check.code }}"
data-name="{{ check.name_then_code }}"
data-url="{% url 'hc-remove-check' check.code %}">
<span class="glyphicon glyphicon-trash"></span>
Remove


Loading…
Cancel
Save