FileManager.vue 28.1 KB
Newer Older
1
<template>
2
  <b-container>
3
4
    <!-- This first row is so far only used to provide a dropdown for
    choosing one of the loaded shows (which the user has access to) -->
5
6
7
8
9
    <b-row>
      <b-col>
        <h3>Dateien und Playlists</h3>
      </b-col>
      <b-col align="right">
10
11
12
13
14
15
        <b-dropdown
          id="ddshows"
          text="Sendereihe auswählen"
          variant="info"
        >
          <b-dropdown-item
16
            v-for="(show, index) in shows"
17
18
19
20
21
            :key="show.id"
            @click="switchShow(index)"
          >
            {{ show.name }}
          </b-dropdown-item>
22
23
24
        </b-dropdown>
      </b-col>
    </b-row>
25
    <hr>
26
27
28
29

    <!-- The jumbotron is used to display the name and short description of the
    currently selected show and let the user choose between editing files and
    playlists -->
30
31
32
33
34
35
36
37
38
39
    <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>
40
      <hr>
41
42
      <div align="center">
        <b-button-group>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
          <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>
57
58
59
60
        </b-button-group>
      </div>
    </b-jumbotron>

61
62
    <!-- All the UI for uploading and editing files is only shown if the user
    choose to edit files in the jumbotron above -->
63
    <div v-if="mode === 'files'">
64
      <!-- Only display a spinner if the files are not loaded yet -->
65
66
67
      <div v-if="!loaded.files">
        <b-row>
          <b-col align="center">
68
69
70
71
            <img
              src="../assets/radio.gif"
              alt="loading data"
            >
72
73
74
          </b-col>
        </b-row>
      </div>
75
76
77
78

      <!-- If all file data is loaded we can present an upload button and
      a table of files (if there are already any or if there are any already
      being uploaded/imported )-->
79
      <div v-else>
80
81
82
83
        <!-- Modal: Add new file
        This is the modal that is used when the user clicks on the
        "Upload or add a file" button. When the user hits the OK button,
        the addFile method will be called. -->
84
85
86
87
88
        <b-modal
          id="modal-add-file"
          title="Add new file"
          @ok="addFile"
        >
89
90
          <!-- If the checkbox below is checked we only need a simple input
          for entering an URI, instead of a complete file upload dialogue -->
91
92
93
94
95
96
          <div v-if="addNewFileURI">
            <b-row>
              <b-col md="2">
                <b>Link:</b>
              </b-col>
              <b-col>
97
98
99
100
101
                <b-form-input
                  v-model="uploadSourceURI"
                  type="url"
                  placeholder="Insert a HTTP(S) link here"
                />
102
103
104
              </b-col>
            </b-row>
          </div>
105
106
          <!-- If the checkbox is not checked, we provide a file selection
          dialogue instead of a simple input for an URI -->
107
          <div v-else>
108
109
110
111
112
113
            <b-form-file
              v-model="uploadSourceFile"
              accept="audio/*"
              placeholder="Choose a file..."
              drop-placeholder="Drop file here..."
            />
114
          </div>
115

116
          <hr>
117
118
119

          <!-- This checkbox determines whether there is just a simple input
          or a file selection dialogue (see above) -->
120
          <div align="center">
121
122
123
124
125
            <b-form-checkbox
              v-model="addNewFileURI"
              value="true"
              unchecked_value="false"
            >
126
127
128
129
              Download from remote source instead of uploading a file
            </b-form-checkbox>
          </div>
        </b-modal>
130
131
132
133
134

        <!-- Modal: Edit meta information
        This modal lets the user change a file's meta information (artist,
        album, title). When the user hits OK, the saveFile method is called.
        -->
135
136
137
138
139
140
        <b-modal
          id="modal-edit-file"
          title="Edit meta information"
          size="lg"
          @ok="saveFile"
        >
141
          <!-- Input element: Artist -->
142
          <b-row>
143
144
145
146
147
148
149
150
151
            <b-col md="2">
              Artist:
            </b-col>
            <b-col>
              <b-form-input
                v-model="temp.artist"
                type="text"
              />
            </b-col>
152
          </b-row>
153
154

          <!-- Input element: Album -->
155
          <b-row>
156
157
158
159
160
161
162
163
164
            <b-col md="2">
              Album:
            </b-col>
            <b-col>
              <b-form-input
                v-model="temp.album"
                type="text"
              />
            </b-col>
165
          </b-row>
166
167

          <!-- Input element: Title -->
168
          <b-row>
