Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thepieterdc committed Oct 24, 2019
1 parent 4b59a83 commit 28f2806
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2019. All rights reserved.
*
* @author Pieter De Clercq
* @author Tobiah Lissens
*
* https://github.com/thepieterdc/dodona-plugin-jetbrains/
*/

package io.github.thepieterdc.dodona.plugin.authentication;

/**
* Provides an authentication token to the caller.
*/
@FunctionalInterface
public interface AuthenticationConsumer {
/**
* Authenticates the current class using the provided authentication token.
*
* @param token the authentication token
*/
void authenticate(final String token);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ private DodonaAuthenticator(final DodonaAccountManager accountManager) {
this.accountManager = accountManager;
}

/**
* Provides authentication details to the given consumer.
*
* @param consumer the consumer
*/
public void authenticate(final AuthenticationConsumer consumer) {
this.accountManager.getAccount()
.flatMap(this.accountManager::getToken)
.ifPresent(consumer::authenticate);
}

/**
* Gets the account if available.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018-2019. All rights reserved.
*
* @author Pieter De Clercq
* @author Tobiah Lissens
*
* https://github.com/thepieterdc/dodona-plugin-jetbrains/
*/

package io.github.thepieterdc.dodona.plugin.tasks;

import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import io.github.thepieterdc.dodona.plugin.DodonaBundle;
import io.github.thepieterdc.dodona.plugin.api.DodonaExecutor;
import io.github.thepieterdc.dodona.plugin.authentication.DodonaAuthenticator;
import io.github.thepieterdc.dodona.plugin.ui.browser.BrowserDialog;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.swing.*;

/**
* Shows a submission result.
*/
public class ShowSubmissionTask extends AbstractDodonaBackgroundTask {
private final DodonaExecutor executor;
private final long submissionId;

/**
* ShowSubmissionTask constructor.
*
* @param project the current project
* @param submissionId the submission id
*/
private ShowSubmissionTask(final Project project,
final long submissionId) {
super(project, DodonaBundle.message("tasks.show_submission.title"));
this.executor = DodonaAuthenticator.getInstance().getExecutor();
this.submissionId = submissionId;
}

/**
* Creates a submission rendering task.
*
* @param project the current project
* @param submissionId the id of the submission to display
* @return the task
*/
@Nonnull
public static DodonaBackgroundTask create(final Project project,
final long submissionId) {
return new ShowSubmissionTask(project, submissionId);
}

@Override
public void run(@NotNull final ProgressIndicator progress) {
// Update the progressbar.
progress.setIndeterminate(true);
progress.setText(DodonaBundle.message("tasks.show_submission.loading"));

// Fetch the url of the submission.
final String url = this.executor.execute(dodona ->
dodona.submissions().get(this.submissionId), progress)
.getUrl();

// Show a BrowserDialog with the submission
SwingUtilities.invokeLater(() -> {
// Create the window.
final BrowserDialog browser = new BrowserDialog(
this.myProject,
DodonaBundle.message("tasks.show_submission.title")
);

// Append the authentication data.
DodonaAuthenticator.getInstance().authenticate(browser);

// Load the url and show the browser.
browser.loadUrl(url);
browser.show();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
import io.github.thepieterdc.dodona.plugin.DodonaBundle;
import io.github.thepieterdc.dodona.plugin.api.DodonaExecutor;
import io.github.thepieterdc.dodona.plugin.authentication.DodonaAuthenticator;
import io.github.thepieterdc.dodona.plugin.exercise.Identification;
import io.github.thepieterdc.dodona.plugin.exercise.identification.IdentificationService;
import io.github.thepieterdc.dodona.plugin.exceptions.CancelledException;
import io.github.thepieterdc.dodona.plugin.exceptions.warnings.SubmissionTimeoutException;
import io.github.thepieterdc.dodona.plugin.exercise.Identification;
import io.github.thepieterdc.dodona.plugin.feedback.FeedbackService;
import io.github.thepieterdc.dodona.plugin.notifications.ErrorReporter;
import io.github.thepieterdc.dodona.resources.Exercise;
Expand Down Expand Up @@ -128,12 +127,13 @@ private Submission awaitEvaluation(final ProgressIndicator progress,
*/
@Nonnull
public static DodonaBackgroundTask create(final Project project, final String code) {
// Attempt to identify the exercise, otherwise return a new task to
// perform this job.
return IdentificationService.getInstance()
.identify(code)
.map(result -> new SubmitSolutionTask(project, result, code))
.orElseThrow(RuntimeException::new);
// // Attempt to identify the exercise, otherwise return a new task to
// // perform this job.
// return IdentificationService.getInstance()
// .identify(code)
// .map(result -> new SubmitSolutionTask(project, result, code))
// .orElseThrow(RuntimeException::new);
return ShowSubmissionTask.create(project, 4029932L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.github.thepieterdc.dodona.plugin.ui.browser.BrowserDialog">
<grid id="27dc6" binding="rootPanel" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<focusable value="false"/>
</properties>
<border type="none"/>
<children/>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2018-2019. All rights reserved.
*
* @author Pieter De Clercq
* @author Tobiah Lissens
*
* https://github.com/thepieterdc/dodona-plugin-jetbrains/
*/

package io.github.thepieterdc.dodona.plugin.ui.browser;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.ui.AsyncProcessIcon;
import io.github.thepieterdc.dodona.plugin.authentication.AuthenticationConsumer;
import org.jetbrains.annotations.NonNls;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
* Dialog showing a webbrowser.
*/
public class BrowserDialog extends DialogWrapper implements AuthenticationConsumer {
@NonNls
private static final String CARD_LOADING = "BROWSER_LOADING";
@NonNls
private static final String CARD_PAGE = "BROWSER_PAGE";

@NonNls
private static final String CONTENT_TYPE = "text/html";

private static final int HEIGHT = 250;
private static final int WIDTH = 400;

private String token;

private final AsyncProcessIcon loadingIcon;

private final JEditorPane browserPanel;
private JPanel rootPanel;

/**
* BrowserDialog constructor.
*
* @param project the current project
*/
public BrowserDialog(final Project project,
final String title) {
super(project, true);
this.browserPanel = new JEditorPane();
this.loadingIcon = new AsyncProcessIcon(this.getClass() + ".loading");
this.rootPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));

this.setTitle(title);
this.init();

this.initialize();
}

@Override
public void authenticate(final String nwToken) {
this.token = nwToken;
}

@Override
protected JComponent createCenterPanel() {
return this.rootPanel;
}

/**
* Initializes the UI.
*/
private void initialize() {
// Configure the browser panel.
this.browserPanel.setContentType(CONTENT_TYPE);
this.browserPanel.setEditable(false);

// Add the browser panel.
this.rootPanel.add(
ScrollPaneFactory.createScrollPane(this.browserPanel),
CARD_PAGE
);

// Add the loading panel.
final JPanel loadingPanel = new JPanel(new BorderLayout());
loadingPanel.add(this.loadingIcon, BorderLayout.CENTER);
this.rootPanel.add(loadingPanel, CARD_LOADING);
}

/**
* Loads the given url in the browser window.
*
* @param url the url to load
*/
public void loadUrl(final String url) {
try {
this.browserPanel.setPage(url);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2018-2019. All rights reserved.
*
* @author Pieter De Clercq
* @author Tobiah Lissens
*
* https://github.com/thepieterdc/dodona-plugin-jetbrains/
*/

/**
* Browser component.
*/
@ParametersAreNonnullByDefault
package io.github.thepieterdc.dodona.plugin.ui.browser;

import javax.annotation.ParametersAreNonnullByDefault;
2 changes: 2 additions & 0 deletions src/main/resources/messages/Dodona.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ toolwindow.deadlines.none=No upcoming deadlines
toolwindow.deadlines.title=Deadlines
tasks.select_exercise.progress.identify=Awaiting exercise selection...
tasks.select_exercise.title=Select an Exercise
tasks.show_submission.loading=Loading submission...
tasks.show_submission.title=Submission Result
tasks.submit_solution.evaluating=Awaiting evaluation...
tasks.submit_solution.submitting=Submitting solution...
tasks.submit_solution.title=Submit Solution
Expand Down

0 comments on commit 28f2806

Please sign in to comment.