ShowManagerModalSchedules.vue 4.27 KB
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
<template>
  <div>
    <!-- Modal for adding new shows -->
    <b-modal
      id="idModalSchedules"
      ref="modalSchedules"
      title="Add/delete emission"
      size="lg"
      @ok="updateSchedules"
    >
      <p v-if="loaded.show">
        Editing schedules for <b>{{ show.name }}</b>
      </p>

      <full-calendar
        ref="calendar"
        editable="false"
        default-view="agendaWeek"
        :events="calendarSlots"
        :config="calendarConfig"
      />
    </b-modal>
  </div>
</template>

<script>
import axios from 'axios'
import {FullCalendar} from 'vue-full-calendar'
import 'fullcalendar/dist/fullcalendar.css'

export default {
  components: {
    FullCalendar,
  },
  data () {
    return {
      show: null,
      shows: [],
      timeslots: [],
      calendarSlots: [],
41
42
43

      // this is the whole configuration for our schedule calendar, including
      // rendering functions and all
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
      calendarConfig: {
        height: 600,
        firstDay: 1,
        header: {
          left: 'title',
          center: '',
          right: 'today prev,next'
        },
        views: {
          agendaWeek: {
            columnHeaderFormat: 'ddd D.M.',
            timeFormat: 'k:mm',
            slotLabelFormat: 'k:mm',
            allDaySlot: false,
          },
        },
60
61
62
63
64
        // here we add a simple tooltip to every event, so that the full title
        // of a show can be viewed
        eventRender: function(event, element) {
          element.attr('title', event.title);
        },
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
      },
      loaded: {
        show: false,
        shows: false,
        timeslots: false,
      },
    }
  },

  mounted() {
    this.$root.$on('bv::modal::shown', (bvEvent, modalId) => {
      if (this.$refs.calendar && modalId === 'idModalSchedules') {
        this.loadShows()
        this.$refs.calendar.fireMethod('render')
      }
    })
  },

  methods: {
    // opens the main modal
    open (show) {
      this.show = show
      this.loaded.show = true
      this.timeslots = []
      this.calendarSlots = []
      this.$refs.modalSchedules.show()
    },

    getShowTitleById (id) {
      let i = this.shows.findIndex(show => show.id === id)
      if (i >= 0) {
        return this.shows[i].name
      } else {
        return 'Error: no show found for this timeslot'
      }
    },

    loadTimeslots (start, end) {
      this.loaded.timeslots = false
      let uri = process.env.VUE_APP_API_STEERING + 'timeslots?start=' + start + '&end=' + end
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
      }).then(response => {
        let slots = response.data
        for (let i in slots) {
          let highlighting = 'otherShow'
          if (slots[i].show === this.show.id) {
            highlighting = 'currentShow'
          }
          this.calendarSlots.push({
            start: slots[i].start,
            end: slots[i].end,
            title: this.getShowTitleById(slots[i].show),
            className: highlighting
          })
        }
        this.loaded.timeslots = true
      }).catch(error => {
        this.$log.error(error.response.status + ' ' + error.response.statusText)
        this.$log.error(error.response)
        alert('Error: could not load timeslots. See console for details.')
      })
    },

    loadShows () {
      this.loaded.shows = false
      let uri = process.env.VUE_APP_API_STEERING + 'shows'
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
      }).then(response => {
        this.shows = response.data
        this.loaded.shows = true
        let start = this.$refs.calendar.fireMethod('getView').start.format()
        let end = this.$refs.calendar.fireMethod('getView').end.format()
        this.loadTimeslots(start, end)
      }).catch(error => {
        this.$log.error(error.response.status + ' ' + error.response.statusText)
        this.$log.error(error.response)
        alert('Error: could not load shows. See console for details.')
      })
    },

    updateSchedules () {
      this.$log.debug(this.$refs.calendar.fireMethod('getView').start.format())
    }
  },
}
</script>

<style>
.otherShow {
  background-color: #eee;
}
a.currentShow {
  background-color: #17a2b8;
}
</style>