Search in sources :

Example 1 with StudyObject

use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.

the class StepikModuleType method modifySettingsStep.

@Nullable
@Override
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep, @NotNull ModuleBuilder moduleBuilder) {
    JTextField nameField = settingsStep.getModuleNameField();
    if (nameField != null) {
        CourseModuleBuilder courseModuleBuilder = (CourseModuleBuilder) moduleBuilder;
        StudyObject studyObject = courseModuleBuilder.getWizardStep().getSelectedStudyObject();
        String projectDirectory = settingsStep.getContext().getProjectFileDirectory();
        String projectName = ProjectWizardUtils.getProjectDefaultName(projectDirectory, studyObject);
        nameField.setText(projectName);
    }
    return null;
}
Also used : StudyObject(org.stepik.api.objects.StudyObject) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StudyObject

use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.

the class StepikProjectGenerator method initEmptyStudyNode.

@NotNull
private static StudyObject initEmptyStudyNode() {
    StudyObject course = new Course();
    course.setTitle("Empty");
    course.setDescription("Please, press refresh button");
    return course;
}
Also used : StudyObject(org.stepik.api.objects.StudyObject) Course(org.stepik.api.objects.courses.Course) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with StudyObject

use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.

the class StepikProjectGenerator method getCourses.

@NotNull
public static CompletableFuture<List<StudyObject>> getCourses(@NotNull SupportedLanguages programmingLanguage) {
    return CompletableFuture.supplyAsync(() -> {
        List<StudyObject> courses = new ArrayList<>();
        List<Long> coursesIds = getHardcodedCoursesId(programmingLanguage);
        if (!coursesIds.isEmpty()) {
            StepikApiClient stepikApiClient = authAndGetStepikApiClient();
            try {
                courses = stepikApiClient.courses().get().id(coursesIds).execute().getCourses().stream().map(course -> (StudyObject) course).collect(Collectors.toList());
            } catch (StepikClientException e) {
                logger.warn("Failed get courses", e);
            }
        }
        courses.sort((course1, course2) -> {
            long id1 = course1.getId();
            long id2 = course2.getId();
            int index1 = coursesIds.indexOf(id1);
            int index2 = coursesIds.indexOf(id2);
            return Integer.compare(index1, index2);
        });
        return courses;
    });
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) ArrayList(java.util.ArrayList) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with StudyObject

use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.

the class JavaWizardStep method onWizardFinished.

@Override
public void onWizardFinished() throws CommitStepException {
    if (!(valid && leaving)) {
        return;
    }
    SupportedLanguages selectedLang = panel.getLanguage();
    generator.setDefaultLang(selectedLang);
    StudyObject studyObject = panel.getSelectedStudyObject();
    generator.createCourseNodeUnderProgress(project, studyObject);
    long id = studyObject.getId();
    if (id == 0) {
        return;
    }
    boolean wasEnrollment = ProjectWizardUtils.enrollmentCourse(studyObject);
    if (wasEnrollment) {
        logger.warn("User didn't enrollment on course: " + id);
    }
    String messageTemplate = "Leaving step the project wizard with the selected study object: type=%s, id = %s, name = %s";
    logger.info(String.format(messageTemplate, studyObject.getClass().getSimpleName(), id, studyObject.getTitle()));
}
Also used : SupportedLanguages(org.stepik.core.SupportedLanguages) StudyObject(org.stepik.api.objects.StudyObject)

Example 5 with StudyObject

use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.

the class CourseListModel method update.

void update(@NotNull SupportedLanguages programmingLanguage) {
    StepikProjectGenerator.getCourses(programmingLanguage).thenAccept(newCourseList -> {
        StudyObject selectedCourse = getSelectedItem();
        courses.clear();
        if (!newCourseList.isEmpty()) {
            courses.addAll(newCourseList);
            if (selectedCourse == EMPTY_STUDY_OBJECT || !courses.contains(selectedCourse)) {
                selectedCourse = courses.get(0);
            }
        } else {
            courses.add(EMPTY_STUDY_OBJECT);
        }
        StudyObject finalSelectedCourse = selectedCourse;
        SwingUtilities.invokeLater(() -> {
            setSelectedItem(finalSelectedCourse);
            fireIntervalAdded(this, 0, getSize() - 1);
        });
    });
}
Also used : StudyObject(org.stepik.api.objects.StudyObject)

Aggregations

StudyObject (org.stepik.api.objects.StudyObject)8 StepikApiClient (org.stepik.api.client.StepikApiClient)3 StepikClientException (org.stepik.api.exceptions.StepikClientException)3 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)3 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 StudyNode (org.stepik.core.courseFormat.StudyNode)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Course (org.stepik.api.objects.courses.Course)1 Progresses (org.stepik.api.objects.progresses.Progresses)1 Recommendation (org.stepik.api.objects.recommendations.Recommendation)1 Recommendations (org.stepik.api.objects.recommendations.Recommendations)1 Step (org.stepik.api.objects.steps.Step)1 Steps (org.stepik.api.objects.steps.Steps)1 SupportedLanguages (org.stepik.core.SupportedLanguages)1