ShowManagerModalSchedules.vue 4.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<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"
21
        @view-render="renderView"
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
      />
    </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: [],
42
43

      // this is the whole configuration for our schedule calendar, including
44
      // simple event handlers that do not need the whole components scope
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
      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,
          },
        },
61
62
63
64
65
        // 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);
        },
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
      },
      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'
      }
    },

103
104
105
106
107
108
109
110
111
112
    // this is called when the user changes the calendar view, so we just
    // refetch the timeslots with the updated visible date range
    renderView (view) {
      this.$log.debug(view.start.format() + ' ' + view.end.format())
      if (this.loaded.shows) {
        this.$log.debug('refetching')
        this.loadTimeslots(view.start.format(), view.end.format())
      }
    },

113
114
    loadTimeslots (start, end) {
      this.loaded.timeslots = false
115
      this.calendarSlots = []
116
117
118
119
120
      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 => {
121
122
        this.timeslots = response.data
        for (let i in this.timeslots) {
123
          let highlighting = 'otherShow'
124
          if (this.timeslots[i].show === this.show.id) {
125
126
127
            highlighting = 'currentShow'
          }
          this.calendarSlots.push({
128
129
130
            start: this.timeslots[i].start,
            end: this.timeslots[i].end,
            title: this.getShowTitleById(this.timeslots[i].show),
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
            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>