Browse Source

Merge branch 'master' of ssh://gitea.yvvas.com:4022/craft-in-america/vue-wp

tags/0.9.0
j 5 years ago
parent
commit
195f3c85f0

+ 22
- 8
plugins/cia-endpoints/includes/class.make-endpoint.php View File

@@ -51,6 +51,25 @@ class Make_Endpoint_For extends WP_REST_Controller {
51 51
         return new WP_REST_Response( $this->prepare_item_for_response($args), 200 );
52 52
     }
53 53
 
54
+    private function _getAttachments($item) {
55
+        // Get media
56
+        $attached = array();
57
+            
58
+        // Image sizes you want
59
+        $desiredSizes = ['thumbnail', 'medium', 'large', 'full'];
60
+        
61
+        foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
62
+            $imageSizes = array();
63
+            foreach ( $desiredSizes as $size ):
64
+                $imageSizes[$size] = wp_get_attachment_image_url($attached_media->ID, $size);
65
+            endforeach;
66
+            // store size:url map under image id
67
+            $attached[$attached_media->ID] = $imageSizes;
68
+        endforeach;
69
+
70
+        return $attached;
71
+    }
72
+
54 73
     public function prepare_item_for_response( $args ) {
55 74
         $collection = array();
56 75
         
@@ -63,16 +82,11 @@ class Make_Endpoint_For extends WP_REST_Controller {
63 82
                 parse_blocks( $item->post_content )
64 83
             );
65 84
 
66
-            // Get media
67
-            $media_ids = [];
68
-            foreach (get_attached_media( '', $item->ID ) as $attached_media):
69
-                array_push($media_ids, $attached_media->ID);
70
-            endforeach;
71
-            $filtered[attached] = $media_ids;
85
+            $filtered[attached] = $this->_getAttachments($item);
72 86
             
73 87
             // Galleries From blocks
74
-            $galleries = [];
75
-            foreach (get_attached_media( '', $item->ID ) as $attached_media):
88
+            $media_ids = array();
89
+            foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
76 90
                 array_push($media_ids, $attached_media->ID);
77 91
             endforeach;
78 92
             $filtered[galleries] = get_ids_from_gallery_block(

+ 1
- 0
plugins/cia-post-types/cia-post-types.php View File

@@ -56,6 +56,7 @@ class PostType {
56 56
         ];
57 57
         
58 58
         if( $this->post_type == 'artist' ) { $args['taxonomies'] = ['category']; }
59
+        if( $this->post_type == 'event' ) { $args['taxonomies'] = ['type']; }
59 60
 
60 61
         register_post_type( $this->post_type, $args );
61 62
     }

+ 12
- 9
plugins/cia-post-types/includes/custom-types.php View File

@@ -1,18 +1,23 @@
1 1
 <?php
2 2
     function get_all_custom_types() {
3 3
         return [
4
-            // 'customtype',
5 4
             'artist',
6 5
             'episode',
6
+            'event',
7
+                // 'talk',
8
+            
7 9
             // 'short',
8
-            // 'talk',
9
-            // 'object',
10
+                // 'technique',
11
+            
12
+                // 'object',
13
+
10 14
             // 'guide',
11
-            // 'event',
15
+
12 16
             // 'exhibition',
13
-            // 'technique',
14
-            // 'profile',
17
+            
15 18
             // 'publication',
19
+                // 'profile',
20
+            
16 21
             // 'release',
17 22
             // 'article',
18 23
             // 'product'
@@ -30,9 +35,7 @@
30 35
             case 'short':
31 36
                 return 'dashicons-video-alt3';
32 37
                 break;
33
-            case 'talk':
34
-                return 'dashicons-format-chat';
35
-                break;
38
+
36 39
             case 'object';
37 40
                 return 'dashicons-visibility';
38 41
                 break;

+ 1830
- 2127
vue-theme/package-lock.json
File diff suppressed because it is too large
View File


+ 14
- 14
vue-theme/package.json View File

@@ -15,35 +15,35 @@
15 15
   "author": "TOJ",
16 16
   "license": "UNLICENSED",
17 17
   "devDependencies": {
18
-    "@babel/core": "^7.12.3",
18
+    "@babel/core": "^7.12.10",
19 19
     "@babel/plugin-syntax-dynamic-import": "^7.8.3",
20
-    "@babel/preset-env": "^7.9.0",
21
-    "@vue/compiler-sfc": "^3.0.2",
22
-    "axios": "^0.19.2",
23
-    "babel-loader": "^8.1.0",
20
+    "@babel/preset-env": "^7.12.11",
21
+    "@vue/compiler-sfc": "^3.0.5",
22
+    "axios": "^0.21.1",
23
+    "babel-loader": "^8.2.2",
24 24
     "css-loader": "^3.6.0",
25
-    "file-loader": "^6.1.1",
25
+    "file-loader": "^6.2.0",
26 26
     "postcss-calc": "^7.0.5",
27 27
     "postcss-import": "^12.0.1",
28 28
     "postcss-loader": "^3.0.0",
29 29
     "precss": "^4.0.0",
30 30
     "pug": "^2.0.4",
31
-    "pug-plain-loader": "^1.0.0",
31
+    "pug-plain-loader": "^1.1.0",
32 32
     "style-loader": "^2.0.0",
33 33
     "sugarss": "^2.0.0",
34
-    "url-loader": "^4.0.0",
34
+    "url-loader": "^4.1.1",
35 35
     "vue-hot-reload-api": "^2.3.4",
36
-    "vue-loader": "^16.0.0-beta.8",
36
+    "vue-loader": "^16.1.2",
37 37
     "vue-template-compiler": "^2.6.12",
38
-    "webpack": "^4.44.2",
38
+    "webpack": "^4.45.0",
39 39
     "webpack-cli": "^3.3.12",
40
-    "webpack-dev-server": "^3.11.0"
40
+    "webpack-dev-server": "^3.11.1"
41 41
   },
42 42
   "dependencies": {
43 43
     "compression-webpack-plugin": "^3.1.0",
44
-    "vue": "^3.0.2",
45
-    "vue-router": "^4.0.0-rc.1",
46
-    "vuex": "^4.0.0-beta.4"
44
+    "vue": "^3.0.5",
45
+    "vue-router": "^4.0.2",
46
+    "vuex": "^4.0.0-rc.2"
47 47
   },
48 48
   "babel": {
49 49
     "presets": [

+ 17
- 25
vue-theme/src/components/gallery.vue View File

@@ -1,18 +1,11 @@
1 1
 <template lang="pug">
2 2
 .gallery.active.f-col.center
3 3
     button(@click="hideGallery").hide hide
4
-    
5
-    .wrap(v-if="allMediaLoaded")
6
-        p image: {{ imageIds[activeImageIndex] }}
7
-        p {{ imageIds }}
8
-        p {{ allMedia }}
9
-    .loading(v-else)
10
-        p loading...
11 4
 
12
-    ul
13
-        li(v-for="(image, i) of images" :class="{ active: i === selected }")
14
-            .image-wrapper.f-col.center
15
-                img(:src="image")
5
+    figure.f-col.center
6
+        img(v-if="selectedImageUrl" :src="selectedImageUrl")
7
+        p placeholder caption
8
+
16 9
     .controls.f-row
17 10
         button(@click="prev") left
18 11
         .f-grow
@@ -26,11 +19,21 @@ export default {
26 19
     props: {
27 20
         imageIds: { type: Array, required: true },
28 21
         activeImageIndex: { type: Number, default: 0 },
29
-        activeGalleryIndex: { type: Number },
22
+        imageSizes: { required: true }
30 23
     },
31 24
     data() { 
32 25
         return {
33
-            selected: -1
26
+            selected: 0
27
+        }
28
+    },
29
+    computed:{
30
+        selectedImageId() {
31
+            return this.imageIds[this.selected]
32
+        },
33
+        selectedImageUrl() {
34
+            const image = this.imageSizes[this.selectedImageId]
35
+            if(!image) return
36
+            return image.large
34 37
         }
35 38
     },
36 39
     computed: {
@@ -98,18 +101,7 @@ export default {
98 101
             z-index: 1011
99 102
         button.hide
100 103
             z-index: 1100
101
-        ul
102
-            list-style: none
103
-            li
104
-                display: none
105
-                &.active
106
-                    display: block
107
-                .image-wrapper
108
-                    height: 100%
109
-                    width: 50vw
110
-                    background-color: yellow
111
-                h1
112
-                    color: green
104
+
113 105
         .controls
114 106
             position: absolute
115 107
             width: 100vw

+ 4
- 4
vue-theme/src/components/navigation/navigation.vue View File

@@ -9,16 +9,16 @@ nav.main.f-row.center
9 9
         li.f-grow
10 10
             p &nbsp;
11 11
         li
12
-            router-link(to="/")
12
+            router-link(:to="`/`")
13 13
                 p.t-up home
14 14
         li
15
-            router-link(to="/posts")
15
+            router-link(:to="`/posts`")
16 16
                 p.t-up news
17 17
         li
18
-            router-link(to="/artists")
18
+            router-link(:to="`/artists`")
19 19
                 p.t-up artists
20 20
         li
21
-            router-link(to="/episodes")
21
+            router-link(:to="`/episodes`")
22 22
                 p.t-up episodes
23 23
 </template>
24 24
 

+ 4
- 4
vue-theme/src/pages/index.vue View File

@@ -3,25 +3,25 @@
3 3
 .page--index.f-row.between
4 4
     article.f-grow
5 5
         .f-row
6
-            section(v-if="allEpisodesLoaded").shadow
6
+            section(v-if="allEpisodesLoaded && allEpisodes.length").shadow
7 7
                 router-link(:to="`./episodes`")
8 8
                     h4.t-cap episodes
9 9
                 router-link(:to="{ path: `/episodes/${Object.values(allEpisodes)[0].slug}` }")
10 10
                     p {{ Object.values(allEpisodes)[0].title }}
11 11
 
12
-            section(v-if="allArtistsLoaded").shadow
12
+            section(v-if="allArtistsLoaded && allArtists.length").shadow
13 13
                 router-link(:to="`./artists`")
14 14
                     h4.t-cap artists
15 15
                 router-link(:to="{ path: `/artists/${Object.values(allArtists)[0].slug}` }")
16 16
                     p {{ Object.values(allArtists)[0].title }}
17 17
                     
18
-            section(v-if="allPagesLoaded").shadow
18
+            section(v-if="allPagesLoaded && allPages.length").shadow
19 19
                 h4.t-cap pages
20 20
                 router-link(:to="{ path: `/pages/${Object.values(allPages)[0].slug}` }")
21 21
                     p {{ Object.values(allPages)[0].title }}
22 22
         
23 23
         .f-row
24
-            section(v-if="allPostsLoaded").shadow
24
+            section(v-if="allPostsLoaded && allPosts.length").shadow
25 25
                 router-link(:to="`./posts`")
26 26
                     h4.t-cap posts
27 27
                 router-link(:to="{ path: `/posts/${Object.values(allPosts)[0].slug}` }")

+ 1
- 1
vue-theme/src/pages/list.vue View File

@@ -7,7 +7,7 @@
7 7
                 h1 &nbsp;sorted by {{ sortBy.replace('-', ' ') }}
8 8
 
9 9
         .posts(:class="{ 'is-grid': isGrid }")
10
-            section(v-for="post in posts").shadow
10
+            section(v-for="post in posts" :key="post.slug").shadow.post
11 11
                 router-link(:to="`/${type}/${post.slug}`")
12 12
                     h4 {{ post.title }} 
13 13
                     p(style="font-size: 9px;") {{ post.date }}

+ 30
- 25
vue-theme/src/pages/single.vue View File

@@ -1,32 +1,28 @@
1 1
 <template lang="pug">
2 2
 .page--single.f-row.between
3
-    article.f-grow.shadow
3
+    article(v-if="post").f-grow.shadow
4 4
         header
5
-            h1 {{ type }}:{{ $route.params.slug }} single
6
-            p categories: 
7
-                span(v-for="category in post.categories") {{ category }}&nbsp;
5
+            h1 {{ type }}:{{ $route.params.slug }} {{ post.title }}
6
+            p categories: {{ post.categories }}
8 7
 
9
-        section(v-if="post")
10
-            h4 {{ post.title }}
11
-            p {{ activeGalleryIndex }}
12
-            .block-wrapper(v-for="(block, i) in post.blocks")
13
-                    //- ?: are objects are always gallery blocks
14
-                    .gallery.block(v-if="typeof block === 'object'")
15
-                        p gallery number: {{ i }}
16
-                        ul
17
-                            li(v-for="(imageID, j) in post.galleries[block.gallery].ids") 
18
-                                button(@click="openGallery(i - 1, j)") gallery: {{ i }} image: {{ imageID }}
19
-                        //- Fullscreen gallery
20
-                        gallery(
21
-                            v-if="activeGalleryIndex == (i - 1)"
22
-                            :activeGalleryIndex="activeGalleryIndex"
23
-                            :image-ids="post.galleries[block.gallery].ids"
24
-                            :activeImageIndex="activeImageIndex"
25
-                            v-on:close="activeGalleryIndex = -1"
26
-                        )
8
+        .post-single.block-wrapper(v-for="(block, i) in post.blocks" :key="`block-${i}`")
9
+            //- ?: are objects are always gallery blocks
10
+            .gallery.block(v-if="typeof block === 'object'")
11
+                p gallery number: {{ i }}
12
+                ul
13
+                    li(v-for="(imageID, j) in post.galleries[block.gallery].ids") 
14
+                        button(@click="openGallery(i - 1, j)") gallery: {{ i }} image: {{ imageID }}
15
+                //- Fullscreen gallery
16
+                gallery(
17
+                    v-if="activeGalleryIndex == (i - 1)"
18
+                    :image-ids="post.galleries[block.gallery].ids"
19
+                    :activeImageIndex="activeImageIndex"
20
+                    v-on:close="activeGalleryIndex = -1"
21
+                    :image-sizes="post.attached"
22
+                )
27 23
 
28
-                    //- Just a regular block
29
-                    .block(v-else v-html="block")
24
+            //- Just a regular block
25
+            .block(v-else v-html="block")
30 26
 
31 27
     sidebar(v-if="sidebar" :type="`${type}`")
32 28
         .shadow
@@ -100,6 +96,14 @@ export default {
100 96
 
101 97
             const json = JSON.parse(post.hero)
102 98
             this.$store.commit('SET_HERO', json)
99
+        },
100
+        async checkAndSetImages(posts) {
101
+            const post = posts[this.$route.params.slug]
102
+            if(!post || ! post.attached) return
103
+
104
+            const imagesAttached = post.attached
105
+            await this.$store.dispatch(`getMediaById`, imagesAttached)
106
+            console.log(this.$store.media)
103 107
         }
104 108
     },
105 109
     watch: {
@@ -108,11 +112,12 @@ export default {
108 112
             // this.checkForImages(newVal)
109 113
             
110 114
             this.checkAndSetHero(newVal)
115
+            this.checkAndSetImages(newVal)
111 116
         }
112 117
     },
113 118
     created() {
114 119
         let type = convertTitleCase(this.$route.params.type)
115
-        this.$store.dispatch(`getMediaById`, [7])
120
+        
116 121
         if(!this[`all{type}Loaded`]) {
117 122
             // console.log('Retrieving...', type)
118 123
             this.$store.dispatch(`getAll${type}`)

+ 1
- 1
vue-theme/src/router/index.js View File

@@ -4,7 +4,7 @@ import routes from './routes'
4 4
 import { convertTitleCase } from '@/utils/helpers'
5 5
 
6 6
 const router = createRouter({
7
-    history: createWebHistory('/'),
7
+    history: createWebHistory(),
8 8
     routes
9 9
 })
10 10
 

Loading…
Cancel
Save