dev-ui.model-component.js Maven / Gradle / Ivy
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 ModelComponent 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 = {
"_model": {state: true}
}
// Components callbacks
/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getModelInfo().then(jsonRpcResponse => {
this._model = {};
Object.keys(jsonRpcResponse.result).forEach(key => {
this._model[key] = {};
this._model[key].solutionClass = jsonRpcResponse.result[key].solutionClass;
this._model[key].entityInfoList = [];
jsonRpcResponse.result[key].entityClassList.forEach(entityClass => {
const entityInfo = {};
entityInfo.name = entityClass;
entityInfo.genuineVariableList = jsonRpcResponse.result[key].entityClassToGenuineVariableListMap[entityClass];
entityInfo.shadowVariableList = jsonRpcResponse.result[key].entityClassToShadowVariableListMap[entityClass];
this._model[key].entityInfoList.push(entityInfo);
});
});
});
}
/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
return html`${until(this._renderModel(), html`Loading model...`)}`;
}
// View / Templates
_renderModel() {
if (this._model) {
let model = this._model;
const keys = Object.keys(model);
if (keys.length === 1) {
return html`
Solution Class:
${model[keys[0]].solutionClass}
`;
} else {
let modelValues = [];
keys.sort().forEach(k => {
model[k].entityInfoList.forEach(e => {
modelValues.push({
name: k,
solutionClass: model[k].solutionClass,
entityClassName: e.name,
genuineVariableList: e.genuineVariableList,
shadowVariableList: e.shadowVariableList,
});
});
});
return html`
`;
}
}
}
_nameRenderer(entry) {
return html`
${entry.name}`;
}
_solutionClassNameRenderer(entry) {
return html`
${entry.solutionClass}`;
}
_cassNameRendererPerEntry(entry) {
return html`
${entry.entityClassName}`;
}
_genuineVariablesRendererPerEntry(entry) {
return html`
${entry.genuineVariableList.join(', ')}`;
}
_shadowVariablesRendererPerEntry(entry) {
return html`
${entry.shadowVariableList.join(', ')}`;
}
_entityClassNameRenderer(entityInfo) {
return html`
${entityInfo.name}`;
}
_genuineVariablesRenderer(entityInfo) {
return html`
${entityInfo.genuineVariableList.join(', ')}`;
}
_shadowVariablesRenderer(entityInfo) {
return html`
${entityInfo.shadowVariableList.join(', ')}`;
}
}
customElements.define('model-component', ModelComponent);