mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
set URL when inferring type
This commit is contained in:
parent
02f10158d6
commit
cc400fc314
@ -13,6 +13,7 @@ import edu.kit.typicalc.model.parser.ParseError;
|
|||||||
import edu.kit.typicalc.presenter.Presenter;
|
import edu.kit.typicalc.presenter.Presenter;
|
||||||
import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
||||||
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -35,14 +36,13 @@ public class MainViewImpl extends AppLayout implements MainView, HasErrorParamet
|
|||||||
|
|
||||||
private final UpperBar upperBar;
|
private final UpperBar upperBar;
|
||||||
|
|
||||||
private String termToType = "x"; //todo replace with real value
|
|
||||||
/**
|
/**
|
||||||
* Creates a new MainViewImpl.
|
* Creates a new MainViewImpl.
|
||||||
*/
|
*/
|
||||||
public MainViewImpl() {
|
public MainViewImpl() {
|
||||||
setDrawerOpened(false);
|
setDrawerOpened(false);
|
||||||
MainViewListener presenter = new Presenter(new ModelImpl(), this);
|
MainViewListener presenter = new Presenter(new ModelImpl(), this);
|
||||||
upperBar = new UpperBar(presenter, this::setContent);
|
upperBar = new UpperBar(presenter, this::setContent, this::setTermInURL);
|
||||||
addToNavbar(upperBar);
|
addToNavbar(upperBar);
|
||||||
addToDrawer(new DrawerContent());
|
addToDrawer(new DrawerContent());
|
||||||
}
|
}
|
||||||
@ -50,7 +50,6 @@ public class MainViewImpl extends AppLayout implements MainView, HasErrorParamet
|
|||||||
@Override
|
@Override
|
||||||
public void setTypeInferenceView(final TypeInfererInterface typeInferer) {
|
public void setTypeInferenceView(final TypeInfererInterface typeInferer) {
|
||||||
TypeInferenceView tiv = new TypeInferenceView(typeInferer);
|
TypeInferenceView tiv = new TypeInferenceView(typeInferer);
|
||||||
UI.getCurrent().getPage().getHistory().replaceState(null, new Location(ROUTE + SLASH + termToType));
|
|
||||||
setContent(tiv);
|
setContent(tiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +69,20 @@ public class MainViewImpl extends AppLayout implements MainView, HasErrorParamet
|
|||||||
List<String> segments = event.getLocation().getSegments();
|
List<String> segments = event.getLocation().getSegments();
|
||||||
String term = segments.get(segments.size() - 1);
|
String term = segments.get(segments.size() - 1);
|
||||||
upperBar.inferTerm(decodeURL(term));
|
upperBar.inferTerm(decodeURL(term));
|
||||||
return HttpServletResponse.SC_OK;
|
} else if (event.getLocation().getPath().equals(ROUTE)) {
|
||||||
|
setContent(new StartPageView());
|
||||||
|
upperBar.inferTerm(StringUtils.EMPTY);
|
||||||
} else if (event.getLocation().getPath().equals("")) {
|
} else if (event.getLocation().getPath().equals("")) {
|
||||||
setContent(new StartPageView());
|
setContent(new StartPageView());
|
||||||
return HttpServletResponse.SC_OK;
|
|
||||||
} else {
|
} else {
|
||||||
setContent(new NotFoundView(event));
|
setContent(new NotFoundView());
|
||||||
return HttpServletResponse.SC_NOT_FOUND;
|
return HttpServletResponse.SC_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
return HttpServletResponse.SC_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTermInURL(String lambdaTerm) {
|
||||||
|
UI.getCurrent().getPage().getHistory().replaceState(null, new Location(ROUTE + SLASH + lambdaTerm));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String decodeURL(String encodedUrl) {
|
private String decodeURL(String encodedUrl) {
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package edu.kit.typicalc.view.main;
|
package edu.kit.typicalc.view.main;
|
||||||
|
|
||||||
import com.vaadin.flow.component.html.Label;
|
import com.vaadin.flow.component.html.H1;
|
||||||
|
import com.vaadin.flow.component.html.H2;
|
||||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||||
import com.vaadin.flow.router.BeforeEnterEvent;
|
|
||||||
import com.vaadin.flow.router.ParentLayout;
|
import com.vaadin.flow.router.ParentLayout;
|
||||||
|
|
||||||
@ParentLayout(MainViewImpl.class)
|
@ParentLayout(MainViewImpl.class)
|
||||||
public class NotFoundView extends VerticalLayout {
|
public class NotFoundView extends VerticalLayout {
|
||||||
|
|
||||||
|
|
||||||
public NotFoundView(BeforeEnterEvent event) {
|
public NotFoundView() {
|
||||||
Label error = new Label(event.getLocation().getPath());
|
H1 error404 = new H1("404 - Not found");
|
||||||
add(error);
|
H2 suggestion = new H2("Try \"/infer/<term>\" or type your favourite term into the input field");
|
||||||
|
add(error404, suggestion); // todo make beautiful
|
||||||
setAlignItems(Alignment.CENTER);
|
setAlignItems(Alignment.CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ import com.vaadin.flow.component.html.H1;
|
|||||||
import com.vaadin.flow.component.icon.Icon;
|
import com.vaadin.flow.component.icon.Icon;
|
||||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
|
import com.vaadin.flow.router.Location;
|
||||||
import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
||||||
import edu.kit.typicalc.view.main.MainView.MainViewListener;
|
import edu.kit.typicalc.view.main.MainView.MainViewListener;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -40,16 +41,21 @@ public class UpperBar extends HorizontalLayout {
|
|||||||
|
|
||||||
private final transient MainViewListener presenter;
|
private final transient MainViewListener presenter;
|
||||||
private final transient Consumer<Component> setContent;
|
private final transient Consumer<Component> setContent;
|
||||||
|
private final transient Consumer<String> setTermInURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new UpperBar with the provided mainViewListener.
|
* Initializes a new UpperBar with the provided mainViewListener.
|
||||||
*
|
*
|
||||||
* @param presenter the listener used to communicate with the model
|
* @param presenter the listener used to communicate with the model
|
||||||
* @param setContent function to set the content of the application
|
* @param setContent function to set the content of the application
|
||||||
|
* @param setTermInURL function to set the term into the URL
|
||||||
*/
|
*/
|
||||||
protected UpperBar(final MainViewListener presenter, final Consumer<Component> setContent) {
|
protected UpperBar(final MainViewListener presenter, final Consumer<Component> setContent,
|
||||||
|
final Consumer<String> setTermInURL) {
|
||||||
|
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
this.setContent = setContent;
|
this.setContent = setContent;
|
||||||
|
this.setTermInURL = setTermInURL;
|
||||||
|
|
||||||
this.viewTitle = new H1(getTranslation("root.typicalc"));
|
this.viewTitle = new H1(getTranslation("root.typicalc"));
|
||||||
viewTitle.addClickListener(event -> routeToStartPage());
|
viewTitle.addClickListener(event -> routeToStartPage());
|
||||||
@ -74,17 +80,18 @@ public class UpperBar extends HorizontalLayout {
|
|||||||
* @param lambdaString the lambda term to be type-inferred
|
* @param lambdaString the lambda term to be type-inferred
|
||||||
*/
|
*/
|
||||||
protected void typeInfer(final String lambdaString) {
|
protected void typeInfer(final String lambdaString) {
|
||||||
inputBar.reset(); //TODO should term remain in input field?
|
// inputBar.reset(); //TODO should term remain in input field?
|
||||||
|
setTermInURL.accept(lambdaString);
|
||||||
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
|
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
|
||||||
if (lambdaString.equals(StringUtils.EMPTY)) {
|
// todo ich finde es ohne Wechsel auf Startseite besser, man bekommt ja schon ne Warnung
|
||||||
routeToStartPage();
|
// if (lambdaString.equals(StringUtils.EMPTY)) {
|
||||||
}
|
// routeToStartPage();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void routeToStartPage() {
|
private void routeToStartPage() {
|
||||||
setContent.accept(new StartPageView());
|
setContent.accept(new StartPageView());
|
||||||
UI.getCurrent().getPage().getHistory().replaceState(null, StringUtils.EMPTY);
|
UI.getCurrent().getPage().getHistory().replaceState(null, new Location(StringUtils.EMPTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onHelpIconClick() {
|
private void onHelpIconClick() {
|
||||||
|
Loading…
Reference in New Issue
Block a user