EDU-810 Friendly message in case we got no recommendations for the adaptive course

This commit is contained in:
Valentina Kiryushkina
2017-01-11 16:15:46 +03:00
parent 37320e074a
commit 0b29608d59
3 changed files with 13 additions and 8 deletions
@@ -848,4 +848,8 @@ public class StudyUtils {
final int endOffset = startOffset + length + delta;
return Pair.create(startOffset, endOffset);
}
public static boolean isCourseValid(@Nullable Course course) {
return course != null && !(course.isAdaptive() && course.getLessons().isEmpty());
}
}
@@ -93,6 +93,10 @@ public class StudyProjectGenerator {
Messages.showWarningDialog("Some problems occurred while creating the course", "Error in Course Creation");
return;
}
else if (course.isAdaptive() && course.getLessons().isEmpty()) {
Messages.showWarningDialog("There is no recommended tasks for this adaptive course", "Error in Course Creation");
return;
}
final File courseDirectory = StudyUtils.getCourseDirectory(course);
StudyTaskManager.getInstance(project).setCourse(course);
ApplicationManager.getApplication().runWriteAction(() -> {
@@ -135,7 +139,7 @@ public class StudyProjectGenerator {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
return execCancelable(() -> {
final Course course = EduStepicConnector.getCourse(project, mySelectedCourseInfo);
if (course != null) {
if (StudyUtils.isCourseValid(course)) {
flushCourse(course);
course.initCourse(false);
}
@@ -212,19 +212,16 @@ public class EduStepicConnector {
}
}
else {
final Lesson lesson = new Lesson();
course.setName(info.getName());
//TODO: more specific name?
lesson.setName("Adaptive");
course.addLesson(lesson);
final Task recommendation = EduAdaptiveStepicConnector.getNextRecommendation(project, course);
if (recommendation != null) {
final Lesson lesson = new Lesson();
lesson.setName("Adaptive");
course.addLesson(lesson);
lesson.addTask(recommendation);
return course;
}
else {
return null;
}
return course;
}
return null;
}