Skip to content

Commit 2c02d92

Browse files
authored
refactor: converted all DOM manipulations to Vue's reactive system in SaveImage.vue (#291)
* refactor: converted all DOM manipulations to vue's reactive system in SaveImage.vue * refactor: added some typescript annotation * fix: minor errors fixed
1 parent 594cb5b commit 2c02d92

File tree

1 file changed

+53
-80
lines changed

1 file changed

+53
-80
lines changed
Lines changed: 53 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<template>
2-
<v-dialog
3-
v-model="SimulatorState.dialogBox.saveimage_dialog"
4-
:persistent="false"
5-
>
2+
<v-dialog v-model="dialogState.saveimage_dialog" :persistent="false">
63
<v-card class="messageBoxContent">
74
<v-card-text>
85
<p class="dialogHeader">Render Image</p>
96
<v-btn
107
size="x-small"
118
icon
129
class="dialogClose"
13-
@click="SimulatorState.dialogBox.saveimage_dialog = false"
10+
@click="dialogState.saveimage_dialog = false"
1411
>
1512
<v-icon>mdi-close</v-icon>
1613
</v-btn>
@@ -25,96 +22,88 @@
2522
type="radio"
2623
name="imgType"
2724
:value="imageType.toLowerCase()"
28-
checked="checked"
29-
@click="checkImgType"
25+
v-model="selectedImageType"
26+
@change="checkImgType(imageType)"
3027
/>
3128
{{ imageType }}
3229
<span></span>
3330
</label>
3431
</div>
3532
<div class="download-dialog-section-2">
3633
<div
37-
v-if="toShow == true"
34+
v-if="toShow"
3835
class="option inline btn-group btn-group-toggle"
3936
style="border: none"
4037
data-toggle="buttons"
4138
>
4239
<div
4340
id="radio-full"
4441
class="btn"
45-
:class="
46-
fullImg == true
47-
? 'active-btn'
48-
: 'inactive-btn'
49-
"
42+
:class="fullImg ? 'active-btn' : 'inactive-btn'"
5043
role="button"
51-
@click="updateView(1)"
44+
@click="updateView(true)"
5245
>
5346
<input type="radio" name="view" value="full" />
5447
Full Circuit View
5548
</div>
5649
<div
5750
id="radio-current"
5851
class="btn"
59-
:class="
60-
fullImg == false
61-
? 'active-btn'
62-
: 'inactive-btn'
63-
"
52+
:class="!fullImg ? 'active-btn' : 'inactive-btn'"
6453
role="button"
65-
@click="updateView(0)"
54+
@click="updateView(false)"
6655
>
6756
<input
6857
type="radio"
6958
name="view"
7059
value="current"
71-
checked="checked"
7260
/>Current View
7361
</div>
7462
</div>
75-
<div
76-
v-if="toShow1 == true"
77-
class="download-dialog-section-2_2"
78-
>
63+
<div v-if="toShow1" class="download-dialog-section-2_2">
7964
<label class="cb-checkbox">
8065
<input
8166
type="checkbox"
8267
name="transparent"
8368
value="transparent"
69+
v-model="transparent"
8470
/>
8571
Transparent Background
8672
</label>
8773
</div>
8874
</div>
89-
<div
90-
v-if="toShow == true"
91-
class="download-dialog-section-3"
92-
>
75+
<div v-if="toShow" class="download-dialog-section-3">
9376
<span>Resolution:</span>
9477
<label class="option custom-radio inline"
9578
><input
9679
type="radio"
9780
name="resolution"
9881
value="1"
99-
checked="checked" />1x<span></span
82+
83+
v-model="resolution"
84+
/>1x<span></span
10085
></label>
10186
<label class="option custom-radio inline"
10287
><input
10388
type="radio"
10489
name="resolution"
105-
value="2" />2x<span></span
90+
value="2"
91+
v-model="resolution"
92+
/>2x<span></span
10693
></label>
10794
<label class="option custom-radio inline"
10895
><input
10996
type="radio"
11097
name="resolution"
111-
value="4" />4x<span></span
98+
value="4"
99+
v-model="resolution"
100+
/>4x<span></span
112101
></label>
113102
</div>
114103
</div>
115104
</v-card-text>
116105
<v-card-actions>
117-
<v-btn class="messageBtn" block @click="renderCircuit()">
106+
<v-btn class="messageBtn" block @click="renderCircuit">
118107
Render Circuit Image
119108
</v-btn>
120109
</v-card-actions>
@@ -125,60 +114,44 @@
125114
<script lang="ts" setup>
126115
import { generateImage } from '#/simulator/src/data/save'
127116
import { useState } from '#/store/SimulatorStore/state'
128-
import { onMounted, ref } from '@vue/runtime-core'
117+
import { ref, computed, Ref } from '@vue/runtime-core'
118+
129119
const SimulatorState = useState()
130120
131-
const imgTypeList = ref([''])
132-
imgTypeList.value = ['PNG', 'JPEG', 'SVG', 'BMP', 'GIF', 'TIFF']
133-
const toShow = ref(true)
134-
const toShow1 = ref(true)
135-
const fullImg = ref(false)
121+
const dialogState = computed(() => SimulatorState.dialogBox)
136122
137-
onMounted(() => {
138-
SimulatorState.dialogBox.saveimage_dialog = false
139-
})
123+
const imgTypeList: Ref<string[]> = ref(['PNG', 'JPEG', 'SVG', 'BMP', 'GIF', 'TIFF'])
124+
const toShow: Ref<boolean> = ref(true)
125+
const toShow1: Ref<boolean> = ref(true)
126+
const fullImg: Ref<boolean> = ref(false)
127+
const resolution: Ref<number> = ref(1)
128+
const transparent: Ref<boolean> = ref(false)
129+
const selectedImageType: Ref<string> = ref('png')
140130
141-
function renderCircuit() {
142-
SimulatorState.dialogBox.saveimage_dialog = false
143-
generateImage(
144-
$('input[name=imgType]:checked').val(),
145-
$('input[name=view]:checked').val(),
146-
$('input[name=transparent]:checked').val(),
147-
$('input[name=resolution]:checked').val()
148-
)
149-
}
131+
function checkImgType(imageType: string) {
132+
const isDisabled = imageType.toLowerCase() === 'svg'
133+
toShow.value = !isDisabled
134+
toShow1.value = imageType.toLowerCase() === 'png'
150135
151-
function checkImgType() {
152-
$('input[name=resolution]').prop('disabled', false)
153-
$('input[name=transparent]').prop('disabled', false)
154-
const imgType = $('input[name=imgType]:checked').val()
155-
imgType == 'svg' ? (toShow.value = false) : (toShow.value = true)
156-
if (imgType === 'png') {
157-
toShow1.value = true
158-
} else {
159-
toShow1.value = false
160-
}
161-
if (imgType === 'svg') {
162-
$('input[name=resolution][value=1]').trigger('click')
163-
$('input[name=view][value="full"]').trigger('click')
164-
$('input[name=resolution]').prop('disabled', true)
165-
$('input[name=view]').prop('disabled', true)
166-
} else if (imgType !== 'png') {
167-
$('input[name=transparent]').attr('checked', false)
168-
$('input[name=transparent]').prop('disabled', true)
169-
$('input[name=view]').prop('disabled', false)
170-
$('.cb-inner').addClass('disable')
171-
} else {
172-
$('input[name=view]').prop('disabled', false)
173-
$('.cb-inner').removeClass('disable')
136+
if (isDisabled) {
137+
resolution.value = 1
138+
fullImg.value = true
139+
} else if (imageType.toLowerCase() !== 'png') {
140+
transparent.value = false
174141
}
175142
}
176143
177-
function updateView(x) {
178-
if (x == 1) {
179-
fullImg.value = true
180-
} else {
181-
fullImg.value = false
182-
}
144+
function updateView(isFullImg: boolean) {
145+
fullImg.value = isFullImg
146+
}
147+
148+
function renderCircuit() {
149+
SimulatorState.dialogBox.saveimage_dialog = false
150+
generateImage(
151+
selectedImageType.value,
152+
fullImg.value ? 'full' : 'current',
153+
transparent.value,
154+
resolution.value
155+
)
183156
}
184157
</script>

0 commit comments

Comments
 (0)