Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
178
179
180
181
182
183
184
185
186
187
188
189
<template>
<div>
<b-modal
ref="modalShowManagerPlaylist"
title="Edit playlist for this timeslot"
size="lg"
>
<p v-if="loaded.playlists">
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>
<div v-if="loaded.playlists">
<b-table
ref="playlistsTable"
striped
:fields="playlistsTableFields"
:items="playlists"
>
<!-- Column: Entries
This column displays the number of entries of the playlist.
-->
<template
slot="entries"
slot-scope="data"
>
{{ 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).
-->
<template
slot="actions"
slot-scope="data"
>
<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>
</b-button-group>
</template>
</b-table>
</div>
<div v-else>
<img
src="../assets/radio.gif"
alt="loading playlists"
>
</div>
</b-modal>
</div>
</template>
<script>
import axios from 'axios'
import prettyDate from '../mixins/prettyDate'
export default {
mixins: [ prettyDate ],
data () {
return {
show: null,
schedule: null,
timeslot: null,
timeslotObject: null,
playlists: null,
loaded: {
playlists: false,
},
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: {
open (show, schedule, timeslot) {
this.show = show
this.schedule = schedule
this.timeslot = timeslot
this.timeslotObject = this.getTimeslotObject(timeslot)
this.loadPlaylists()
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
},
loadPlaylists () {
this.loaded.playlists = false
let uri = process.env.VUE_APP_API_TANK + 'shows/' + this.show.slug + '/playlists'
axios.get(uri, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
}).then(response => {
// we don't have to check separately, if there are playlists, because tank
// always provides an empty array if there are no playlists (or even if there is no corresponding show)
this.playlists = response.data.results
this.loaded.playlists = true
}).catch(error => {
this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response)
alert('Error: could not fetch playlists from tank. See console for details.')
})
},
notYetImplemented: function () {
alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
},
}
}
</script>
<style scoped>
</style>