| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <template lang="pug">
- .page--single.f-row.between
- article(v-if="!post")
- header
- p loading...
- article(v-else).f-grow.shadow
- header
- h1 {{ type }}:{{ $route.params.slug }} {{ post.title }}
- p(v-if="post.categories") categories: {{ post.categories }}
- p(v-if="post.type") type: {{ post.type }}
- p(v-if="post.subtypes") subtypes: {{ post.subtypes }}
-
- .date-info(v-if="type === 'events' || post.type === 'exhibitions'")
- p start: {{ dateFrom(post.start) }}
- p end: {{ dateFrom(post.end) }}
-
- block.post-single.block-wrapper(v-for="(block, index) in post.blocks" :block="block" :key="`block-${index}`")
-
- credits(v-if="type === 'episodes'" :post="post")
-
- sidebar(v-if="sidebar" :type="`${type}`" layout="single")
- .shadow(v-if="Object.keys(p2pPostsByType).length" v-for="p2pPostType in Object.keys(p2pPostsByType)")
- h3.t-up related {{ p2pPostType }}s
- ul
- li(v-for="relatedPost in p2pPostsByType[p2pPostType]")
- router-link(v-if="relatedPost" :to="`/${relatedPost.type}s/${relatedPost.slug}`")
- p {{ relatedPost.title }}
- </template>
-
- <script>
- import sidebar from '@/components/sidebars/sidebar'
- import gallery from '@/components/gallery/'
- import block from '@/components/content-block/block'
- import credits from '@/components/credits'
-
- import { postTypeGetters } from './mixin-post-types'
-
- import { convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
-
- export default {
- components: { sidebar, gallery, block, credits },
- props: {
- sidebar: { type: Boolean },
- id: { type: Number }
- },
- mixins: [postTypeGetters],
- data() {
- return {
- // Gallery control
- activeGalleryIndex: -1,
- activeImageID: -1
- }
- },
- computed: {
- type() { // Checks for type and fixes Episodes route edge case
- return typeFromRoute(this.$route)
- },
- /**
- * We get the actual post data using the slug
- */
- post() {
- if(!this[this.type]) return
-
- const type = dePluralize(this.type)
-
- // State not a getter!
- const singleOfTypeFromState = this[this.type][`single${convertTitleCase(type)}`]
-
- if(!singleOfTypeFromState) return
-
- return singleOfTypeFromState
- },
-
- idsForGallery() {
- return this.post.galleries[this.activeGalleryIndex].attrs.ids
- },
- /**
- * We need a convenient way to get all the images
- * broken down by gallery. We use the active gallery
- * image IDs to create a map. We match the ID to the
- * image size and url information returned by post.attached
- */
- imagesInGallery() {
- if(!this.activeGalleryIndex < 0) return {}
- // Create a map of images by their ID
- // {
- // imageId: { 'thumbnail': url, 'large': url }
- // }
- return this.idsForGallery.reduce((imageMap, id) => {
- imageMap[id] = this.post.attached[id]
- return imageMap
- }, {})
- },
- activeImageIndex() {
- return Object.keys(this.imagesInGallery).indexOf(this.activeImageID.toString())
- },
- p2pPostsByType() {
- return this.post ? Object.values(this.post.relatedto).reduce((byType, relatedPost) => {
- if(!byType[relatedPost.type]) byType[relatedPost.type] = []
- byType[relatedPost.type].push(relatedPost)
- return byType
- }, {}) : {}
- }
- },
- methods: {
- getImageIdsForGallery(galleryIndex) {
- console.log(galleryIndex)
- return galleryIndex >= 0 ? this.post.galleries[galleryIndex].attrs.ids : []
- },
- /**
- * We set the active gallery to the index.
- * Everything kicks off when activeGallery
- * is set. We also need to set the activeImageID
- * to the image clicked
- * @param {number} galleryIndex
- * @param {string} imageID
- */
- openGallery(galleryIndex, imageID) {
- this.activeGalleryIndex = galleryIndex
- this.activeImageID = imageID ? imageID : 0
- },
-
- /**
- * Everytime the posts object changes
- * we use this to set a new HERO
- * in vuex
- * @param {object} posts
- */
- checkAndSetHero(post) {
- if(!post || !post.hero) return
-
- const json = JSON.parse(post.hero)
- this.$store.commit('SET_HERO', json)
- },
-
- /**
- * Date Object from unix strings from db
- */
- dateFrom(unix) {
- return new Date( parseInt(unix) * 1000 )
- },
-
- async loadPostData() {
- /**
- * Conditionally load based on post type
- * which is derived from the route
- * !: posts watcher fires when this finishes
- */
- let type = convertTitleCase(this.type)
- let allPostsOfType = this.$store.state[this.type].all
-
- /**
- * Load posts if they're not already in state
- */
- if(!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
- const res = await this.$store.dispatch(`getAll${type}`)
- allPostsOfType = res
- console.log(`reloaded ${type}...`)
- }
- const singlePostData = Object.values(allPostsOfType).filter(post => post.slug == this.$route.params.slug)[0]
-
- if(!singlePostData) return
- await this.$store.dispatch(`getSingle${dePluralize(type)}`, singlePostData.id)
- }
- },
- watch: {
- post(newVal, oldVal) {
- this.checkAndSetHero(newVal)
- },
- $route(newVal, oldVal) {
- console.log('route changed...')
- this.loadPostData()
- }
- },
- async created() {
- this.loadPostData()
- }
- }
- </script>
-
- <style lang="postcss">
- .page--single
- article
- > ul
- list-style: none
- li
- img
- width: 100%
- </style>
|