diff --git a/dist/entry.js b/dist/entry.js index e2ed479104..ce82468559 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -70,12 +70,11 @@ var Entry = {events_:{}, block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ return (new Date).getTime() - this.startTime; }, addActivity:function(a) { Entry.stateManager && Entry.stateManager.addActivity(a); +}, startActivityLogging:function() { + Entry.reporter && Entry.reporter.start(Entry.projectId, window.user._id, Entry.startTime); }, getActivityLog:function() { var a = {}; - a.projectId = Entry.projectId; Entry.stateManager && (a.activityLog = Entry.stateManager.activityLog_); - window.user && (a.userId = window.user._id); - a.startTime = Entry.startTime; return a; }}; window.Entry = Entry; @@ -4813,6 +4812,9 @@ Entry.initialize_ = function() { this.toast = new Entry.Toast; this.hw && this.hw.closeConnection(); this.hw = new Entry.HW; + if ("workspace" == this.type || "phone" == this.type) { + this.reporter = new Entry.Reporter; + } this.initContextMenu(); }; Entry.createDom = function(a, b) { @@ -7774,6 +7776,26 @@ Entry.Popup.prototype.resize = function(a) { a.style.width = String(b) + "px"; a.style.height = String(c + 35) + "px"; }; +Entry.Reporter = function() { + this.userId; + this.projectId; +}; +Entry.Reporter.prototype.start = function(a, b, c) { + this.io = io(window.location.href.split("/")[2]); + this.io.emit("activity", {message:"start", userId:b, projectId:a, time:c}); + this.userId = b; + this.projectId = a; +}; +Entry.Reporter.prototype.report = function(a) { + if (this.io) { + var b = [], c; + for (c in a.params) { + var d = a.params[c]; + "object" !== typeof d ? b.push(d) : d.id && b.push(d.id); + } + this.io.emit("activity", {message:a.message, userId:this.userId, projectId:this.projectId, time:a.time, params:b}); + } +}; Entry.Scene = function() { this.scenes_ = []; this.selectedScene = null; @@ -8439,7 +8461,6 @@ Entry.State.prototype.generateMessage = function() { Entry.StateManager = function() { this.undoStack_ = []; this.redoStack_ = []; - this.activityLog_ = []; this.isIgnore = this.isRestore = !1; Entry.addEventListener("cancelLastCommand", function(a) { Entry.stateManager.cancelLastCommand(); @@ -8468,14 +8489,14 @@ Entry.StateManager.prototype.addCommand = function(a, b, c, d) { var e = new Entry.State, f = Array.prototype.slice.call(arguments); Entry.State.prototype.constructor.apply(e, f); this.redoStack_.push(e); - this.activityLog_.push(e); + Entry.reporter && Entry.reporter.report(e); } else { - e = new Entry.State, f = Array.prototype.slice.call(arguments), Entry.State.prototype.constructor.apply(e, f), this.undoStack_.push(e), this.activityLog_.push(e), this.updateView(); + e = new Entry.State, f = Array.prototype.slice.call(arguments), Entry.State.prototype.constructor.apply(e, f), this.undoStack_.push(e), Entry.reporter && Entry.reporter.report(e), this.updateView(); } } }; Entry.StateManager.prototype.cancelLastCommand = function() { - this.canUndo() && (this.undoStack_.pop(), this.activityLog_.pop(), this.updateView()); + this.canUndo() && (this.undoStack_.pop(), this.updateView()); }; Entry.StateManager.prototype.undo = function() { if (this.canUndo() && !this.isRestoring()) { @@ -8530,7 +8551,7 @@ Entry.StateManager.prototype.isSaved = function() { return 0 == this.undoStack_.length || this.undoStack_[this.undoStack_.length - 1].stamp == this.stamp && "string" == typeof this.stamp; }; Entry.StateManager.prototype.addActivity = function(a) { - this.activityLog_.push(new Entry.State(a)); + Entry.reporter && Entry.reporter.report(new Entry.State(a)); }; Entry.Toast = function() { this.toasts_ = []; diff --git a/dist/entry.min.js b/dist/entry.min.js index 17f9f98e49..4a36dcc15a 100644 --- a/dist/entry.min.js +++ b/dist/entry.min.js @@ -5,7 +5,8 @@ loadInterfaceState:function(){if("workspace"==Entry.type)if(localStorage&&localS var b=a.canvasWidth;b?300>b?b=300:720b?b=244:400svg").css({width:b-64+"px"});$(".entryBlocklyWorkspace").css({left:b+"px"});Entry.playground.resizeHandle_.style.left=b+"px"; -Entry.playground.variableViewWrapper_.style.width=b+"px";this.interfaceState=a}Blockly.fireUiEvent(window,"resize")},getUpTime:function(){return(new Date).getTime()-this.startTime},addActivity:function(a){Entry.stateManager&&Entry.stateManager.addActivity(a)},getActivityLog:function(){var a={};a.projectId=Entry.projectId;Entry.stateManager&&(a.activityLog=Entry.stateManager.activityLog_);window.user&&(a.userId=window.user._id);a.startTime=Entry.startTime;return a}};window.Entry=Entry;Blockly.Blocks.arduino_text={init:function(){this.setColour("#00979D");this.appendDummyInput().appendField(new Blockly.FieldTextInput("Arduino"),"NAME");this.setOutput(!0,"String");this.setInputsInline(!0)}};Entry.block.arduino_text=function(a,b){return b.getStringField("NAME")}; +Entry.playground.variableViewWrapper_.style.width=b+"px";this.interfaceState=a}Blockly.fireUiEvent(window,"resize")},getUpTime:function(){return(new Date).getTime()-this.startTime},addActivity:function(a){Entry.stateManager&&Entry.stateManager.addActivity(a)},startActivityLogging:function(){Entry.reporter&&Entry.reporter.start(Entry.projectId,window.user._id,Entry.startTime)},getActivityLog:function(){var a={};Entry.stateManager&&(a.activityLog=Entry.stateManager.activityLog_);return a}}; +window.Entry=Entry;Blockly.Blocks.arduino_text={init:function(){this.setColour("#00979D");this.appendDummyInput().appendField(new Blockly.FieldTextInput("Arduino"),"NAME");this.setOutput(!0,"String");this.setInputsInline(!0)}};Entry.block.arduino_text=function(a,b){return b.getStringField("NAME")}; Blockly.Blocks.arduino_send={init:function(){this.setColour("#00979D");this.appendDummyInput().appendField(Lang.Blocks.ARDUINO_arduino_send_1);this.appendValueInput("VALUE").setCheck(["Number","String",null]);this.appendDummyInput().appendField(Lang.Blocks.ARDUINO_arduino_send_2);this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip("")}}; Entry.block.arduino_send=function(a,b){var c=b.getValue("VALUE",b),d=new XMLHttpRequest;d.open("POST","http://localhost:23518/arduino/",!1);d.send(String(c));Entry.assert(200==d.status,"arduino is not connected");return b.callReturn()}; Blockly.Blocks.arduino_get_string={init:function(){this.setColour("#00979D");this.appendDummyInput().appendField(Lang.Blocks.ARDUINO_arduino_get_string_1);this.appendValueInput("VALUE").setCheck(["Number","String",null]);this.appendDummyInput().appendField(Lang.Blocks.ARDUINO_arduino_get_string_2);this.setOutput(!0,"String");this.setInputsInline(!0)}}; @@ -437,7 +438,8 @@ p.closeConnection=function(){this.socket&&this.socket.close()};p.downloadConnect a)};document.onkeyup=function(a){Entry.dispatchEvent("keyUpped",a)};window.onresize=function(a){Entry.dispatchEvent("windowResized",a)};window.onbeforeunload=this.beforeUnload;Entry.addEventListener("saveWorkspace",function(a){Entry.addActivity("save")});"IE"!=Entry.getBrowserType().substr(0,2)||window.flashaudio?(createjs.Sound.registerPlugins([createjs.WebAudioPlugin]),Entry.soundQueue=new createjs.LoadQueue,Entry.soundQueue.installPlugin(createjs.Sound),Entry.loadAudio_(["/media/click.mp3","/media/click.wav", "/media/click.ogg"],"click"),Entry.loadAudio_(["/media/delete.mp3","/media/delete.ogg","/media/delete.wav"],"delete")):(createjs.FlashAudioPlugin.swfPath="/media/",createjs.Sound.registerPlugins([createjs.FlashAudioPlugin]),Entry.soundQueue=new createjs.LoadQueue,Entry.soundQueue.installPlugin(createjs.Sound),Entry.loadAudio_(["/media/click.mp3","/media/click.wav","/media/click.ogg"],"click"),Entry.loadAudio_(["/media/delete.mp3","/media/delete.ogg","/media/delete.wav"],"delete"),window.flashaudio= !0)};Entry.loadAudio_=function(a,b){if(window.Audio&&a.length)for(;0d.style.opacity&&(clearInterval(a),d.style.display="none",Entry.removeElement(d));d.style.opacity*=.9},20)},1E3)}; Entry.Toast.prototype.alert=function(a,b,c){var d=Entry.createElement("div","entryToast");d.addClass("entryToast");d.addClass("entryToastAlert");d.bindOnClick(function(){Entry.toast.body_.removeChild(this)});var e=Entry.createElement("div","entryToast");e.addClass("entryToastTitle");e.innerHTML=a;d.appendChild(e);a=Entry.createElement("p","entryToast");a.addClass("entryToastMessage");a.innerHTML=b;d.appendChild(a);this.toasts_.push(d);this.body_.appendChild(d);c||window.setTimeout(function(){d.style.opacity= diff --git a/src/entry.js b/src/entry.js index c8194033dd..a18d0ff883 100644 --- a/src/entry.js +++ b/src/entry.js @@ -271,18 +271,22 @@ Entry.addActivity = function(activityType) { Entry.stateManager.addActivity(activityType); } +Entry.startActivityLogging = function() { + if (Entry.reporter) + Entry.reporter.start( + Entry.projectId, + window.user._id, + Entry.startTime); +}; + /** * return activity log * @return {object} */ Entry.getActivityLog = function() { var log = {}; - log.projectId = Entry.projectId; if (Entry.stateManager) log.activityLog = Entry.stateManager.activityLog_; - if (window.user) - log.userId = window.user._id; - log.startTime = Entry.startTime; return log; } diff --git a/src/init.js b/src/init.js index 84611a2755..fa5007fb72 100644 --- a/src/init.js +++ b/src/init.js @@ -166,6 +166,9 @@ Entry.initialize_ = function() { */ this.hw = new Entry.HW(); + if (this.type == 'workspace' || this.type == 'phone') + this.reporter = new Entry.Reporter(); + this.initContextMenu(); }; diff --git a/src/reporter.js b/src/reporter.js new file mode 100644 index 0000000000..2a4ea05cf4 --- /dev/null +++ b/src/reporter.js @@ -0,0 +1,40 @@ +/** + * @fileoverview Show dialog on canvas + */ + +Entry.Reporter = function() { + this.userId; + this.projectId; +}; + +Entry.Reporter.prototype.start = function(projectId, userId, startTime) { + this.io = io(window.location.href.split("/")[2]); + this.io.emit('activity', { + message: 'start', + userId: userId, + projectId: projectId, + time: startTime + }); + this.userId = userId; + this.projectId = projectId; +}; + +Entry.Reporter.prototype.report = function(state) { + if (!this.io) + return; + var params = []; + for (var i in state.params) { + var param = state.params[i]; + if (typeof param !== "object") + params.push(param); + else if (param.id) + params.push (param.id); + } + this.io.emit('activity', { + message: state.message, + userId: this.userId, + projectId: this.projectId, + time: state.time, + params: params + }); +}; diff --git a/src/state_manager.js b/src/state_manager.js index 9382688fbe..15e2b3c47e 100644 --- a/src/state_manager.js +++ b/src/state_manager.js @@ -9,7 +9,6 @@ Entry.StateManager = function() { this.undoStack_ = new Array(); this.redoStack_ = new Array(); - this.activityLog_ = []; /** prevent add command when undo and redo */ this.isRestore = false; this.isIgnore = false; @@ -76,13 +75,15 @@ Entry.StateManager.prototype.addCommand = var argumentArray = Array.prototype.slice.call(arguments); Entry.State.prototype.constructor.apply(state, argumentArray); this.redoStack_.push(state); - this.activityLog_.push(state); + if (Entry.reporter) + Entry.reporter.report(state); } else { var state = new Entry.State(); var argumentArray = Array.prototype.slice.call(arguments); Entry.State.prototype.constructor.apply(state, argumentArray); this.undoStack_.push(state); - this.activityLog_.push(state); + if (Entry.reporter) + Entry.reporter.report(state); this.updateView(); } }; @@ -94,7 +95,6 @@ Entry.StateManager.prototype.cancelLastCommand = function() { if (!this.canUndo()) return; this.undoStack_.pop(); - this.activityLog_.pop(); this.updateView(); }; @@ -223,5 +223,6 @@ Entry.StateManager.prototype.isSaved = function () { * @param {String} activityType */ Entry.StateManager.prototype.addActivity = function (activityType) { - this.activityLog_.push(new Entry.State(activityType)); + if (Entry.reporter) + Entry.reporter.report(new Entry.State(activityType)); };