Search in sources :

Example 11 with StudyNode

use of org.stepik.core.courseFormat.StudyNode in project intellij-plugins by StepicOrg.

the class ProjectPsiFilesUtils method isNotMovableOrRenameElement.

public static boolean isNotMovableOrRenameElement(@NotNull PsiElement element, @NotNull Set<Class<? extends PsiElement>> acceptableClasses) {
    Project project = element.getProject();
    StudyNode root = StepikProjectManager.getProjectRoot(project);
    if (root == null) {
        return false;
    }
    if (notAccept(element, acceptableClasses)) {
        return false;
    }
    PsiFileSystemItem file = getFile(element);
    if (file == null) {
        return false;
    }
    String path = getRelativePath(file);
    return ProjectFilesUtils.isNotMovableOrRenameElement(root, path);
}
Also used : Project(com.intellij.openapi.project.Project) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 12 with StudyNode

use of org.stepik.core.courseFormat.StudyNode in project intellij-plugins by StepicOrg.

the class StepikDirectoryNode method getTypeSortWeight.

@Override
public int getTypeSortWeight(boolean sortByType) {
    StudyNode node = StudyUtils.getStudyNode(myProject, getValue().getVirtualFile());
    String path = getRelativePath(getValue());
    if (node != null && node.getPath().equals(path)) {
        return node.getPosition();
    }
    return Integer.MAX_VALUE;
}
Also used : StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 13 with StudyNode

use of org.stepik.core.courseFormat.StudyNode in project intellij-plugins by StepicOrg.

the class StudyUtils method getStudyNode.

@Nullable
public static StudyNode getStudyNode(@NotNull Project project, @NotNull VirtualFile nodeVF) {
    String path = getRelativePath(project, nodeVF);
    StudyNode root = StepikProjectManager.getProjectRoot(project);
    if (root == null) {
        return null;
    }
    return getStudyNode(root, path);
}
Also used : StudyNode(org.stepik.core.courseFormat.StudyNode) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with StudyNode

use of org.stepik.core.courseFormat.StudyNode in project intellij-plugins by StepicOrg.

the class StudyUtils method getRecommendation.

@Nullable
public static StudyNode<?, ?> getRecommendation(@NotNull StudyNode root) {
    StudyObject data = root.getData();
    if (data == null || !data.isAdaptive()) {
        return null;
    }
    StudyNode studyNode = null;
    StepikApiClient stepikClient = authAndGetStepikApiClient();
    if (!isAuthenticated()) {
        return null;
    }
    try {
        Recommendations recommendations = stepikClient.recommendations().get().course(root.getId()).execute();
        if (!recommendations.isEmpty()) {
            Recommendation recommendation = recommendations.getFirst();
            long lesson = recommendation.getLesson();
            Steps steps = stepikClient.steps().get().lesson(lesson).execute();
            if (!steps.isEmpty()) {
                long stepId = steps.getFirst().getId();
                studyNode = root.getChildByClassAndId(Step.class, stepId);
            }
        }
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return studyNode;
}
Also used : Recommendations(org.stepik.api.objects.recommendations.Recommendations) Steps(org.stepik.api.objects.steps.Steps) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) StudyObject(org.stepik.api.objects.StudyObject) Step(org.stepik.api.objects.steps.Step) StepikClientException(org.stepik.api.exceptions.StepikClientException) Recommendation(org.stepik.api.objects.recommendations.Recommendation) StudyNode(org.stepik.core.courseFormat.StudyNode) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with StudyNode

use of org.stepik.core.courseFormat.StudyNode in project intellij-plugins by StepicOrg.

the class StepHelper method solvedLesson.

public boolean solvedLesson() {
    try {
        StudyNode lesson = stepNode.getParent();
        if (lesson == null) {
            return false;
        }
        StudyObject data = lesson.getData();
        if (data == null) {
            return false;
        }
        String progressId = data.getProgress();
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        Progresses progresses = stepikApiClient.progresses().get().id(progressId).execute();
        return !progresses.isEmpty() && progresses.getFirst().isPassed();
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return false;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Progresses(org.stepik.api.objects.progresses.Progresses) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StudyNode (org.stepik.core.courseFormat.StudyNode)21 Project (com.intellij.openapi.project.Project)6 StepNode (org.stepik.core.courseFormat.StepNode)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 StepikApiClient (org.stepik.api.client.StepikApiClient)4 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)4 StepikProjectManager (org.stepik.core.StepikProjectManager)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)2 NotNull (org.jetbrains.annotations.NotNull)2 StepikClientException (org.stepik.api.exceptions.StepikClientException)2 StudyObject (org.stepik.api.objects.StudyObject)2 SupportedLanguages (org.stepik.core.SupportedLanguages)2 PresentationData (com.intellij.ide.projectView.PresentationData)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Application (com.intellij.openapi.application.Application)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileEditorManagerAdapter (com.intellij.openapi.fileEditor.FileEditorManagerAdapter)1