169
170
171
172
173
174
175
176
177
            <b-col md="2">
              Title:
            </b-col>
            <b-col>
              <b-form-input
                v-model="temp.title"
                type="text"
              />
            </b-col>
178
          </b-row>
179

180
          <hr>
181
182
183
184
185

          <!-- As additional orientation we provide the source this file was
          uploaded/imported from. This might help the user to manage all files
          and set the meta information accordingly.
          -->
186
          <b-row>
187
188
189
            <b-col md="2">
              Sourced from:
            </b-col>
190
191
192
            <b-col>{{ temp.uri }}</b-col>
          </b-row>
        </b-modal>
193
194
195

        <!-- Now for the files. If there are none yet, just show an alert and
        a button for uploading/importing a new file -->
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
        <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
            v-b-modal.modal-add-file
            variant="success"
          >
            Upload or add a file
          </b-button>
212
        </div>
213
214
215

        <!-- If there already are files for this show we'll show the button
        for uploading/importing a new file and then a table with all files -->
216
        <div v-else>
217
          <!-- This is the button -->
218
219
220
221
222
223
224
225
226
227
          <div
            align="center"
            style="padding-bottom: 1.5em;"
          >
            <b-button
              v-b-modal.modal-add-file
              variant="success"
            >
              Upload or add a file
            </b-button>
228
          </div>
229
230

          <!-- And here comes the table -->
231
232
233
234
235
236
          <b-table
            ref="filesTable"
            striped
            :fields="filesTableFields"
            :items="files"
          >
237
238
239
240
241
242
243
244
245
246
            <!-- The first two columns in the table (Index & Artist) are filled
            in automatically, because we do not use these fields for displaying
            upload/import progress information.
            -->

            <!-- Column: Album
            This column displays either the album meta information or, in case
            the file is just being uploaded/imported, a spinner visualising an
            ongoing import.
            -->
247
248
249
250
251
252
253
254
255
            <template
              slot="metadata.album"
              slot-scope="data"
            >
              <span v-if="data.item.source.import.state !== 'done'"><img
                src="../assets/radio.gif"
                width="24"
                alt="loading data"
              ></span>
256
257
              <span v-else>{{ data.value }}</span>
            </template>
258
259
260
261
262
263

            <!-- Column: Title
            This column displays either the title meta information or, in case
            the file is just being uploaded/imported, the current phase
            of the ongoing import (fetching or normalizing).
            -->
264
265
266
267
            <template
              slot="metadata.title"
              slot-scope="data"
            >
268
269
              <span v-if="data.item.source.import.state === 'done'">{{ data.value }}</span>
              <span v-else-if="data.item.source.import.progress !== undefined">{{ data.item.source.import.progress.step }} :</span>
270
            </template>
271
272
273
274
275

            <!-- Column: Duration
            This column displays either the duration of the audio file, or, if
            the file is just being uploaded/imported, the current progress.
            -->
276
277
278
279
            <template
              slot="duration"
              slot-scope="data"
            >
280
              <!-- In case the import is already done just print a pretty duration -->
281
282
283
              <div v-if="data.item.source.import.state === 'done'">
                {{ prettyNanoseconds(data.value) }}
              </div>
284
285
286
287
              <!-- Or print the progress for ongoing imports. We use the variant
              prop of the b-progress to display the bar in different colours -
              either the info variant for the fetching phase or the success
              variant for the normalizing phase -->
288
              <div v-else-if="data.item.source.import.progress !== undefined">
289
290
291
292
293
294
295
                <b-progress
                  :value="data.item.source.import.progress.progress"
                  :max="1"
                  show-progress
                  :variant="data.item.source.import.progress.step === 'fetching' ? 'info' : 'success'"
                  animated
                />
296
              </div>
297
            </template>
298
299
300
301
302

            <!-- Column: Size
            This column displays the size of the audio file, if the file is
            already fully imported. Otherwise we'll just leave it empty.
            -->
303
304
305
306
            <template
              slot="size"
              slot-scope="data"
            >
307
              <span v-if="data.item.source.import.state === 'done'">{{ prettyFileSize(data.value) }}</span>
308
            </template>
309
310
311
312
313

            <!-- Column: Actions
            This column displays the available button for actions  the user can
            take on this file (e.g. editing and deleting).
            -->
314
315
316
317
            <template
              slot="actions"
              slot-scope="data"
            >
318
              <b-button-group size="sm">
319
320
321
322
323
324
325
326
327
                <b-button @click="editFile(data.item.id)">
                  Edit
                </b-button>
                <b-button
                  variant="danger"
                  @click="deleteFile(data.item.id)"
                >
                  Delete
                </b-button>
