Add ability to disable local testing from samples in adaptive courses
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Thu, 28 Jul 2016 07:40:45 +0000 (10:40 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Thu, 28 Jul 2016 17:40:28 +0000 (20:40 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/StudyTaskManager.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.form
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/StepicStudyOptions.java

index 8213a2bc47287644bf55595682786ef943c05199..f2af92b87b69d73aa1e8ef0f78f89fff80feef31 100644 (file)
@@ -46,6 +46,7 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
   public boolean myShouldUseJavaFx = StudyUtils.hasJavaFx();
   private StudyToolWindow.StudyToolWindowMode myToolWindowMode = StudyToolWindow.StudyToolWindowMode.TEXT;
   private boolean myTurnEditingMode = false;
+  private boolean myEnableTestingFromSamples = true;
 
   @Transient private final Project myProject;
 
@@ -202,4 +203,12 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
   public void setUser(@NotNull final StepicUser user) {
     myUser = user;
   }
+
+  public boolean isEnableTestingFromSamples() {
+    return myEnableTestingFromSamples;
+  }
+
+  public void setEnableTestingFromSamples(boolean enableTestingFromSamples) {
+    myEnableTestingFromSamples = enableTestingFromSamples;
+  }
 }
index 4557795ead314f1a10c2666564564d6d19b0ec2e..4db6a266904382059d8fe4a11f0c830c5669a320 100644 (file)
@@ -130,7 +130,12 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun
   private void checkForAdaptiveCourse(ProgressIndicator indicator) {
     final StudyTestsOutputParser.TestsOutput testOutput = getTestOutput(indicator);
     if (testOutput != null) {
-      if (testOutput.isSuccess()) {
+      // As tests in adaptive courses are created from
+      // samples and stored in task, to disable it we should ignore local testing results
+      if (StudyTaskManager.getInstance(myProject).isEnableTestingFromSamples() && !testOutput.isSuccess()) {
+        onTaskFailed(testOutput.getMessage());
+      }
+      else {
         final Pair<Boolean, String> pair = EduAdaptiveStepicConnector.checkTask(myProject, myTask);
         if (pair != null && !(!pair.getFirst() && pair.getSecond().isEmpty())) {
           if (pair.getFirst()) {
@@ -152,9 +157,6 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun
                                                                                                     myProject));
         }
       }
-      else {
-        onTaskFailed(testOutput.getMessage());
-      }
     }
   }
 
index 86fa610cb50ef424dabe7eb8e2e68d4708b11eb2..05a78d765af9abf8ebf40f0bcf97d56317ae5745 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.learning.stepic.StepicStudyOptions">
-  <grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
-      <xy x="20" y="20" width="646" height="400"/>
+      <xy x="20" y="20" width="706" height="400"/>
     </constraints>
     <properties/>
     <clientProperties>
     <children>
       <vspacer id="6ace">
         <constraints>
-          <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
       </vspacer>
       <grid id="e4354" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
         <border type="none"/>
           </component>
         </children>
       </grid>
+      <grid id="a8a02" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="3" left="0" bottom="0" right="0"/>
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none"/>
+        <children>
+          <component id="78d63" class="com.intellij.ui.components.JBLabel">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="Testing from samples in adaptive courses"/>
+            </properties>
+          </component>
+          <component id="4b6cb" class="com.intellij.ui.components.JBCheckBox" binding="myEnableTestingFromSamples">
+            <constraints>
+              <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <selected value="true"/>
+            </properties>
+          </component>
+          <hspacer id="976b3">
+            <constraints>
+              <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+            </constraints>
+          </hspacer>
+        </children>
+      </grid>
     </children>
   </grid>
 </form>
index 9b48578db82afc3712efec1ff494a3b880905549..8039f880fb55db1d98e70fda7c203ae72f6b3c74 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.ui.DocumentAdapter;
+import com.intellij.ui.components.JBCheckBox;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.settings.StudyOptionsProvider;
@@ -26,6 +27,8 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.text.Document;
@@ -39,6 +42,7 @@ public class StepicStudyOptions implements StudyOptionsProvider {
   private JTextField myLoginTextField;
   private JPasswordField myPasswordField;
   private JPanel myPane;
+  private JBCheckBox myEnableTestingFromSamples;
 
   private boolean myCredentialsModified;
 
@@ -72,6 +76,13 @@ public class StepicStudyOptions implements StudyOptionsProvider {
       public void focusLost(FocusEvent e) {
       }
     });
+
+    myEnableTestingFromSamples.addChangeListener(new ChangeListener() {
+      @Override
+      public void stateChanged(ChangeEvent e) {
+        myCredentialsModified = true;
+      }
+    });
     reset();
   }
 
@@ -107,11 +118,13 @@ public class StepicStudyOptions implements StudyOptionsProvider {
   public void reset() {
     Project project = StudyUtils.getStudyProject();
     if (project != null) {
-      final StepicUser user = StudyTaskManager.getInstance(project).getUser();
+      StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
+      final StepicUser user = taskManager.getUser();
       if (user != null) {
         setLogin(user.getEmail());
         setPassword(DEFAULT_PASSWORD_TEXT);
       }
+      myEnableTestingFromSamples.setSelected(taskManager.isEnableTestingFromSamples());
       resetCredentialsModification();
     }
     else {
@@ -129,7 +142,9 @@ public class StepicStudyOptions implements StudyOptionsProvider {
     if (myCredentialsModified) {
       final Project project = StudyUtils.getStudyProject();
       if (project != null) {
-        final StepicUser user = StudyTaskManager.getInstance(project).getUser();
+        StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
+        taskManager.setEnableTestingFromSamples(myEnableTestingFromSamples.isSelected());
+        final StepicUser user = taskManager.getUser();
         user.setEmail(getLogin());
         user.setPassword(getPassword());
         if (!StringUtil.isEmptyOrSpaces(getLogin()) && !StringUtil.isEmptyOrSpaces(getPassword())) {