Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Migrate to new Quarkus Dev UI #284

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- ************************************************************************ -->
<version.ch.qos.logback>1.4.11</version.ch.qos.logback>
<version.org.apache.logging.log4j>2.20.0</version.org.apache.logging.log4j>
<version.io.quarkus>3.3.2</version.io.quarkus>
<version.io.quarkus>3.4.1</version.io.quarkus>
<version.org.apache.commons.math3>3.6.1</version.org.apache.commons.math3>
<version.org.apache.commons.text>1.10.0</version.org.apache.commons.text>
<version.org.apache.poi>5.2.3</version.org.apache.poi>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;

import ai.timefold.solver.core.api.domain.autodiscover.AutoDiscoverMemberType;
Expand Down Expand Up @@ -43,7 +44,9 @@
import ai.timefold.solver.quarkus.bean.UnavailableTimefoldBeanProvider;
import ai.timefold.solver.quarkus.config.TimefoldRuntimeConfig;
import ai.timefold.solver.quarkus.deployment.config.TimefoldBuildTimeConfig;
import ai.timefold.solver.quarkus.devui.TimefoldDevUIPropertiesSupplier;
import ai.timefold.solver.quarkus.devui.SolverConfigText;
import ai.timefold.solver.quarkus.devui.TimefoldDevUIPropertiesRPCService;
import ai.timefold.solver.quarkus.devui.TimefoldDevUIRecorder;
import ai.timefold.solver.quarkus.gizmo.TimefoldGizmoBeanFactory;

import org.jboss.jandex.AnnotationInstance;
Expand Down Expand Up @@ -76,11 +79,12 @@
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.gizmo.ClassOutput;
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.gizmo.ResultHandle;
Expand Down Expand Up @@ -148,20 +152,48 @@ DetermineIfNativeBuildItem ifNativeBuild() {
}

@BuildStep(onlyIf = IsDevelopment.class)
public DevConsoleRuntimeTemplateInfoBuildItem getSolverConfig(SolverConfigBuildItem solverConfigBuildItem,
CurateOutcomeBuildItem curateOutcomeBuildItem) {
@Record(STATIC_INIT)
public CardPageBuildItem registerDevUICard(
TimefoldDevUIRecorder devUIRecorder,
SolverConfigBuildItem solverConfigBuildItem,
BuildProducer<SyntheticBeanBuildItem> syntheticBeans) {
CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();
SolverConfig solverConfig = solverConfigBuildItem.getSolverConfig();
if (solverConfig != null) {
StringWriter effectiveSolverConfigWriter = new StringWriter();
SolverConfigIO solverConfigIO = new SolverConfigIO();
solverConfigIO.write(solverConfig, effectiveSolverConfigWriter);
return new DevConsoleRuntimeTemplateInfoBuildItem("solverConfigProperties",
new TimefoldDevUIPropertiesSupplier(effectiveSolverConfigWriter.toString()), this.getClass(),
curateOutcomeBuildItem);
syntheticBeans.produce(SyntheticBeanBuildItem.configure(SolverConfigText.class)
.scope(ApplicationScoped.class)
.supplier(devUIRecorder.solverConfigTextSupplier(effectiveSolverConfigWriter.toString()))
.done());
} else {
return new DevConsoleRuntimeTemplateInfoBuildItem("solverConfigProperties",
new TimefoldDevUIPropertiesSupplier(), this.getClass(), curateOutcomeBuildItem);
syntheticBeans.produce(SyntheticBeanBuildItem.configure(SolverConfigText.class)
.scope(ApplicationScoped.class)
.supplier(devUIRecorder.solverConfigTextSupplier(""))
.done());
}
cardPageBuildItem.addPage(Page.webComponentPageBuilder()
.title("Configuration")
.icon("font-awesome-solid:wrench")
.componentLink("config-component.js"));

cardPageBuildItem.addPage(Page.webComponentPageBuilder()
.title("Model")
.icon("font-awesome-solid:wrench")
.componentLink("model-component.js"));

cardPageBuildItem.addPage(Page.webComponentPageBuilder()
.title("Constraints")
.icon("font-awesome-solid:wrench")
.componentLink("constraints-component.js"));

return cardPageBuildItem;
}

@BuildStep(onlyIf = IsDevelopment.class)
public JsonRPCProvidersBuildItem registerRPCService() {
return new JsonRPCProvidersBuildItem("Timefold Solver", TimefoldDevUIPropertiesRPCService.class);
}

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {css, html, LitElement} from 'lit';
import {JsonRpc} from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import {until} from 'lit/directives/until.js';
import '@vaadin/grid';
import '@vaadin/grid/vaadin-grid-sort-column.js';

export class ConfigComponent extends LitElement {

jsonRpc = new JsonRpc("Timefold Solver");

// Component style
static styles = css`
.button {
background-color: transparent;
cursor: pointer;
}

.clearIcon {
color: orange;
}
`;

// Component properties
static properties = {
"_config": {state: true}
}

// Components callbacks

/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getConfig().then(jsonRpcResponse => {
this._config = jsonRpcResponse.result.config;
});
}

/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
return html`${until(this._renderConfig(), html`<span>Loading config...</span>`)}`;
}

// View / Templates

_renderConfig() {
if (this._config) {
let config = this._config;
return html`
<pre>${config}</pre>`;
}
}
}

customElements.define('config-component', ConfigComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {css, html, LitElement} from 'lit';
import {JsonRpc} from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import {until} from 'lit/directives/until.js';
import '@vaadin/grid';
import {columnBodyRenderer} from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

export class ConstraintsComponent extends LitElement {

jsonRpc = new JsonRpc("Timefold Solver");

// Component style
static styles = css`
.button {
background-color: transparent;
cursor: pointer;
}

.clearIcon {
color: orange;
}
`;

// Component properties
static properties = {
"_constraints": {state: true}
}

// Components callbacks

/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getConstraints().then(jsonRpcResponse => {
this._constraints = [];
jsonRpcResponse.result.forEach(c => {
this._constraints.push(c);
});
});
}

/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
return html`${until(this._renderConstraintTable(), html`<span>Loading constraints...</span>`)}`;
}

// View / Templates

_renderConstraintTable() {
if (this._constraints) {
let constraints = this._constraints;
return html`
<vaadin-grid .items="${constraints}" class="datatable" theme="no-border">
<vaadin-grid-column auto-width
header="Name"
${columnBodyRenderer(this._nameRenderer, [])}>
</vaadin-grid-column>
</vaadin-grid>`;
}
}

_nameRenderer(constraint) {
return html`
${constraint}`;
}

}

customElements.define('constraints-component', ConstraintsComponent);
Loading