Archive.html is feature-complete
It just needs some love in table style and alignments
This commit is contained in:
parent
1d5355c771
commit
cfa08ddb72
4 changed files with 49 additions and 7 deletions
|
@ -15,14 +15,49 @@
|
|||
<script src="/static/js/jquery.ui.datepicker-it.min.js"></script>
|
||||
<script src="/static/js/rec.js"></script>
|
||||
<script>
|
||||
function delta(end, start) {
|
||||
//end, start are unix timestamps
|
||||
diff = parseInt(end, 10) - parseInt(start, 10); //diff is in seconds
|
||||
msec = diff*1000;
|
||||
var hh = Math.floor(msec / 1000 / 60 / 60);
|
||||
msec -= hh * 1000 * 60 * 60;
|
||||
var mm = Math.floor(msec / 1000 / 60);
|
||||
msec -= mm * 1000 * 60;
|
||||
var ss = Math.floor(msec / 1000);
|
||||
msec -= ss * 1000;
|
||||
|
||||
if(hh === 0) {
|
||||
if(mm === 0) {
|
||||
return ss + 's';
|
||||
}
|
||||
return mm + 'min ' + ss + 's';
|
||||
}
|
||||
return hh + 'h ' + mm + 'm ' + ss + 's';
|
||||
}
|
||||
$(function() {
|
||||
"use strict";
|
||||
RecAPI.get_archive().success(function(archive) {
|
||||
$.each(archive, function(idx, rec) {
|
||||
$('#ongoing-recs-table tbody')
|
||||
.append($('<tr/>').append($('<td/>')
|
||||
.append($('<a/>').prop('href', '/output/' + rec.filename).text(rec.filename))));
|
||||
});
|
||||
/* To get sorted traversal, we need to do an array containing keys */
|
||||
var keys = [];
|
||||
for(var prop in archive) {
|
||||
keys.push(prop);
|
||||
}
|
||||
keys.sort(function(a,b) { return b - a; }); //descending
|
||||
|
||||
/* ok, now we can traverse the objects */
|
||||
for(var i =0; i < keys.length; i++) {
|
||||
var rec = archive[keys[i]];
|
||||
console.log(rec);
|
||||
var name = $('<td/>').text(rec.name);
|
||||
var start = $('<td/>').text(config.date_read(
|
||||
parseInt(rec.starttime, 10)).toLocaleString()
|
||||
);
|
||||
var duration = $('<td/>').text(delta(rec.endtime, rec.starttime));
|
||||
var fn = $('<td/>').append($('<a/>').prop('href', '/output/' +
|
||||
rec.filename).text(rec.filename));
|
||||
var row = $('<tr/>').append(name).append(start).append(duration).append(fn);
|
||||
$('#ongoing-recs-table tbody').append(row);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
@ -47,6 +82,9 @@ $(function() {
|
|||
id="ongoing-recs-table" style="margin-top: 3em;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Inizio</th>
|
||||
<th>Durata</th>
|
||||
<th>Filename</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -102,10 +102,10 @@ $.widget("ror.ongoingrec", {
|
|||
var rec = this.options.rec;
|
||||
this.element.find('input').val(rec.name);
|
||||
this.element.find(':ror-countclock').countclock("option", "since",
|
||||
rec.starttime !== null ? new Date(rec.starttime*1000) : null);
|
||||
rec.starttime !== null ? config.date_read(rec.starttime) : null);
|
||||
if(this.options.state > 0) {
|
||||
this.element.find(':ror-countclock').countclock("option", "to",
|
||||
rec.endtime !== null ? new Date(rec.endtime*1000) : null
|
||||
rec.endtime !== null ? config.date_read(rec.endtime) : null
|
||||
);
|
||||
} else {
|
||||
this.element.find(':ror-countclock').countclock("option", "to", null);
|
||||
|
|
|
@ -4,6 +4,9 @@ var config = {
|
|||
date_write: function(d) {
|
||||
return Math.floor(d.getTime() / 1000);
|
||||
},
|
||||
date_read: function(unix_timestamp) {
|
||||
return new Date(unix_timestamp * 1000);
|
||||
},
|
||||
datetimeformat: function(d) {
|
||||
if(Math.abs(new Date() - d) > (3*60*60*1000)) {
|
||||
return d.toLocaleString();
|
||||
|
|
|
@ -145,6 +145,7 @@ class RecDB:
|
|||
def get_archive_recent(self):
|
||||
query = self._query_saved()
|
||||
query = self._query_newer(timedelta(days=15), query)
|
||||
query = query.order_by(Rec.starttime.desc())
|
||||
return query.all()
|
||||
|
||||
def _query_ongoing(self, query=None):
|
||||
|
|
Loading…
Reference in a new issue