-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: add resource filtering and new asset buttons (#1583)
Co-authored-by: Cole Blanchard <cblanchard@Coles-MacBook-Pro.local> Co-authored-by: Yohann Paris <github@yohannparis.com>
- Loading branch information
Showing
8 changed files
with
273 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/client/hmi-client/src/page/project/components/tera-model-modal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.