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

feat: stratified initials and parameter metadata on model page #3743

Merged
merged 68 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0f0a9e9
intial and param components for model page
shawnyama May 28, 2024
fcfb01c
rm old compoennt
shawnyama May 28, 2024
e7781a2
Merge branch 'main' into model-page-init-param-tables
shawnyama May 28, 2024
49a5ca9
Merge branch 'main' into model-page-init-param-tables
shawnyama May 28, 2024
626a3d1
saving behavior
shawnyama May 28, 2024
82c3b62
Merge branch 'model-page-init-param-tables' of https://github.com/DAR…
shawnyama May 28, 2024
1953103
integrate editing initial and param data
shawnyama May 29, 2024
67be9a3
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
ae3db1e
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
ab2480e
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
1db277d
pass emit properly
shawnyama May 29, 2024
06956c3
parameter units edit fix
shawnyama May 29, 2024
5bfaa20
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
728ac08
consistent key name
shawnyama May 29, 2024
820ce06
unit should be named units to keep things consistent
shawnyama May 29, 2024
a2666f1
get concept properly and yohann comments
shawnyama May 29, 2024
7aded6d
better imports
shawnyama May 29, 2024
43a6e5a
attempt to get concepts in, disabling input for now since it ruins th…
shawnyama May 29, 2024
e30f08b
comments
shawnyama May 29, 2024
3f1b784
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
fe9e03f
lodash
shawnyama May 29, 2024
27e3810
move emit function to script
shawnyama May 29, 2024
e9ca885
simplify divider
shawnyama May 29, 2024
dc6912d
Merge branch 'main' into model-page-init-param-tables
shawnyama May 29, 2024
b4ed79e
use grid
shawnyama May 30, 2024
399f964
use grid even better
shawnyama May 30, 2024
c4d6612
Merge branch 'main' into model-page-init-param-tables
shawnyama May 30, 2024
e0e2130
alignitems
shawnyama May 30, 2024
6e2a67f
Merge branch 'model-page-init-param-tables' of https://github.com/DAR…
shawnyama May 30, 2024
465ecce
base initial target can be given metadata and units and concept are s…
shawnyama May 30, 2024
021a78c
Merge branch 'main' into model-page-init-param-tables
shawnyama May 31, 2024
f27e620
improve unit edits, leave concept editing for another pr
shawnyama May 31, 2024
c27d78e
Merge branch 'model-page-init-param-tables' of https://github.com/DAR…
shawnyama May 31, 2024
5cc1f8b
Merge branch 'main' into model-page-init-param-tables
shawnyama May 31, 2024
7c8ee91
comment
shawnyama May 31, 2024
81a0f99
Merge branch 'model-page-init-param-tables' of https://github.com/DAR…
shawnyama May 31, 2024
9845af1
merge
shawnyama May 31, 2024
c281ced
pass mmt
shawnyama May 31, 2024
ad07c30
toggle base inits and params
shawnyama Jun 1, 2024
f552acd
merge
shawnyama Jun 1, 2024
d40b995
only create a base param if there is more than one stratified param
shawnyama Jun 1, 2024
4061904
param metadata is also editable
shawnyama Jun 1, 2024
8d5f499
hookup stratified matrix component
shawnyama Jun 3, 2024
ba7f314
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 3, 2024
b83cd21
pass prop
shawnyama Jun 3, 2024
192fcdf
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 3, 2024
6e72c66
no need for matrices for initials
shawnyama Jun 3, 2024
b9b50a3
readonly stratified matrix
shawnyama Jun 3, 2024
884207f
grid adjustments for toggle button
shawnyama Jun 3, 2024
d780923
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 3, 2024
b51385f
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 4, 2024
de8d889
update spacing
shawnyama Jun 4, 2024
6d53d3b
fix gap
shawnyama Jun 4, 2024
4c7444e
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 10, 2024
e86d3c8
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 11, 2024
a2d91c2
clean up parameter html
shawnyama Jun 11, 2024
4aa6bea
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 11, 2024
1a80a3b
comment
shawnyama Jun 11, 2024
91e948b
Merge branch 'model-page-stratified-init-param-entries' of https://gi…
shawnyama Jun 11, 2024
d415b68
s
shawnyama Jun 12, 2024
807c005
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 12, 2024
010845c
resolve conflicts
shawnyama Jun 12, 2024
bbcf95a
fix: Read states for intial metadata (#3830)
shawnyama Jun 14, 2024
bc0206a
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 14, 2024
a11b847
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 14, 2024
ccada20
rm old init and param tables
shawnyama Jun 14, 2024
17b47ed
Merge branch 'model-page-stratified-init-param-entries' of https://gi…
shawnyama Jun 14, 2024
eaa2f3c
Merge branch 'main' into model-page-stratified-init-param-entries
shawnyama Jun 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template #header>
<div class="flex align-items-center justify-space-between">
<h4 class="w-full">{{ id }} matrix</h4>
<div class="flex align-items-center gap-2 white-space-nowrap">
<div v-if="!isReadOnly" class="flex align-items-center gap-2 white-space-nowrap">
<label for="matrixShouldEval" class="mr-2">Evaluate expressions</label>
<InputSwitch
inputId="matrixShouldEval"
Expand All @@ -22,6 +22,7 @@
/>
</template>
<template #footer>
<!--FIXME: This design is odd, since these buttons do the same thing-->
<Button size="large" label="OK" @click="emit('close-modal')" />
<Button
size="large"
Expand All @@ -48,7 +49,7 @@ const props = defineProps<{
mmtParams: MiraTemplateParams;
id: string;
stratifiedMatrixType: StratifiedMatrix;
openValueConfig: boolean;
isReadOnly?: boolean;
}>();

const emit = defineEmits(['close-modal', 'update-cell-value']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,23 @@
@keyup.enter="onEnterValueCell(cell.content.id, rowIdx, colIdx)"
@click="onEnterValueCell(cell.content.id, rowIdx, colIdx)"
>
<template v-if="cell.content.id">
<section class="flex flex-column">
<InputText
v-if="editableCellStates[rowIdx][colIdx]"
class="cell-input"
:class="stratifiedMatrixType !== StratifiedMatrix.Initials && 'big-cell-input'"
v-model.lazy="valueToEdit"
v-focus
@focusout="updateCellValue(cell.content.id, rowIdx, colIdx)"
@keyup.stop.enter="updateCellValue(cell.content.id, rowIdx, colIdx)"
/>
<section v-if="cell.content.id" class="flex flex-column">
<InputText
v-if="editableCellStates[rowIdx][colIdx]"
class="cell-input"
:class="stratifiedMatrixType !== StratifiedMatrix.Initials && 'big-cell-input'"
v-model.lazy="valueToEdit"
v-focus
@focusout="updateCellValue(cell.content.id, rowIdx, colIdx)"
@keyup.stop.enter="updateCellValue(cell.content.id, rowIdx, colIdx)"
/>
<div class="w-full" :class="{ 'hide-content': editableCellStates[rowIdx][colIdx] }">
<div
class="w-full"
:class="{ 'hide-content': editableCellStates[rowIdx][colIdx] }"
class="subdue mb-1 flex align-items-center gap-1 w-full justify-content-between"
v-if="stratifiedMatrixType !== StratifiedMatrix.Initials"
>
<div
class="subdue mb-1 flex align-items-center gap-1 w-full justify-content-between"
v-if="stratifiedMatrixType !== StratifiedMatrix.Initials"
>
{{ cell?.content.id }}
<!--
{{ cell?.content.id }}
<!--
<span
v-if="cell?.content?.controllers"
class="pi pi-info-circle"
Expand All @@ -67,16 +63,14 @@
}"
/>
-->
</div>
<div>
<div
class="mathml-container"
v-html="expressionMap[rowIdx + ':' + colIdx] ?? '...'"
/>
</div>
</div>
</section>
</template>
<div
v-if="!isReadOnly"
class="mathml-container"
v-html="expressionMap[rowIdx + ':' + colIdx] ?? '...'"
/>
</div>
</section>
<span v-else class="subdue">n/a</span>
</td>
</tr>
Expand Down Expand Up @@ -108,6 +102,7 @@ const props = defineProps<{
mmtParams: MiraTemplateParams;
id: string;
stratifiedMatrixType: StratifiedMatrix;
isReadOnly?: boolean;
shouldEval: boolean;
}>();

Expand Down Expand Up @@ -144,7 +139,7 @@ const vFocus = {
};

function onEnterValueCell(variableName: string, rowIdx: number, colIdx: number) {
if (!variableName) return;
if (!variableName || props.isReadOnly) return;
valueToEdit.value = getVariable(props.mmt, variableName).value;
editableCellStates.value[rowIdx][colIdx] = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
:mmt="mmt"
:mmt-params="mmtParams"
:stratified-matrix-type="StratifiedMatrix.Rates"
:open-value-config="openValueConfig"
@close-modal="openValueConfig = false"
@update-configuration="
(configToUpdate: ModelConfiguration) => emit('update-configuration', configToUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
:mmt="mmt"
:mmt-params="mmtParams"
:stratified-matrix-type="StratifiedMatrix.Initials"
:open-value-config="!!matrixModalId"
@close-modal="matrixModalId = ''"
@update-cell-value="
emit('update-expression', { id: $event.variableName, value: $event.newValue })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
:mmt="mmt"
:mmt-params="mmtParams"
:stratified-matrix-type="StratifiedMatrix.Initials"
:open-value-config="matrixModalContext.isOpen"
@close-modal="matrixModalContext.isOpen = false"
@update-cell-value="(configToUpdate: any) => updateCellValue(configToUpdate)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
:mmt="mmt"
:mmt-params="mmtParams"
:stratified-matrix-type="StratifiedMatrix.Parameters"
:open-value-config="!!matrixModalId"
@close-modal="matrixModalId = ''"
@update-cell-value="
emit('update-parameters', [
Expand Down
shawnyama marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
:mmt="mmt"
:mmt-params="mmtParams"
:stratified-matrix-type="StratifiedMatrix.Parameters"
:open-value-config="matrixModalContext.isOpen"
@close-modal="matrixModalContext.isOpen = false"
@update-cell-value="(configToUpdate: any) => updateCellValue(configToUpdate)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Initial variables<span class="artifact-amount">({{ initialsLength }})</span>
</template>
<tera-initials-metadata
v-if="!isEmpty(mmt.initials)"
:model="model"
:mmt="mmt"
@update-initial-metadata="emit('update-initial-metadata', $event)"
/>
</AccordionTab>
Expand All @@ -14,7 +16,10 @@
Parameters<span class="artifact-amount">({{ parameters?.length }})</span>
</template>
<tera-parameters-metadata
v-if="!isEmpty(mmt.parameters)"
:model="model"
:mmt="mmt"
:mmt-params="mmtParams"
@update-parameter="emit('update-parameter', $event)"
/>
</AccordionTab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
</AccordionTab>
<AccordionTab header="Parameters">
<tera-parameters-metadata
v-if="!isEmpty(mmt.parameters)"
:model="model"
:mmt="mmt"
:mmt-params="mmtParams"
@update-parameter="emit('update-parameter', $event)"
/>
</AccordionTab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Initial variables<span class="artifact-amount">({{ initialsLength }})</span>
</template>
<tera-initials-metadata
v-if="!isEmpty(mmt.initials)"
:model="model"
:mmt="mmt"
@update-initial-metadata="emit('update-initial-metadata', $event)"
/>
</AccordionTab>
Expand All @@ -14,7 +16,10 @@
Parameters<span class="artifact-amount">({{ parametersLength }})</span>
</template>
<tera-parameters-metadata
v-if="!isEmpty(mmt.parameters)"
:model="model"
:mmt="mmt"
:mmt-params="mmtParams"
@update-parameter="emit('update-parameter', $event)"
/>
</AccordionTab>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<section>
<section :class="{ 'has-toggle': isBase, 'no-second-row': isStratified }">
<h6>{{ target }}</h6>
<tera-input
label="Name"
Expand All @@ -16,13 +16,22 @@
})
"
/>
<tera-input
label="Unit"
:model-value="getInitialUnits(model, target)"
@update:model-value="$emit('update-initial-metadata', { key: 'units', value: $event })"
/>
<!--TODO: Add support for editing concepts--->
<tera-input label="Concept" :model-value="getInitialConcept(model, target)" disabled />
<template v-if="!isStratified">
<Button
v-if="isBase"
:icon="showStratifiedVariables ? 'pi pi-chevron-down' : 'pi pi-chevron-right'"
text
rounded
@click="$emit('toggle-stratified-variables')"
/>
<tera-input
label="Unit"
:model-value="getInitialUnits(model, target)"
@update:model-value="$emit('update-initial-metadata', { key: 'units', value: $event })"
/>
<!--TODO: Add support for editing concepts-->
<tera-input label="Concept" :model-value="getInitialConcept(model, target)" disabled />
</template>
</section>
</template>

Expand All @@ -35,26 +44,47 @@ import {
getInitialConcept
} from '@/model-representation/service';
import TeraInput from '@/components/widgets/tera-input.vue';
import Button from 'primevue/button';

defineProps<{
model: Model;
target: string;
isBase?: boolean;
isStratified?: boolean;
showStratifiedVariables?: boolean;
}>();

defineEmits(['update-initial-metadata', 'toggle-stratified-variables', 'open-matrix']);
</script>

<style scoped>
section {
display: grid;
grid-template-areas:
'symbol name description description'
'unit unit concept .';
'unit unit concept .';
grid-template-columns: max-content 30% 30% auto;
gap: var(--gap-small);
align-items: center;
}

section.has-toggle {
grid-template-areas:
'symbol name description description'
'toggle unit concept .';
}

section.no-second-row {
gap: 0 var(--gap-small);
}

h6 {
grid-area: symbol;
justify-self: center;
}

button {
grid-area: toggle;
}

:deep([label='Name']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
<template>
<ul>
<ul v-if="isStratified">
<li v-for="([baseTarget, values], index) in collapsedInitials.entries()" :key="baseTarget">
<tera-initial-metadata-entry
:model="model"
:target="baseTarget"
is-base
:show-stratified-variables="toggleStates[index]"
@toggle-stratified-variables="toggleStates[index] = !toggleStates[index]"
@update-initial-metadata="updateBaseInitial(baseTarget, $event)"
/>
<ul v-if="toggleStates[index]" class="stratified">
<li v-for="target in values" :key="target">
<tera-initial-metadata-entry
:model="model"
:target="target"
is-stratified
@update-initial-metadata="$emit('update-initial-metadata', { target, ...$event })"
/>
</li>
</ul>
</li>
</ul>
<ul v-else>
<li v-for="{ target } in initials" :key="target">
<tera-initial-metadata-entry
:model="model"
Expand All @@ -11,22 +33,51 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Model } from '@/types/Types';
import { MiraModel } from '@/model-representation/mira/mira-common';
import { getInitials } from '@/model-representation/service';
import { collapseInitials, isStratifiedModel } from '@/model-representation/mira/mira';
import TeraInitialMetadataEntry from '@/components/model/tera-initial-metadata-entry.vue';

const props = defineProps<{
model: Model;
mmt: MiraModel;
}>();

defineEmits(['update-initial-metadata']);
const emit = defineEmits(['update-initial-metadata']);

const initials = getInitials(props.model);
const isStratified = isStratifiedModel(props.mmt);
const collapsedInitials = collapseInitials(props.mmt);

const toggleStates = ref(Array.from({ length: collapsedInitials.size }, () => false));

function updateBaseInitial(baseTarget: string, event: any) {
emit('update-initial-metadata', { target: baseTarget, ...event });
// Update stratified initials if the event is a unit change
const targets = collapsedInitials.get(baseTarget);
if (targets && event.key === 'units') {
targets.forEach((target) => emit('update-initial-metadata', { target, ...event }));
}
}
</script>

<style scoped>
li {
padding: var(--gap-small) 0;
padding-bottom: var(--gap-small);
border-bottom: 1px solid var(--surface-border);
}

.stratified {
gap: var(--gap-small);
margin: var(--gap-small) 0 0 var(--gap-medium);

& > li {
border-left: 2px solid var(--primary-color-dark);
padding-left: var(--gap);
padding-bottom: 0;
border-bottom: none;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import TeraRegnetTables from '@/components/model/regnet/tera-regnet-tables.vue';
import TeraStockflowTables from '@/components/model/stockflow/tera-stockflow-tables.vue';
import { AMRSchemaNames } from '@/types/common';
import { getModelType } from '@/services/model';
import { updateInitialMetadata, updateParameter } from '@/model-representation/service';
import {
updateInitialMetadata,
updateParameter,
updateParameterMetadata
} from '@/model-representation/service';

const props = defineProps<{
model: Model;
Expand Down Expand Up @@ -50,8 +54,12 @@ function onUpdateInitialMetadata(event: any) {
}

function onUpdateParameter(event: any) {
const { parameterId, key, value } = event;
updateParameter(transientModel.value, parameterId, key, value);
const { parameterId, key, value, isMetadata } = event;
if (isMetadata) {
updateParameterMetadata(transientModel.value, parameterId, key, value);
} else {
updateParameter(transientModel.value, parameterId, key, value);
}
}

// Apply changes to the model when the component unmounts or the user navigates away
Expand Down
Loading
Loading