|
| 1 | +<!-- |
| 2 | + - @copyright Copyright (c) 2021 Richard Steinmetz <richard@steinmetz.cloud> |
| 3 | + - |
| 4 | + - @author Richard Steinmetz <richard@steinmetz.cloud> |
| 5 | + - |
| 6 | + - @license GNU AGPL version 3 or any later version |
| 7 | + - |
| 8 | + - This program is free software: you can redistribute it and/or modify |
| 9 | + - it under the terms of the GNU Affero General Public License as |
| 10 | + - published by the Free Software Foundation, either version 3 of the |
| 11 | + - License, or (at your option) any later version. |
| 12 | + - |
| 13 | + - This program is distributed in the hope that it will be useful, |
| 14 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + - GNU Affero General Public License for more details. |
| 17 | + - |
| 18 | + - You should have received a copy of the GNU Affero General Public License |
| 19 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + - |
| 21 | + --> |
| 22 | + |
| 23 | +<template> |
| 24 | + <div class="appointment-config-list"> |
| 25 | + <AppNavigationCaption |
| 26 | + class="appointment-config-list__caption" |
| 27 | + :title="t('calendar', 'Appointment')"> |
| 28 | + <template #actions> |
| 29 | + <ActionButton @click="showModalForNewConfig = true"> |
| 30 | + <PlusIcon slot="icon" :size="20" decorative /> |
| 31 | + {{ t('calendar', 'Add new') }} |
| 32 | + </ActionButton> |
| 33 | + </template> |
| 34 | + </AppNavigationCaption> |
| 35 | + <AppointmentConfigListItem |
| 36 | + v-for="config in configs" |
| 37 | + :key="config.id" |
| 38 | + :config="config" /> |
| 39 | + |
| 40 | + <AppointmentConfigModal |
| 41 | + v-if="showModalForNewConfig" |
| 42 | + :is-new="true" |
| 43 | + :config="defaultConfig" |
| 44 | + @save="saveNewConfig" |
| 45 | + @close="closeModal" /> |
| 46 | + </div> |
| 47 | +</template> |
| 48 | + |
| 49 | +<script> |
| 50 | +import AppointmentConfigListItem from './AppointmentConfigList/AppointmentConfigListItem' |
| 51 | +import AppNavigationCaption from '@nextcloud/vue/dist/Components/AppNavigationCaption' |
| 52 | +import ActionButton from '@nextcloud/vue/dist/Components/ActionButton' |
| 53 | +import PlusIcon from 'vue-material-design-icons/Plus' |
| 54 | +import AppointmentConfigModal from '../AppointmentConfigModal' |
| 55 | +import AppointmentConfig, { generateAppointmentConfigs } from '../../models/appointmentConfig' |
| 56 | +import logger from '../../utils/logger' |
| 57 | +import { mapState } from 'vuex' |
| 58 | +
|
| 59 | +export default { |
| 60 | + name: 'AppointmentConfigList', |
| 61 | + components: { |
| 62 | + AppointmentConfigListItem, |
| 63 | + AppNavigationCaption, |
| 64 | + ActionButton, |
| 65 | + PlusIcon, |
| 66 | + AppointmentConfigModal, |
| 67 | + }, |
| 68 | + data() { |
| 69 | + return { |
| 70 | + loading: false, |
| 71 | + showModalForNewConfig: false, |
| 72 | + } |
| 73 | + }, |
| 74 | + computed: { |
| 75 | + ...mapState({ |
| 76 | + configs: state => Object.values(state.appointmentConfigs.configs), |
| 77 | + }), |
| 78 | + defaultConfig() { |
| 79 | + return new AppointmentConfig() |
| 80 | + }, |
| 81 | + }, |
| 82 | + async created() { |
| 83 | + for (const config of generateAppointmentConfigs()) { |
| 84 | + await this.$store.dispatch('addConfig', { config }) |
| 85 | + } |
| 86 | + }, |
| 87 | + methods: { |
| 88 | + closeModal() { |
| 89 | + this.showModalForNewConfig = false |
| 90 | + }, |
| 91 | + async saveNewConfig(config) { |
| 92 | + logger.info('Saving new config', { config }) |
| 93 | +
|
| 94 | + this.loading = true |
| 95 | + try { |
| 96 | + await this.$store.dispatch('addConfig', { config }) |
| 97 | + this.closeModal() |
| 98 | + } catch (error) { |
| 99 | + logger.error('Creating appointment config failed', { error, config }) |
| 100 | + } finally { |
| 101 | + this.loading = false |
| 102 | + } |
| 103 | + }, |
| 104 | + }, |
| 105 | +} |
| 106 | +</script> |
| 107 | + |
| 108 | +<style lang="scss" scoped> |
| 109 | +</style> |
0 commit comments