Search in sources :

Example 1 with StudyNode

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

the class StepikStepNavigationAction method navigateStep.

@Override
public void navigateStep(@NotNull final Project project) {
    StudyNode currentNode = StepikProjectManager.getSelected(project);
    if (currentNode == null) {
        currentNode = StepikProjectManager.getProjectRoot(project);
    }
    StudyNode targetNode;
    targetNode = getTargetStep(currentNode);
    if (targetNode == null) {
        return;
    }
    NavigationUtils.navigate(project, targetNode);
}
Also used : StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 2 with StudyNode

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

the class Metrics method postMetrics.

private static void postMetrics(@NotNull Project project, @NotNull Metric metric, @NotNull MetricsStatus status) {
    executor.schedule(() -> {
        StepikApiClient stepikApiClient;
        stepikApiClient = authAndGetStepikApiClient();
        if (!isAuthenticated()) {
            return;
        }
        final StepikMetricsPostQuery query = stepikApiClient.metrics().post().timestamp(System.currentTimeMillis() / 1000L).tags(metric.getTags()).data(metric.getData()).name("ide_plugin").tags("name", "S_Union").tags("ide_name", ApplicationInfo.getInstance().getVersionName()).data("ide_version", ApplicationInfo.getInstance().getBuild().toString()).data("plugin_version", PluginUtils.getVersion()).data("session", session).tags("status", status);
        StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
        if (projectManager != null) {
            query.data("project_id", projectManager.getUuid()).tags("project_programming_language", projectManager.getDefaultLang().getName()).data("project_manager_version", projectManager.getVersion());
            StudyNode projectRoot = projectManager.getProjectRoot();
            if (projectRoot != null) {
                Class<? extends StudyNode> projectRootClass = projectRoot.getClass();
                query.tags("project_root_class", projectRootClass.getSimpleName()).data("project_root_id", projectRoot.getId());
                query.data("course_id", projectRoot.getCourseId(stepikApiClient));
            }
        }
        query.executeAsync().exceptionally((e) -> {
            String message = String.format("Failed post metric: %s", query.toString());
            logger.warn(message, e);
            return null;
        });
    }, 500, TimeUnit.MILLISECONDS);
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikMetricsPostQuery(org.stepik.api.queries.metrics.StepikMetricsPostQuery) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 3 with StudyNode

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

the class StepHelper method getLink.

@NotNull
public String getLink() {
    StepNode stepNode = getStepNode();
    StudyNode parent = stepNode.getParent();
    if (parent != null) {
        return String.format("https://stepik.org/lesson/%d/step/%d", parent.getId(), stepNode.getPosition());
    }
    return "https://stepik.org/";
}
Also used : StepNode(org.stepik.core.courseFormat.StepNode) StudyNode(org.stepik.core.courseFormat.StudyNode) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with StudyNode

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

the class StepikPyProjectGenerator method createCourseFromGenerator.

private void createCourseFromGenerator(@NotNull Project project) {
    generator.generateProject(project);
    FileUtil.createDirectory(new File(project.getBasePath(), EduNames.SANDBOX_DIR));
    StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
    if (projectManager == null) {
        logger.warn("failed to generate builders: StepikProjectManager is null");
        return;
    }
    projectManager.setDefaultLang(generator.getDefaultLang());
    StudyNode root = projectManager.getProjectRoot();
    if (root == null) {
        logger.warn("failed to generate builders: Root is null");
        return;
    }
    if (root instanceof StepNode) {
        getOrCreateSrcDirectory(project, (StepNode) root, true);
    } else {
        createSubDirectories(project, generator.getDefaultLang(), root, null);
        VirtualFileManager.getInstance().syncRefresh();
    }
    Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> application.runWriteAction(() -> {
        StudyProjectComponent.getInstance(project).registerStudyToolWindow();
        StepikProjectManager.updateAdaptiveSelected(project);
    })));
}
Also used : StepikProjectManager(org.stepik.core.StepikProjectManager) StepNode(org.stepik.core.courseFormat.StepNode) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Application(com.intellij.openapi.application.Application) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 5 with StudyNode

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

the class StepikTreeStructureProvider method isHidden.

private boolean isHidden(@NotNull Project project, @Nullable Object value) {
    if (StepikProjectManager.isAdaptive(project)) {
        if (!(value instanceof PsiFileSystemItem)) {
            return false;
        }
        String relativePath = getRelativePath((PsiFileSystemItem) value);
        StudyNode root = StepikProjectManager.getProjectRoot(project);
        if (root == null) {
            return false;
        }
        StudyNode node = StudyUtils.getStudyNode(root, relativePath);
        if (node == null) {
            return false;
        }
        StudyNode<?, ?> selected = StepikProjectManager.getSelected(project);
        if (selected == null) {
            return true;
        }
        String selectedPath = selected.getPath();
        String nodePath = node.getPath();
        if (!selectedPath.startsWith(nodePath) && selected.getParent() != node.getParent()) {
            return true;
        }
    }
    return false;
}
Also used : PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) 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