Skip to content

Commit

Permalink
list view for audio
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon committed Nov 7, 2014
1 parent a74d337 commit 0fe14ea
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,6 @@ def load_json(self, data):

def editable_by(self, user):
return user.is_authenticated() and user.id == self.user_id

def is_closed(self):
return self.state == Annotation.STATE_CLOSED
12 changes: 10 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from .auth import lm
from .models import Annotation
from .models import AudioAnnotation
from .models import Comment
from .models import db
from .models import Document
Expand Down Expand Up @@ -125,8 +126,15 @@ def view_list(id):
"""
id = kore_id(id)
doc = Document.query.get_or_404(id)
annotations = Annotation.query.filter_by(doc=id)
return render_template('list.html',
if doc.filetype == 'pdf' or doc.filetype == 'image':
annotations = Annotation.query.filter_by(doc=id)
template = 'list.html'
elif doc.filetype == 'audio':
annotations = AudioAnnotation.query.filter_by(doc_id=id)
template = 'list_audio.html'
else:
assert False, 'Unknown filetype: {}'.format(doc.filetype)
return render_template(template,
doc=doc,
annotations=annotations,
)
Expand Down
6 changes: 5 additions & 1 deletion static/coffee/audioplayer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class AudioPlayer
@ctx.fillRect wf, 0, aw, size

for annotation in @annotations
@ctx.fillStyle = "orange"
switch annotation.state
when 'open'
@ctx.fillStyle = "orange"
when 'closed'
@ctx.fillStyle = "lightgreen"
annStart = @secondsToPixels annotation.start
annSize = @secondsToPixels annotation.length
@ctx.fillRect wf, annStart, aw, annSize
Expand Down
4 changes: 2 additions & 2 deletions static/coffee/listview.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
list_view_init = ->
list_view_init = (base) ->
$('.ann-state-checkbox').click ->
annid = $(this).data 'annid'
state = if @checked then 'closed' else 'open'
$.ajax
url: '/annotation/' + annid
url: base + annid
type: 'PUT'
data:
state: state
2 changes: 1 addition & 1 deletion templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
{% endblock %}
{% block js_end %}
<script>
list_view_init();
list_view_init('/annotation/');
</script>
{% endblock %}
42 changes: 42 additions & 0 deletions templates/list_audio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% from 'macros.html' import annotation_state %}
{% extends "base.html" %}
{% block content %}

<div class="col-md-9">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Text</th>
<th>Done?</th>
</tr>
</thead>
<tbody>
{% for ann in annotations %}
<tr>
<td>{{ann.start|round(1)}} s</td>
<td>{{ann.text}}</td>
<td>{{annotation_state(ann)}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-md-3">
<div id="subnav" data-spy="affix">

<div class="list-group">
<a href="{{url_for('.view_doc', id=doc.id)}}" class="list-group-item">
<span class="glyphicon glyphicon-file"></span>
Document mode
</a>
</div>
</div>
</div>

{% endblock %}
{% block js_end %}
<script>
list_view_init('/audioannotation/');
</script>
{% endblock %}

0 comments on commit 0fe14ea

Please sign in to comment.