diff --git a/website/source/assets/javascripts/demo/controllers/demo.js b/website/source/assets/javascripts/demo/controllers/demo.js index 12e6e20fb..96fff22f7 100644 --- a/website/source/assets/javascripts/demo/controllers/demo.js +++ b/website/source/assets/javascripts/demo/controllers/demo.js @@ -16,14 +16,17 @@ Demo.DemoController = Ember.ObjectController.extend({ var data = JSON.parse(message.data), controller = this; + // ignore pongs + if (data.pong) { + return + } + // Add the item if (data.stdout !== "") { - console.log("stdout:", data.stout); controller.appendLog(data.stdout, false); } if (data.stderr !== "") { - console.log("stderr:", data.stderr); controller.appendLog(data.stderr, false); } diff --git a/website/source/assets/javascripts/demo/model/clock.js b/website/source/assets/javascripts/demo/model/clock.js new file mode 100644 index 000000000..235af53f6 --- /dev/null +++ b/website/source/assets/javascripts/demo/model/clock.js @@ -0,0 +1,63 @@ +Ember.Clock = Ember.Object.extend({ + second: null, + checks: 0, + isPolling: false, + pollImmediately: true, + pollInterval: null, + tickInterval: null, + defaultPollInterval: 10000, + defaultTickInterval: 1000, + + init: function () { + this.scheduleTick(); + this.pollImmediately && this.startPolling(); + }, + + computedPollInterval: function() { + return this.pollInterval || this.defaultPollInterval; // Time between polls (in ms) + }.property().readOnly(), + + computedTickInterval: function() { + return this.tickInterval || this.defaultTickInterval; // Time between ticks (in ms) + }.property().readOnly(), + + // Schedules the function `f` to be executed every `interval` time. + schedulePoll: function(f) { + return Ember.run.later(this, function() { + f.apply(this); + this.incrementProperty('checks') + this.set('timer', this.schedulePoll(f)); + }, this.get('computedPollInterval')); + }, + + scheduleTick: function () { + return Ember.run.later(this, function () { + this.tick(); + this.scheduleTick(); + }, this.get('computedTickInterval')); + }, + + // Stops the polling + stopPolling: function() { + this.set('isPolling', false); + Ember.run.cancel(this.get('timer')); + }, + + // Starts the polling, i.e. executes the `onPoll` function every interval. + startPolling: function() { + this.set('isPolling', true); + this.set('timer', this.schedulePoll(this.get('onPoll'))); + }, + + // Moves the clock + tick: function () { + var now = new Date(); + this.setProperties({ + second: now.getSeconds() + }); + }, + + // Override this while making a new Clock object. + onPoll: function(){ + }, +}); diff --git a/website/source/assets/javascripts/demo/routes/step.js b/website/source/assets/javascripts/demo/routes/step.js index 2de915a9a..add170d35 100644 --- a/website/source/assets/javascripts/demo/routes/step.js +++ b/website/source/assets/javascripts/demo/routes/step.js @@ -1,5 +1,29 @@ Demo.DemoStepRoute = Ember.Route.extend({ model: function(params) { return this.store.find('step', params.id); - } + }, + + afterModel: function(model) { + var clock = Ember.Clock.create({ + defaultPollInterval: 5000, + pollImmediately: false, + onPoll: function() { + var socket = this.controllerFor('demo').get('socket'); + socket.send(JSON.stringify({type: "ping"})); + }.bind(this) + }); + + this.set('clock', clock); + }, + + activate: function() { + this.get('clock').startPolling(); + }, + + deactivate: function() { + var clock = this.get('clock'); + if(clock.get('isPolling')) { + clock.stopPolling(); + } + }, }); diff --git a/website/source/assets/javascripts/demo/views/step.js b/website/source/assets/javascripts/demo/views/step.js index e999b3aa8..cdd5fcab3 100644 --- a/website/source/assets/javascripts/demo/views/step.js +++ b/website/source/assets/javascripts/demo/views/step.js @@ -55,8 +55,6 @@ Demo.DemoStepView = Ember.View.extend({ submitted: function() { var element = this.$(); - console.log("submitted"); - // Focus the input element.find('input.shell')[0].focus();