Method "$t" conflicts with an existing Vue instance method. Avoid defining component methods that start with _ or $.
<template>
<span>
<v-icon @click="handleCreate(tenant, device, check)">
mdi-volume-high
</v-icon>
<v-dialog
v-model="silenceFormVisible"
max-width="800"
>
<v-card>
<v-card-title
primary-title
>
Create Silence
</v-card-title>
<v-form
ref="silenceForm"
label-position="left"
label-width="130px"
style="width: 400px; margin-left:50px;"
>
Tenant: {{ form.tenant }}<br>
Device: {{ form.device }}<br>
Check: {{ form.check }}<br>
<v-textarea
v-model="form.reason"
:rows="3"
label="Reson"
type="textarea"
placeholder="A reason is required"
/>
<v-checkbox
v-model="form.expireonresolve"
label="Expire on Resolve"
/>
<v-radio-group v-model="form.options">
<v-radio
label="immediately"
value="immediately"
/>
<v-radio
label="scheduled"
value="scheduled"
/>
<v-radio
label="cron"
value="cron"
/>
</v-radio-group>
<v-select
v-if="form.options === 'immediately'"
v-model="form.duration"
:auto-select-first="true"
:items="durationOptions"
placeholder="Duration"
label="Duration"
item-text="display_name"
item-value="key"
/>
<VueCronEditorBuefy
v-if="form.options === 'cron'"
v-model="form.cron"
/>
<v-btn @click="silenceFormVisible = false">
Cancel
</v-btn>
<v-btn
type="primary"
@click="onSilence"
>
Silence
</v-btn>
</v-form>
</v-card>
</v-dialog>
</span>
</template>
<script>
import { createSilence, createSchedule, createCron } from '@/utils/silence-api'
import VueCronEditorBuefy from 'vue-cron-editor-buefy'
import store from '@/store'
const durationOptions = [
{ key: 900, display_name: '15 minutes' },
{ key: 3600, display_name: '1 hour' },
{ key: 43200, display_name: '12 hours' },
{ key: 86400, display_name: 'a day' }
]
export default {
name: 'Silence',
components: { VueCronEditorBuefy },
props: {
tenant: {
required: true,
type: String,
default: ''
},
device: {
required: true,
type: String,
default: ''
},
check: {
type: String,
default: ''
}
},
data () {
return {
list: null,
listLoading: true,
durationOptions,
form: {
cron: '',
tenant: '',
device: '',
check: '',
duration: '',
reason: '',
options: 'immediately',
expireonresolve: false,
scheduleRange: []
},
silenceFormVisible: false
}
},
methods: {
onSilence () {
var obj = {}
obj = this.form
var data = {}
if (this.form.options === 'immediately') {
if (obj.check === '') {
data = { 'subscription': 'client:' + obj.device, 'reason': obj.reason, 'creator': store.getters.name, 'expire': obj.duration, 'expireonresolve': obj.expireonresolve }
} else {
data = { 'subscription': 'client:' + obj.device, 'reason': obj.reason, 'creator': store.getters.name, 'check': obj.check, 'expire': obj.duration, 'expireonresolve': obj.expireonresolve }
}
createSilence(obj.tenant, data).then(response => {
})
}
if (this.form.options === 'scheduled') {
const expire = (obj.scheduleRange[1].getTime() / 1000) - (obj.scheduleRange[0].getTime() / 1000)
if (obj.check === '') {
data = {
'subscription': 'client:' + obj.device,
'reason': obj.reason,
'creator': store.getters.name,
'expireonresolve': obj.expireonresolve,
'begin': obj.scheduleRange[0].getTime() / 1000,
'expire': expire
}
} else {
data = {
'subscription': 'client:' + obj.device,
'reason': obj.reason,
'creator': store.getters.name,
'check': obj.check,
'expireonresolve': obj.expireonresolve,
'begin': this.form.scheduleRange[0].getTime() / 1000,
'expire': expire
}
}
createSchedule(this.form.tenant, data).then(response => {
this.loading = false
})
}
if (this.form.options === 'cron') {
if (obj.check === '') {
data = {
'subscription': 'client:' + obj.device,
'reason': obj.reason,
'creator': store.getters.name,
'expireonresolve': obj.expireonresolve,
'expire': obj.duration,
'cron': obj.cron
}
} else {
data = {
'subscription': 'client:' + obj.device,
'reason': obj.reason,
'creator': store.getters.name,
'check': obj.check,
'expireonresolve': obj.expireonresolve,
'expire': obj.duration,
'cron': obj.cron
}
}
createCron(this.form.tenant, data).then(response => {
this.loading = false
})
}
this.silenceFormVisible = false
},
handleCreate (tenant, device, check) {
this.form.tenant = tenant
this.form.device = device
this.form.check = check
this.silenceFormVisible = true
}
},
template: '<cron/>'
}
</script>