Skip to content

Commit

Permalink
Add link to submission's web page in successful result view
Browse files Browse the repository at this point in the history
  • Loading branch information
Redande committed Nov 15, 2018
1 parent dfa7dbd commit 3b3abfb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void showSubmissionButton(URI showSubmissionUrl) {
if (showSubmissionUrl == null) {
return;
}
showSubmissionButton.setAction(new AbstractAction("Show submission in browser") {
showSubmissionButton.setAction(new AbstractAction("View submission in browser") {
@Override
public void actionPerformed(ActionEvent ae) {
try {
Expand Down
109 changes: 71 additions & 38 deletions tmc-plugin/src/fi/helsinki/cs/tmc/ui/SuccessfulSubmissionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import fi.helsinki.cs.tmc.core.domain.Exercise;
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;

import java.awt.Component;

import fi.helsinki.cs.tmc.core.domain.submission.FeedbackAnswer;
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackQuestion;
import fi.helsinki.cs.tmc.ui.feedback.FeedbackQuestionPanel;
import fi.helsinki.cs.tmc.ui.feedback.FeedbackQuestionPanelFactory;

import com.google.common.base.Optional;

import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -25,28 +27,31 @@
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openide.awt.HtmlBrowser;

import static fi.helsinki.cs.tmc.ui.Boxer.*;
import static fi.helsinki.cs.tmc.ui.Boxer.hbox;
import static fi.helsinki.cs.tmc.ui.Boxer.hglue;

public class SuccessfulSubmissionDialog extends JDialog {

private static final Logger log = Logger.getLogger(SuccessfulSubmissionDialog.class.getName());

private JButton okButton;

private JButton showSubmissionButton;

private List<FeedbackQuestionPanel> feedbackQuestionPanels;

public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result) {
this.setTitle(exercise.getName() + " passed");

JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
setContentPane(contentPane);

addYayLabel();
addVSpace(6);
if (exercise.requiresReview() && !result.getMissingReviewPoints().isEmpty()) {
Expand All @@ -59,17 +64,17 @@ public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result) {
addVSpace(20);
addFeedbackQuestions(result); //TODO: maybe put in box
addVSpace(10);
addOkButton();
addButtons(result);

pack();
}

public void addOkListener(ActionListener okListener) {
this.okButton.addActionListener(okListener);
}

public List<FeedbackAnswer> getFeedbackAnswers() {
List<FeedbackAnswer> answers = new ArrayList<FeedbackAnswer>();
List<FeedbackAnswer> answers = new ArrayList<>();
for (FeedbackQuestionPanel panel : feedbackQuestionPanels) {
FeedbackAnswer answer = panel.getAnswer();
if (answer != null) {
Expand All @@ -78,42 +83,42 @@ public List<FeedbackAnswer> getFeedbackAnswers() {
}
return answers;
}

private void addVSpace(int height) {
add(Box.createVerticalStrut(height));
}

private Box leftAligned(Component component) {
return hbox(component, hglue());
}

private void addYayLabel() {
JLabel yayLabel = new JLabel("All tests passed on the server.");

Font font = yayLabel.getFont();
font = font.deriveFont(Font.BOLD, font.getSize2D() * 1.2f);
yayLabel.setFont(font);

yayLabel.setForeground(new java.awt.Color(0, 153, 51));
yayLabel.setIcon(ConvenientDialogDisplayer.getDefault().getSmileyIcon());

getContentPane().add(leftAligned(yayLabel));
}

private void addRequiresReviewLabels() {
JLabel lbl1 = new JLabel("This exercise requires a code review.");
JLabel lbl2 = new JLabel("It will have a yellow marker until it's accepted by an instructor.");
getContentPane().add(leftAligned(lbl1));
getContentPane().add(leftAligned(lbl2));
}

private void addPointsLabel(SubmissionResult result) {
JLabel pointsLabel = new JLabel(getPointsMsg(result));
pointsLabel.setFont(pointsLabel.getFont().deriveFont(Font.BOLD));

getContentPane().add(leftAligned(pointsLabel));
}

private String getPointsMsg(SubmissionResult result) {
if (!result.getPoints().isEmpty()) {
String msg = "Points permanently awarded: " + StringUtils.join(result.getPoints(), ", ") + ".";
Expand All @@ -131,19 +136,19 @@ private void addModelSolutionButton(SubmissionResult result) {
public void actionPerformed(ActionEvent ev) {
try {
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL(solutionUrl));
} catch (Exception ex) {
} catch (MalformedURLException ex) {
ConvenientDialogDisplayer.getDefault().displayError("Failed to open browser.\n" + ex.getMessage());
}
}
});

getContentPane().add(leftAligned(solutionButton));
}
}

private void addFeedbackQuestions(SubmissionResult result) {
this.feedbackQuestionPanels = new ArrayList<FeedbackQuestionPanel>();
this.feedbackQuestionPanels = new ArrayList<>();

if (!result.getFeedbackQuestions().isEmpty() && result.getFeedbackAnswerUrl() != null) {
for (FeedbackQuestion question : result.getFeedbackQuestions()) {
try {
Expand All @@ -153,12 +158,12 @@ private void addFeedbackQuestions(SubmissionResult result) {
log.warning(e.getMessage());
}
}

if (!feedbackQuestionPanels.isEmpty()) { // Some failsafety
JLabel feedbackLabel = new JLabel("Feedback (leave empty to not send)");
feedbackLabel.setFont(feedbackLabel.getFont().deriveFont(Font.BOLD));
getContentPane().add(leftAligned(feedbackLabel));

for (FeedbackQuestionPanel panel : feedbackQuestionPanels) {
getContentPane().add(leftAligned(panel));
}
Expand All @@ -167,17 +172,45 @@ private void addFeedbackQuestions(SubmissionResult result) {
}
}
}

private void addOkButton() {

private void addButtons(SubmissionResult result) {
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

Optional<URI> submissionUrl = Optional.absent();
final String submissionUrlString = result.getSubmissionUrl();
if (submissionUrlString != null && !submissionUrlString.isEmpty()) {
submissionUrl = Optional.of(URI.create(submissionUrlString));
}
addShowSubmissionButton(buttonPane, submissionUrl);
addOkButton(buttonPane);
getContentPane().add(buttonPane);
}

private void addOkButton(JPanel buttonPane) {
okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
okButton.addActionListener((ActionEvent e) -> {
setVisible(false);
dispose();
});
buttonPane.add(hbox(hglue(), okButton));
}

private void addShowSubmissionButton(JPanel buttonPane, Optional<URI> submissionUrl) {
if (!submissionUrl.isPresent()) {
return;
}
showSubmissionButton = new JButton("View submission in browser");
showSubmissionButton.setAction(new AbstractAction("View submission in browser") {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
public void actionPerformed(ActionEvent ae) {
try {
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(submissionUrl.get().toURL());
} catch (MalformedURLException ex) {
ConvenientDialogDisplayer.getDefault().displayError("Failed to open browser.\n" + ex.getMessage());
}
}
});
getContentPane().add(hbox(hglue(), okButton));
buttonPane.add(showSubmissionButton);
}

}

0 comments on commit 3b3abfb

Please sign in to comment.