328
329
330
              </b-button-group>
            </template>
          </b-table>
331
        </div>
332
        <!-- End of files table -->
333
334
335
      </div>
    </div>

336
337
    <!-- All the UI for creating and editing playlists is only shown if the user
    choose to edit playlists in the jumbotron above -->
338
    <div v-if="mode === 'playlists'">
339
      <!-- Only display a spinner if the playlists are not loaded yet -->
340
341
342
      <div v-if="!loaded.playlists">
        <b-row>
          <b-col align="center">
343
344
345
346
            <img
              src="../assets/radio.gif"
              alt="loading data"
            >
347
348
349
          </b-col>
        </b-row>
      </div>
350
351
352

      <!-- If all playlist data is loaded we can present an create button and
      a table of playlists (if there are already any)-->
353
      <div v-else>
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
        <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>
370
371
        </div>
        <div v-else>
372
373
374
375
          <b-table
            striped
            :items="playlistsTable"
          />
376
        </div>
377
      </div>
378
    </div>
379
  </b-container>
380
381
382
</template>

<script>
383
import axios from 'axios'
384
385
import filesize from 'filesize'
import prettyDate from '../mixins/prettyDate'
386
387

export default {
388
  // generic functions that we want to use from our mixins folder
389
  mixins: [ prettyDate ],
390
391
392

  // the data this component will be handling: mostly flags and local versions
  // of the data fetched from the AuRa tank API
393
394
395
396
397
  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
398
399
      files: [],
      playlists: [],
400
      mode: 'files',
401
      uploadInterval: null,
402
403

      // some flags to signal if API data is already fully loaded
404
405
406
407
408
      loaded: {
        shows: false,
        files: false,
        playlists: false
      },
409
410
411
412
413
414
415

      // variables used by file upload/import modal
      addNewFileURI: false,
      uploadSourceURI: '',
      uploadSourceFile: null,

      // we need this for the modal to edit a file's meta information
416
417
418
419
420
421
      temp: {
        id: null,
        artist: '',
        album: '',
        title: ''
      },
422
423

      // for formatting the buttons - this way we could customize it later
424
425
426
      button: {
        files: 'info',
        playlists: 'outline-info'
427
      },
428
429

      // configuration of the files table, which will use the files array as data
430
431
432
433
434
435
436
437
438
      filesTableFields: [
        { key: 'id', label: 'Index' },
        { key: 'metadata.artist', label: 'Artist' },
        { key: 'metadata.album', label: 'Album' },
        { key: 'metadata.title', label: 'Title' },
        { key: 'duration', label: 'Duration' },
        { key: 'size', label: 'Size' },
        { key: 'actions', label: 'Actions' },
      ]
439
440
    }
  },
441
442
443

  // TODO: if we can use the playlists object itself (similar to the files in
  // in the files table, we can get rid of the computed properties)
444
445
446
447
448
449
450
451
452
453
454
455
456
457
  computed: {
    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
    }
  },
458
459
460
461
462

  // Right after this component is set up, we want to fetch all available shows
  // from the AuRa tank module. This works quite similar to the ShowManager.
  // We also want to load the files and playlists as soon as the shows are
  // loaded.
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
  created () {
    // when we enter this module, we want to load all shows of the current user
    // before we search for corresponding shows in the tank
    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)
    })
  },
490
491
492

  // Now for our hotchpotch of methods, mostly for fetching data from and
  // posting/updating data to the AuRa tank API
