mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-09 19:00:48 +00:00
Improved error message
This commit is contained in:
parent
2bbba50ddc
commit
cee2a964cc
@ -1,3 +1,12 @@
|
||||
#errorNotificationContent {
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
#additionalInfo {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#errorSummary {
|
||||
color: white;
|
||||
}
|
||||
|
3
frontend/styles/view/main/error-details.css
Normal file
3
frontend/styles/view/main/error-details.css
Normal file
@ -0,0 +1,3 @@
|
||||
[part="toggle"] {
|
||||
color: white;
|
||||
}
|
@ -2,37 +2,60 @@ package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.details.Details;
|
||||
import com.vaadin.flow.component.html.Paragraph;
|
||||
import com.vaadin.flow.component.html.Span;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.notification.NotificationVariant;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
|
||||
import edu.kit.typicalc.model.parser.ParseError;
|
||||
|
||||
/**
|
||||
* The notification being displayed on invalid input.
|
||||
*/
|
||||
@CssImport("./styles/view/error-notification.css")
|
||||
@CssImport(value = "./styles/view/main/error-details.css", themeFor = "vaadin-details")
|
||||
public class ErrorNotification extends Notification {
|
||||
|
||||
private static final long serialVersionUID = 239587L;
|
||||
|
||||
private static final String NOTIFICATION_ID = "errorNotification";
|
||||
private static final String NOTIFICATION_CONTENT_ID = "errorNotificationContent";
|
||||
private static final String ADDITIONAL_INFO_ID = "additionalInfo";
|
||||
private static final String ERROR_SUMMARY_ID = "errorSummary";
|
||||
|
||||
/**
|
||||
* Creates a new ErrorNotification with a specific error message.
|
||||
* Creates a new ErrorNotification with a specific error.
|
||||
*
|
||||
* @param errorMessage the error message
|
||||
* @param error the error
|
||||
*/
|
||||
protected ErrorNotification(String errorMessage) {
|
||||
protected ErrorNotification(ParseError error) {
|
||||
VerticalLayout container = new VerticalLayout();
|
||||
container.setId(NOTIFICATION_CONTENT_ID);
|
||||
Span errorSpan = new Span(errorMessage);
|
||||
Button closeButton = new Button(getTranslation("root.close"), event -> this.close());
|
||||
|
||||
container.add(errorSpan, closeButton);
|
||||
container.add(buildErrorMessage(error), closeButton);
|
||||
addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||
add(container);
|
||||
setPosition(Position.MIDDLE);
|
||||
setId(NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
private Details buildErrorMessage(ParseError error) {
|
||||
VerticalLayout additionalInformation = new VerticalLayout();
|
||||
additionalInformation.setId(ADDITIONAL_INFO_ID);
|
||||
Paragraph summary = new Paragraph(getTranslation("root." + error.toString()));
|
||||
summary.setId(ERROR_SUMMARY_ID);
|
||||
Details generalInformation = new Details(summary, additionalInformation);
|
||||
|
||||
if (error == ParseError.TOO_FEW_TOKENS) {
|
||||
additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp")));
|
||||
} else {
|
||||
additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + error.getCause().getText()));
|
||||
additionalInformation.add(new Span(getTranslation("root.position") + error.getCause().getPos()));
|
||||
}
|
||||
|
||||
return generalInformation;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.vaadin.flow.component.dependency.JsModule;
|
||||
import com.vaadin.flow.component.dialog.Dialog;
|
||||
import com.vaadin.flow.component.icon.Icon;
|
||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.component.textfield.TextField;
|
||||
import com.vaadin.flow.i18n.LocaleChangeEvent;
|
||||
@ -58,7 +57,6 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField.setId(INPUT_FIELD_ID);
|
||||
inputField.setClearButtonVisible(true);
|
||||
inputField.setMaxLength(MAX_INPUT_LENGTH);
|
||||
// TODO: perhaps remove the error message? more than 1000 can't be entered now
|
||||
// attach a listener that replaces \ with λ
|
||||
// JavaScript is used because Vaadin does not have APIs for selectionStart/selectionEnd
|
||||
// and this will be much faster than a bunch of network round trips per character entered!
|
||||
@ -110,13 +108,8 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
private void onTypeInferButtonClick(Consumer<Pair<String, Map<String, String>>> callback) {
|
||||
String currentInput = inputField.getOptionalValue().orElse(StringUtils.EMPTY);
|
||||
|
||||
if (currentInput.length() <= MAX_INPUT_LENGTH) {
|
||||
UI.getCurrent().getPage().setTitle(getTranslation("root.typicalc") + " - " + currentInput);
|
||||
callback.accept(Pair.of(currentInput, typeAssumptionsArea.getTypeAssumptions()));
|
||||
} else {
|
||||
Notification errorNotification = new ErrorNotification(getTranslation("root.overlongInput"));
|
||||
errorNotification.open();
|
||||
}
|
||||
UI.getCurrent().getPage().setTitle(getTranslation("root.typicalc") + " - " + currentInput);
|
||||
callback.accept(Pair.of(currentInput, typeAssumptionsArea.getTypeAssumptions()));
|
||||
}
|
||||
|
||||
private void onTypeAssumptionsButton() {
|
||||
|
@ -60,8 +60,7 @@ public class MainViewImpl extends AppLayout
|
||||
|
||||
@Override
|
||||
public void displayError(ParseError error) {
|
||||
//TODO add error keys to bundle
|
||||
Notification errorNotification = new ErrorNotification(getTranslation("root." + error.toString()));
|
||||
Notification errorNotification = new ErrorNotification(error);
|
||||
errorNotification.open();
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,12 @@ root.helpShareButton=Durch Klicken des Teilen Knopfs öffnet sich ein Dialog, in
|
||||
Typherleitungsbaums des eingegebenen Terms und die benötigen Pakete zum Einbinden des LaTeX-Codes angezeigt werden. \
|
||||
Zusätzlich dazu enthält der Dialog einen Permalink zur aktuellen Seite, der sowohl den Term als auch die Typannahmen \
|
||||
kodiert.
|
||||
root.TOO_FEW_TOKENS=Falsche Eingabe! Der Term endet abrupt.
|
||||
root.tooFewTokensHelp=Überprüfen sie, ob alle Let-, Abs- und App-Terme über die nötigen Argumente verfügen.
|
||||
root.UNEXPECTED_TOKEN=Der Term entspricht nicht der im Info-Dialog spezifizierten Syntax!
|
||||
root.UNEXPECTED_CHARACTER=Der Term enhält ein Zeichen, welches an dieser Stelle nicht erlaubt ist!
|
||||
root.wrongCharacter=Falsches Zeichen: \u0020
|
||||
root.position=An Position: \u0020
|
||||
|
||||
root.absLetLatex=\
|
||||
\\begin{prooftree}\
|
||||
|
Loading…
Reference in New Issue
Block a user