Search in sources :

Example 1 with StepType

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

the class Metrics method stepAction.

private static void stepAction(@NotNull String actionName, @NotNull Project project, @NotNull StepNode stepNode, @NotNull MetricsStatus status) {
    Metric metric = new Metric();
    metric.addTags("action", actionName);
    metric.addData("step_id", stepNode.getId());
    metric.addTags("step_programming_language", stepNode.getCurrentLang().getName());
    StepType stepType = stepNode.getType();
    metric.addTags("step_type", stepType.getName());
    postMetrics(project, metric, status);
}
Also used : StepType(org.stepik.core.courseFormat.StepType) Metric(org.stepik.api.objects.metrics.Metric)

Example 2 with StepType

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

the class StudyToolWindow method setText.

private void setText(@Nullable StepNode stepNode) {
    if (stepNode == null) {
        setEmptyText();
        rightPanel.setVisible(false);
        return;
    }
    browserWindow.showLoadAnimation();
    StepType stepType = stepNode.getType();
    if (stepType != VIDEO && stepType != CODE) {
        SwingUtilities.invokeLater(() -> rightPanel.setVisible(false));
    }
    boolean isTheory = stepType == VIDEO || stepType == TEXT;
    postView(stepNode, isTheory);
    StepHelper stepHelper = null;
    switch(stepType) {
        case UNKNOWN:
            stepHelper = new StepHelper(project, stepNode);
            break;
        case CODE:
            stepHelper = new CodeQuizHelper(project, stepNode);
            updateLanguageBox(stepNode);
            break;
        case TEXT:
            stepHelper = new TextTheoryHelper(project, stepNode);
            break;
        case VIDEO:
            stepHelper = new VideoTheoryHelper(project, stepNode);
            break;
        case CHOICE:
            stepHelper = new ChoiceQuizHelper(project, stepNode);
            break;
        case STRING:
            stepHelper = new StringQuizHelper(project, stepNode);
            break;
        case SORTING:
            stepHelper = new SortingQuizHelper(project, stepNode);
            break;
        case MATCHING:
            stepHelper = new MatchingQuizHelper(project, stepNode);
            break;
        case NUMBER:
            stepHelper = new NumberQuizHelper(project, stepNode);
            break;
        case DATASET:
            stepHelper = new DatasetQuizHelper(project, stepNode);
            break;
        case TABLE:
            stepHelper = new TableQuizHelper(project, stepNode);
            break;
        case FILL_BLANKS:
            stepHelper = new QuizHelper(project, stepNode);
            break;
        case MATH:
            stepHelper = new QuizHelper(project, stepNode);
            break;
        case FREE_ANSWER:
            stepHelper = new FreeAnswerQuizHelper(project, stepNode);
            break;
    }
    HashMap<String, Object> params = new HashMap<>();
    params.put("stepNode", stepHelper);
    params.put("darcula", LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo);
    browserWindow.loadContent("quiz/" + stepHelper.getType(), params);
}
Also used : CodeQuizHelper(org.stepik.core.courseFormat.stepHelpers.CodeQuizHelper) TableQuizHelper(org.stepik.core.courseFormat.stepHelpers.TableQuizHelper) HashMap(java.util.HashMap) StepType(org.stepik.core.courseFormat.StepType) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) TextTheoryHelper(org.stepik.core.courseFormat.stepHelpers.TextTheoryHelper) StringQuizHelper(org.stepik.core.courseFormat.stepHelpers.StringQuizHelper) VideoTheoryHelper(org.stepik.core.courseFormat.stepHelpers.VideoTheoryHelper) SortingQuizHelper(org.stepik.core.courseFormat.stepHelpers.SortingQuizHelper) ChoiceQuizHelper(org.stepik.core.courseFormat.stepHelpers.ChoiceQuizHelper) StringQuizHelper(org.stepik.core.courseFormat.stepHelpers.StringQuizHelper) QuizHelper(org.stepik.core.courseFormat.stepHelpers.QuizHelper) DatasetQuizHelper(org.stepik.core.courseFormat.stepHelpers.DatasetQuizHelper) TableQuizHelper(org.stepik.core.courseFormat.stepHelpers.TableQuizHelper) MatchingQuizHelper(org.stepik.core.courseFormat.stepHelpers.MatchingQuizHelper) FreeAnswerQuizHelper(org.stepik.core.courseFormat.stepHelpers.FreeAnswerQuizHelper) SortingQuizHelper(org.stepik.core.courseFormat.stepHelpers.SortingQuizHelper) NumberQuizHelper(org.stepik.core.courseFormat.stepHelpers.NumberQuizHelper) CodeQuizHelper(org.stepik.core.courseFormat.stepHelpers.CodeQuizHelper) MatchingQuizHelper(org.stepik.core.courseFormat.stepHelpers.MatchingQuizHelper) NumberQuizHelper(org.stepik.core.courseFormat.stepHelpers.NumberQuizHelper) DatasetQuizHelper(org.stepik.core.courseFormat.stepHelpers.DatasetQuizHelper) StepHelper(org.stepik.core.courseFormat.stepHelpers.StepHelper) FreeAnswerQuizHelper(org.stepik.core.courseFormat.stepHelpers.FreeAnswerQuizHelper) ChoiceQuizHelper(org.stepik.core.courseFormat.stepHelpers.ChoiceQuizHelper)

