From 51a1953d99b86a9e649abd049a90de10ea243138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Jun 2016 13:24:29 +0200 Subject: [PATCH] Move timelapse event processing to timelapse viewmodel --- src/octoprint/static/js/app/dataupdater.js | 90 +------------------ .../static/js/app/viewmodels/timelapse.js | 79 ++++++++++++++++ 2 files changed, 80 insertions(+), 89 deletions(-) diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index 643164cb..6296e530 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -16,8 +16,6 @@ function DataUpdater(allViewModels) { self._lastProcessingTimes = []; self._lastProcessingTimesSize = 20; - self._timelapse_popup = undefined; - self.connect = function() { var options = {}; if (SOCKJS_DEBUG) { @@ -218,96 +216,10 @@ function DataUpdater(allViewModels) { var type = data["type"]; var payload = data["payload"]; var html = ""; - var format = {}; log.debug("Got event " + type + " with payload: " + JSON.stringify(payload)); - if (type == "MovieRendering") { - if (self._timelapse_popup !== undefined) { - self._timelapse_popup.remove(); - } - self._timelapse_popup = new PNotify({ - title: gettext("Rendering timelapse"), - text: _.sprintf(gettext("Now rendering timelapse %(movie_basename)s. Due to performance reasons it is not recommended to start a print job while a movie is still rendering."), payload), - hide: false, - callbacks: { - before_close: function() { - self._timelapse_popup = undefined; - } - } - }); - } else if (type == "MovieDone") { - if (self._timelapse_popup !== undefined) { - self._timelapse_popup.remove(); - } - self._timelapse_popup = new PNotify({ - title: gettext("Timelapse ready"), - text: _.sprintf(gettext("New timelapse %(movie_basename)s is done rendering."), payload), - type: "success", - callbacks: { - before_close: function(notice) { - if (self._timelapse_popup == notice) { - self._timelapse_popup = undefined; - } - } - } - }); - } else if (type == "MovieFailed") { - html = "

" + _.sprintf(gettext("Rendering of timelapse %(movie_basename)s failed with return code %(returncode)s"), payload) + "

"; - html += pnotifyAdditionalInfo('
' + payload.error + '
'); - - if (self._timelapse_popup !== undefined) { - self._timelapse_popup.remove(); - } - self._timelapse_popup = new PNotify({ - title: gettext("Rendering failed"), - text: html, - type: "error", - hide: false, - callbacks: { - before_close: function(notice) { - if (self._timelapse_popup == notice) { - self._timelapse_popup = undefined; - } - } - } - }); - } else if (type == "PostRollStart") { - var title = gettext("Capturing timelapse postroll"); - - var text; - if (!payload.postroll_duration) { - text = _.sprintf(gettext("Now capturing timelapse post roll, this will take only a moment..."), format); - } else { - format = { - time: moment().add(payload.postroll_duration, "s").format("LT") - }; - - if (payload.postroll_duration > 60) { - format.duration = _.sprintf(gettext("%(minutes)d min"), {minutes: payload.postroll_duration / 60}); - text = _.sprintf(gettext("Now capturing timelapse post roll, this will take approximately %(duration)s (so until %(time)s)..."), format); - } else { - format.duration = _.sprintf(gettext("%(seconds)d sec"), {seconds: payload.postroll_duration}); - text = _.sprintf(gettext("Now capturing timelapse post roll, this will take approximately %(duration)s..."), format); - } - } - - if (self._timelapse_popup !== undefined) { - self._timelapse_popup.remove(); - } - self._timelapse_popup = new PNotify({ - title: title, - text: text, - hide: false, - callbacks: { - before_close: function(notice) { - if (self._timelapse_popup == notice) { - self._timelapse_popup = undefined; - } - } - } - }); - } else if (type == "SlicingStarted") { + if (type == "SlicingStarted") { gcodeUploadProgress.addClass("progress-striped").addClass("active"); gcodeUploadProgressBar.css("width", "100%"); if (payload.progressAvailable) { diff --git a/src/octoprint/static/js/app/viewmodels/timelapse.js b/src/octoprint/static/js/app/viewmodels/timelapse.js index cb0fbb5c..2098d9d2 100644 --- a/src/octoprint/static/js/app/viewmodels/timelapse.js +++ b/src/octoprint/static/js/app/viewmodels/timelapse.js @@ -4,6 +4,8 @@ $(function() { self.loginState = parameters[0]; + self.timelapsePopup = undefined; + self.defaultFps = 25; self.defaultPostRoll = 0; self.defaultInterval = 10; @@ -227,11 +229,88 @@ $(function() { }); }; + self.displayTimelapsePopup = function(options) { + if (self.timelapsePopup !== undefined) { + self.timelapsePopup.remove(); + } + + _.extend(options, { + callbacks: { + before_close: function(notice) { + if (self.timelapsePopup == notice) { + self.timelapsePopup = undefined; + } + } + } + }); + + self.timelapsePopup = new PNotify(options); + }; + self.onDataUpdaterReconnect = function() { self.requestData(); }; + self.onEventPostRollStart = function(payload) { + var title = gettext("Capturing timelapse postroll"); + + var text; + if (!payload.postroll_duration) { + text = _.sprintf(gettext("Now capturing timelapse post roll, this will take only a moment..."), format); + } else { + var format = { + time: moment().add(payload.postroll_duration, "s").format("LT") + }; + + if (payload.postroll_duration > 60) { + format.duration = _.sprintf(gettext("%(minutes)d min"), {minutes: payload.postroll_duration / 60}); + text = _.sprintf(gettext("Now capturing timelapse post roll, this will take approximately %(duration)s (so until %(time)s)..."), format); + } else { + format.duration = _.sprintf(gettext("%(seconds)d sec"), {seconds: payload.postroll_duration}); + text = _.sprintf(gettext("Now capturing timelapse post roll, this will take approximately %(duration)s..."), format); + } + } + + self.displayTimelapsePopup({ + title: title, + text: text, + hide: false + }); + }; + + self.onEventMovieRendering = function(payload) { + self.displayTimelapsePopup({ + title: gettext("Rendering timelapse"), + text: _.sprintf(gettext("Now rendering timelapse %(movie_basename)s. Due to performance reasons it is not recommended to start a print job while a movie is still rendering."), payload), + hide: false + }); + }; + + self.onEventMovieFailed = function(payload) { + var html = "

" + _.sprintf(gettext("Rendering of timelapse %(movie_basename)s failed with return code %(returncode)s"), payload) + "

"; + html += pnotifyAdditionalInfo('
' + payload.error + '
'); + + self.displayTimelapsePopup({ + title: gettext("Rendering failed"), + text: html, + type: "error", + hide: false + }); + }; + self.onEventMovieDone = function(payload) { + self.displayTimelapsePopup({ + title: gettext("Timelapse ready"), + text: _.sprintf(gettext("New timelapse %(movie_basename)s is done rendering."), payload), + type: "success", + callbacks: { + before_close: function(notice) { + if (self.timelapsePopup == notice) { + self.timelapsePopup = undefined; + } + } + } + }); self.requestData(); };