ShowManager.vue 20 KB
Newer Older
1
<template>
2
  <b-container>
3
4
5
6
7
8
9
10
11
12
13
    <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">
14
        <span v-if="loaded.shows">{{ shows[currentShow].name }}</span>
15
16
17
        <span v-else>Shows are being loaded</span>
      </template>
      <template slot="lead">
18
        <span v-if="loaded.shows">{{ shows[currentShow].short_description }}</span>
19
20
        <img src="../assets/16x16/emblem-system.png" alt="edit short description" v-on:click="notYetImplemented" />
      </template>
21
      <p v-if="loaded.shows">
22
        <b>Description:</b> <img src="../assets/16x16/emblem-system.png" alt="edit description" v-on:click="notYetImplemented" />
23
        <div v-if="loaded.shows">
24
25
26
27
28
29
30
          <!-- 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>

31
    <div v-if="!loaded.shows">
32
33
34
      <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="loaded.timeslots">
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
              {{ prettyDate(timeslot.start) }} ({{ prettyDuration(timeslot.start, timeslot.end) }})
51
              <span v-if="loaded.notes">{{ prettyTimeslotNote(timeslot.id) }}</span>
52
              <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="loaded.timeslots">
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
                {{ prettyDate(timeslot.start) }} ({{ prettyDuration(timeslot.start, timeslot.end) }})
73
                <span v-if="loaded.notes">{{ prettyTimeslotNote(timeslot.id) }}</span>
74
                <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
        </div>
        <div v-else style="text-align: center;"><img src="../assets/radio.gif" alt="loading data" /><br /></div>
      </div>
82

83
84
      <hr />

85
      <div v-if="loaded.shows" class="showsettings">
86
        <h2>Allgemeine Einstellungen zur Sendereihe:</h2>
87
        <b-row>
88
89

          <b-col lg="6">
90
91
92
93
94
95
96
            <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>
97
98

          <b-col lg="6">
99
            <p>
100
              <b>Website:</b>
101
102
103
104
105
              <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>
106
107

          <b-col lg="6">
108
109
110
111
112
113
114
            <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>
115
116

          <b-col lg="6">
117
118
119
120
121
122
123
            <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>
124
125

          <b-col lg="6">
126
127
128
129
130
131
132
133
134
            <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>
135
136

          <b-col lg="6">
137
138
139
140
141
142
143
            <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>
144
145

          <b-col lg="6">
146
147
148
149
150
151
152
            <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>
153
154
155
156
157
158
159

        </b-row>

        <b-row>

          <b-col lg="2">
            <b>Categories <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" /> :</b>
160
          </b-col>
161
162
163
164
165
166
167
168
169
170
171
172
          <b-col lg="4">
            <div v-if="loaded.categories">
              <p v-if="shows[currentShow].category.length === 0">
                <small><i>(none set)</i></small>
              </p>
              <p v-else>
                <ul>
                  <li v-for="cat in current.categories">{{ cat.category }}</li>
                </ul>
              </p>
            </div>
            <div v-else><img src="../assets/radio.gif" height="24px" alt="loading data" /><br /></div>
173
          </b-col>
174
175
176

          <b-col lg="2">
            <b>Languages <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" /> :</b>
177
          </b-col>
178
179
180
181
182
183
184
185
186
187
188
189
          <b-col lg="4">
            <div v-if="loaded.categories">
              <p v-if="shows[currentShow].language.length === 0">
                <small><i>(none set)</i></small>
              </p>
              <p v-else>
                <ul>
                  <li v-for="lang in current.languages">{{ lang.name }}</li>
                </ul>
              </p>
            </div>
            <div v-else><img src="../assets/radio.gif" height="24px" alt="loading data" /><br /></div>
190
          </b-col>
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

          <b-col lg="2">
            <b>Topics <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" /> :</b>
          </b-col>
          <b-col lg="4">
            <div v-if="loaded.topics">
              <p v-if="shows[currentShow].topic.length === 0">
                <small><i>(none set)</i></small>
              </p>
              <p v-else>
                <ul>
                  <li v-for="topic in current.topics">{{ topic.topic }}</li>
                </ul>
              </p>
            </div>
            <div v-else><img src="../assets/radio.gif" height="24px" alt="loading data" /><br /></div>
