Skip to content

Commit

Permalink
Improved model tree, fixed #189
Browse files Browse the repository at this point in the history
  • Loading branch information
hvarg committed Dec 11, 2019
1 parent 953fadd commit 93c7659
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 107 deletions.
4 changes: 2 additions & 2 deletions src/screens/models/configure/new-setup.ts
Expand Up @@ -251,8 +251,8 @@ export class ModelsNewSetup extends connect(store)(PageViewElement) {
let notes = usageEl.value;

if (!name || !assignMe) {
if (!name) nameEl.setAttribute('invalid', true);
if (!assignMe) assignMeEl.setAttribute('invalid', true);
if (!name) nameEl.setAttribute('invalid', 'true');
if (!assignMe) assignMeEl.setAttribute('invalid', 'true');
this._scrollUp();
showNotification("formValuesIncompleteNotification", this.shadowRoot!);
return;
Expand Down
108 changes: 3 additions & 105 deletions src/screens/models/models-configure.ts
Expand Up @@ -13,6 +13,7 @@ import './configure/configuration';
import './configure/setup';
import './configure/new-setup';
import './configure/parameter';
import './models-tree'

import { fetchIOAndVarsSNForConfig, fetchAuthorsForModelConfig, fetchParametersForConfig,
fetchMetadataNoioForModelConfig, addParameters, addCalibration, addMetadata,
Expand Down Expand Up @@ -236,116 +237,13 @@ export class ModelsConfigure extends connect(store)(PageViewElement) {
];
}

_getId (resource) {
return resource.id.split('/').pop();
}

_createUrl (model, version?, config?, setup?) {
let url = 'models/configure/' + this._getId(model);
if (version) {
url += '/' + this._getId(version);
if (config) {
url += '/' + this._getId(config);
if (setup) {
url += '/' + this._getId(setup);
}
}
}
return url;
}

_select (model, version, config, setup?) {
goToPage(this._createUrl(model, version, config, setup));
}

_selectNew (model, version, config?) {
goToPage(this._createUrl(model, version, config) + '/new');
}

_renderVersionTree () {
if (!this._models || !this._region || !this._regions)
return html`<div style="width:100%; text-align: center;"><wl-progress-spinner></wl-progress-spinner></div>`;

if (this._region && this._region.model_catalog_uri === 'https://w3id.org/okn/i/mint/Texas')
this._region.model_catalog_uri = 'https://w3id.org/okn/i/mint/United_States';

const visibleSetup = (setup) => setup && (
!setup.hasRegion || setup.hasRegion.length === 0 ||
(this._region && !this._region.model_catalog_uri) ||
setup.hasRegion.filter((r:any) => r.id === this._region.model_catalog_uri).length > 0 ||
setup.hasRegion.filter((r:any) =>
this._regions[r.id] &&
this._regions[r.id].country &&
this._regions[r.id].country.length > 0 &&
this._regions[r.id].country[0].id === this._region.model_catalog_uri
).length > 0
);

return html`
<ul>
${Object.values(this._models).filter((model: any) => !!model.hasVersion).map((model: any) => html`
<li>
${model.label}
${!this._versions ? html`<loading-dots style="--width: 20px"></loading-dots>` : html`
<ul>
${model.hasVersion.filter(v => !!this._versions[v.id]).map((v) => this._versions[v.id]).map((version) => html`
<li>
${version.label ? version.label : version.id.split('/').pop()}
${!this._configs ? html`<loading-dots style="--width: 20px"></loading-dots>` : html`
<ul>
${(version.hasConfiguration || []).filter(c => !!c.id).map((c) => this._configs[c.id]).map((config) => html`
<li>
<a @click="${()=>{this._select(model, version, config)}}">
${config ? config.label : 'ERR: no-config-label'}
</a>
<ul>
${((config ? config.hasSetup : []) || []).map((s) => this._configs[s.id])
.filter(visibleSetup)
.map(setup => html`
<li>
<a @click="${()=>{this._select(model, version, config, setup)}}">
${setup ? setup.label : html`ERR: no-setup-label
${console.log(setup)}
`}
</a>
</li>
`)}
<li>
<a class="inline-new-button" @click="${()=>{this._selectNew(model, version, config)}}">
<wl-icon>add_circle_outline</wl-icon>
Add new setup
</a>
</li>
</ul>
</li>
`)}
<!--li>
<a class="inline-new-button" @click="">
<wl-icon>add_circle_outline</wl-icon>
Add new configuration
</a>
</li-->
</ul>`}
</li>`)}
</ul>
`}
</li>
`)}
</ul>`;
}
//${()=>{this._selectNew(model, version)}}

protected render() {
return html`
<div class="twocolumns">
<div class="${this._hideModels ? 'left_closed' : 'left'}">
<div class="clt">
<div class="cltrow_padded">
<div class="cltmain">
<wl-title level="4" style="margin: 0px">Models:</wl-title>
</div>
</div>
${this._renderVersionTree()}
<wl-title level="4" style="margin: 4px; padding: 10px;">Models:</wl-title>
<models-tree active></models-tree>
</div>
</div>
Expand Down
258 changes: 258 additions & 0 deletions src/screens/models/models-tree.ts
@@ -0,0 +1,258 @@
import { property, html, customElement, css } from 'lit-element';
import { PageViewElement } from '../../components/page-view-element';

import { SharedStyles } from '../../styles/shared-styles';
import { store, RootState } from '../../app/store';
import { connect } from 'pwa-helpers/connect-mixin';
import { goToPage } from '../../app/actions';
import { ExplorerStyles } from './model-explore/explorer-styles'

import { IdMap } from 'app/reducers';

//import { ModelConfiguration, SoftwareVersion, Model, Region } from '@mintproject/modelcatalog_client';

import './configure/configuration';
import './configure/setup';
import './configure/new-setup';
import './configure/parameter';

//import { } from '../../util/model-catalog-actions';

import "weightless/progress-spinner";
import '../../components/loading-dots'

@customElement('models-tree')
export class ModelsTree extends connect(store)(PageViewElement) {
@property({type: Object})
private _regions : any = null;

@property({type: Object})
private _models : any = null;

@property({type: Object})
private _versions : any = null;

@property({type: Object})
private _configs : any = null;

@property({type: Object})
private _visible : IdMap<boolean> = {};

@property({type: String})
private _selectedModel : string = '';

@property({type: String})
private _selectedVersion : string = '';

@property({type: String})
private _selectedConfig : string = '';

@property({type: String})
private _selectedSetup : string = '';

@property({type: Boolean})
private _creating : boolean = false;

static get styles() {
return [ExplorerStyles,
css `
.inline-new-button {
line-height: 1.2em;
font-size: 1.2em;
}
.inline-new-button > wl-icon {
--icon-size: 1.2em;
vertical-align: top;
}
ul {
padding-left: 20px;
font-size: 13px;
}
li {
list-style-type: none;
font-size: 13px;
}
li > a {
cursor: pointer;
}
.ta-right {
text-align: right;
}
span[selected], a[selected] {
font-weight: 900;
font-size: 14px;
}
span {
cursor: pointer;
}
`,
SharedStyles
];
}

_getId (resource) {
return resource.id.split('/').pop();
}

_createUrl (model, version?, config?, setup?) {
let url = 'models/configure/' + this._getId(model);
if (version) {
url += '/' + this._getId(version);
if (config) {
url += '/' + this._getId(config);
if (setup) {
url += '/' + this._getId(setup);
}
}
}
return url;
}

_select (model, version, config, setup?) {
goToPage(this._createUrl(model, version, config, setup));
}

_selectNew (model, version, config?) {
goToPage(this._createUrl(model, version, config) + '/new');
}

protected render() {
if (!this._models || !this._region || !this._regions)
return html`<div style="width:100%; text-align: center;"><wl-progress-spinner></wl-progress-spinner></div>`;

if (this._region && this._region.model_catalog_uri === 'https://w3id.org/okn/i/mint/Texas')
this._region.model_catalog_uri = 'https://w3id.org/okn/i/mint/United_States';

const visibleSetup = (setup) => setup && (
!setup.hasRegion || setup.hasRegion.length === 0 ||
(this._region && !this._region.model_catalog_uri) ||
setup.hasRegion.filter((r:any) => r.id === this._region.model_catalog_uri).length > 0 ||
setup.hasRegion.filter((r:any) =>
this._regions[r.id] &&
this._regions[r.id].country &&
this._regions[r.id].country.length > 0 &&
this._regions[r.id].country[0].id === this._region.model_catalog_uri
).length > 0
);

return html`
<ul style="padding-left: 10px; margin-top: 4px;">
${Object.values(this._models).filter((model: any) => !!model.hasVersion).map((model: any) => html`
<li>
<span @click="${() => {
this._visible[model.id] = !this._visible[model.id];
this.requestUpdate();
}}">
<wl-icon>${this._visible[model.id] ? 'expand_more' : 'expand_less'}</wl-icon>
<span ?selected="${this._selectedModel === model.id}" style="vertical-align: top;">
${model.label}
</span>
</span>
${this._visible[model.id] ? html`
${!this._versions ? html`<loading-dots style="--width: 20px"></loading-dots>` : html`
<ul>
${model.hasVersion.filter(v => !!this._versions[v.id]).map((v) => this._versions[v.id]).map((version) => html`
<li>
<span @click=${() => {
this._visible[version.id] = !this._visible[version.id];
this.requestUpdate();
}}>
<wl-icon>${this._visible[version.id] ? 'expand_more' : 'expand_less'}</wl-icon>
<span ?selected="${this._selectedVersion === version.id}" style="vertical-align: top;">
${version.label ? version.label : version.id.split('/').pop()}
</span>
</span>
${this._visible[version.id] ? html`
${!this._configs ? html`<loading-dots style="--width: 20px"></loading-dots>` : html`
<ul style="padding-left: 30px;">
${(version.hasConfiguration || []).filter(c => !!c.id).map((c) => this._configs[c.id]).map((config) => html`
<li>
<a @click="${()=>{this._select(model, version, config)}}" ?selected="${this._selectedConfig === config.id}">
${config ? config.label : config.id.split('/').pop()}
</a>
<ul>
${((config ? config.hasSetup : []) || []).map((s) => this._configs[s.id])
.filter(visibleSetup)
.map(setup => html`
<li>
<a @click="${()=>{this._select(model, version, config, setup)}}" ?selected="${this._selectedSetup === setup.id}">
${setup ? setup.label : setup.id.split('/').pop()}
</a>
</li>
`)}
<li>
<a class="inline-new-button" @click="${()=>{this._selectNew(model, version, config)}}">
<wl-icon>add_circle_outline</wl-icon>
<span ?selected="${this._creating && this._selectedConfig === config.id}">
Add new setup
</span>
</a>
</li>
</ul>
</li>
`)}
<!--li>
<a class="inline-new-button" @click="">
<wl-icon>add_circle_outline</wl-icon>
Add new configuration
</a>
</li-->
</ul>`}
` : ''}
</li>`)}
</ul>
`}
` : ''}
</li>
`)}
</ul>`;
}

firstUpdated () {
/*Everything is loaded*/
}

stateChanged(state: RootState) {
if (state.explorerUI) {
let ui = state.explorerUI;
// check whats changed
let modelChanged : boolean = (ui.selectedModel !== this._selectedModel);
let versionChanged : boolean = (modelChanged || ui.selectedVersion !== this._selectedVersion)
let configChanged : boolean = (versionChanged || ui.selectedConfig !== this._selectedConfig);
let setupChanged : boolean = (configChanged || ui.selectedCalibration !== this._selectedSetup);
this._creating = (ui.mode === 'new');

super.setRegionId(state);

if (modelChanged) {
this._selectedModel = ui.selectedModel;
this._visible[this._selectedModel] = true;
}
if (versionChanged) {
this._selectedVersion = ui.selectedVersion;
this._visible[this._selectedVersion] = true;
}
if (configChanged) {
this._selectedConfig = ui.selectedConfig;
}
if (setupChanged) {
this._selectedSetup = ui.selectedCalibration;
}

if (state.modelCatalog) {
let db = state.modelCatalog;
this._models = db.models;
this._versions = db.versions;
this._configs = db.configurations;
this._regions = db.regions;
}
}
}
}

0 comments on commit 93c7659

Please sign in to comment.