FileManager.vue 6.93 KB
Newer Older
1
<template>
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
  <b-container>
    <b-row>
      <b-col>
        <h3>Dateien und Playlists</h3>
      </b-col>
      <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="loaded.shows">
          {{ shows[currentShow].name }}
        </span>
        <span v-else>Shows are being loaded</span>
      </template>
      <template slot="lead">
        <span v-if="loaded.shows">{{ shows[currentShow].short_description }}</span>
      </template>
      <hr />
      <div align="center">
        <b-button-group>
          <b-button size="lg" :variant="button.files" @click="switchMode('files')">Files</b-button>
          <b-button size="lg" :variant="button.playlists" @click="switchMode('playlists')">Playlists</b-button>
        </b-button-group>
      </div>
    </b-jumbotron>

    <div v-if="mode === 'files'">
      <div v-if="!loaded.files">
        <b-row>
          <b-col align="center">
            <img src="../assets/radio.gif" alt="loading data" />
          </b-col>
        </b-row>
      </div>
      <div v-else>
42
43
44
45
46
47
48
        <div v-if="files.length === 0" align="center">
          <b-alert show variant="warning">There are no files for this show yet.</b-alert>
          <b-button variant="success" @click="notYetImplemented">Upload a file</b-button>
        </div>
        <div v-else>
          <b-table striped :items="filesTable" />
        </div>
49
50
51
52
53
54
55
56
57
58
59
60
      </div>
    </div>

    <div v-if="mode === 'playlists'">
      <div v-if="!loaded.playlists">
        <b-row>
          <b-col align="center">
            <img src="../assets/radio.gif" alt="loading data" />
          </b-col>
        </b-row>
      </div>
      <div v-else>
61
62
63
64
65
66
67
        <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="notYetImplemented">Create a playlist</b-button>
        </div>
        <div v-else>
          <b-table striped :items="playlistsTable" />
        </div>
68
      </div>
69
    </div>
70
  </b-container>
71
72
73
</template>

<script>
74
import axios from 'axios'
75
76
import filesize from 'filesize'
import prettyDate from '../mixins/prettyDate'
77
78
79
80
81
82
83

export default {
  data () {
    return {
      shows: [],        // an array of objects describing our shows (empty at load, will be populated on created())
      currentShow: 0,   // index of the currently selected show in our shows array
      currentShowID: 0, // actual id of the currently selected show
84
85
      files: [],
      playlists: [],
86
87
88
89
90
91
92
93
94
95
96
97
      mode: 'files',
      loaded: {
        shows: false,
        files: false,
        playlists: false
      },
      button: {
        files: 'info',
        playlists: 'outline-info'
      }
    }
  },
98
  mixins: [ prettyDate ],
99
100
101
102
103
104
105
106
107
  computed: {
    filesTable: function (){
      var arr = []
      for (var i in this.files) {
        arr.push({
          id: this.files[i].id,
          artist: this.files[i].metadata.artist,
          album:this.files[i].metadata.album,
          title: this.files[i].metadata.title,
108
109
          duration: this.prettyNanoseconds(this.files[i].duration),
          size: filesize(this.files[i].size),
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
          updated: this.files[i].updated,
          actions: '...'
        })
      }
      return arr
    },
    playlistsTable: function (){
      var arr = []
      for (var i in this.files) {
        arr.push({
          id: this.files[i].id,
          other_fields: 'not yet implemented',
          updated: this.files[i].updated,
          actions: '...'
        })
      }
      return arr
    }
  },
129
  methods: {
130
131
132
    notYetImplemented: function () {
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
    },
133
134
135
136
    switchShow: function (index) {
      // set the current show and its ID to whatever we want to switch to now
      this.currentShow = index
      this.currentShowID = this.shows[this.currentShow].id
137
      this.fetchShows(this.shows[this.currentShow].slug)
138
139
140
141
142
143
144
145
146
147
    },
    switchMode: function (mode) {
      if (this.mode !== mode) {
        this.mode = mode
        for (var b in this.button) {
          if (b === mode) this.button[b] = 'info'
          else this.button[b] = 'outline-info'
        }
      }
    },
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    fetchShows: function (slug) {
      this.loaded.files = false
      this.loaded.playlists = false
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + slug + '/files'
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
      }).then(response => {
        // we don't have to check separately, if there are files, because tank
        // always provides an empty array if there are no files (or even if there is no corresponding show)
        this.files = response.data.results
        this.loaded.files = true
      }).catch(error => {
        alert('There was an error fetching files from tank: ' + error)
      })
163
      uri = process.env.VUE_APP_API_TANK + 'shows/' + slug + '/playlists'
164
165
166
167
168
169
170
171
172
173
174
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
      }).then(response => {
        // we don't have to check separately, if there are playlists, because tank
        // always provides an empty array if there are no playlists (or even if there is no corresponding show)
        this.playlists = response.data.results
        this.loaded.playlists = true
      }).catch(error => {
        alert('There was an error fetching playlists from tank: ' + error)
      })
175
176
177
178
    }
  },
  created () {
    // when we enter this module, we want to load all shows of the current user
179
    // before we search for corresponding shows in the tank
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    var uri = process.env.VUE_APP_API_STEERING_SHOWS
    // only the superuser should see all shows and therefore files and playlists
    // normal users should only see their own shows
    if (!this.$parent.user.steeringUser.is_superuser) {
      uri += '?owner=' + this.$parent.user.steeringUser.id
    }
    // now make the API call to fetch the shows
    axios.get(uri, {
      withCredentials: true,
      headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
    }).then(response => {
      if (response.data.length === 0) {
        alert('There are now shows associated with your account!')
        return
      }
      this.shows = response.data
      this.currentShowID = this.shows[0].id
      this.currentShow = 0
      this.loaded.shows = true
      this.switchShow(this.currentShow)
    }).catch(error => {
      alert('There was an error fetching shows from steering: ' + error)
    })
  }
}
205
206
207
</script>

<style>
208
209
210
211
212
div.filelistbox {
  border: 1px solid #e9ecef;
  border-radius: 0.3rem;
  padding: 1rem 2rem;
}
213
</style>