ShowManager.vue 14.3 KB
Newer Older
1
<template>
2
  <b-container>
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
    <b-row>
      <b-col align="right">
        <b-dropdown id="ddshows" text="Sendereihe auswählen" variant="info">
          <b-dropdown-item v-for="(show, index) in this.shows" :key="show.id" v-on:click="switchShow(index)">{{ show.name }}</b-dropdown-item>
        </b-dropdown>
      </b-col>
    </b-row>
    <hr />

    <b-jumbotron>
      <template slot="header">
        <span v-if="showsLoaded">{{ shows[currentShow].name }}</span>
        <span v-else>Shows are being loaded</span>
      </template>
      <template slot="lead">
        <span v-if="showsLoaded">{{ shows[currentShow].short_description }}</span>
        <img src="../assets/16x16/emblem-system.png" alt="edit short description" v-on:click="notYetImplemented" />
      </template>
      <p v-if="showsLoaded">
        <b>Description:</b> <img src="../assets/16x16/emblem-system.png" alt="edit description" v-on:click="notYetImplemented" />
        <div v-if="showsLoaded">
          <!-- TODO: see if we can make a nice but secure html rendering of the description -->
          {{ shows[currentShow].description.replace(/<[^>]*>/g, '') }}
          <!-- TODO: add image and logo here? -->
        </div>
      </p>
    </b-jumbotron>

    <div v-if="!showsLoaded">
      <b-row>
        <b-col align="center">
          <img src="../assets/radio.gif" alt="loading data" />
35
36
        </b-col>
      </b-row>
37
38
    </div>
    <div v-else>
39
      <p align="left">Die nächsten <select v-model="numUpcoming">
40
41
42
43
        <option>8</option>
        <option>16</option>
        <option value="all">alle</option>
      </select> Sendungen:</p>
44
      <div v-if="timeslotsLoaded">
45
46
        <b-row>
          <b-col>
47
            <div v-for="timeslot in this.timeslotsFutureShow">
48
49
              <img v-if="timeslot.playlist_id === null" src="../assets/16x16/go-top.png" alt="choose a playlist for this episode" v-on:click="notYetImplemented" />
              <img v-else src="../assets/16x16/media-playback-start.png" alt="play" v-on:click="notYetImplemented" />
50
51
52
              {{ prettyDate(timeslot.start) }} ({{ prettyDuration(timeslot.start, timeslot.end) }})
              <span v-if="notesLoaded">{{ prettyTimeslotNote(timeslot.id) }}</span>
              <span v-else style="background: ../assets/radio.gif"></span>
53
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
54
            </div>
55
56
          </b-col>
        </b-row>
57
      </div>
58
      <div v-else style="text-align: center;"><img src="../assets/radio.gif" alt="loading data" /><br /></div>
59

60
      <div class="recenttimeslots">
61
62
63
64
65
        <p>Die letzten <select v-model="numRecent">
          <option>8</option>
          <option>16</option>
          <option value="all">alle</option>
        </select> Sendungen:</p>
66
        <div v-if="timeslotsLoaded">
67
68
          <b-row>
            <b-col>
69
              <div v-for="timeslot in this.timeslotsPastShow">
70
71
                <img v-if="timeslot.playlist_id === null" src="../assets/16x16/go-top.png" alt="choose a playlist for this episode" v-on:click="notYetImplemented" />
                <img v-else src="../assets/16x16/media-playback-start.png" alt="play" v-on:click="notYetImplemented" />
72
73
74
                {{ prettyDate(timeslot.start) }} ({{ prettyDuration(timeslot.start, timeslot.end) }})
                <span v-if="notesLoaded">{{ prettyTimeslotNote(timeslot.id) }}</span>
                <span v-else style="background: ../assets/radio.gif"></span>
75
                <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
76
              </div>
77
78
            </b-col>
          </b-row>
79
80
81
82
83
        </div>
        <div v-else style="text-align: center;"><img src="../assets/radio.gif" alt="loading data" /><br /></div>
      </div>
      <hr />

84
      <div v-if="showsLoaded" class="showsettings">