493
  methods: {
494
495
496

    // Just a placeholder function we can use in the UI, to signal if something
    // is not yet implemented
497
498
499
    notYetImplemented: function () {
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
    },
500
501
502

    // We want to have a nice format for the file size, given a size in Bytes.
    // For that we're useing the filesize npm module.
503
504
505
    prettyFileSize: function (s) {
      return filesize(s)
    },
506
507

    // Returns a file object from the files array, given a file ID
508
509
510
511
512
513
514
515
    getFileById: function (id) {
      for (var i in this.files) {
        if (this.files[i].id === id) {
          return this.files[i]
        }
      }
      return null
    },
516
517
518
519

    // To start modifying the meta information for a file we have to set our
    // temporary data (which will be used to check if anything changed) and
    // then open the editing modal
520
    editFile: function (id) {
521
522
523
524
525
526
527
528
      var file = this.getFileById(id)
      this.temp.id = file.id
      this.temp.artist = file.metadata.artist
      this.temp.album = file.metadata.album
      this.temp.title = file.metadata.title
      this.temp.uri = file.source.uri
      this.$bvModal.show('modal-edit-file')
    },
529
530
531
532

    // Once the OK button is hit in the file editing modal, we have to check
    // if anything changed and then send an appropriate metadata obecjt to
    // the AuRa tank API to update it
533
534
    saveFile: function (){
      var file = this.getFileById(this.temp.id)
535
      // we only want to send a PATCH request if some metadata actually changed
536
      if (this.temp.artist !== file.metadata.artist || this.temp.album !== file.metadata.album || this.temp.title !== file.metadata.title ) {
537
538
539
        // if a metadata property was in use before and now shall be emptied
        // we cannot just omit the property, but have to explicitly send null
        var metadata = {
540
          artist: this.temp.artist ? this.temp.artist : null,
541
542
543
          album: this.temp.album ? this.temp.album : null,
          title: this.temp.title ? this.temp.title : null
        }
544
        var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + file.id
545
        // TODO: add mechanism to indicate the running patch request in the files table
546
547
548
549
550
551
552
553
554
555
556
        axios.patch(uri, metadata, {
          withCredentials: true,
          headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
        }).then(response => {
          this.getFileById(this.temp.id).metadata = response.data.metadata
        }).catch(error => {
          console.log('Error:')
          console.log(error)
          alert('Error: could not save metadata info to file. See console log for details.')
        })
      }
557
    },
558
559
560

    // Deletes a file with a specific, calling the AuRa tank API and afterwards
    // fetching a fresh list of files from it.
561
562
    deleteFile: function (id) {
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id
563
      // TODO: add mechanism to indicate the running delete request in the files table
564
565
566
567
      axios.delete(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token },
      }).then(
568
        this.fetchFiles(this.shows[this.currentShow].slug)
569
570
571
572
573
574
      ).catch(error => {
        console.log('Error:')
        console.log(error)
        alert('Error: could not delete file. See console log for details.')
      })
    },
575
576
577
578
579
580

    // With this function we add a new file in the AuRa tank by calling its API.
    // Depending on wheter we add a remote file which tank then imports by itself,
    // or if we want to upload a local file, we source-uri has to look different.
    // And for uploading a local file this is just the first step. Afterwards the
    // actual upload has to be started with the startUpload function.
581
    addFile: function () {
582
583
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files'
      if (this.addNewFileURI) {
584
585
586
587
        // TODO: add mechanism to indicate the running post request in the files table
        axios.post(uri, { 'source-uri': this.uploadSourceURI }, {
          withCredentials: true,
          headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
588
        }).then(() => {
589
          this.fetchFiles(this.shows[this.currentShow].slug)
590
591
592
593
          if (this.uploadInterval === null) {
            this.uploadInterval = setInterval(() => { this.fetchImports(this.shows[this.currentShow].slug) }, 250)
          }
        }).catch(error => {
594
595
596
597
          console.log('Error:')
          console.log(error)
          alert('Error: could not add the new remote import. See console log for details.')
        })
598
      } else if (this.uploadSourceFile) {
599
        // TODO: add mechanism to indicate the running post request in the files table
600
601
602
603
604
        axios.post(uri, { 'source-uri': encodeURI('upload://' + this.uploadSourceFile.name) }, {
          withCredentials: true,
          headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
        }).then(response => {
          this.startUpload(response.data.id)
605
          this.fetchFiles(this.shows[this.currentShow].slug)
606
607
608
          if (this.uploadInterval === null) {
            this.uploadInterval = setInterval(() => { this.fetchImports(this.shows[this.currentShow].slug) }, 250)
          }
609
610
611
612
613
614
        }).catch(error => {
          console.log('Error:')
          console.log(error)
          alert('Error: could not add the new file upload. See console log for details.')
        })
      } else {
615
        alert('Something is wrong. You have choosen to upload a file, but the corresponding file object does not exist.')
616
617
      }
    },
618
619
620
621

    // When a new file was added with the addFile function we can start an upload
    // fetching the import endpoint of this file and then call the upload
    // function, which atually puts the file onto the server.
622
623
624
625
626
627
628
629
630
631
632
633
634
635
    startUpload: function (id) {
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/import'
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token },
        params: {'wait-for': 'running'}
      }).then(
        this.upload(id)
      ).catch(error => {
        console.log('Error:')
        console.log(error)
        alert('Error: could not start the file upload. See console log for details.')
      })
    },
