|
| 1 | +<template> |
| 2 | + <v-dialog |
| 3 | + v-model="SimulatorState.dialogBox.export_project_dialog" |
| 4 | + :persistent="true" |
| 5 | + > |
| 6 | + <v-card class="exportProjectCard"> |
| 7 | + <v-card-text> |
| 8 | + <p>Export as file</p> |
| 9 | + <v-btn |
| 10 | + size="x-small" |
| 11 | + icon |
| 12 | + class="dialogClose" |
| 13 | + @click=" |
| 14 | + SimulatorState.dialogBox.export_project_dialog = false |
| 15 | + " |
| 16 | + > |
| 17 | + <v-icon>mdi-close</v-icon> |
| 18 | + </v-btn> |
| 19 | + <div class="fileNameInput"> |
| 20 | + <p>File name:</p> |
| 21 | + <input |
| 22 | + v-model="fileNameInput" |
| 23 | + id="fileNameInputField" |
| 24 | + class="inputField" |
| 25 | + type="text" |
| 26 | + placeholder="untitled" |
| 27 | + required |
| 28 | + /> |
| 29 | + <p>.cv</p> |
| 30 | + </div> |
| 31 | + </v-card-text> |
| 32 | + <v-card-actions> |
| 33 | + <v-btn class="messageBtn" @click="exportAsFile"> Save </v-btn> |
| 34 | + </v-card-actions> |
| 35 | + </v-card> |
| 36 | + </v-dialog> |
| 37 | +</template> |
| 38 | + |
| 39 | +<script lang="ts"> |
| 40 | +import { ref } from 'vue' |
| 41 | +import { useState } from '#/store/SimulatorStore/state' |
| 42 | +import { useProjectStore } from '#/store/projectStore' |
| 43 | +import { generateSaveData } from '#/simulator/src/data/save' |
| 44 | +import { download } from '#/simulator/src/utils' |
| 45 | +import { escapeHtml } from '#/simulator/src/utils' |
| 46 | +
|
| 47 | +export function ExportProject() { |
| 48 | + const SimulatorState = useState() |
| 49 | + SimulatorState.dialogBox.export_project_dialog = true |
| 50 | + setTimeout(() => { |
| 51 | + const fileNameInputField = document.getElementById( |
| 52 | + 'fileNameInputField' |
| 53 | + ) as HTMLInputElement |
| 54 | + fileNameInputField?.select() |
| 55 | + }, 100) |
| 56 | +} |
| 57 | +</script> |
| 58 | + |
| 59 | +<script lang="ts" setup> |
| 60 | +const SimulatorState = useState() |
| 61 | +const projectStore = useProjectStore() |
| 62 | +
|
| 63 | +const fileNameInput = ref( |
| 64 | + projectStore.getProjectName + |
| 65 | + '__' + |
| 66 | + new Date().toLocaleString().replace(/[: \/,-]/g, '_') |
| 67 | +) |
| 68 | +
|
| 69 | +const exportAsFile = async () => { |
| 70 | + let fileName = escapeHtml(fileNameInput.value) || 'untitled' |
| 71 | + const circuitData = await generateSaveData( |
| 72 | + projectStore.getProjectName, |
| 73 | + false |
| 74 | + ) |
| 75 | + fileName = `${fileName.replace(/[^a-z0-9]/gi, '_')}.cv` |
| 76 | + download(fileName, circuitData) |
| 77 | + SimulatorState.dialogBox.export_project_dialog = false |
| 78 | +} |
| 79 | +</script> |
| 80 | + |
| 81 | +<style scoped> |
| 82 | +.exportProjectCard { |
| 83 | + height: auto; |
| 84 | + width: 30rem; |
| 85 | + justify-content: center; |
| 86 | + margin: auto; |
| 87 | + backdrop-filter: blur(5px); |
| 88 | + border-radius: 5px; |
| 89 | + border: 0.5px solid var(--br-primary) !important; |
| 90 | + background: var(--bg-primary-moz) !important; |
| 91 | + background-color: var(--bg-primary-chr) !important; |
| 92 | + color: white; |
| 93 | +} |
| 94 | +
|
| 95 | +/* media query for .messageBoxContent */ |
| 96 | +@media screen and (max-width: 991px) { |
| 97 | + .exportProjectCard { |
| 98 | + width: 100%; |
| 99 | + } |
| 100 | +} |
| 101 | +.fileNameInput { |
| 102 | + display: flex; |
| 103 | + align-items: baseline; |
| 104 | + justify-content: center; |
| 105 | + gap: 1rem; |
| 106 | +} |
| 107 | +
|
| 108 | +.fileNameInput p { |
| 109 | + white-space: nowrap; |
| 110 | +} |
| 111 | +
|
| 112 | +.fileNameInput input { |
| 113 | + text-align: center; |
| 114 | +} |
| 115 | +</style> |
| 116 | + |
| 117 | +<!-- For any bugs refer to SaveAs.js file in main repo --> |
0 commit comments