Newer
Older
<!--
Web client of the Sensor Management System software developed within the
Helmholtz DataHub Initiative by GFZ and UFZ.
- Nils Brinckmann (GFZ, nils.brinckmann@gfz-potsdam.de)
- Marc Hanisch (GFZ, marc.hanisch@gfz-potsdam.de)
- Helmholtz Centre Potsdam - GFZ German Research Centre for
Geosciences (GFZ, https://www.gfz-potsdam.de)
Parts of this program were developed within the context of the
following publicly funded projects or measures:
- Helmholtz Earth and Environment DataHub
(https://www.helmholtz.de/en/research/earth_and_environment/initiatives/#h51095)
Licensed under the HEESIL, Version 1.0 or - as soon they will be
approved by the "Community" - subsequent versions of the HEESIL
(the "Licence").
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:
https://gitext.gfz-potsdam.de/software/heesil
Unless required by applicable law or agreed to in writing, software
distributed under the Licence is distributed on an "AS IS" basis,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the Licence for the specific language governing
permissions and limitations under the Licence.
-->
<template>
<div>
<ProgressIndicator
v-model="isInProgress"
:dark="isSaving"
/>
<v-row>
<v-col
cols="12"
md="5"
>
<v-autocomplete :items="allExceptSelected" :item-text="(x) => x" :item-value="(x) => x.id" label="New contact" @change="select" />
</v-col>
<v-col
cols="12"
md="2"
align-self="center"
>
<v-btn
small
color="primary"
:disabled="selectedContact == null"
@click="addContact"
>
Add
</v-btn>
<v-btn
small
text
nuxt
:to="'/devices/' + deviceId + '/contacts'"
</div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'nuxt-property-decorator'
import { Contact } from '@/models/Contact'
import ProgressIndicator from '@/components/ProgressIndicator.vue'
@Component({
components: {
}
})
export default class DeviceAddContactPage extends Vue {
private alreadyUsedContacts: Contact[] = []
private allContacts: Contact[] = []
private selectedContact: Contact | null = null
private isLoading: boolean = false
private isSaving: boolean = false
@Prop({
default: () => [] as Contact[],
required: true,
type: Array
})
readonly value!: Contact[]
created () {
this.alreadyUsedContacts = [...this.value] as Contact[]
}
mounted () {
this.$api.contacts.findAll().then((foundContacts) => {
this.allContacts = foundContacts
this.$store.commit('snackbar/setError', 'Failed to fetch related contacts')
this.isLoading = false
})
}
get isInProgress (): boolean {
return this.isLoading || this.isSaving
}
if (this.selectedContact && this.selectedContact.id && this.isLoggedIn) {
this.$api.devices.addContact(this.deviceId, this.selectedContact.id).then(() => {
this.alreadyUsedContacts.push(this.selectedContact as Contact)
this.$emit('input', this.alreadyUsedContacts)
this.$router.push('/devices/' + this.deviceId + '/contacts')
this.$store.commit('snackbar/setError', 'Failed to add a contact')
})
}
}
const idx = this.allContacts.findIndex((c: Contact) => c.id === newContactId)
if (idx > -1) {
this.selectedContact = this.allContacts[idx]
} else {
this.selectedContact = null
}
}
return this.allContacts.filter(c => !this.alreadyUsedContacts.find(rc => rc.id === c.id))
}
return this.$route.params.deviceId
}
return this.$store.getters['oidc/isAuthenticated']
}
}
</script>