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"> <div class="col-lg-12 mb-4">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </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>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -1,11 +1,39 @@
{% for timer in timers %} {% extends 'babyblotter/page.html' %}
<div class="card border-success text-center mb-2"> {% load widget_tweaks %}
<div class="card-header text-white bg-success ">{{ timer.name }}</div> {% load duration %}
<div class="card-body text-success">
<h4 class="card-text">{{ timer.current_duration }}</h4> {% block title %}Sleep{% endblock %}
</div>
<div class="card-footer text-muted small"> {% block content %}
{{ timer.start }} <h1>Timers</h1>
</div> <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> </div>
{% endfor %} {% endblock %}

View File

@ -8,13 +8,20 @@
<div class="dropdown-menu" aria-labelledby="nav-timer-menu-link"> <div class="dropdown-menu" aria-labelledby="nav-timer-menu-link">
{% if perms.core.add_timer %} {% if perms.core.add_timer %}
<a class="dropdown-item" href="{% url 'timer-add-quick' %}"> <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> </a>
{% if timers %}
<div class="dropdown-divider"></div>
{% endif %}
{% endif %} {% endif %}
{% for timer in timers %} {% 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> <a class="dropdown-item" href="{% url 'timer-detail' timer.id %}">{{ timer }}</a>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -9,13 +9,6 @@ from core.models import Timer
register = template.Library() 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) @register.inclusion_tag('core/timer_nav.html', takes_context=True)
def timer_nav(context, active=True): def timer_nav(context, active=True):
request = context['request'] or None request = context['request'] or None

View File

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

View File

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