207
          </b-col>
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

          <b-col lg="2">
            <b>Musicfocus <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" /> :</b>
          </b-col>
          <b-col lg="4">
            <div v-if="loaded.musicfocus">
              <p v-if="shows[currentShow].musicfocus.length === 0">
                <small><i>(none set)</i></small>
              </p>
              <p v-else>
                <ul>
                  <li v-for="focus in current.musicfocus">{{ focus.focus }}</li>
                </ul>
              </p>
            </div>
            <div v-else><img src="../assets/radio.gif" height="24px" alt="loading data" /><br /></div>
          </b-col>

          <b-col lg="2">
            <b>Hosts <img src="../assets/16x16/emblem-system.png" alt="edit" v-on:click="notYetImplemented" /> :</b>
          </b-col>

          <b-col lg="4">
            <div v-if="loaded.hosts">
              <p v-if="shows[currentShow].hosts.length === 0">
                <small><i>(none set)</i></small>
              </p>
              <p v-else>
                <!-- TODO: make link on name; when user clicks, open modal to edit host -->
                <ul>
                  <li v-for="host in current.hosts">{{ host.name }}</li>
                </ul>
              </p>
            </div>
            <div v-else><img src="../assets/radio.gif" height="24px" alt="loading data" /><br /></div>
          </b-col>

245
        </b-row>
246
      </div>
247
    </div>
248
  </b-container>
249
250
251
</template>

<script>
252
import timeslotSort from '../mixins/timeslotSort'
253
import axios from 'axios'
254
255
256
257
258
259
260
261
262

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

