Переглянути джерело

:recycle: adding arrangement helper for modules | adding by-episode and by-material for shorts guides and techniques

tags/0.9.0
J 4 роки тому
джерело
коміт
846026350d

+ 8
- 12
vue-theme/src/components/sidebars/sidebar.vue Переглянути файл

@@ -10,17 +10,14 @@ aside.sidebar
10 10
                         p {{ option }}
11 11
                 //- exhibition, event list sidebar
12 12
                 template(v-if="['exhibition', 'event'].includes(type) && layout === 'list'")
13
-                    p 
14
-                        router-link(:to="`/${type}`")
15
-                            p by all
16
-                    p 
17
-                        router-link(:to="`/${type}/sorted/by-current-and-upcoming`")
18
-                            p by current and upcoming
13
+                    router-link(:to="`/${type}`")
14
+                        p by all
15
+                    router-link(:to="`/${type}/sorted/by-current-and-upcoming`")
16
+                        p by current and upcoming
19 17
                 //- list sidebar 
20 18
                 template(v-if="['short', 'guide', 'publication', 'technique', 'post'].includes(type) && layout === 'list'")
21
-                    p 
22
-                        router-link(:to="`/${type}`")
23
-                            p by all
19
+                    router-link(:to="`/${type}`")
20
+                        p by all
24 21
 
25 22
         //- p2p types and related posts
26 23
         .shadow(v-if="layout === 'single' && Object.keys(related).length" v-for="p2pPostType in Object.keys(related)")
