mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add Update Course action for adaptive courses
This commit is contained in:
@@ -84,6 +84,8 @@
|
||||
text="Switch Task Description Panel">
|
||||
</action>
|
||||
|
||||
<action id="Edu.UpdateRecommendation" class="com.jetbrains.edu.learning.actions.StudyUpdateRecommendationAction"/>
|
||||
|
||||
<!--course creator-->
|
||||
<action id="CreateLesson" class="com.jetbrains.edu.coursecreator.actions.CCCreateLesson">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
|
||||
@@ -119,7 +119,8 @@ public interface EduPluginConfigurator {
|
||||
StudyPreviousTaskAction.ACTION_ID,
|
||||
StudyNextTaskAction.ACTION_ID,
|
||||
StudyRefreshTaskFileAction.ACTION_ID,
|
||||
StudyShowHintAction.ACTION_ID
|
||||
StudyShowHintAction.ACTION_ID,
|
||||
StudyUpdateRecommendationAction.ACTION_ID
|
||||
};
|
||||
ActionManager actionManager = ActionManager.getInstance();
|
||||
Arrays.stream(ids)
|
||||
|
||||
@@ -447,7 +447,7 @@ public class StudyUtils {
|
||||
@NotNull
|
||||
private static String getFooterWithLink(Task task) {
|
||||
return
|
||||
"<div class=\"footer\">" + "<a href=" + EduStepikUtils.getLink(task) + ">Open on Stepik</a>" + "</div>";
|
||||
"<div class=\"footer\">" + "<a href=" + EduStepikUtils.getAdaptiveLink(task) + ">Open on Stepik</a>" + "</div>";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.jetbrains.edu.learning.actions;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.learning.courseFormat.RemoteCourse;
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.Task;
|
||||
import com.jetbrains.edu.learning.navigation.StudyNavigator;
|
||||
import com.jetbrains.edu.learning.stepic.EduAdaptiveStepicConnector;
|
||||
import icons.EducationalCoreIcons;
|
||||
|
||||
public class StudyUpdateRecommendationAction extends DumbAwareAction {
|
||||
public static final String ACTION_ID = "Edu.UpdateRecommendation";
|
||||
|
||||
public StudyUpdateRecommendationAction() {
|
||||
super("Update course", "Update course", EducationalCoreIcons.Stepik);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
assert project != null;
|
||||
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
assert course != null;
|
||||
|
||||
Lesson adaptiveLesson = course.getLessons().get(0);
|
||||
assert adaptiveLesson != null;
|
||||
|
||||
int taskNumber = adaptiveLesson.getTaskList().size();
|
||||
Task lastRecommendationInCourse = adaptiveLesson.getTaskList().get(taskNumber - 1);
|
||||
Task lastRecommendationOnStepik = ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
() -> {
|
||||
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
|
||||
return StudyUtils.execCancelable(() -> EduAdaptiveStepicConnector.getNextRecommendation(project, (RemoteCourse)course));
|
||||
},
|
||||
"Updating Course", true, project);
|
||||
|
||||
if (lastRecommendationOnStepik != null && lastRecommendationOnStepik.getStepId() != lastRecommendationInCourse.getStepId()) {
|
||||
lastRecommendationOnStepik.initTask(adaptiveLesson, false);
|
||||
EduAdaptiveStepicConnector.replaceCurrentTask(project, lastRecommendationOnStepik, adaptiveLesson);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
|
||||
ProjectView.getInstance(project).refresh();
|
||||
StudyNavigator.navigateToTask(project, lastRecommendationOnStepik);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Presentation presentation = e.getPresentation();
|
||||
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null || !course.isAdaptive()) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
presentation.setEnabledAndVisible(true);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -363,7 +363,7 @@ public class EduAdaptiveStepicConnector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void replaceCurrentTask(@NotNull Project project, @NotNull Task task, @NotNull Lesson lesson) {
|
||||
public static void replaceCurrentTask(@NotNull Project project, @NotNull Task task, @NotNull Lesson lesson) {
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
assert course != null;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EduStepikUtils {
|
||||
@Nullable
|
||||
public static String getLink(@Nullable Task task) {
|
||||
public static String getLink(@Nullable Task task, int stepNumber) {
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -31,6 +31,12 @@ public class EduStepikUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
return String.format("%s/lesson/%d/step/%d", EduStepicNames.STEPIC_URL, lesson.getId(), task.getPosition());
|
||||
return String.format("%s/lesson/%d/step/%d", EduStepicNames.STEPIC_URL, lesson.getId(), stepNumber);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getAdaptiveLink(@Nullable Task task) {
|
||||
String link = getLink(task, 1);
|
||||
return link == null ? null : link + "?adaptive=true";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user