Skip to content
Snippets Groups Projects
AddShowModal.vue 5.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
      <div>
        <!-- Modal for adding new shows -->
        <b-modal
          ref="modalAddShow"
          :title="$t('showCreator.title')"
          :cancel-title="$t('cancel')"
          size="lg"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        >
          <b-container fluid>
            <b-row>
              <b-col cols="3"> {{ $t('showMeta.showName') }}: </b-col>
              <b-col cols="9">
                <b-form-input
                  v-model="newShow.name"
                  type="text"
    
                  data-testid="add-show-modal:show-name"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  :placeholder="$t('showMeta.showNamePlaceholder')"
                />
              </b-col>
              <b-col cols="3" />
              <b-col cols="9">
                <small class="slug">{{ $t('slug') }}: {{ temporarySlug }}</small>
              </b-col>
            </b-row>
            <br />
    
            <b-row>
              <b-col cols="3"> {{ $t('showMeta.shortDescription') }}: </b-col>
              <b-col cols="9">
                <b-form-input
    
                  v-model="newShow.shortDescription"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  type="text"
    
                  data-testid="add-show-modal:show-description"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  :placeholder="$t('showMeta.shortDescriptionPlaceholder')"
                />
              </b-col>
            </b-row>
            <br />
    
            <b-row>
              <b-col cols="3"> {{ $t('showMeta.type') }}: </b-col>
              <b-col cols="9">
                <div v-if="!loaded.types">
                  <img src="/assets/radio.gif" :alt="$t('loading')" />
                </div>
                <div v-else>
    
                  <b-form-select
    
                    v-model="newShow.typeId"
    
                    :options="showTypeSelector"
                    data-testid="add-show-modal:show-type"
                  />
    
                  <p
                    v-if="showTypeSelector.length === 0"
                    v-html="$t('showCreator.missingShowTypes', { adminUrl })"
                  />
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                </div>
              </b-col>
            </b-row>
            <br />
    
            <b-row>
              <b-col cols="3"> {{ $t('showMeta.fundingCategory') }}: </b-col>
              <b-col cols="9">
    
                <div v-if="!loaded.fundingCategories">
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  <img src="/assets/radio.gif" :alt="$t('loading')" />
                </div>
                <div v-else>
                  <b-form-select
    
                    v-model="newShow.fundingCategoryId"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                    :options="showFundingCategorySelector"
    
                    data-testid="add-show-modal:show-funding-category"
    
                  <p
                    v-if="showFundingCategorySelector.length === 0"
                    v-html="$t('showCreator.missingShowFundingCategories', { adminUrl })"
                  />
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                </div>
              </b-col>
            </b-row>
          </b-container>
        </b-modal>
      </div>
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
    import slugify from '../../mixins/slugify.js'
    import { mapGetters } from 'vuex'
    
    import { mapStores } from 'pinia'
    import { useUserStore } from '@/stores/auth'
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
    
    export default {
      mixins: [slugify],
      data() {
        return {
    
          adminUrl: `${import.meta.env.VUE_APP_BASEURI_STEERING}/admin`,
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          newShow: {
            name: '',
            slug: '',
    
            shortDescription: '',
            typeId: 0,
            fundingCategoryId: 0,
            categoryIds: [],
            hostIds: [],
            ownerIds: [],
            languageIds: [],
            topicIds: [],
            musicFocusIds: [],
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
      },
    
      computed: {
    
        ...mapStores(useUserStore),
        users() {
          return this.steeringUserStore.items
        },
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        loaded() {
          return this.$store.state.shows.loaded
        },
    
        temporarySlug: function () {
          return this.slugify(this.newShow.name)
        },
    
        showTypeSelector: function () {
    
          return this.types.map(({ id, name }) => ({ value: id, text: name }))
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        },
    
        showFundingCategorySelector: function () {
    
          return this.fundingCategories.map(({ id, name }) => ({
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            value: id,
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          }))
        },
    
        ...mapGetters({
          types: 'shows/types',
    
          fundingCategories: 'shows/fundingCategories',
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        }),
      },
    
      methods: {
        // create a new show and POST it to the steering API
        // new shows have to at least contain a name, a slug and a short-description.
        // also a valide show type and funding category have to be choosen.
        // for all other categories we can use an empty array and let the user fill
        // it out through the existing show manager modals, after the show is created
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          // only try to add a new show if name and short description are filled out
    
          if (this.newShow.name.trim() === '' || this.newShow.shortDescription.trim() === '') {
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            // TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
            alert('Please provide at least a title and a short description for this show.')
            return
          }
          // also the type and funding category have to be set
    
          if (this.types.findIndex((type) => type.id === this.newShow.typeId) === -1) {
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            // TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
            alert('Please choose a type for this show.')
            return
          }
          if (
    
            this.fundingCategories.findIndex((cat) => cat.id === this.newShow.fundingCategoryId) === -1
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          ) {
            // TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
            alert('Please choose a funding category for this show.')
            return
          }
    
          // as the slug is a computed property we have to assign it to the new show's slug property
          this.newShow.slug = this.temporarySlug
    
    
          const modal = this.$refs.modalAddShow
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          this.$store.dispatch('shows/submitShow', {
            show: this.newShow,
            callback: (response) => {
              modal.hide()
    
              this.$router.push({ name: 'show-basic-data', params: { showId: response.data.id } })
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            },
          })
        },
    
        // clear and fetch modal data and open the modal to add new shows
        openModal() {
          this.newShow.name = ''
          this.newShow.slug = ''
    
          this.newShow.shortDescription = ''
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
          this.$refs.modalAddShow.show()
        },
      },
    }
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
    .slug {
      color: gray;
    }