Skip to content

Commit

Permalink
task: add resource filtering and new asset buttons (#1583)
Browse files Browse the repository at this point in the history
Co-authored-by: Cole Blanchard <[email protected]>
Co-authored-by: Yohann Paris <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent b2d086c commit 0fd1dc9
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ import {
} from '@/model-representation/petrinet/petrinet-service';
import { RouteName } from '@/router/routes';
import { getCuriesEntities } from '@/services/concept';
import { createModel, getModel, updateModel } from '@/services/model';
import { createModel, getModel, getModelConfigurations, updateModel } from '@/services/model';
import * as ProjectService from '@/services/project';
import { getRelatedArtifacts } from '@/services/provenance';
import { ResultType, FeatureConfig } from '@/types/common';
Expand Down Expand Up @@ -936,6 +936,7 @@ async function confirmEdit() {
if (model.value && transientTableValue.value) {
const { tableType, idx, updateProperty } = transientTableValue.value;
const modelClone = cloneDeep(model.value);
const modelConfigs = await getModelConfigurations(model?.value?.id);

switch (tableType) {
case 'parameters':
Expand All @@ -950,7 +951,9 @@ async function confirmEdit() {

// note that this is making a call to an async function to update the different model configs
// but we don't need to wait for it to finish because we don't need immediate access to the model configs
updateConfigFields(model.value!.id, ode.parameters![idx][key], value as string);
if (modelConfigs) {
updateConfigFields(modelConfigs, ode.parameters![idx][key], value as string);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import _, { cloneDeep } from 'lodash';
import API from '@/api/api';
import { IGraph } from '@graph-scaffolder/types';
import { PetriNetModel, Model, PetriNetTransition, TypingSemantics } from '@/types/Types';
import {
PetriNetModel,
Model,
PetriNetTransition,
TypingSemantics,
ModelConfiguration
} from '@/types/Types';
import { PetriNet } from '@/petrinet/petrinet-service';
import { getModelConfigurations } from '@/services/model';
import { updateModelConfiguration } from '@/services/model-configurations';

export interface NodeData {
Expand Down Expand Up @@ -160,30 +165,6 @@ export const convertToIGraph = (amr: Model) => {
const DUMMY_VALUE = -999;
export const convertToAMRModel = (g: IGraph<NodeData, EdgeData>) => g.amr;

export const newAMR = (modelName: string) => {
const amr: Model = {
id: '',
name: modelName,
description: '',
schema:
'https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/petrinet_v0.5/petrinet/petrinet_schema.json',
schema_name: 'petrinet',
model_version: '0.1',
model: {
states: [],
transitions: []
},
semantics: {
ode: {
rates: [],
initials: [],
parameters: []
}
}
};
return amr;
};

export const addState = (amr: Model, id: string, name: string) => {
if (amr.model.states.find((s) => s.id === id)) {
return;
Expand Down Expand Up @@ -516,9 +497,11 @@ export const updateParameterId = (amr: Model, id: string, newId: string) => {
}
};

export const updateConfigFields = async (modelId: string, id: string, newId: string) => {
const modelConfigs = await getModelConfigurations(modelId);

export const updateConfigFields = async (
modelConfigs: ModelConfiguration[],
id: string,
newId: string
) => {
modelConfigs.forEach((config) => {
updateParameterId(config.configuration, id, newId);
// note that this is making an async call but we don't need to wait for it to finish
Expand Down Expand Up @@ -682,3 +665,27 @@ export const extractStateMatrixData = (amr: Model, stateIds: string[], dimension
});
return results;
};

export function newAMR(modelName: string) {
const amr: Model = {
id: '',
name: modelName,
description: '',
schema:
'https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/petrinet_v0.5/petrinet/petrinet_schema.json',
schema_name: 'petrinet',
model_version: '0.1',
model: {
states: [],
transitions: []
},
semantics: {
ode: {
rates: [],
initials: [],
parameters: []
}
}
};
return amr;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<Teleport to="body">
<tera-modal v-if="isVisible" class="modal" @modal-mask-clicked="emit('close-modal')">
<template #header>
<h4>New model</h4>
</template>
<template #default>
<form>
<label for="new-model">Enter a unique name for your model</label>
<InputText
v-bind:class="invalidInputStyle"
id="new-model"
type="text"
v-model="newModelName"
placeholder="new model"
/>
</form>
</template>
<template #footer>
<Button @click="createNewModel">Create model</Button>
<Button class="p-button-secondary" @click="emit('close-modal')"> Cancel </Button>
</template>
</tera-modal>
</Teleport>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue';
import TeraModal from '@/components/widgets/tera-modal.vue';
import Button from 'primevue/button';
import InputText from 'primevue/inputtext';
import { IProject, ProjectAssetTypes } from '@/types/Project';
import { logger } from '@/utils/logger';
import { addNewModelToProject } from '@/services/model';
import router from '@/router';
import { RouteName } from '@/router/routes';
const props = defineProps<{
project: IProject;
isVisible: boolean;
}>();
const emit = defineEmits(['close-modal']);
// New Model Modal
const newModelName = ref<string>('');
const isValidName = ref<boolean>(true);
const invalidInputStyle = computed(() => (!isValidName.value ? 'p-invalid' : ''));
const existingModelNames = computed(() => {
const modelNames: string[] = [];
props.project.assets?.models.forEach((item) => {
modelNames.push(item.name);
});
return modelNames;
});
async function createNewModel() {
if (newModelName.value.trim().length === 0) {
isValidName.value = false;
logger.info('Model name cannot be empty - please enter a different name');
return;
}
if (existingModelNames.value.includes(newModelName.value.trim())) {
isValidName.value = false;
logger.info('Duplicate model name - please enter a different name');
return;
}
isValidName.value = true;
const modelId = await addNewModelToProject(newModelName.value.trim(), props.project);
if (modelId) {
router.push({
name: RouteName.ProjectRoute,
params: {
assetName: 'Model',
pageType: ProjectAssetTypes.MODELS,
assetId: modelId
}
});
}
emit('close-modal');
}
</script>

<style></style>
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
size="large"
icon="pi pi-share-alt"
class="p-button p-button-secondary quick-link-button"
@click="isNewModelModalVisible = true"
@click="emit('open-new-asset', ProjectAssetTypes.MODELS)"
/>
<Button
size="large"
class="p-button p-button-secondary quick-link-button"
@click="emit('open-workflow')"
@click="emit('open-new-asset', ProjectAssetTypes.SIMULATION_WORKFLOW)"
>
<vue-feather
class="p-button-icon-left"
Expand Down Expand Up @@ -244,37 +244,6 @@
</tera-modal>
</section>
</section>
<!-- New model modal -->
<Teleport to="body">
<tera-modal
v-if="isNewModelModalVisible"
class="modal"
@modal-mask-clicked="isNewModelModalVisible = false"
>
<template #header>
<h4>New model</h4>
</template>
<template #default>
<form>
<label for="new-model">Enter a unique name for your model</label>
<InputText
v-bind:class="invalidInputStyle"
id="new-model"
type="text"
v-model="newModelName"
placeholder="new model"
/>
</form>
</template>
<template #footer>
<Button @click="createNewModel">Create model</Button>
<Button class="p-button-secondary" @click="isNewModelModalVisible = false">
Cancel
</Button>
</template>
</tera-modal>
</Teleport>
</main>
</template>
Expand Down Expand Up @@ -306,7 +275,7 @@ import { uploadArtifactToProject } from '@/services/artifact';
const props = defineProps<{
project: IProject;
}>();
const emit = defineEmits(['open-workflow', 'open-asset', 'new-model']);
const emit = defineEmits(['open-asset', 'open-new-asset']);
const router = useRouter();
const isRenamingProject = ref(false);
const inputElement = ref<HTMLInputElement | null>(null);
Expand All @@ -319,20 +288,6 @@ const selectedResources = ref();
const openedRow = ref(null);
const isNewModelModalVisible = ref<boolean>(false);
const newModelName = ref<string>('');
const isValidName = ref<boolean>(true);
const invalidInputStyle = computed(() => (!isValidName.value ? 'p-invalid' : ''));
const existingModelNames = computed(() => {
const modelNames: string[] = [];
props.project.assets?.models.forEach((item) => {
modelNames.push(item.name);
});
return modelNames;
});
const assets = computed(() => {
const tabs = new Map<ProjectAssetTypes, Set<Tab>>();
Expand Down Expand Up @@ -389,22 +344,6 @@ async function processFiles(files: File[], csvDescription: string) {
});
}
function createNewModel() {
if (newModelName.value.trim().length === 0) {
isValidName.value = false;
logger.info('Model name cannot be empty - please enter a different name');
return;
}
if (existingModelNames.value.includes(newModelName.value.trim())) {
isValidName.value = false;
logger.info('Duplicate model name - please enter a different name');
return;
}
isValidName.value = true;
emit('new-model', newModelName.value.trim());
isNewModelModalVisible.value = false;
}
async function openImportModal() {
isUploadResourcesModalVisible.value = true;
results.value = null;
Expand Down
Loading

0 comments on commit 0fd1dc9

Please sign in to comment.