-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathNewScreenDialog.vue
More file actions
240 lines (235 loc) · 6.31 KB
/
NewScreenDialog.vue
File metadata and controls
240 lines (235 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!--
# Copyright 2023 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
-->
<template>
<!-- Dialog for creating new screen -->
<v-dialog v-model="show" persistent width="600" @keydown.esc="show = false">
<v-card>
<v-toolbar height="24">
<v-spacer />
<span>Create New Screen</span>
<v-spacer />
<v-btn
icon="mdi-close-box"
variant="text"
density="compact"
data-test="new-screen-close-icon"
@click="show = false"
/>
</v-toolbar>
<v-card-text>
<v-alert
v-model="duplicateScreenAlert"
type="error"
closable
density="compact"
>
Screen {{ newScreenName.toUpperCase() }} already exists!
</v-alert>
<v-row class="pt-3">
<v-col> Screens must belong to a target. Select a target: </v-col>
</v-row>
<v-row dense>
<v-col>
<v-select
v-model="selectedTarget"
label="Select Target"
:items="targets"
item-title="label"
item-value="value"
@update:model-value="targetSelect"
/>
</v-col>
</v-row>
<v-row dense>
<v-col>
Screens can be auto-generated based on an existing Packet. This
creates a LABELVALUE line for every item in the packet. The screen
can then be edited and customized.
</v-col>
</v-row>
<v-row dense>
<v-col> Leave this blank to start with a blank screen. </v-col>
</v-row>
<v-row dense>
<v-col>
<v-autocomplete
v-model="selectedPacketName"
label="New screen packet"
hide-details
density="compact"
:items="packetNames"
item-title="label"
item-value="value"
data-test="new-screen-packet"
/>
</v-col>
</v-row>
<v-row dense>
<v-col>
<v-text-field
v-model="newScreenName"
flat
autofocus
clearable
label="Screen Name (without .txt)"
:rules="[rules.required]"
data-test="new-screen-name"
@keyup="newScreenKeyup($event)"
/>
<div v-if="newScreenSaving" class="pl-2">
<v-progress-circular indeterminate color="primary" />
</div>
</v-col>
</v-row>
</v-card-text>
<v-divider />
<v-card-actions class="px-2">
<v-spacer />
<v-btn variant="outlined" @click="show = false"> Cancel </v-btn>
<v-btn variant="flat" @click="saveNewScreen"> Save </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
import { OpenC3Api } from '@openc3/js-common/services'
export default {
props: {
modelValue: Boolean,
target: {
type: String,
},
screens: {
type: Object,
},
},
data() {
return {
api: null,
targets: [],
newScreenSaving: false,
newScreenName: '',
duplicateScreenAlert: false,
packetNames: [],
selectedTarget: '',
selectedPacketName: '',
rules: {
required: (value) => !!value || 'Required.',
},
}
},
computed: {
show: {
get() {
return this.modelValue
},
set(value) {
this.$emit('update:modelValue', value)
},
},
existingScreens() {
if (this.screens[this.selectedTarget]) {
return this.screens[this.selectedTarget].join(', ')
} else {
return 'None'
}
},
},
watch: {
selectedPacketName: function (value) {
if (value === 'BLANK') {
this.newScreenName = ''
this.duplicateScreenAlert = false
} else {
this.newScreenName = value.toLowerCase()
if (
this.screens[this.selectedTarget] &&
this.screens[this.selectedTarget].indexOf(
this.newScreenName.toUpperCase(),
) !== -1
) {
this.duplicateScreenAlert = true
} else {
this.duplicateScreenAlert = false
}
}
},
newScreenName: function (value) {
if (
this.screens[this.selectedTarget] &&
this.screens[this.selectedTarget].indexOf(value.toUpperCase()) !== -1
) {
this.duplicateScreenAlert = true
} else {
this.duplicateScreenAlert = false
}
},
},
created() {
this.api = new OpenC3Api()
this.duplicateScreenAlert = false
this.newScreenSaving = false
this.selectedTarget = this.target
this.api
.get_target_names({ params: { scope: window.openc3Scope } })
.then((targets) => {
this.targets = targets.filter((item) => item !== 'UNKNOWN')
})
this.targetSelect(this.selectedTarget)
},
methods: {
targetSelect(target) {
this.selectedTarget = target
this.api.get_all_tlm_names(this.selectedTarget).then((names) => {
this.packetNames = names.map((name) => {
return {
label: name,
value: name,
}
})
this.packetNames.unshift({
label: '[ BLANK ]',
value: 'BLANK',
})
})
},
newScreenKeyup(event) {
if (event.key === 'Enter') {
this.saveNewScreen()
}
},
saveNewScreen() {
if (this.duplicateScreenAlert || this.newScreenName === '') {
return
}
this.newScreenSaving = true
this.$emit(
'success',
this.newScreenName.toUpperCase(),
this.selectedPacketName,
this.selectedTarget,
)
},
},
}
</script>
<style scoped>
.v-alert {
margin-bottom: 0px;
}
</style>