diff --git a/server/pages/old.html b/server/pages/old.html
index 8fa9b06..253873d 100644
--- a/server/pages/old.html
+++ b/server/pages/old.html
@@ -14,7 +14,7 @@
-
+
@@ -60,9 +60,9 @@
diff --git a/server/static/js/new.js b/server/static/js/new.js
index 5c38634..8adc37b 100644
--- a/server/static/js/new.js
+++ b/server/static/js/new.js
@@ -1,4 +1,4 @@
-/*global $, config, RecAPI*/
+/*global $, config, RecAPI, poll_job*/
//TODO: move to a separate file(?)
$.widget("ror.countclock", {
@@ -37,9 +37,9 @@ $.widget("ror.countclock", {
$.widget("ror.ongoingrec", {
options: {
rec: null,
- state: 0,
- filename: null,
- /*0 = ongoing, 1 = encoding, 2 = ready to download, 9 = errors*/
+ state: 0,
+ filename: null,
+ /*0 = ongoing, 1 = encoding, 2 = ready to download, 9 = errors*/
},
_create: function() {
"use strict";
@@ -49,11 +49,11 @@ $.widget("ror.ongoingrec", {
var view = this.element.data('rec', rec).addClass('ongoing-rec').append(
$(' | ').append(
$('').attr('placeholder', 'Nome trasmissione')
- )
- ).append( $(' | ').countclock()).append(
- $(' | ').append($('')
- .addClass('pure-button pure-button-large'))
- );
+ )
+ ).append( $(' | ').countclock()).append(
+ $(' | ').append($('')
+ .addClass('pure-button pure-button-large'))
+ );
this._update();
view.on("change", "input", function(evt) {
@@ -62,8 +62,8 @@ $.widget("ror.ongoingrec", {
prevrec.name = $(evt.target).val();
$(evt.target).parents('tr.ongoing-rec').data('rec', prevrec);
widget._trigger("change", evt,
- {rec: rec, widget: widget, changed: {name: rec.name}}
- );
+ {rec: rec, widget: widget, changed: {name: rec.name}}
+ );
});
view.on("click", ".rec-stop", function(evt) {
widget._trigger("stop", evt, {rec: rec, widget: widget});
@@ -71,16 +71,16 @@ $.widget("ror.ongoingrec", {
view.on("click", ".rec-failed", function(evt) {
$('').html($('').text(widget.options.errormsg))
.dialog({modal: true, title: "Dettaglio errori",
- buttons: {
- Retry: function() {
- console.log("retrying");
- widget._setOption("state", 0);
- widget._trigger("retry", evt, {rec: rec, widget: widget});
- $(this).dialog("close");
- }, Cancel: function() {
- $(this).dialog("close");
- }
- }
+ buttons: {
+ Retry: function() {
+ console.log("retrying");
+ widget._setOption("state", 0);
+ widget._trigger("retry", evt, {rec: rec, widget: widget});
+ $(this).dialog("close");
+ }, Cancel: function() {
+ $(this).dialog("close");
+ }
+ }
});
});
@@ -102,56 +102,43 @@ $.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 ? new Date(rec.starttime*1000) : 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 ? new Date(rec.endtime*1000) : null
+ );
} else {
this.element.find(':ror-countclock').countclock("option", "to", null);
}
-
+
this.element.find('a').removeClass(
- 'pure-button-disabled rec-encoding rec-download rec-failed rec-stop');
- switch(this.options.state) {
- case 0:
- this.element.find('a').addClass("rec-stop").html(
- $('').addClass('fa fa-stop')).append(' Stop');
+ 'pure-button-disabled rec-encoding rec-download rec-failed rec-stop');
+ switch(this.options.state) {
+ case 0:
+ this.element.find('a').addClass("rec-stop").html(
+ $('').addClass('fa fa-stop')).append(' Stop');
break;
- case 1:
- this.element.find('a')
+ case 1:
+ this.element.find('a')
.addClass("pure-button-disabled rec-encoding").html(
- $('').addClass('fa fa-clock-o')).append(' Aspetta');
+ $('').addClass('fa fa-clock-o')).append(' Aspetta');
break;
- case 2:
- this.element.find('a').addClass("rec-download")
+ case 2:
+ this.element.find('a').addClass("rec-download")
.prop('href', this.options.filename)
.html(
- $('').addClass('fa fa-download').css('color',
- 'green')).append(' Scarica');
+ $('').addClass('fa fa-download').css('color', 'green'))
+ .append(' Scarica');
break;
- case 9:
- this.element.find('a').addClass("rec-failed").html(
- $('').addClass('fa fa-warning')).append(' Errori');
+ case 9:
+ this.element.find('a').addClass("rec-failed")
+ .html(
+ $('').addClass('fa fa-warning')).append(' Errori');
break;
- }
+ }
}
});
-function poll_job(job_id, callback) {
- $.getJSON('/api/jobs/' + job_id)
- .done(function(data) {
- if(data.job_status !== 'WIP') {
- console.log("polling completed for job[" + job_id + "]", data);
- callback(data);
- } else {
- setTimeout(function() { poll_job(job_id, callback); },
- config.polling_interval);
- }
- });
-}
-
function add_new_rec() {
//progress()
return RecAPI.create()
@@ -200,9 +187,9 @@ function stop_rec(rec, widget) {
return gen_rec(rec, widget);
});
stop_xhr.fail(function(res_update) {
- var error = JSON.parse(res_update.responseText).message;
- widget.option("errormsg", error);
- widget.option("state", 9);
+ var error = JSON.parse(res_update.responseText).message;
+ widget.option("errormsg", error);
+ widget.option("state", 9);
});
return stop_xhr; //RecAPI.stop
}
diff --git a/server/static/js/old.js b/server/static/js/old.js
index f8114a1..cee817b 100644
--- a/server/static/js/old.js
+++ b/server/static/js/old.js
@@ -1,4 +1,4 @@
-/*global $*/
+/*global $, poll_job*/
var form = {
MAX_MINS: 5*60, // 5 hours
@@ -42,6 +42,37 @@ var form = {
}
};
+function click(widget) {
+ /*global RecAPI*/
+ var v = form.get_values();
+ RecAPI.fullcreate(v.name, v.start, v.end)
+ .done(function(res_create) {
+ console.log("ok, created");
+ RecAPI.generate(res_create.rec)
+ .done(function(res_gen) {
+ console.log("ok, generated", res_create);
+ //TODO: start polling
+ $('#download').thebutton('option', 'state', 'Wait');
+ poll_job(res_gen.job_id, function(data) {
+ if(data.job_status !== 'DONE') {
+ console.error("Job failed!", data);
+ widget.thebutton("option", "state", 'Failed');
+ widget.thebutton("option", "errormsg", data.exception);
+ } else {
+ widget.thebutton("option", "filename", res_gen.result);
+ widget.thebutton("option", "state", 'Download');
+ }
+ });
+ })
+ .fail(function() {
+ console.error("Oh shit, generate failed", res_create.rec);
+ });
+ })
+ .fail(function() {
+ console.error("Oh shit, fullcreate failed");
+ });
+}
+
$(function() {
"use strict";
$( "#from-date" ).datepicker({
@@ -66,36 +97,18 @@ $(function() {
}
});
$('#to-date, #from-date').datepicker($.datepicker.regional.it);
+ $('#download').thebutton();
- $('#form').ajaxForm({
- beforeSubmit: function() {
- console.log("check", form.check());
- if(form.check().length > 0) {
- console.log("Form not valid, aborting");
- return false;
+ $('#download').click(function() {
+ if(!$('#download').hasClass('rec-run')) {
+ return;
}
- return true;
- },
- success: function() {
- /*global RecAPI*/
- var v = form.get_values();
- RecAPI.fullcreate(v.name, v.start, v.end)
- .done(function(res) {
- console.log("ok, created");
- RecAPI.generate(res.rec)
- .done(function(res) {
- console.log("ok, generated", res);
- })
- .fail(function() {
- console.error("Oh shit, generate failed", res.rec);
- });
- })
- .fail(function() {
- console.error("Oh shit, fullcreate failed");
- });
-
- return false;
- }
+ var check = form.check();
+ if(check.length > 0) {
+ console.log("Errors in form", check);
+ return;
+ }
+ click($('#download'));
});
});
/* vim: set ts=2 sw=2 noet fdm=indent: */
diff --git a/server/static/js/rec.js b/server/static/js/rec.js
index ab7a8be..2a7b8b6 100644
--- a/server/static/js/rec.js
+++ b/server/static/js/rec.js
@@ -47,3 +47,17 @@ var RecAPI = {
return $.getJSON('/api/get/ongoing');
}
};
+
+function poll_job(job_id, callback) {
+ $.getJSON('/api/jobs/' + job_id)
+ .done(function(data) {
+ if(data.job_status !== 'WIP') {
+ console.log("polling completed for job[" + job_id + "]", data);
+ callback(data);
+ } else {
+ setTimeout(function() { poll_job(job_id, callback); },
+ config.polling_interval);
+ }
+ });
+}
+
diff --git a/server/static/js/ui.js b/server/static/js/ui.js
new file mode 100644
index 0000000..97a9bf1
--- /dev/null
+++ b/server/static/js/ui.js
@@ -0,0 +1,83 @@
+/*global $*/
+$.widget("ror.thebutton", {
+ options: {
+ state: 'Create',
+ filename: null,
+ errormsg: null
+ },
+ _create: function() {
+ "use strict";
+ //create an appropriate button
+ var widget = this;
+ var state = this.options.rec;
+ widget.element.addClass('pure-button');
+
+ widget.element.on("click", function(evt) {
+ /*global error_dialog*/
+ if(widget.element.hasClass("rec-failed")) {
+ error_dialog(widget.options.errormsg,
+ function() {
+ console.log("Should retry, TODO");
+ $(this).dialog("close");
+ widget._setOption('state', 'Create');
+ widget.element.click();
+ },
+ function() {
+ $(this).dialog("close");
+ });
+ }
+ });
+
+ this._update();
+ },
+ _setOption: function(key, value) {
+ this.options[key] = value;
+ if(key === 'state') {
+ if(this.options.state !== 'Download') {
+ this.options.filename = null;
+ }
+ }
+ this._update();
+ },
+ _update: function() {
+ this.element.removeClass('pure-button-disabled rec-run rec-create ' +
+ 'rec-encoding rec-download rec-failed rec-stop');
+ switch(this.options.state) {
+ case 'Stop':
+ this.element.addClass("rec-stop rec-run").html(
+ $('').addClass('fa fa-stop')).append(' Stop');
+ break;
+ case 'Create':
+ this.element.addClass('rec-create rec-run').html(
+ $('').addClass('fa fa-gear')).append(' Create');
+ break;
+ case 'Failed':
+ this.element.addClass("rec-failed").html(
+ $('').addClass('fa fa-warning')).append(' Errori');
+ break;
+ case 'Wait':
+ this.element.addClass("pure-button-disabled rec-encoding") .html(
+ $('').addClass('fa fa-clock-o')).append(' Wait');
+ break;
+ case 'Download':
+ this.element
+ .addClass("rec-download")
+ .prop('href', this.options.filename)
+ .html(
+ $('').addClass('fa fa-download').css('color', 'green'))
+ .append(' Scarica');
+ break;
+ }
+ }
+});
+
+function error_dialog(msg, retry, cancel) {
+ $('').html($('').text(msg))
+ .dialog({modal: true, title: "Dettaglio errori",
+ buttons: {
+ Retry: retry,
+ Cancel: cancel
+ }
+ });
+}
+/* vim: set ts=2 sw=2 noet fdm=indent: */