636
637
638

    // Upload a file to the AuRa tank API - given it was created with the addFile
    // and started with the startUpload methods.
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    upload: function (id) {
      /*
       * NOTE: there is no npm package for flow.js and importing it manually did not
       *       work so far. therefore this is commented out and we are using the simple
       *       upload method, until there is a nice npm package for flow.js or somone
       *       resolves this issue otherwise
      var flow = new Flow({
        target: process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/upload',
        chunkSize: 100 * 1024,
        prioritizeFirstAndLastChunk: true
      })
      flow.on('fileSuccess', function(file, message) {
        console.log(file, message)
      })
      flow.on('fileError', function(file, message) {
        console.log(file, message)
        alert('Error: could not upload your file. See console log for details.')
      })
      flow.addFile(this.uploadSourceFile)
      flow.upload()
      */
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/upload'
      axios.put(uri, this.uploadSourceFile, {
        withCredentials: true,
        headers: {
          'Authorization': 'Bearer ' + this.$parent.user.access_token,
          'Content-Type': 'application/octet-stream'
        }
667
668
669
670
671
672
673
      }).then(() => {
        console.log('Sucessfully uploaded file.')
        // now we start polling for the import progress
        // the fetchImports function has to make sure to deactivate the interval
        // again, when all running imports are done (in this first raw version;
        // ideally we should refine this so that every single file gets updated independently)
        //this.uploadInterval = setInterval(() => { this.fetchImports(this.shows[this.currentShow].slug) }, 100)
674
675
676
677
678
      }).catch(error => {
        console.log('Error:')
        console.log(error)
        alert('Error: could not start the file upload. See console log for details.')
      })
679
    },
680
681
682

    // This switches the UI elements to reflect another show and fetches all
    // relevent data from the tank API.
683
684
685
686
    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
687
      this.fetchShow(this.shows[this.currentShow].slug)
688
    },
689
690
691

    // This function is used to visually switch between the files and playlists
    // editing mode.
692
693
694
695
    switchMode: function (mode) {
      if (this.mode !== mode) {
        this.mode = mode
        for (var b in this.button) {
696
697
          if (b === mode) { this.button[b] = 'info' }
          else { this.button[b] = 'outline-info' }
698
699
700
        }
      }
    },
701
702
703
704
705

    // This function fetches all running imports for a given show. It should
    // be called periodically to reflect the upload/import progress. When no
    // more active imports are available the corresponding updateInterval
    // should be cleared again.
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
    fetchImports: function (slug){
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + slug + '/imports'
      axios.get(uri, {
        withCredentials: true,
        headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
      }).then(response => {
        // if all imports are done, we will receive an empty result set and stop
        // polling the server again. now we can also refetch all file statuses.
        if (response.data.results === null) {
          clearInterval(this.uploadInterval)
          this.uploadInterval = null
          this.fetchShow(slug)
        } else {
          for (var i in response.data.results) {
            var f = this.getFileById(response.data.results[i].id)
            if (f) {
              f.source.import.progress = {
                progress: response.data.results[i].progress.progress,
                step: response.data.results[i].progress.step
              }
            }
            var p = '[import]'
            p += ' id: ' + response.data.results[i].id
            p += ', progress: ' + response.data.results[i].progress.progress
            p += ', step: ' + response.data.results[i].progress.step
            console.log(p)
            this.$refs.filesTable.refresh()
          }
        }
      }).catch(error => {
        console.log(error)
        alert('There was an error fetching current imports. See console for details.')
      })
    },
740
741

    // Just a wrapper to fetch both, files and playlists information.
742
743
744
745
    fetchShow: function (slug) {
      this.fetchFiles(slug)
      this.fetchPlaylists(slug)
    },
746
747

    // Fetch all files for a given show from the AuRa tank API
748
    fetchFiles: function (slug) {
749
750
751
752
753
754
755
756
757
758
759
760
761
      this.loaded.files = 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)
      })
762
    },
763
764

    // Fetch all playlists for a given show from the AuRa tank API
765
766
767
    fetchPlaylists: function (slug) {
      this.loaded.playlists = false
      var uri = process.env.VUE_APP_API_TANK + 'shows/' + slug + '/playlists'
768
769
770
771
772
773
774
775
776
777
778
      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)
      })
779
780
781
    }
  }
}
782
783
784
</script>

<style>
785
786
787
788
789
div.filelistbox {
  border: 1px solid #e9ecef;
  border-radius: 0.3rem;
  padding: 1rem 2rem;
}
790
791
792
793
794
795
796
797
798
799
800
.stateNew {
  color: red;
  font-weight: bold;
}
.stateRunning {
  color: darkgreen;
}
.stateUndefined {
  color: orange;
  font-weight: bold;
}
801
</style>