Skip to content
Snippets Groups Projects
FallbackSelector.vue 4.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
      <b-modal
        ref="modalFallbackSelector"
        :title="$t('playlistSelector.defaultTitle')"
        :cancel-title="$t('cancel')"
        size="lg"
      >
        <p v-if="loaded">
          {{ $t('playlistSelector.currentPlaylistLabel') }}:
    
          <span v-if="show.defaultPlaylistId === null">
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <i
              ><small>{{ $t('noneSetFeminine') }}</small></i
            >
          </span>
          <span v-else>
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <br />
            <span v-if="currentPlaylistDescription">
              {{ $t('showMeta.description') }}: <b>{{ currentPlaylistDescription }}</b>
            </span>
          </span>
        </p>
    
        <div v-if="loaded">
          <b-table ref="playlistsTable" striped :fields="playlistsTableFields" :items="playlists">
            <!-- Column: Entries
    
                    This column displays the number of entries of the playlist.
                    -->
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <template #cell(entries)="data">
              <span
                v-b-tooltip.html="playlistToolTip(data.value)"
                class="tw-underline hover:tw-no-underline tw-cursor-help"
              >
                {{ $t('playlistTable.items', { smart_count: data.value.length }) }}
              </span>
            </template>
    
            <!-- Column: Duration
    
                    This column displays the number of entries of the playlist.
                    -->
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <template #cell(duration)="data">
              {{ playlistDuration(data.item) }}
            </template>
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <!-- Column: Actions
    
                    This column displays the available buttons for actions the user can
                    take on this playlist (e.g. editing and deleting).
                    -->
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            <template #cell(actions)="data">
              <b-button-group size="sm">
                <b-button
    
                  v-if="data.item.id !== show.defaultPlaylistId"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  variant="info"
                  @click="choose(data.item.id)"
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                  {{ $t('playlistTable.assign') }}
    
                </b-button>
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
                <b-button v-else variant="danger" @click="choose(null)">
                  {{ $t('playlistTable.unset') }}
                </b-button>
              </b-button-group>
            </template>
          </b-table>
        </div>
        <div v-else>
          <img src="/assets/radio.gif" :alt="$t('loading')" />
        </div>
    
        <div>
          <b-button :to="'files'">
            {{ $t('playlistSelector.goToFiles') }}
          </b-button>
        </div>
      </b-modal>
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
    import { mapGetters } from 'vuex'
    
    import prettyDate from '@/mixins/prettyDate'
    import playlist from '@/mixins/playlist'
    
    export default {
      mixins: [prettyDate, playlist],
    
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
      data() {
        return {
          saveFunction: null,
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
      },
    
      computed: {
        loaded() {
          return this.$store.state.playlists.loaded.playlists
        },
    
        playlistsTableFields() {
          return [
            { key: 'id', label: this.$t('playlistTable.index') },
            { key: 'description', label: this.$t('playlistTable.description') },
            { key: 'entries', label: this.$t('playlistTable.entries') },
            { key: 'duration', label: this.$t('playlistTable.duration') },
            { key: 'actions', label: this.$t('playlistTable.actions'), class: 'text-right' },
          ]
        },
    
        currentPlaylistDescription() {
          let description = false
    
          if (this.show.defaultPlaylistId !== null) {
            const choosenList = this.playlists.find((list) => list.id === this.show.defaultPlaylistId)
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            if (choosenList && choosenList.description.length > 0) {
              description = choosenList.description
            }
          }
          return description
        },
    
        ...mapGetters({
          playlists: 'playlists/playlists',
        }),
      },
    
      methods: {
        open(saveFunction) {
          this.saveFunction = saveFunction
          this.$refs.modalFallbackSelector.show()
        },
    
        hide() {
          this.$refs.modalFallbackSelector.hide()
        },
    
        choose(id) {
          this.saveFunction(id)
        },
    
        playlistToolTip(entries) {
          let text = '<div style="white-space: nowrap;" align="left">'
    
          for (const i in entries) {
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
            text += i + ': ' + entries[i].uri + '<br>'
          }
          text += '</div>'
          return text
        },
      },
    }