diff --git a/app/actors/PLMActor.scala b/app/actors/PLMActor.scala index f8de66aa..fe0a4c66 100644 --- a/app/actors/PLMActor.scala +++ b/app/actors/PLMActor.scala @@ -177,6 +177,10 @@ class PLMActor ( "exercises" -> ExerciseToJson.exercisesWrite(lectures) )) } + case "getLastCommit" => + getCommitId(msg, "commitId") + case "loadContent" => + getCommitId(msg, "loadContent") case "getLangs" => sendMessage("langs", Json.obj( "selected" -> LangToJson.langWrite(currentPreferredLang), @@ -305,6 +309,17 @@ class PLMActor ( ) } } + + def getCommitId(msg: JsValue, response: String) { + var optExerciseID : Option[String] = (msg \ "args" \ "exerciseID").asOpt[String] + var optLanguage : Option[String] = (msg \ "args" \ "language").asOpt[String] + var filename: String = null + (optExerciseID.getOrElse(None), optLanguage.getOrElse(None)) match { + case (exerciseID: String, language: String) => + filename = exerciseID + "." + language + ".code" + sendMessage(response, Json.obj("id" -> plm.getLastCommitId(exerciseID, language))) + } + } def initExecutionManager() { executionManager.setPLMActor(this) diff --git a/app/models/PLM.scala b/app/models/PLM.scala index 6ecdd526..87c75a5a 100644 --- a/app/models/PLM.scala +++ b/app/models/PLM.scala @@ -43,6 +43,7 @@ class PLM( var game = new Game(initUserUUID, plmLogger, locale, lastProgLang.getOrElse("Java"), gitUtils, trackUser, properties) var gitGest = new Git(initUserUUID, gitUtils) + def lessons: Map[String, Lesson] = game.getMapLessons def switchLesson(lessonID: String): Lecture = { @@ -75,6 +76,10 @@ class PLM( return _currentExercise } + def getLastCommitId(exerciseID: String, language: String) : String = { + return gitUtils.getLastCommitId(exerciseID, language) + } + def getSelectedWorldID(): String = { return game.getSelectedWorld.getName } diff --git a/lib/plm-2.6-pre-20150202.jar b/lib/plm-2.6-20151010.jar similarity index 95% rename from lib/plm-2.6-pre-20150202.jar rename to lib/plm-2.6-20151010.jar index b4c6e1c6..9972556f 100644 Binary files a/lib/plm-2.6-pre-20150202.jar and b/lib/plm-2.6-20151010.jar differ diff --git a/public/app/exercise/exercise.controller.js b/public/app/exercise/exercise.controller.js index b9eacfc5..e4c1c55a 100644 --- a/public/app/exercise/exercise.controller.js +++ b/public/app/exercise/exercise.controller.js @@ -96,6 +96,7 @@ exercise.ide = 'codemirror'; exercise.toolbox = null; exercise.studentCode = null; + exercise.commitId = null; exercise.drawServiceType = ''; exercise.drawService = null; @@ -148,6 +149,7 @@ exercise.idle = false; connection.sendMessage('userBack', {}); } + saveEditorContent(); startIdleLoop(); } @@ -157,6 +159,21 @@ exercise.editor.on('change', resetIdleLoop); resizeCodeMirror(); }; + + + function saveEditorContent() { + // Save the editor content in the local storage + $window.localStorage.setItem("editor." + exercise.id + "." + exercise.currentProgrammingLanguage, editor.getValue()); + $window.localStorage.setItem("commitId." + exercise.id + "." + exercise.currentProgrammingLanguage, exercise.commitId); + } + + function loadEditorContent() { + var args = { + exerciseID: exercise.id, + language: exercise.currentProgrammingLanguage + } + connection.sendMessage('loadContent', args); + } function getExercise() { var args = { @@ -205,13 +222,31 @@ case 'newHumanLang': updateUI(exercise.currentProgrammingLanguage, args.instructions, args.api, null); break; + case 'commitId': + exercise.commitId = args.id; + break; + case 'loadContent': + exercise.commitId = args.id; + var localCommitId = $window.localStorage.getItem("commitId." + exercise.id + "." + exercise.currentProgrammingLanguage); + if (localCommitId === exercise.commitId || localCommitId === "") { + var editorValue = $window.localStorage.getItem("editor." + exercise.id + "." + exercise.currentProgrammingLanguage); + if (editorValue !== null) { + editor.setValue(editorValue); + // FIXME + console.log("content loaded from local storage"); + } + } else + // FIXME + console.log("content NOT loaded"); + break; } + } function setExercise(data) { exercise.id = data.id; exercise.name = data.id.split('.').pop(); - + navigation.setInlesson(true); navigation.setCurrentPageTitle(exercise.lessonName + ' / ' + exercise.name); @@ -459,6 +494,7 @@ } } progLangs.setCurrentProglang(progLang); + exercise.currentProgrammingLanguage = progLang.lang.toLowerCase(); updateUI(progLang, data.instructions, data.api, data.code.trim()); } @@ -468,8 +504,8 @@ exercise.resultType = null; exercise.result = ''; exercise.logs = ''; - exercisesList.setCurrentLessonID(exercise.lessonID); + } function updateInstructions(instructions, api) { @@ -614,7 +650,8 @@ exercise.updateModelLoop = $timeout(updateModel, $scope.timer); } - function updateModel() { + function updateModel() { + connection.sendMessage("getLastCommit", {exerciseID: exercise.id, language: exercise.currentProgrammingLanguage}) var currentState = exercise.currentWorld.currentState; var nbStates = exercise.currentWorld.operations.length - 1; if (currentState !== nbStates) { @@ -833,6 +870,7 @@ $timeout(function () { exercise.editor.refresh(); }, 0); + loadEditorContent(); } } updateInstructions(instructions, api); @@ -848,4 +886,4 @@ } return buffer; } -})(); \ No newline at end of file +})();