Skip to content

Commit dc17ef0

Browse files
committed
Add multi device type modification warning dialog
1 parent fe8004a commit dc17ef0

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

src/components/ZclCreateModifyEndpoint.vue

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,36 @@ limitations under the License.
120120
/>
121121
</q-card-actions>
122122
</q-card>
123+
<q-dialog v-model="showWarningDialog" persistent>
124+
<zcl-warning-dialog
125+
title="Do you want to proceed?"
126+
message="ZCL device type is being modified which can cause all the configuration on the endpoint to be cleared and re-adjusted."
127+
cancel-label="No"
128+
ok-label="Yes"
129+
@ok="
130+
() => {
131+
warningDialogReturnValue = 'ok'
132+
saveOrCreateHandler()
133+
}
134+
"
135+
/>
136+
</q-dialog>
123137
</div>
124138
</template>
125139

126140
<script>
127141
import * as RestApi from '../../src-shared/rest-api'
128142
import * as DbEnum from '../../src-shared/db-enum'
129143
import CommonMixin from '../util/common-mixin'
144+
import ZclWarningDialog from './ZclWarningDialog.vue'
130145
const _ = require('lodash')
131146

132147
export default {
133148
name: 'ZclCreateModifyEndpoint',
134149
props: ['endpointReference'],
135150
emits: ['saveOrCreateValidated', 'updateData'],
136151
mixins: [CommonMixin],
152+
components: { ZclWarningDialog },
137153
watch: {
138154
deviceTypeRefAndDeviceIdPair(val) {
139155
this.setDeviceTypeCallback(val)
@@ -175,6 +191,7 @@ export default {
175191

176192
// Set device types only in edit mode
177193
this.deviceTypeTmp = deviceTypes
194+
this.deviceTypeMountSnapshot = JSON.parse(JSON.stringify(deviceTypes))
178195
this.primaryDeviceTypeTmp = deviceTypes[0] ?? null // First item is the primary device type
179196
} else {
180197
this.shownEndpoint.endpointIdentifier = this.getSmallestUnusedEndpointId()
@@ -198,8 +215,11 @@ export default {
198215
saveOrCreateCloseFlag: false,
199216
deviceTypeTmp: [], // Temp store for the selected device types
200217
primaryDeviceTypeTmp: null, // Temp store for the selected primary device type
201-
enableMultipleDevice: false, // TODO make it data driven
202-
enablePrimaryDevice: false, // TODO make it data driven
218+
enableMultipleDevice: false,
219+
enablePrimaryDevice: false,
220+
showWarningDialog: false,
221+
warningDialogReturnValue: null,
222+
deviceTypeMountSnapshot: null,
203223
}
204224
},
205225
computed: {
@@ -361,6 +381,21 @@ export default {
361381
}
362382
},
363383
saveOrCreateHandler() {
384+
// Check if warning dialog available for the given situation
385+
if (
386+
this.endpointReference &&
387+
this.warningDialogReturnValue == null &&
388+
this.deviceType?.length > 1
389+
) {
390+
// Check if warning dialog should be shown
391+
let deviceTypeChanged = true
392+
// this.deviceTypeMountSnapshot
393+
if (deviceTypeChanged) {
394+
this.showWarningDialog = true
395+
return
396+
}
397+
}
398+
this.warningDialogReturnValue = null
364399
let profile = this.$store.state.zap.isProfileIdShown
365400
? this.$refs.profile.validate()
366401
: true

src/components/ZclWarningDialog.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<div>
3+
<q-card>
4+
<q-card-section class="content-size">
5+
<div class="text-h6 text-align:left q-mb-md">
6+
{{ title }}
7+
</div>
8+
<div>
9+
{{ message }}
10+
</div>
11+
</q-card-section>
12+
<q-card-actions>
13+
<q-btn :label="cancelLabel" v-close-popup class="col" @click="cancel" />
14+
<q-btn
15+
:label="okLabel"
16+
color="primary"
17+
class="col v-step-4"
18+
@click="ok"
19+
/>
20+
</q-card-actions>
21+
</q-card>
22+
</div>
23+
</template>
24+
<script>
25+
export default {
26+
name: 'ZclWarningDialog',
27+
emits: ['cancel', 'ok'],
28+
props: {
29+
title: { type: String, required: true },
30+
message: { type: String, required: false },
31+
cancelLabel: {
32+
type: String,
33+
required: false,
34+
default: () => 'Cancel',
35+
},
36+
okLabel: { type: String, required: false, default: () => 'Ok' },
37+
},
38+
methods: {
39+
cancel() {
40+
this.$emit('cancel')
41+
},
42+
ok() {
43+
this.$emit('ok')
44+
},
45+
},
46+
}
47+
</script>
48+
<style scoped>
49+
.content-size {
50+
min-width: 400px;
51+
}
52+
</style>

0 commit comments

Comments
 (0)