85
        <h2>Allgemeine Einstellungen zur Sendereihe:</h2>
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
190
191
192
193
194
195
196
197
198
199
200
201
        <b-row>
          <b-col xl="4" lg="6">
            <p>
              <b>E-Mail:</b>
              <span v-if="shows[currentShow].email === null"><small><i>(none set)</i></small></span>
              <span v-else>{{ shows[currentShow].email }}</span>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <b>Website:</b> {{ shows[currentShow].website }}
              <span v-if="shows[currentShow].website === null"><small><i>(none set)</i></small></span>
              <span v-else><a :href="shows[currentShow].website">{{ shows[currentShow].website }}</a></span>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
              <!-- TODO: fetch name for type_id from steering api -->
              <b>Type:</b> {{ shows[currentShow].type_id }}
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
              <!-- TODO: fetch name for rtrcategory_id from steering api -->
              <b>RTR-Category:</b> {{ shows[currentShow].rtrcategory_id }}
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
              <!-- TODO: fetch name for predecessor_id from steering api -->
              <b>Predecessor:</b>
              <span v-if="shows[currentShow].predecessor_id === null"><small><i>This show has no predecessor show.</i></small></span>
              <span v-else>{{ shows[currentShow].predecessor_id }}</span>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <b>CBA Series ID:</b>
              <span v-if="shows[currentShow].cba_series_id === null"><small><i>(none set)</i></small></span>
              <span v-else>{{ shows[currentShow].cba_series_id }}</span>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p>
              <b>Fallback Pool:</b>
              <span v-if="shows[currentShow].fallback_pool === ''"><small><i>(none set)</i></small></span>
              <span v-else>{{ shows[currentShow].fallback_pool }}</span>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p v-if="shows[currentShow].category.length === 0">
              <b>Categories:</b>
              <small><i>(none set)</i></small>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
            <p v-else>
              <b>Categories:</b>
              <span v-for="cat in shows[currentShow].category">{{ cat.category }} </span>
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p v-if="shows[currentShow].language.length === 0">
              <b>Languages:</b>
              <small><i>(none set)</i></small>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
            <p v-else>
              <b>Languages:</b>
              <span v-for="lang in shows[currentShow].language">{{ lang.name }} </span>
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p v-if="shows[currentShow].topic.length === 0">
              <b>Topics:</b>
              <small><i>(none set)</i></small>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
            <p v-else>
              <b>Topics:</b>
              <span v-for="top in shows[currentShow].topic">{{ top.topic }} </span>
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p v-if="shows[currentShow].musicfocus.length === 0">
              <b>Musicfocus:</b>
              <small><i>(none set)</i></small>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
            <p v-else>
              <b>Musicfocus:</b>
              <span v-for="m in shows[currentShow].musicfocus">{{ m.focus }} </span>
            </p>
          </b-col>
          <b-col xl="4" lg="6">
            <p v-if="shows[currentShow].hosts === 0">
              <b>Hosts:</b>
              <small><i>(none set)</i></small>
              <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" />
            </p>
            <p v-else>
              <b>Hosts:</b>
              <!-- TODO: make link on name; when user clicks, open modal to edit host -->
              <span v-for="host in shows[currentShow].hosts">{{ host.name }} </span>
            </p>
          </b-col>
        </b-row>
202
      </div>
203
    </div>
204
  </b-container>
205
206
207
</template>

<script>
208
import timeslotSort from '../mixins/timeslotSort'
209
210
211
212
213
214
215
216
217

function leadingZero (num) {
  if (num < 10) return '0' + num
  else return num.toString()
}

