ShowManagerModalPlaylist.vue 5.11 KB
Newer Older
1
2
3
4
5
6
7
<template>
  <div>
    <b-modal
      ref="modalShowManagerPlaylist"
      title="Edit playlist for this timeslot"
      size="lg"
    >
8
      <p v-if="loaded">
9
10
11
12
13
14
15
16
17
18
19
20
21
        Currently chosen playlist ID:
        <span v-if="timeslotObject.playlist_id === null">
          <i><small>(none set)</small></i>
        </span>
        <span v-else>
          {{ timeslotObject.playlist_id }}
          <span v-if="currentPlaylistDescription">
            , Description: <b>{{ currentPlaylistDescription }}</b>
          </span>
        </span>
      </p>

      <p>Available playlists:</p>
22
      <div v-if="loaded">
23
24
25
26
27
28
29
30
31
        <b-table
          ref="playlistsTable"
          striped
          :fields="playlistsTableFields"
          :items="playlists"
        >
          <!-- Column: Entries
          This column displays the number of entries of the playlist.
          -->
32
          <template v-slot:cell(entries)="data">
33
34
35
36
37
38
39
40
41
42
43
44
45
46
            {{ data.value.length }} items
            <b-button
              v-b-tooltip.html="playlistToolTip(data.value)"
              variant="outline-success"
              size="sm"
            >
              show entries
            </b-button>
          </template>

          <!-- Column: Actions
          This column displays the available buttons for actions the user can
          take on this playlist (e.g. editing and deleting).
          -->
47
          <template v-slot:cell(actions)="data">
48
49
50
51
52
53
54
55
            <b-button-group size="sm">
              <b-button
                v-if="data.item.id !== timeslotObject.playlist_id"
                variant="info"
                @click="choose(data.item.id)"
              >
                Take it!
              </b-button>
56
57
58
59
60
61
62
              <b-button
                v-else
                variant="danger"
                @click="choose(null)"
              >
                Unset
              </b-button>
63
64
65
66
67
68
            </b-button-group>
          </template>
        </b-table>
      </div>
      <div v-else>
        <img
69
          src="../../assets/radio.gif"
70
71
72
          alt="loading playlists"
        >
      </div>
73
74
75
76
77
78

      <div align="center">
        <b-button :to="'files'">
          Go to FileManager
        </b-button>
      </div>
79
80
81
82
83
84
    </b-modal>
  </div>
</template>

<script>
import axios from 'axios'
85
import prettyDate from '../../mixins/prettyDate'
86
87
88
89
90
91
92
93
94
95
96

export default {
  mixins: [ prettyDate ],

  data () {
    return {
      show: null,
      schedule: null,
      timeslot: null,
      timeslotObject: null,
      playlists: null,
97
      loaded: false,
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

      playlistsTableFields: [
        { key: 'id', label: 'Index' },
        { key: 'description', label: 'Description' },
        { key: 'entries', label: 'Entries' },
        { key: 'actions', label: 'Actions', class: 'text-right' },
      ],
    }
  },

  computed: {
    currentPlaylistDescription () {
      let description = false
      if (this.timeslotObject && this.timeslotObject.playlist_id !== null) {
        let choosenList = this.playlists.find(list => list.id === this.timeslotObject.playlist_id)
        if (choosenList && choosenList.description.length > 0) {
          description = choosenList.description
        }
      }
      return description
    }
  },

  methods: {
122
    open (show, schedule, timeslot, playlists) {
123
124
125
      this.show = show
      this.schedule = schedule
      this.timeslot = timeslot
126
      this.playlists = playlists
127
      this.timeslotObject = this.getTimeslotObject(timeslot)
128
      this.loaded = true
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
      this.$refs.modalShowManagerPlaylist.show()
    },

    getTimeslotObject (id) {
      let timeslot = this.$parent.current.timeslots.find(slot => slot.id === id)
      return timeslot
    },

    choose (id) {
      let timeslot = this.getTimeslotObject(this.timeslot)
      if (timeslot === null) {
        this.$log.error('choosen playlist id', id)
        this.$log.error('timeslot id', id)
        this.$log.error('ShowManager.current.timeslots', this.$parent.current.timeslots)
        alert('Error: could not find timeslot for chosen playlist. See console for details.')
      }
      timeslot.playlist_id = id
      let show = this.$parent.shows[this.$parent.currentShow].id
      let uri = process.env.VUE_APP_API_STEERING + 'shows/' + show + '/schedules/' + timeslot.schedule + '/timeslots/' + timeslot.id + '/'
      axios.put(uri, timeslot, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
      }).then(() => {
        this.$refs.modalShowManagerPlaylist.hide()
      }).catch(error => {
        this.$log.error(error.response.status + ' ' + error.response.statusText)
        this.$log.error(error.response)
        alert('Error: could not update timeslot with chosen playlist. See console for details.')
      })
    },

    playlistToolTip (entries) {
      let text = '<div style="white-space: nowrap;" align="left">'
      for (let i in entries) {
        text += i + ': ' + entries[i].uri + '<br>'
      }
      text += '</div>'
      return text
    },

    notYetImplemented: function () {
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
    },
  }
}
</script>

<style scoped>
</style>