mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-09 19:00:48 +00:00
make TypeInferenceView reload safe
This commit is contained in:
parent
88c64c30d3
commit
1a5625b6ad
@ -1,10 +1,7 @@
|
||||
import {MathjaxAdapter} from "./mathjax-adapter";
|
||||
import {TemplateResult} from "lit-html";
|
||||
import {html} from "lit-element";
|
||||
|
||||
class MathjaxUnification extends MathjaxAdapter {
|
||||
private content: String = "Loading...";
|
||||
private latex: String[] = [];
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
@ -13,21 +10,12 @@ class MathjaxUnification extends MathjaxAdapter {
|
||||
}
|
||||
|
||||
render(): TemplateResult {
|
||||
return html`<mjx-doc id="mjx-document"><mjx-head></mjx-head><mjx-body>
|
||||
<div id="tc-content">${this.content}</div>
|
||||
</mjx-body></mjx-doc>`;
|
||||
return super.render();
|
||||
}
|
||||
|
||||
protected showStep(n: number): void {
|
||||
this.content = this.latex[n];
|
||||
protected showStep(_n: number): void {
|
||||
this.requestTypeset();
|
||||
}
|
||||
|
||||
public setTex(tex: String): void {
|
||||
console.log(tex);
|
||||
this.latex.push(tex);
|
||||
console.log(this.latex)
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('tc-unification', MathjaxUnification);
|
@ -2,7 +2,9 @@ package edu.kit.typicalc.view.content.typeinferencecontent;
|
||||
|
||||
import com.vaadin.flow.component.Tag;
|
||||
import com.vaadin.flow.component.dependency.JsModule;
|
||||
import com.vaadin.flow.component.html.Div;
|
||||
import com.vaadin.flow.component.littemplate.LitTemplate;
|
||||
import com.vaadin.flow.component.template.Id;
|
||||
import edu.kit.typicalc.view.MathjaxAdapter;
|
||||
|
||||
/**
|
||||
@ -16,6 +18,9 @@ public class MathjaxUnification extends LitTemplate implements MathjaxAdapter {
|
||||
|
||||
private final String[] latex;
|
||||
|
||||
@Id("tc-content")
|
||||
private Div content;
|
||||
|
||||
/**
|
||||
* Creates a new HTML element that renders the constraints and unification and
|
||||
* calculates the steps.
|
||||
@ -23,9 +28,6 @@ public class MathjaxUnification extends LitTemplate implements MathjaxAdapter {
|
||||
*/
|
||||
public MathjaxUnification(String[] latex) {
|
||||
this.latex = latex;
|
||||
for (String s : latex) {
|
||||
getElement().callJsFunction("setTex", s);
|
||||
}
|
||||
showStep(0);
|
||||
}
|
||||
|
||||
@ -36,6 +38,10 @@ public class MathjaxUnification extends LitTemplate implements MathjaxAdapter {
|
||||
|
||||
@Override
|
||||
public void showStep(int n) {
|
||||
if (n < latex.length) {
|
||||
content.removeAll();
|
||||
content.add(latex[n]);
|
||||
}
|
||||
getElement().callJsFunction("showStep", n);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
package edu.kit.typicalc.view.content.typeinferencecontent;
|
||||
|
||||
import com.vaadin.flow.component.AttachEvent;
|
||||
import com.vaadin.flow.component.ComponentEventListener;
|
||||
import com.vaadin.flow.component.ComponentUtil;
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.html.Div;
|
||||
import com.vaadin.flow.component.orderedlayout.Scroller;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import com.vaadin.flow.router.PageTitle;
|
||||
import com.vaadin.flow.router.PreserveOnRefresh;
|
||||
import com.vaadin.flow.router.Route;
|
||||
import edu.kit.typicalc.model.TypeInfererInterface;
|
||||
import edu.kit.typicalc.view.content.ControlPanel;
|
||||
@ -14,8 +17,9 @@ import edu.kit.typicalc.view.main.MainViewImpl;
|
||||
|
||||
@Route(value = "visualize", layout = MainViewImpl.class)
|
||||
@PageTitle("TypeInferenceView")
|
||||
@PreserveOnRefresh
|
||||
public class TypeInferenceView extends VerticalLayout
|
||||
implements ControlPanelView {
|
||||
implements ControlPanelView, ComponentEventListener<AttachEvent> {
|
||||
|
||||
private int currentStep = 0;
|
||||
|
||||
@ -29,6 +33,7 @@ public class TypeInferenceView extends VerticalLayout
|
||||
typeInferer = ComponentUtil.getData(UI.getCurrent(), TypeInfererInterface.class);
|
||||
setId("type-inference-view");
|
||||
setSizeFull();
|
||||
addAttachListener(this);
|
||||
content = new Div();
|
||||
controlPanel = new ControlPanel(this);
|
||||
Scroller scroller = new Scroller(content);
|
||||
@ -80,4 +85,10 @@ public class TypeInferenceView extends VerticalLayout
|
||||
currentStep = currentStep > 0 ? currentStep - 1 : currentStep;
|
||||
refreshElements(currentStep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComponentEvent(AttachEvent attachEvent) {
|
||||
currentStep = 0;
|
||||
refreshElements(currentStep);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user