Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add confirm for closing dialogs #32

Merged
merged 8 commits into from
Nov 12, 2024
39 changes: 30 additions & 9 deletions src/components/BlackoutList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
<v-btn
color="blue darken-1"
flat
@click="close"
@click="() => dialog = false"
>
{{ $t('Cancel') }}
</v-btn>
Expand Down Expand Up @@ -635,9 +635,22 @@ export default {
this.getServices()
this.getTags()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
this.editedItem.period = this.defaultTimes()
this.editedItemStart.period = JSON.parse(JSON.stringify(this.editedItem.period))
},
methods: {
compareDict(a, b) {
if (a === null) return true
for (const key in a) {
if (b[key] === undefined) return false
if (a[key] !== null && typeof a[key] === typeof({})) {
if (b[key] === null || a[key].length !== b[key].length || !this.compareDict(a[key], b[key])) return false
}
else if (a[key] !== b[key]) return false
}
return true
},
getBlackouts() {
this.$store.dispatch('blackouts/getBlackouts')
},
Expand Down Expand Up @@ -696,6 +709,7 @@ export default {
editItem(item) {
this.editedId = item.id
this.editedItem = Object.assign({}, item)
this.editedItemStart = JSON.parse(JSON.stringify(item))
this.dialog = true
},
copyItem(item) {
Expand All @@ -709,13 +723,19 @@ export default {
this.$store.dispatch('blackouts/deleteBlackout', item.id)
},
close() {
this.dialog = false
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItem.period = this.defaultTimes()
this.editedId = null
}, 300)
let change = !this.compareDict(this.editedItem, this.editedItemStart)
if (this.saved || !change || confirm('Are you sure you want to close the dialog?')) {
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
this.editedItem.period = this.defaultTimes()
this.editedItemStart.period = JSON.parse(JSON.stringify(this.editedItem.period))
this.editedId = null
this.saved = false
}, 300)
}
else setTimeout(() => this.dialog = true, 0.1)
},
validate() {
if (this.$refs.form.validate()) {
Expand Down Expand Up @@ -763,7 +783,8 @@ export default {
})
)
}
this.close()
this.dialog = false
this.saved = true
}
}
}
Expand Down
37 changes: 28 additions & 9 deletions src/components/EscalationRuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,21 @@ export default {
this.getEnvironments()
this.getServices()
this.getTags()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItem = Object.assign({}, JSON.parse(JSON.stringify(this.defaultItem)))
this.editedItemStart = Object.assign({}, JSON.parse(JSON.stringify(this.defaultItem)))
},
methods: {
compareDict(a, b) {
if (a === null) return true
for (const key in a) {
if (b[key] === undefined) return false
if (a[key] !== null && typeof a[key] === typeof({})) {
if (b[key] === null || a[key].length !== b[key].length || !this.compareDict(a[key], b[key])) return false
}
else if (a[key] !== b[key]) return false
}
return true
},
getEscalationRules() {
this.$store.dispatch('escalationRules/getEscalationRules')
},
Expand All @@ -732,7 +744,8 @@ export default {

editItem(item) {
this.editedId = item.id
this.editedItem = Object.assign({}, item)
this.editedItem = Object.assign({}, JSON.parse(JSON.stringify(item)))
this.editedItemStart = JSON.parse(JSON.stringify(item))
this.dialog = true
},
copyItem(item) {
Expand All @@ -748,12 +761,17 @@ export default {
)
},
close() {
this.dialog = false
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedId = null
}, 300)
let change = !this.compareDict(this.editedItem, this.editedItemStart)
if (this.saved || !change || confirm('Are you sure you want to close the dialog?')) {
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = JSON.parse(JSON.stringify(this.defaultItem))
this.editedItemStart = JSON.parse(JSON.stringify(this.defaultItem))
this.editedId = null
this.saved = false
}, 300)
}
else setTimeout(() => this.dialog = true, 0.1)
},
validate() {
if (this.$refs.form.validate()) {
Expand Down Expand Up @@ -823,7 +841,8 @@ export default {
})
)
}
this.close()
this.dialog = false
this.saved = true
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/components/NotificationChannelList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<v-btn
color="blue darken-1"
flat
@click="close"
@click="() => dialog = false"
>
{{ $t('Cancel') }}
</v-btn>
Expand Down Expand Up @@ -519,8 +519,20 @@ export default {
this.getEncryptionKey()
this.getCustomers()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
},
methods: {
compareDict(a, b) {
if (a === null) return true
for (const key in a) {
if (b[key] === undefined) return false
if (a[key] !== null && typeof a[key] === typeof({})) {
if (b[key] === null || a[key].length !== b[key].length || !this.compareDict(a[key], b[key])) return false
}
else if (a[key] !== b[key]) return false
}
return true
},
getEncryptionKey() {
this.$store.dispatch('notificationChannels/getEncryptionKey')
},
Expand All @@ -539,6 +551,7 @@ export default {
editItem(item) {
this.editedId = item.id
this.editedItem = Object.assign({}, item)
this.editedItemStart = Object.assign({}, item)
this.dialog = true
},
testItem(item) {
Expand All @@ -558,12 +571,17 @@ export default {
)
},
close() {
this.dialog = false
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedId = null
}, 300)
let change = !this.compareDict(this.editedItem, this.editedItemStart)
if (this.saved || !change || confirm('Are you sure you want to close the dialog?')) {
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
this.editedId = null
this.saved = false
}, 300)
}
else setTimeout(() => this.dialog = true, 0.1)
},
closeTest() {
this.testDialog = false
Expand Down Expand Up @@ -600,7 +618,8 @@ export default {
this.editedItem
)
}
this.close()
this.dialog = false
this.saved = true
}
}
}
Expand Down
37 changes: 28 additions & 9 deletions src/components/NotificationGroupList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<v-btn
color="blue darken-1"
flat
@click="close"
@click="() => dialog = false"
>
{{ $t('Cancel') }}
</v-btn>
Expand Down Expand Up @@ -312,8 +312,20 @@ export default {
this.getNotificationGroups()
this.getUsers()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
},
methods: {
compareDict(a, b) {
if (a === null) return true
for (const key in a) {
if (b[key] === undefined) return false
if (a[key] !== null && typeof a[key] === typeof({})) {
if (b[key] === null || a[key].length !== b[key].length || !this.compareDict(a[key], b[key])) return false
}
else if (a[key] !== b[key]) return false
}
return true
},
getNotificationGroups() {
this.$store.dispatch('notificationGroups/getNotificationGroups')
},
Expand All @@ -327,6 +339,7 @@ export default {
editItem(item) {
this.editedId = item.id
this.editedItem = Object.assign({}, item)
this.editedItemStart = Object.assign({}, item)
this.dialog = true
},
copyItem(item) {
Expand All @@ -337,14 +350,19 @@ export default {
deleteItem(item) {
confirm(i18n.t('ConfirmDelete')) &&
this.$store.dispatch('notificationGroups/deleteNotificationGroup', item.id)
},
},
close() {
this.dialog = false
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedId = null
}, 300)
let change = !this.compareDict(this.editedItem, this.editedItemStart)
if (this.saved || !change || confirm('Are you sure you want to close the dialog?')) {
setTimeout(() => {
this.$refs.form.resetValidation()
this.editedItem = Object.assign({}, this.defaultItem)
this.editedItemStart = Object.assign({}, this.defaultItem)
this.editedId = null
this.saved = false
}, 300)
}
else setTimeout(() => this.dialog = true, 0.1)
},
validate() {
if (this.$refs.form.validate()) {
Expand All @@ -371,7 +389,8 @@ export default {
})
)
}
this.close()
this.dialog = false
this.saved = true
}
}
}
Expand Down
Loading
Loading