export default {
  data () {
    return {
218
219
220
      shows: [],      // an array of objects describing our shows (empty at load, will be populated on created())
      timeslots: [],  // same as with shows, only for the related timeslots
      notes: [],      // same as with shows, only for the related notes
221
      showsLoaded: false,
222
223
224
225
      timeslotsLoaded: false,
      notesLoaded: false,
      currentShow: 0,   // index of the currently selected show in our shows array
      currentShowID: 0, // actual id of the currently selected show
226
227
228
229
      numUpcoming: 8,
      numRecent: 8
    }
  },
230
  mixins: [ timeslotSort ],
231
  computed: {
232
233
234
    timeslotsFutureShow: function () {
      if (this.numUpcoming === 'all') return this.timeslotsFuture
      else return this.timeslotsFuture.slice(0, this.numUpcoming)
235
    },
236
237
238
239
    timeslotsPastShow: function () {
      // if (this.numRecent === 'all') return this.timeslotsPast
      // else return this.timeslotsPast.slice(0, this.numRecent)
      return this.timeslotsPast
240
241
242
    }
  },
  methods: {
243
    switchShow: function (index) {
244
245
246
247
248
249
      // if we already had some show loaded with timeslots and notes, set these to
      // not loaded, so we don't display old timeslots and notes while already
      // the new show is displayed and new timeslots and notes are still loading
      this.timeslotsLoaded = false
      this.notesLoaded = false
      // set the current show and its ID to whatever we want to switch to now
250
      this.currentShow = index
251
      this.currentShowID = this.shows[this.currentShow].id
252
253
      // now fetch the single timeslots for a given show from PV backend
      this.$http.get(process.env.API_STEERING_SHOWS + this.currentShowID + '/timeslots').then(response => {
254
255
        if (response.body.hasOwnProperty('error')) alert(response.body.error)
        else {
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
          this.timeslots = response.body
          this.timeslotsLoaded = true
          // now that we have the timeslots we can fetch notes for all those timeslots
          // TODO: curently we are fetching all notes for the show into a single array
          // for bigger data sets it might be preferable to fetch only the notes for those
          // timeslots that are also visible to the user
          this.$http.get(process.env.API_STEERING_SHOWS + this.currentShowID + '/notes').then(response => {
            if (response.body.hasOwnProperty('error')) alert(response.body.error)
            else {
              this.notes = response.body
              this.notesLoaded = true
            }
          }, response => {
            alert('There was an error fetching notes from the server')
          })
          // done fetching notes
272
273
        }
      }, response => {
274
        alert('There was an error fetching timeslots from the server')
275
      })
276
277
278
279
280
281
282
283
284
      // done fetching timeslots
    },
    getTimeslotNote: function (timeslotID) {
      for (var n in this.notes) {
        if (this.notes[n].timeslot === timeslotID && this.notes[n].title !== undefined) {
          return this.notes[n].title
        }
      }
      return null
285
286
287
    },
    prettyDate: function (date) {
      var d = new Date(date)
288
289
      // note: Date.getMonth() returns the month as an index from 0 to 11
      return leadingZero(d.getDate()) + '.' + leadingZero(d.getMonth() + 1) + '.' + d.getFullYear() + ' ' + leadingZero(d.getHours()) + ':' + leadingZero(d.getMinutes())
290
291
    },
    prettyDuration: function (start, end) {
292
293
294
295
296
      var duration = (new Date(end).getTime() - new Date(start).getTime()) / 1000
      var hours = Math.floor(duration / 60 / 60)
      var minutes = (duration / 60) % 60
      return leadingZero(hours) + ':' + leadingZero(minutes)
    },
297
298
299
300
301
302
303
304
    prettyTimeslotNote: function (timeslotID) {
      var note = this.getTimeslotNote(timeslotID)
      if (note !== null) {
        return this.prettyTitle(note)
      } else {
        return ''
      }
    },
305
306
307
308
309
    prettyTitle: function (title) {
      if (title === '') return '...'
      else if (title.length > 25) return title.slice(0, 25) + '...'
      else return title
    },
310
    notYetImplemented: function () {
311
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
312
313
314
315
    }
  },
  created () {
    // fetch sendereihen from PV backend
316
    this.$http.get(process.env.API_STEERING_SHOWS).then(response => {
317
318
319
      if (response.body.hasOwnProperty('error')) {
        alert(response.body.error)
      } else {
320
        this.shows = response.body
321
322
323
        this.currentShowID = this.shows[0].id
        this.currentShow = 0
        this.showsLoaded = true
324
        this.switchShow(this.currentShow)
325
326
      }
    }, response => {
327
      alert('There was an error fetching shows from the server')
328
329
330
331
332
    })
  }
}
</script>

333
<style scoped>
334
div.recenttimeslots {
335
336
  margin-top: 2em;
}
337
.showsettings, .recenttimeslots, .nexttimeslots {
338
339
  text-align: left;
}
340
</style>