Playlists.vue 5.32 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
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
<template>
  <div>
    <edit-playlists-modal ref="editPlaylistsModal" />

    <!-- Only display a spinner if the playlists are not loaded yet -->
    <div v-if="!loaded.playlists">
      <b-row>
        <b-col align="center">
          <img
            src="../../assets/radio.gif"
            alt="loading data"
          >
        </b-col>
      </b-row>
    </div>

    <!-- If all playlist data is loaded we can present a create button and
    a table of playlists (if there are already any)-->
    <div v-else>
      <!-- If no playlists are available, only show an alert and a create button -->
      <div
        v-if="playlists.length === 0"
        align="center"
      >
        <b-alert
          show
          variant="warning"
        >
          There are no playlists for this show yet.
        </b-alert>
        <b-button
          variant="success"
          @click="addPlaylist"
        >
          Create a playlist
        </b-button>
      </div>
      <!-- In case there are playlists, show the button and then the table -->
      <div v-else>
        <div
          align="center"
          style="padding-bottom: 1.5em;"
        >
          <b-button
            variant="success"
            @click="addPlaylist"
          >
            Create a playlist
          </b-button>
        </div>
        <b-table
          id="playlistsTable"
          striped
          :fields="playlistsTableFields"
          :items="playlists"
        >
          <!-- Column: Entries
          This column displays the number of entries of the playlist.
          -->
          <template v-slot:cell(entries)="data">
            {{ data.value.length }} items
            <b-button
              v-b-tooltip.html="playlistToolTip(data.value)"
              variant="outline-success"
              size="sm"
            >
              show entries
            </b-button>
          </template>

71
72
73
74
          <!-- Column: Duration
          This column displays the duration of all playlist entries combined
          -->
          <template v-slot:cell(duration)="data">
75
            {{ playlistDuration(data) }}
76
77
          </template>

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
          <!-- Column: Last edit
          This column lists the last date this playlist was changed.
          -->
          <template v-slot:cell(updated)="data">
            {{ prettyDateTime(data.value) }}
          </template>

          <!-- Column: Actions
          This column displays the available buttons for actions the user can
          take on this playlist (e.g. editing and deleting).
          -->
          <template v-slot:cell(actions)="data">
            <b-button-group size="sm">
              <b-button @click="editPlaylist(data.item.id)">
                Edit
              </b-button>
              <b-button
                variant="danger"
                @click="deletePlaylist(data.item.id)"
              >
                Delete
              </b-button>
            </b-button-group>
          </template>
        </b-table>
      </div>
      <!-- End of playlists table -->
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import prettyDate from '../../mixins/prettyDate'
import editPlaylistsModal from './EditPlaylistModal.vue'

export default {
  components: {
    'edit-playlists-modal': editPlaylistsModal,
  },

  mixins: [ prettyDate ],

  // include the modal for displaying file import logs
  data () {
    return {
      // for adding and editing the playlists we need some temporary stuff
      playlistEditor: {
        id: null,
        mode: 'add',  // should be either 'add' or 'edit'
        description: '',
        entries: [],
        newStreamURL: null
      },

      // configuration of the playlists table, which will use the playlists array as data
      playlistsTableFields: [
        { key: 'id', label: 'Index' },
        { key: 'description', label: 'Description' },
        { key: 'entries', label: 'Entries' },
138
        { key: 'duration', label: 'Duration' },
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
        { key: 'updated', label: 'Last edit' },
        { key: 'actions', label: 'Actions', class: 'text-right' },
      ],

      playlistEditTableFields: [
        { key: 'id', label: 'Index' },
        { key: 'type', label: 'Type' },
        { key: 'source', label: 'Source' },
        { key: 'actions', label: 'Actions', class: 'text-right' },
      ]
    }
  },

  computed: {
    loaded () {
      return {
        playlists: this.$store.state.playlists.loaded.playlists,
      }
    },

    ...mapGetters({
      selectedShow: 'shows/selectedShow',
      playlists: 'playlists/playlists',
    })
  },

  methods: {
    playlistToolTip (entries) {
      let text = '<div style="white-space: nowrap;" align="left">'
      for (var i in entries) {
        text += i + ': ' + entries[i].uri + '<br>'
      }
      text += '</div>'
      return text
    },

    deletePlaylist (id) {
      // TODO: add mechanism to indicate the running delete request in the files table
      this.$store.dispatch('playlists/delete', {
        slug: this.selectedShow.slug,
        id: id
      })
    },

    addPlaylist () {
      this.$refs.editPlaylistsModal.addPlaylist()
    },

    editPlaylist (id) {
      this.$refs.editPlaylistsModal.editPlaylist(id)
    },
190

191
    playlistDuration({ item }) {
192
193
194
195
      const totalDuration = item.entries.reduce((acc, entry) => acc + entry.duration, 0)

      return this.prettyNanoseconds(totalDuration)
    }
196
197
198
  },
}
</script>