use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.
the class CourseModuleBuilder method createCourseFromGenerator.
private void createCourseFromGenerator(@NotNull ModifiableModuleModel moduleModel, @NotNull Project project) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
generator.generateProject(project);
String moduleDir = getModuleFileDirectory();
if (moduleDir == null) {
return;
}
logger.info("Module dir = " + moduleDir);
new SandboxModuleBuilder(moduleDir).createModule(moduleModel);
StudyNode root = StepikProjectManager.getProjectRoot(project);
if (root == null) {
logger.info("Failed to generate builders: project root is null");
return;
}
if (root instanceof StepNode) {
getOrCreateSrcDirectory(project, (StepNode) root, true, moduleModel);
} else {
createSubDirectories(project, generator.getDefaultLang(), root, moduleModel);
VirtualFileManager.getInstance().syncRefresh();
}
}
use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.
the class NavigationUtils method navigate.
public static void navigate(@NotNull Project project, @NotNull StudyNode targetNode) {
for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
FileEditorManager.getInstance(project).closeFile(file);
}
VirtualFile projectDir = project.getBaseDir();
if (projectDir == null) {
return;
}
VirtualFile mainFile;
if (targetNode instanceof StepNode) {
VirtualFile srcDir = getOrCreateSrcDirectory(project, (StepNode) targetNode, true);
if (srcDir == null) {
return;
}
StepNode stepNode = (StepNode) targetNode;
mainFile = srcDir.findChild(stepNode.getCurrentLang().getMainFileName());
if (mainFile == null) {
mainFile = srcDir.getChildren().length > 0 ? srcDir : srcDir.getParent();
}
} else {
mainFile = projectDir.findFileByRelativePath(targetNode.getPath());
}
if (mainFile != null) {
updateProjectView(project, mainFile);
}
Metrics.navigateAction(project, targetNode, SUCCESSFUL);
StepikProjectManager.setSelected(project, targetNode);
ToolWindow runToolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.RUN);
if (runToolWindow != null) {
runToolWindow.hide(null);
}
}
use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.
the class QuizHelper method loadSubmission.
private void loadSubmission(StepikApiClient stepikApiClient, long userId) {
long attemptId = attempt.getId();
StepNode stepNode = getStepNode();
StepikSubmissionsGetQuery query = stepikApiClient.submissions().get().order(Order.DESC).user(userId).step(stepNode.getId());
if (!useLastSubmission) {
query.attempt(attemptId);
}
Submissions submissions = query.execute();
modified = false;
if (!submissions.isEmpty()) {
submission = submissions.getFirst();
boolean lastSubmission = submission.getId() == stepNode.getLastSubmissionId();
boolean outdated = stepNode.getLastReplyTime().after(submission.getTime());
if (lastSubmission && outdated) {
reply = stepNode.getLastReply();
modified = !submission.getReply().equals(reply);
} else {
reply = submission.getReply();
stepNode.setLastReply(submission.getReply());
stepNode.setLastSubmissionId(submission.getId());
}
if (attemptId == submission.getAttempt()) {
status = submission.getStatus();
}
if (ACTIVE.equals(attempt.getStatus()) && status.equals("correct")) {
action = GET_ATTEMPT;
}
stepNode.setStatus(StudyStatus.of(status));
} else {
reply = stepNode.getLastReply();
modified = true;
}
}
use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.
the class Metrics method navigateAction.
public static void navigateAction(@NotNull Project project, @NotNull StudyNode studyNode, @NotNull MetricsStatus status) {
if (studyNode instanceof StepNode) {
StepNode stepNode = (StepNode) studyNode;
stepAction("navigate", project, stepNode, status);
}
}
use of org.stepik.core.courseFormat.StepNode in project intellij-plugins by StepicOrg.
the class ProjectWizardUtils method createSubDirectories.
public static void createSubDirectories(@NotNull Project project, @NotNull SupportedLanguages defaultLanguage, @NotNull StudyNode<?, ?> root, @Nullable ModifiableModuleModel model) {
root.getChildren().forEach(child -> {
FileUtil.createDirectory(new File(project.getBasePath(), child.getPath()));
if (child instanceof StepNode) {
StepNode stepNode = (StepNode) child;
stepNode.setCurrentLang(defaultLanguage);
getOrCreateSrcDirectory(project, stepNode, false, model);
} else {
createSubDirectories(project, defaultLanguage, child, model);
}
});
}
Aggregations