EDU-452 Save task status when converting to new course format
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 8 Sep 2015 07:44:37 +0000 (10:44 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 8 Sep 2015 07:46:48 +0000 (10:46 +0300)
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyTaskManager.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/courseFormat/StudyStatus.java [deleted file]
python/educational/interactive-learning/src/com/jetbrains/edu/learning/navigation/StudyNavigator.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/projectView/StudyDirectoryNode.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/ui/StudyProgressToolWindowFactory.java
python/educational/src/com/jetbrains/edu/EduUtils.java
python/educational/src/com/jetbrains/edu/courseFormat/StudyStatus.java [new file with mode: 0644]
python/educational/src/com/jetbrains/edu/oldCourseFormat/TaskWindow.java

index 4b6d8cdc37b69427d9f005d68106fe254331f1e8..c5207092238fbe9c7a901203cf4bf10a51837132 100644 (file)
@@ -3,12 +3,14 @@ package com.jetbrains.edu.learning;
 import com.intellij.openapi.components.*;
 import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Pair;
 import com.intellij.ui.JBColor;
+import com.intellij.util.Function;
 import com.intellij.util.containers.hash.HashMap;
 import com.intellij.util.xmlb.XmlSerializer;
 import com.jetbrains.edu.EduUtils;
 import com.jetbrains.edu.courseFormat.*;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.courseFormat.UserTest;
 import com.jetbrains.edu.oldCourseFormat.OldCourse;
 import org.jdom.Element;
@@ -203,7 +205,13 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
     if (oldCourseElement != null) {
       myOldCourse = XmlSerializer.deserialize(oldCourseElement, OldCourse.class);
       if (myOldCourse != null) {
-        myCourse = EduUtils.transformOldCourse(myOldCourse);
+        myCourse = EduUtils.transformOldCourse(myOldCourse, new Function<Pair<AnswerPlaceholder, StudyStatus>, Void>() {
+          @Override
+          public Void fun(Pair<AnswerPlaceholder, StudyStatus> pair) {
+            setStatus(pair.first, pair.second);
+            return null;
+          }
+        });
         myOldCourse = null;
       }
     }
index 32cb5fa41be38e397625f242799022ecac5990d7..ec170e878fe72aca0274f0f91b954513b9bc12f9 100644 (file)
@@ -43,7 +43,7 @@ import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import com.jetbrains.edu.learning.run.StudySmartChecker;
@@ -193,7 +193,7 @@ public class StudyCheckAction extends DumbAwareAction {
 
     final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
     final StudyStatus statusBeforeCheck = taskManager.getStatus(task);
-    return new com.intellij.openapi.progress.Task.Backgroundable(project, "Checking task", true) {
+    return new com.intellij.openapi.progress.Task.Backgroundable(project, "Checking Task", true) {
       @Override
       public void onSuccess() {
         StudyUtils.updateToolWindows(project);
index 4d139bb262ee0ffce1f6d4e494b0dcc19d257aa7..cc21a63780660d7057c9d43cea418b529f02717d 100644 (file)
@@ -26,7 +26,7 @@ import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import org.jetbrains.annotations.NotNull;
diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/courseFormat/StudyStatus.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/courseFormat/StudyStatus.java
deleted file mode 100644 (file)
index a383b51..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.jetbrains.edu.learning.courseFormat;
-
-import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
-
-/**
- * @see {@link AnswerPlaceholder#myStatus}
- */
-public enum StudyStatus {
-  Unchecked, Solved, Failed
-}
index 4121c84445f1d8617acc5b2352e60822a25f534c..2fe10db4eebb1e8a1486aa1e35fad8f61e7ba94b 100644 (file)
@@ -10,7 +10,7 @@ import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.List;
index b44fa6eae1c252f26b879e29033aa63ed9a4777a..6c8fd130b7dbcb295f48c0c4dbd072f385c6e56f 100644 (file)
@@ -19,7 +19,7 @@ import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import icons.EducationalIcons;
 import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
index 69a605ce537f60e4bcec7be40d1bde96e4fb9917..01eac4a9d6b49a9dac9219bc82ff3bb8e9e11c89 100644 (file)
@@ -17,7 +17,7 @@ import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
index e00fc14131e39fe5670c7fdbd1706760b18889f7..8951a84b44d7e848b0044224f697085374e6dd88 100644 (file)
@@ -12,7 +12,7 @@ import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.learning.StudyTaskManager;
-import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.courseFormat.StudyStatus;
 import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
 
index 9f5738cbe162bdb34273546861a9487c8d1840f2..7e3ac06bdb05aad53190863470d6468f9a6dfabd 100644 (file)
@@ -9,18 +9,15 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.io.FileUtilRt;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.PsiDirectory;
+import com.intellij.util.Function;
 import com.intellij.util.containers.HashMap;
-import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
-import com.jetbrains.edu.courseFormat.Course;
-import com.jetbrains.edu.courseFormat.Lesson;
-import com.jetbrains.edu.courseFormat.StudyItem;
-import com.jetbrains.edu.courseFormat.Task;
-import com.jetbrains.edu.courseFormat.TaskFile;
+import com.jetbrains.edu.courseFormat.*;
 import com.jetbrains.edu.oldCourseFormat.OldCourse;
 import com.jetbrains.edu.oldCourseFormat.TaskWindow;
 import org.jetbrains.annotations.NonNls;
@@ -280,6 +277,12 @@ public class EduUtils {
 
   @NotNull
   public static Course transformOldCourse(@NotNull final OldCourse oldCourse) {
+    return transformOldCourse(oldCourse, null);
+  }
+
+  @NotNull
+  public static Course transformOldCourse(@NotNull final OldCourse oldCourse,
+                                          @Nullable Function<Pair<AnswerPlaceholder, StudyStatus>, Void> setStatus) {
     Course course = new Course();
     course.setDescription(oldCourse.description);
     course.setName(oldCourse.name);
@@ -307,15 +310,16 @@ public class EduUtils {
           final ArrayList<AnswerPlaceholder> placeholders = new ArrayList<AnswerPlaceholder>();
           for (TaskWindow window : oldTaskFile.taskWindows) {
             final AnswerPlaceholder placeholder = new AnswerPlaceholder();
-
             placeholder.setIndex(window.myIndex);
             placeholder.setHint(window.hint);
             placeholder.setLength(window.length);
             placeholder.setLine(window.line);
             placeholder.setPossibleAnswer(window.possibleAnswer);
             placeholder.setStart(window.start);
-
             placeholders.add(placeholder);
+            if (setStatus != null) {
+              setStatus.fun(Pair.create(placeholder, window.myStatus));
+            }
           }
 
           taskFile.setAnswerPlaceholders(placeholders);
diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/StudyStatus.java b/python/educational/src/com/jetbrains/edu/courseFormat/StudyStatus.java
new file mode 100644 (file)
index 0000000..767a3c9
--- /dev/null
@@ -0,0 +1,5 @@
+package com.jetbrains.edu.courseFormat;
+
+public enum StudyStatus {
+  Unchecked, Solved, Failed
+}
index b9c0f32030154b45bccb6b6a48ac845c0952b9ca..53ef9a90be0e3432825cf75465713c9e32d7afad 100644 (file)
@@ -1,5 +1,7 @@
 package com.jetbrains.edu.oldCourseFormat;
 
+import com.jetbrains.edu.courseFormat.StudyStatus;
+
 /**
  * Implementation of windows which user should type in
  */
@@ -15,4 +17,5 @@ public class TaskWindow {
   public int myInitialLine = -1;
   public int myInitialStart = -1;
   public int myInitialLength = -1;
+  public StudyStatus myStatus = StudyStatus.Unchecked;
 }
\ No newline at end of file