export default {
  data () {
    return {
263
264
265
266
267
      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
      currentShow: 0,   // index of the currently selected show in our shows array
      currentShowID: 0, // actual id of the currently selected show
268
      numUpcoming: 8,
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
      numRecent: 8,
      loaded: {
        shows: false,
        timeslots: false,
        notes: false,
        categories: false,
        hosts: false,
        languages: false,
        topics: false,
        musicfocus: false,
        rtrcategory: false
      },
      current: {
        categories: [],
        hosts: [],
        languages: [],
        topics: [],
        musicfocus: [],
        rtrcategory: []
      }
289
290
    }
  },
291
  mixins: [ timeslotSort ],
292
  computed: {
293
294
295
    timeslotsFutureShow: function () {
      if (this.numUpcoming === 'all') return this.timeslotsFuture
      else return this.timeslotsFuture.slice(0, this.numUpcoming)
296
    },
297
298
299
300
    timeslotsPastShow: function () {
      // if (this.numRecent === 'all') return this.timeslotsPast
      // else return this.timeslotsPast.slice(0, this.numRecent)
      return this.timeslotsPast
301
302
303
    }
  },
  methods: {
304
    switchShow: function (index) {
305
306
307
      // 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
308
309
310
311
312
313
314
315
316
      this.loaded.timeslots = false
      this.loaded.notes = false
      // also for those settings of the show which are only ids or arrays of ids
      // we have to fetch the corresponding names first
      this.loaded.categories = false
      this.loaded.hosts = false
      this.loaded.languages = false
      this.loaded.musicfocus = false
      this.loaded.rtrcategory = false
317
      // set the current show and its ID to whatever we want to switch to now
318
      this.currentShow = index
319
      this.currentShowID = this.shows[this.currentShow].id
320
321
322
323
324
325
326
      // before we load timeslots and notes, we want to fetch the general settings first
      this.getCategories()
      this.getHosts()
      this.getLanguages()
      this.getTopics()
      this.getMusicfocus()
      this.getRTRCategory()
327
      // now fetch the single timeslots for a given show from PV backend
328
      axios.get(process.env.API_STEERING_SHOWS + this.currentShowID + '/timeslots/').then(response => {
329
        this.timeslots = response.data
330
        this.loaded.timeslots = true
331
332
333
334
        // 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
335
336
337
        axios.get(process.env.API_STEERING_SHOWS + this.currentShowID + '/notes/').then(response => {
          this.notes = response.data
          this.loaded.notes = true
338
339
340
341
342
343
        }).catch(error => {
          alert('There was an error fetching notes from the server' + error)
        })
        // done fetching notes
      }).catch(error => {
        alert('There was an error fetching timeslots from the server' + error)
344
      })
345
346
347
348
349
350
351
352
353
      // 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
354
355
356
    },
    prettyDate: function (date) {
      var d = new Date(date)
357
358
      // 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())
359
360
    },
    prettyDuration: function (start, end) {
361
362
363
364
365
      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)
    },
366
367
368
369
370
371
372
373
    prettyTimeslotNote: function (timeslotID) {
      var note = this.getTimeslotNote(timeslotID)
      if (note !== null) {
        return this.prettyTitle(note)
      } else {
        return ''
      }
    },
374
375
376
377
378
    prettyTitle: function (title) {
      if (title === '') return '...'
      else if (title.length > 25) return title.slice(0, 25) + '...'
      else return title
    },
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
    // TODO: all thos getSomething functions could be probably merged into one
    // generic getItem function. Maybe this.current should be an associative array
    // instead of an object then?
    getCategories: function () {
      this.current.categories = []
      var loadingError = false
      if (this.shows[this.currentShow].category.length === 0) {
        this.loaded.categories = true
      } else {
        for (var i in this.shows[this.currentShow].category) {
          axios.get(process.env.API_STEERING + 'categories/' + this.shows[this.currentShow].category[i]).then(response => {
            this.current.categories.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching categories from the server: ' + error)
          })
        }
        if (!loadingError) this.loaded.categories = true
      }
    },
    getHosts: function () {
      this.current.hosts = []
      var loadingError = false
      if (this.shows[this.currentShow].hosts.length === 0) {
        this.loaded.hosts = true
      } else {
        for (var i in this.shows[this.currentShow].hosts) {
          axios.get(process.env.API_STEERING + 'hosts/' + this.shows[this.currentShow].hosts[i] + '/').then(response => {
            this.current.hosts.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching hosts from the server: ' + error)
          })
        }
        if (!loadingError) this.loaded.hosts = true
      }
    },
    getLanguages: function () {
      this.current.languages = []
      var loadingError = false
      if (this.shows[this.currentShow].language.length === 0) {
        this.loaded.categories = true
      } else {
        for (var i in this.shows[this.currentShow].language) {
          axios.get(process.env.API_STEERING + 'languages/' + this.shows[this.currentShow].language[i]).then(response => {
            this.current.languages.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching languages from the server: ' + error)
          })
        }
        if (!loadingError) this.loaded.categories = true
      }
    },
    getTopics: function () {
      this.current.topics = []
      var loadingError = false
      if (this.shows[this.currentShow].topic.length === 0) {
        this.loaded.topics = true
      } else {
        for (var i in this.shows[this.currentShow].topic) {
          axios.get(process.env.API_STEERING + 'topics/' + this.shows[this.currentShow].topic[i]).then(response => {
            this.current.topics.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching topics from the server: ' + error)
          })
        }
        if (!loadingError) this.loaded.topics = true
      }
    },
    getMusicfocus: function () {
      this.current.musicfocus = []
      var loadingError = false
      if (this.shows[this.currentShow].musicfocus.length === 0) {
        this.loaded.musicfocus = true
      } else {
        for (var i in this.shows[this.currentShow].musicfocus) {
          axios.get(process.env.API_STEERING + 'musicfocus/' + this.shows[this.currentShow].musicfocus[i]).then(response => {
            this.current.musicfocus.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching musicfocus from the server: ' + error)
          })
        }
      }
      if (!loadingError) this.loaded.musicfocus = true
    },
    getRTRCategory: function () {
      this.current.rtrcategory = []
      var loadingError = false
      if (this.shows[this.currentShow].rtrcategory.length === 0) {
        this.loaded.rtrcategory = true
      } else {
        for (var i in this.shows[this.currentShow].rtrcategory) {
          axios.get(process.env.API_STEERING + 'rtrcategories/' + this.shows[this.currentShow].rtrcategory[i]).then(response => {
            console.log(response.data)
            this.current.rtrcategory.push(response.data)
          }).catch(error => {
            loadingError = true
            alert('There was an error fetching RTR category from the server: ' + error)
          })
        }
      }
      if (!loadingError) this.loaded.categories = true
    },
485
    notYetImplemented: function () {
486
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
487
488
489
    }
  },
  created () {
490
491
492
493
    axios.get(process.env.API_STEERING_SHOWS).then(response => {
      this.shows = response.data
      this.currentShowID = this.shows[0].id
      this.currentShow = 0
494
      this.loaded.shows = true
495
496
497
      this.switchShow(this.currentShow)
    }).catch(error => {
      alert('There was an error fetching shows from the server: ' + error)
498
499
500
501
502
    })
  }
}
</script>

503
<style scoped>
504
div.recenttimeslots {
505
506
  margin-top: 2em;
}
507
.showsettings, .recenttimeslots, .nexttimeslots {
508
509
  text-align: left;
}
510
</style>