use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyNewProjectPanel method setupBrowseButton.
private void setupBrowseButton() {
if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
myBrowseButton.putClientProperty("JButton.buttonType", null);
myBrowseButton.setIcon(InteractiveLearningIcons.InterpreterGear);
final FileChooserDescriptor fileChooser = new FileChooserDescriptor(true, false, false, true, false, false) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return file.isDirectory() || StudyUtils.isZip(file.getName());
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return StudyUtils.isZip(file.getName());
}
};
myBrowseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final BaseListPopupStep<String> popupStep = new BaseListPopupStep<String>("", "Add local course", LOGIN_TO_STEPIC) {
@Override
public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
return doFinalStep(() -> {
if ("Add local course".equals(selectedValue)) {
Project[] projects = ProjectManager.getInstance().getOpenProjects();
FileChooser.chooseFile(fileChooser, null, projects.length == 0 ? null : projects[0].getBaseDir(), file -> {
String fileName = file.getPath();
int oldSize = myAvailableCourses.size();
CourseInfo courseInfo = myGenerator.addLocalCourse(fileName);
if (courseInfo != null) {
if (oldSize != myAvailableCourses.size()) {
myCoursesComboBox.addItem(courseInfo);
}
myCoursesComboBox.setSelectedItem(courseInfo);
setOK();
} else {
setError(INVALID_COURSE);
myCoursesComboBox.removeAllItems();
myCoursesComboBox.addItem(CourseInfo.INVALID_COURSE);
for (CourseInfo course : myAvailableCourses) {
myCoursesComboBox.addItem(course);
}
myCoursesComboBox.setSelectedItem(CourseInfo.INVALID_COURSE);
}
});
} else if (LOGIN_TO_STEPIC.equals(selectedValue)) {
showLoginDialog(true, "Signing In And Getting Stepik Course List");
}
});
}
};
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
popup.showInScreenCoordinates(myBrowseButton, myBrowseButton.getLocationOnScreen());
}
});
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyProjectGenerator method getCoursesFromCache.
public static List<CourseInfo> getCoursesFromCache() {
List<CourseInfo> courses = new ArrayList<>();
final File cacheFile = new File(OUR_COURSES_DIR, CACHE_NAME);
if (!cacheFile.exists()) {
return courses;
}
try {
final FileInputStream inputStream = new FileInputStream(cacheFile);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
try {
String line;
while ((line = reader.readLine()) != null) {
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final CourseInfo courseInfo = gson.fromJson(line, CourseInfo.class);
courses.add(courseInfo);
}
} catch (IOException | JsonSyntaxException e) {
LOG.error(e.getMessage());
} finally {
StudyUtils.closeSilently(reader);
}
} catch (UnsupportedEncodingException e) {
LOG.error(e.getMessage());
} finally {
StudyUtils.closeSilently(inputStream);
}
} catch (FileNotFoundException e) {
LOG.error(e.getMessage());
}
return courses;
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class CCPushCourse method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
if (course.getId() > 0) {
ProgressManager.getInstance().run(new Task.Modal(project, "Updating Course", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
for (Lesson lesson : course.getLessons()) {
if (lesson.getId() > 0) {
CCStepicConnector.updateLesson(project, lesson, indicator);
} else {
final CourseInfo info = CourseInfo.fromCourse(course);
final int lessonId = CCStepicConnector.postLesson(project, lesson, indicator);
if (lessonId != -1) {
final List<Integer> sections = info.getSections();
final Integer sectionId = sections.get(sections.size() - 1);
CCStepicConnector.postUnit(lessonId, lesson.getIndex(), sectionId);
}
}
}
}
});
} else {
CCStepicConnector.postCourseWithProgress(project, course);
}
EduUsagesCollector.courseUploaded();
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class CCPushLesson method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
return;
}
final Lesson lesson = course.getLesson(lessonDir.getName());
if (lesson == null) {
return;
}
ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Lesson", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText("Uploading lesson to " + EduStepicNames.STEPIC_URL);
if (lesson.getId() > 0) {
CCStepicConnector.updateLesson(project, lesson, indicator);
} else {
final CourseInfo info = CourseInfo.fromCourse(course);
final int lessonId = CCStepicConnector.postLesson(project, lesson, indicator);
final List<Integer> sections = info.getSections();
final Integer sectionId = sections.get(sections.size() - 1);
CCStepicConnector.postUnit(lessonId, lesson.getIndex(), sectionId);
}
}
});
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyStepicFormatTest method testAvailableCourses.
@Test
public void testAvailableCourses() throws IOException {
String responseString = FileUtil.loadFile(new File(getTestDataPath(), "courses.json"));
StepicWrappers.CoursesContainer container = EduStepicClient.deserializeStepicResponse(StepicWrappers.CoursesContainer.class, responseString);
assertNotNull(container.courses);
assertTrue("Incorrect number of courses", container.courses.size() == 4);
List<CourseInfo> filtered = ContainerUtil.filter(container.courses, info -> EduStepicConnector.canBeOpened(info));
assertEquals(ContainerUtil.newArrayList("Adaptive Python", "Introduction to Python", "format2"), ContainerUtil.map(filtered, CourseInfo::getName));
}
Aggregations