Example 3 with StepType

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

the class FormListener method handle.

static void handle(@NotNull Project project, @NotNull StudyBrowserWindow browser, @NotNull HTMLFormElement form) {
    StudyNode root = StepikProjectManager.getProjectRoot(project);
    if (root == null) {
        return;
    }
    StudyNode node = StudyUtils.getStudyNode(root, form.getAction());
    if (!(node instanceof StepNode)) {
        return;
    }
    StepNode stepNode = (StepNode) node;
    Elements elements = new Elements(form.getElements());
    switch(elements.getAction()) {
        case "get_first_attempt":
        case "get_attempt":
            if (!elements.isLocked()) {
                getAttempt(project, stepNode);
            }
            break;
        case "submit":
            String typeStr = elements.getType();
            StepType type = StepType.of(typeStr);
            boolean isFromFile = elements.isFromFile();
            String data = isFromFile ? getDataFromFile(stepNode, project) : null;
            long attemptId = elements.getAttemptId();
            sendStep(project, stepNode, elements, type, attemptId, data);
            break;
        case "save_reply":
            typeStr = elements.getType();
            type = StepType.of(typeStr);
            getReply(stepNode, type, elements, null);
            break;
        case "login":
            String email = elements.getInputValue("email");
            String password = elements.getInputValue("password");
            browser.showLoadAnimation();
            StepikAuthManager.authentication(email, password).whenComplete((state, throwable) -> {
                if (state != StepikAuthState.AUTH) {
                    browser.callFunction("setErrorMessage", "Wrong email or password");
                }
                browser.hideLoadAnimation();
            });
            break;
        default:
            browser.hideLoadAnimation();
    }
}
Also used : StepNode(org.stepik.core.courseFormat.StepNode) StepType(org.stepik.core.courseFormat.StepType) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 4 with StepType

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

the class FormListener method sendStep.

private static void sendStep(@NotNull Project project, @NotNull StepNode stepNode, @NotNull Elements elements, @NotNull StepType type, long attemptId, @Nullable String data) {
    StepikApiClient stepikApiClient = authAndGetStepikApiClient(true);
    StepikSubmissionsPostQuery query = stepikApiClient.submissions().post().attempt(attemptId);
    Reply reply = getReply(stepNode, type, elements, data);
    if (reply == null) {
        return;
    }
    query.reply(reply).executeAsync().whenComplete(((submissions, e) -> {
        if (submissions == null) {
            logger.warn("Failed send step from browser", e);
            StepikProjectManager.updateSelection(project);
            return;
        }
        if (submissions.isEmpty()) {
            logger.warn("Failed send step from browser", e);
            return;
        }
        Submission submission = submissions.getFirst();
        SendAction.checkStepStatus(project, stepikApiClient, stepNode, submission.getId(), new EmptyProgressIndicator());
    }));
}
Also used : HTMLFormElement(org.w3c.dom.html.HTMLFormElement) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudyNode(org.stepik.core.courseFormat.StudyNode) StepikSubmissionsPostQuery(org.stepik.api.queries.submissions.StepikSubmissionsPostQuery) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Submission(org.stepik.api.objects.submissions.Submission) StepikAuthState(org.stepik.core.stepik.StepikAuthState) Files(java.nio.file.Files) StepNode(org.stepik.core.courseFormat.StepNode) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StudyUtils(org.stepik.core.StudyUtils) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) FileChooser(javafx.stage.FileChooser) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SendAction(org.stepik.plugin.actions.SendAction) EventListener(org.w3c.dom.events.EventListener) StepType(org.stepik.core.courseFormat.StepType) Event(org.w3c.dom.events.Event) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikApiClient(org.stepik.api.client.StepikApiClient) Reply(org.stepik.api.objects.submissions.Reply) StepikAuthManager(org.stepik.core.stepik.StepikAuthManager) NotNull(org.jetbrains.annotations.NotNull) StepDescriptionUtils.getReply(org.stepik.core.ui.StepDescriptionUtils.getReply) ProjectFilesUtils.getOrCreateSrcDirectory(org.stepik.core.utils.ProjectFilesUtils.getOrCreateSrcDirectory) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Submission(org.stepik.api.objects.submissions.Submission) Reply(org.stepik.api.objects.submissions.Reply) StepDescriptionUtils.getReply(org.stepik.core.ui.StepDescriptionUtils.getReply) StepikSubmissionsPostQuery(org.stepik.api.queries.submissions.StepikSubmissionsPostQuery)

Aggregations

StepType (org.stepik.core.courseFormat.StepType)4 StepNode (org.stepik.core.courseFormat.StepNode)2 StudyNode (org.stepik.core.courseFormat.StudyNode)2 DarculaLookAndFeelInfo (com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo)1 Logger (com.intellij.openapi.diagnostic.Logger)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FileChooser (javafx.stage.FileChooser)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 Metric (org.stepik.api.objects.metrics.Metric)1 Reply (org.stepik.api.objects.submissions.Reply)1