Add timers list.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-09 11:54:34 -04:00
parent fe1b54842d
commit 1ae44c408f
6 changed files with 55 additions and 30 deletions

View File

@ -8,15 +8,6 @@
<div class="col-lg-12 mb-4">
{% block content %}{% endblock %}
</div>
{% if false and perms.core.view_timer %}
<div class="col-lg-2">
<h1>Timers</h1>
{% if perms.core.add_timer %}
{% add_timer request.path %}
{% endif %}
{% list_timers %}
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -1,11 +1,39 @@
{% for timer in timers %}
<div class="card border-success text-center mb-2">
<div class="card-header text-white bg-success ">{{ timer.name }}</div>
<div class="card-body text-success">
<h4 class="card-text">{{ timer.current_duration }}</h4>
</div>
<div class="card-footer text-muted small">
{{ timer.start }}
</div>
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% load duration %}
{% block title %}Sleep{% endblock %}
{% block content %}
<h1>Timers</h1>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
<tr>
<th>Name</th>
<th>Start</th>
<th>End</th>
<th>Duration</th>
<th>Active</th>
<th>User</th>
</tr>
</thead>
<tbody>
{% for timer in object_list %}
<tr>
<th scope="row"><a href="{% url 'timer-detail' timer.id %}">{{ timer }}</a></th>
<td>{{ timer.start }}</td>
<td>{{ timer.end }}</td>
<td>{{ timer.duration|duration_string }}</td>
<td>{{ timer.active }}</td>
<td>{{ timer.user }}</td>
</tr>
{% empty %}
<tr>
<th colspan="7">No timer entries found.</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
{% endblock %}

View File

@ -8,13 +8,20 @@
<div class="dropdown-menu" aria-labelledby="nav-timer-menu-link">
{% if perms.core.add_timer %}
<a class="dropdown-item" href="{% url 'timer-add-quick' %}">
<i class="fa fa-plus" aria-hidden="true"></i> Create Timer
<i class="fa fa-clock-o" aria-hidden="true"></i> Quick Start Timer
</a>
<a class="dropdown-item" href="{% url 'timer-add' %}">
<i class="fa fa-plus" aria-hidden="true"></i> Start Timer
</a>
{% endif %}
{% if perms.core.view_timer %}
<a class="dropdown-item" href="{% url 'timer-list' %}">
<i class="fa fa-list" aria-hidden="true"></i> View Timers
</a>
{% if timers %}
<div class="dropdown-divider"></div>
{% endif %}
{% endif %}
{% for timer in timers %}
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Active Timers</h6>
<a class="dropdown-item" href="{% url 'timer-detail' timer.id %}">{{ timer }}</a>
{% endfor %}
</div>

View File

@ -9,13 +9,6 @@ from core.models import Timer
register = template.Library()
@register.inclusion_tag('core/timer_list.html', takes_context=True)
def list_timers(context, active=True):
request = context['request'] or None
timers = Timer.objects.filter(user=request.user, active=active)
return {'timers': timers}
@register.inclusion_tag('core/timer_nav.html', takes_context=True)
def timer_nav(context, active=True):
request = context['request'] or None

View File

@ -47,6 +47,7 @@ urlpatterns = [
url(r'^sleep/(?P<pk>[0-9]+)/delete/$', views.SleepDelete.as_view(),
name='sleep-delete'),
url(r'^timers/$', views.TimerList.as_view(), name='timer-list'),
url(r'^timer/add/$', views.TimerAdd.as_view(), name='timer-add'),
url(r'^timer/add/quick/$', views.TimerAddQuick.as_view(),
name='timer-add-quick'),

View File

@ -152,6 +152,11 @@ class SleepDelete(PermissionRequiredMixin, DeleteView):
success_url = '/sleep'
class TimerList(PermissionRequiredMixin, ListView):
model = Timer
permission_required = ('core.view_timer',)
class TimerDetail(PermissionRequiredMixin, DetailView):
model = Timer
permission_required = ('core.view_timer',)