@@ -107,9 +104,8 @@ export default {
107 104
                     break
108 105
                 case 'short':
109 106
                     opts = [
110
-                        Object.keys(this.sortTypes)[2],
111
-                        Object.keys(this.sortTypes)[1],
112 107
                         Object.keys(this.sortTypes)[3],
108
+                        Object.keys(this.sortTypes)[1],
113 109
                     ]
114 110
                     break
115 111
                 case 'guide':
@@ -130,8 +126,8 @@ export default {
130 126
                     break
131 127
                 case 'technique':
132 128
                     opts = [
133
-                        Object.keys(this.sortTypes)[1],
134 129
                         Object.keys(this.sortTypes)[3],
130
+                        Object.keys(this.sortTypes)[1],
135 131
                     ]
136 132
                     break
137 133
             }

+ 91
- 0
vue-theme/src/store/modules/arrangements.js Переглянути файл

@@ -0,0 +1,91 @@
1
+const _arrangeByMaterial = postsList => {
2
+    const byMaterial = {
3
+        clay: []
4
+    }
5
+    postsList.forEach(post => {
6
+        post.materials.forEach(mat => {
7
+            if(!byMaterial[mat]) byMaterial[mat] = []
8
+            byMaterial[mat].push(post)
9
+        })
10
+    })
11
+    const flatPacked = []
12
+    Object.keys(byMaterial).forEach(material => {
13
+        flatPacked.push({ slug: material, title: material, inbetween: true })
14
+        byMaterial[material].forEach(post => flatPacked.push(post))
15
+    })
16
+    return flatPacked
17
+}
18
+
19
+const _arrangeByType = postsList => {
20
+    const byType = {}
21
+    postsList.forEach(post => {
22
+        const subtypes = post.subtypes
23
+        subtypes.forEach(type => {
24
+            if(!byType[type]) byType[type] = []
25
+            byType[type].push(post)
26
+        })
27
+    })
28
+    const flatPacked = []
29
+    Object.keys(byType).forEach(type => {
30
+        flatPacked.push({ slug: type, title: type, inbetween: true })
31
+        byType[type].forEach(post => flatPacked.push(post))
32
+    })
33
+    return flatPacked
34
+}
35
+
36
+const _arrangeByAlpha = postsList => {
37
+    const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
38
+    const flatPacked = []
39
+    
40
+    const storeTitle = letter => {
41
+        if(state.seenTitles.includes(letter)) return
42
+        flatPacked.push({ slug: letter, title: letter, inbetween: true })
43
+        state.seenTitles.push(letter)
44
+    }
45
+
46
+    postsList.forEach(post => {
47
+        const lastWord = post.slug.split('-').filter(c => c).pop()
48
+        const firstCharaOflastWord = lastWord[0]
49
+        const firstCharaOfSortWord = post.sortname ? post.sortname[0] : 'z'
50
+        const charaIndex = alphabet.indexOf(firstCharaOflastWord) < alphabet.indexOf(firstCharaOfSortWord) ? alphabet.indexOf(firstCharaOflastWord) : alphabet.indexOf(firstCharaOfSortWord)
51
+
52
+        storeTitle(alphabet[charaIndex])
53
+        flatPacked.push(post)
54
+    })
55
+    return flatPacked
56
+}
57
+
58
+const _arrangeByEpisode = postsList => {
59
+    const byEpisode = {}
60
+    postsList.forEach(post => {
61
+        const relatedEpisode = post.related_episode
62
+        if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
63
+        byEpisode[relatedEpisode].push(post)
64
+    })
65
+    const flatPacked = []
66
+    Object.keys(byEpisode).forEach(episode => {
67
+        flatPacked.push({ slug: episode, title: episode, inbetween: true })
68
+        byEpisode[episode].forEach(post => flatPacked.push(post))
69
+    })
70
+    return flatPacked
71
+}
72
+
73
+const repackBySort = (postsList, sortedBy) => {
74
+    let repacked = postsList
75
+    if(sortedBy == sortTypes.material) {
76
+        repacked = _arrangeByMaterial(postsList)
77
+    } else if(sortedBy == sortTypes.episode) {
78
+        repacked = _arrangeByEpisode(postsList)
79
+    } else if(sortedBy == sortTypes.subtype) {
80
+        repacked = _arrangeByType(postsList)
81
+    }
82
+    return repacked
83
+}
84
+
85
+export {
86
+    repackBySort,
87
+    _arrangeByMaterial,
88
+    _arrangeByType,
89
+    _arrangeByAlpha,
90
+    _arrangeByEpisode
91
+}

+ 3
- 82
vue-theme/src/store/modules/artist.js Переглянути файл

@@ -1,5 +1,6 @@
1 1
 import api from '../../utils/api'
2 2
 import { sortTypes } from '../../utils/helpers'
3
+import { repackBySort } from './arrangements'
3 4
 
4 5
 const state = {
5 6
     all: [],
@@ -18,92 +19,12 @@ const getters = {
18 19
     allArtistsLoaded: state => state.loaded,
19 20
 }
20 21
 
21
-
22
-const _arrangeByMaterial = artistsList => {
23
-    const byMaterial = {
24
-        clay: []
25
-    }
26
-    artistsList.forEach(artist => {
27
-        artist.materials.forEach(mat => {
28
-            if(!byMaterial[mat]) byMaterial[mat] = []
29
-            byMaterial[mat].push(artist)
30
-        })
31
-    })
32
-    const flatPacked = []
33
-    Object.keys(byMaterial).forEach(material => {
34
-        flatPacked.push({ slug: material, title: material, inbetween: true })
35
-        byMaterial[material].forEach(artist => flatPacked.push(artist))
36
-    })
37
-    return flatPacked
38
-}
39
-
40
-const _arrangeByType = artistsList => {
41
-    const byType = {}
42
-    artistsList.forEach(artist => {
43
-        const subtypes = artist.subtypes
44
-        subtypes.forEach(type => {
45
-            if(!byType[type]) byType[type] = []
46
-            byType[type].push(artist)
47
-        })
48
-    })
49
-    const flatPacked = []
50
-    Object.keys(byType).forEach(type => {
51
-        flatPacked.push({ slug: type, title: type, inbetween: true })
52
-        byType[type].forEach(artist => flatPacked.push(artist))
53
-    })
54
-    return flatPacked
55
-}
56
-
57
-const _arrangeByAlpha = artistsList => {
58
-    const alphabet = [...'9abcdefghijklmnopqrstuvwxyz']
59
-    const flatPacked = []
60
-    
61
-    const storeTitle = letter => {
62
-        if(state.seenTitles.includes(letter)) return
63
-        flatPacked.push({ slug: letter, title: letter, inbetween: true })
64
-        state.seenTitles.push(letter)
65
-    }
66
-
67
-    artistsList.forEach(artist => {
68
-        const lastWord = artist.slug.split('-').filter(c => c).pop()
69
-        const firstCharaOflastWord = lastWord[0]
70
-        const firstCharaOfSortWord = artist.sortname ? artist.sortname[0] : 'z'
71
-        const charaIndex = alphabet.indexOf(firstCharaOflastWord) < alphabet.indexOf(firstCharaOfSortWord) ? alphabet.indexOf(firstCharaOflastWord) : alphabet.indexOf(firstCharaOfSortWord)
72
-
73
-        storeTitle(alphabet[charaIndex])
74
-        flatPacked.push(artist)
75
-    })
76
-    return flatPacked
77
-}
78
-
79
-const _arrangeByEpisode = artistsList => {
80
-    const byEpisode = {}
81
-    artistsList.forEach(artist => {
82
-        const relatedEpisode = artist.related_episode
83
-        if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
84
-        byEpisode[relatedEpisode].push(artist)
85
-    })
86
-    const flatPacked = []
87
-    Object.keys(byEpisode).forEach(episode => {
88
-        flatPacked.push({ slug: episode, title: episode, inbetween: true })
89
-        byEpisode[episode].forEach(artist => flatPacked.push(artist))
90
-    })
91
-    return flatPacked
92
-}
93
-
94 22
 const actions = {
95 23
     getAllArtists({ commit }, { sortType, params }) {
96 24
         commit('CLEAR_ARTISTS')
97 25
         commit('ARTISTS_LOADED', false)
98 26
         const storeFetch = (artists => {
99
-            let repacked = artists
100
-            if(sortType == sortTypes.material) {
101
-                repacked = _arrangeByMaterial(artists)
102
-            } else if(sortType == sortTypes.episode) {
103
-                repacked = _arrangeByEpisode(artists)
104
-            } else if(sortType == sortTypes.subtype) {
105
-                repacked = _arrangeByType(artists)
106
-            }
27
+            let repacked = repackBySort(artists, sortType)
107 28
             commit('STORE_FETCHED_ARTISTS', { artists: repacked })
108 29
             commit('ARTISTS_LOADED', true)
109 30
         })
@@ -113,7 +34,7 @@ const actions = {
113 34
         const storeFetch = (artists => {
114 35
             let repacked = artists
115 36
             if(sortType == sortTypes.alpha) {
116
-                repacked = _arrangeByAlpha(artists)
37
+                repacked = repackBySort(artists, sortType)
117 38
             }
118 39
             commit('ADD_TO_FETCHED_ARTISTS', { artists: repacked })
119 40
             commit('ARTISTS_LOADED', true)

+ 3
- 1
vue-theme/src/store/modules/guide.js Переглянути файл

@@ -1,4 +1,6 @@
1 1
 import api from '../../utils/api'
2
+import { sortTypes } from '../../utils/helpers'
3
+import { repackBySort } from './arrangements'
2 4
 
3 5
 const state = {
4 6
     all: [],
@@ -21,7 +23,7 @@ const actions = {
21 23
         commit('CLEAR_GUIDES')
22 24
         commit('GUIDES_LOADED', false)
23 25
         const storeFetch = (guides => {
24
-            let repacked = guides
26
+            let repacked = repackBySort(guides, sortType)
25 27
             commit('STORE_FETCHED_GUIDES', { guides: repacked })
26 28
             commit('GUIDES_LOADED', true)
27 29
         })

+ 2
- 1
vue-theme/src/store/modules/short.js Переглянути файл

@@ -1,4 +1,5 @@
1 1
 import api from '../../utils/api'
2
+import { repackBySort } from './arrangements'
2 3
 
3 4
 const state = {
4 5
     all: [],
@@ -21,7 +22,7 @@ const actions = {
21 22
         commit('CLEAR_SHORTS')
22 23
         commit('SHORTS_LOADED', false)
23 24
         const storeFetch = (shorts => {
24
-            let repacked = shorts
25
+            let repacked = repackBySort(shorts, sortType)
25 26
             commit('STORE_FETCHED_SHORTS', { shorts: repacked })
26 27
             commit('SHORTS_LOADED', true)
27 28
         })

+ 2
- 1
vue-theme/src/store/modules/technique.js Переглянути файл

@@ -1,4 +1,5 @@
1 1
 import api from '../../utils/api'
2
+import { repackBySort } from './arrangements'
2 3
 
3 4
 const state = {
4 5
     all: [],
@@ -21,7 +22,7 @@ const actions = {
21 22
         commit('CLEAR_TECHNIQUES')
22 23
         commit('TECHNIQUES_LOADED', false)
23 24
         const storeFetch = (techniques => {
24
-            let repacked = techniques
25
+            let repacked = repackBySort(techniques, sortType)
25 26
             commit('STORE_FETCHED_TECHNIQUES', { techniques: repacked })
26 27
             commit('TECHNIQUES_LOADED', true)
27 28
         })

Завантаження…
Відмінити
Зберегти