From e248df42e03abf313bf426c2994fede3e034d81c Mon Sep 17 00:00:00 2001
From: Fulgen301 <tokmajigeorge@gmail.com>
Date: Sun, 14 Oct 2018 18:24:14 +0200
Subject: Adapt to new picture format, support nonexistent authors

---
 src/pages/UploadDetail.vue | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'src/pages/UploadDetail.vue')

diff --git a/src/pages/UploadDetail.vue b/src/pages/UploadDetail.vue
index ec75faa..d93c16d 100644
--- a/src/pages/UploadDetail.vue
+++ b/src/pages/UploadDetail.vue
@@ -2,27 +2,27 @@
   <div>
     <div v-if="upload">
       <q-card>
-        <q-card-media v-if="upload.pictures.length > 0" overlay-position="top">
+        <q-card-media v-if="pictures.length > 0" overlay-position="top">
           <q-card-title slot="overlay">
-            {{ upload.title }}
+            {{ upload.title }} v{{ upload.version }}
             <span slot="subtitle">
-              by {{ upload.author.name }},
+              <span v-if="hasAuthor">by {{ upload.author.name }}</span>,
               updated {{ upload.updatedAt | moment("from") }}
             </span>
             <span slot="right" class="text-white" style="margin-left: 3rem">
             <q-btn @click="$router.push({name: 'upload-list'})" flat round icon="fa-times" color="negative"/>
             </span>
           </q-card-title>
-          <q-carousel class="text-width" v-if="upload.pictures.length > 1" style="height: 300px;" arrows quick-nav infinite autoplay>
-            <q-carousel-slide v-for="picture in upload.pictures" :key="picture.id" :style="`background: url('${$http.defaults.baseURL}/media/${picture.id}') no-repeat; background-size: 100% auto;`">
+          <q-carousel class="text-width" v-if="pictures.length > 1" style="height: 300px;" arrows quick-nav infinite autoplay>
+            <q-carousel-slide v-for="picture in pictures" :key="picture.id" :style="`background: url('${$http.defaults.baseURL}/media/${picture.id}') no-repeat; background-size: 100% auto;`">
             </q-carousel-slide>
           </q-carousel>
-          <div v-else :style="`background: url('${$http.defaults.baseURL}/media/${upload.pictures[0].id}') no-repeat; background-size: 100% auto; height: 300px;`">
+          <div v-else :style="`background: url('${$http.defaults.baseURL}/media/${pictures[0].id}') no-repeat; background-size: 100% auto; height: 300px;`">
           </div>
         </q-card-media>
         <q-card-title class="bg-positive text-white" v-else>
-          {{ upload.title }}
-          <span slot="subtitle" class="text-white">by {{ upload.author.name }}</span>
+          {{ upload.title }} v{{ upload.version }}
+          <span slot="subtitle" class="text-white" v-if="hasAuthor">by {{ upload.author.name }}</span>
           <span slot="right" class="text-white" style="margin-left: 3rem">updated {{ upload.updatedAt | moment("from") }}</span>
           <span slot="right" class="text-white" style="">
             <q-btn @click="$router.push({name: 'upload-list'})" flat round icon="fa-times" color="negative"/>
@@ -284,8 +284,11 @@
       routeId () {
         return this.$route.params.uploadId
       },
+      hasAuthor() {
+        return this.upload && this.upload.author && this.upload.author.name !== ""
+      },
       isAuthor () {
-        return this.upload && this.upload.author && this.upload.author.name === this.name
+        return this.hasAuthor && this.upload.author.name === this.name
       },
       name () {
         return this.$store.state.user.decodedToken.name
@@ -293,6 +296,9 @@
       loggedIn () {
         return this.$store.getters['user/loggedIn']
       },
+      pictures() {
+        return this.upload ? this.upload.files.filter(file => file["content-type"].startsWith("image/")) : []
+      },
       filesDropzoneOptions () {
         return {
           url: `${this.$http.defaults.baseURL}/media`,
-- 
cgit v1.2.3-54-g00ecf

