Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/actors/PLMActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/models/PLM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down
Binary file not shown.
46 changes: 42 additions & 4 deletions public/app/exercise/exercise.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
exercise.ide = 'codemirror';
exercise.toolbox = null;
exercise.studentCode = null;
exercise.commitId = null;

exercise.drawServiceType = '';
exercise.drawService = null;
Expand Down Expand Up @@ -148,6 +149,7 @@
exercise.idle = false;
connection.sendMessage('userBack', {});
}
saveEditorContent();
startIdleLoop();
}

Expand All @@ -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 = {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -459,6 +494,7 @@
}
}
progLangs.setCurrentProglang(progLang);
exercise.currentProgrammingLanguage = progLang.lang.toLowerCase();
updateUI(progLang, data.instructions, data.api, data.code.trim());
}

Expand All @@ -468,8 +504,8 @@
exercise.resultType = null;
exercise.result = '';
exercise.logs = '';

exercisesList.setCurrentLessonID(exercise.lessonID);

}

function updateInstructions(instructions, api) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -833,6 +870,7 @@
$timeout(function () {
exercise.editor.refresh();
}, 0);
loadEditorContent();
}
}
updateInstructions(instructions, api);
Expand All @@ -848,4 +886,4 @@
}
return buffer;
}
})();
})();