@worksafevictoria/wcl7.5 1.13.0 → 1.14.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@
25
25
  />
26
26
  </template>
27
27
 
28
- <template v-if="filters.taxonomies.length > 0" v-slot:cardGroupPreContent>
28
+ <template v-if="filters?.taxonomies?.length > 0" v-slot:cardGroupPreContent>
29
29
  <directory-filters
30
30
  class="wcl-browse-content__filter"
31
31
  :filters="filters"
@@ -38,250 +38,245 @@
38
38
  </card-group>
39
39
  </template>
40
40
 
41
- <script>
42
- import CardGroup from '../../SubComponents/CardGroup/index.vue'
43
- import DirectoryFilters from '../../Global/DirectoryFilters/index.vue'
44
- import Switcher from './switcher.vue'
41
+ <script setup>
42
+ // import { CardGroup, DirectoryFilters, Switcher } from '@worksafevictoria/wcl7.5'
45
43
 
46
- export default {
47
- name: 'BrowseContent',
48
- components: {
49
- CardGroup,
50
- DirectoryFilters,
51
- Switcher,
44
+ const nuxtApp = useNuxtApp()
45
+ const hasMorePages = ref(false)
46
+ const displayedCards = ref([])
47
+ const loading = ref(false)
48
+ const bundleCache = ref({})
49
+ const displayLimit = ref(0)
50
+ const allCards = ref(undefined)
51
+ const props = defineProps({
52
+ background: {
53
+ type: String,
54
+ default: 'grey',
52
55
  },
53
- props: {
54
- background: {
55
- type: String,
56
- default: 'grey',
57
- },
58
- title: {
59
- type: String,
60
- default: '',
61
- },
62
- titleTag: {
63
- type: String,
64
- default: 'h2',
65
- },
66
- bundle: {
67
- type: Array,
68
- default: () => [''],
69
- },
70
- columns: {
71
- type: Number,
72
- default: 0,
73
- },
74
- initialDisplyLimit: {
75
- type: Number,
76
- default: 0,
77
- },
78
- fetchContent: {
79
- type: Function,
80
- required: true,
81
- },
82
- fetchFilters: {
83
- type: Function,
84
- required: false,
85
- default: null,
86
- },
87
- enableBundleFilter: {
88
- type: Boolean,
89
- },
90
- getBundleAlias: {
91
- type: Function,
92
- required: false,
93
- default: null,
94
- },
95
- showMore: {
96
- type: Boolean,
97
- },
98
- type: {
99
- type: String,
100
- required: true,
101
- },
56
+ title: {
57
+ type: String,
58
+ default: '',
102
59
  },
103
- // Temp use of mounted to replace fetch
104
- async mounted() {
105
- if (this.displayedCards.length === 0) {
106
- await this.loadFiltersAndContent()
107
- }
60
+ titleTag: {
61
+ type: String,
62
+ default: 'h2',
108
63
  },
109
- // TODO useAsyncData <script setup>
110
- // async fetch() {
111
- // if (this.displayedCards.length === 0) {
112
- // await this.loadFiltersAndContent()
113
- // }
114
- // },
115
- data() {
116
- return {
117
- hasMorePages: false,
118
- displayedCards: [],
119
- loading: true,
120
- bundleCache: {},
121
- displayLimit: 0,
122
- allCards: undefined,
123
- filters: {
124
- taxonomies: [],
125
- selected: {},
126
- availableBundles: [],
127
- },
128
- }
64
+ bundle: {
65
+ type: Array,
66
+ default: () => [''],
129
67
  },
130
- fetchKey: 'ws-browscontent',
131
- methods: {
132
- async loadFiltersAndContent() {
133
- await Promise.all([
134
- this.fetchFilters ? this.loadFilters() : Promise.resolve(),
135
- this.loadMoreCards(true),
136
- ])
137
- },
138
- init() {
139
- this.allCards = {
140
- total: 0,
141
- cards: [],
142
- }
143
- this.displayLimit = 0
144
- this.hasMorePages = false
145
- this.displayedCards = []
146
- this.bundleCache = {}
147
- },
148
- async fetchCards(currentDisplayedCards, allCards, addMoreBy, bundles) {
149
- const shouldMakeNewFetchCall =
150
- currentDisplayedCards.length + addMoreBy > allCards.cards.length
151
- if (shouldMakeNewFetchCall) {
152
- const cardBundles = await Promise.all(
153
- bundles.map((bundle, index) =>
154
- this.getBundle(bundle, addMoreBy, index),
155
- ),
156
- )
157
- allCards = this.getShuffledCards(cardBundles)
68
+ columns: {
69
+ type: Number,
70
+ default: 0,
71
+ },
72
+ initialDisplyLimit: {
73
+ type: Number,
74
+ default: 0,
75
+ },
76
+ fetchContent: {
77
+ type: Function,
78
+ required: true,
79
+ },
80
+ fetchFilters: {
81
+ type: Function,
82
+ required: false,
83
+ default: null,
84
+ },
85
+ enableBundleFilter: {
86
+ type: Boolean,
87
+ },
88
+ getBundleAlias: {
89
+ type: Function,
90
+ required: false,
91
+ default: null,
92
+ },
93
+ showMore: {
94
+ type: Boolean,
95
+ },
96
+ type: {
97
+ type: String,
98
+ required: true,
99
+ },
100
+ id: {
101
+ type: String,
102
+ required: true,
103
+ },
104
+ })
158
105
 
159
- if (
160
- this.type === 'paragraph--cards_group_latest' ||
161
- this.type === 'paragraph--browse_content'
162
- ) {
163
- allCards.cards = this.sortByDate(allCards.cards)
164
- }
165
- }
166
- return allCards
167
- },
168
- async loadMoreCards(init) {
169
- const attrs = {
170
- group: this.$pageStore?.content?.title,
171
- }
172
- if (this.$gtm && !init) {
173
- this.$gtm.push({ event: 'custom.interaction.showmore.click', ...attrs })
174
- }
175
- if (init) {
176
- this.init()
177
- }
178
- this.loading = true
179
- const addMoreBy = this.initialDisplyLimit
180
- this.displayLimit += addMoreBy
181
- const bundles =
182
- this.filters.availableBundles.length > 0
183
- ? this.filters.availableBundles
184
- : this.bundle
185
- this.allCards = await this.fetchCards(
186
- this.displayedCards,
187
- this.allCards,
188
- addMoreBy,
189
- bundles,
190
- )
191
- this.hasMorePages = this.allCards.total > this.allCards.cards.length
192
- this.displayedCards = this.allCards.cards.slice(0, this.displayLimit)
193
- this.loading = false
194
- },
195
- getBundle(bundle, addMoreBy, index) {
196
- let start
197
- const rows = addMoreBy
198
- const cache = (this.bundleCache[bundle] = this.bundleCache[bundle] || {
199
- response: {
200
- results: [],
201
- numFound: 0,
202
- },
203
- qs: {
204
- start,
205
- },
106
+ const filterKey = computed(() => `filters-${props.id}`)
107
+ const { data: filters } = await useAsyncData(filterKey, async () => {
108
+ try {
109
+ const filters = {
110
+ taxonomies: [],
111
+ selected: {},
112
+ availableBundles: [],
113
+ }
114
+ if (props.fetchFilters) {
115
+ await props.fetchFilters().then((taxonomies) => {
116
+ filters.taxonomies = taxonomies
206
117
  })
118
+ }
119
+ return filters
120
+ } catch (err) {
121
+ console.log('🚀 ~ err:', err)
122
+ }
123
+ })
207
124
 
208
- if (cache.qs.start === undefined) {
209
- start = 0
210
- } else if (cache.response.numFound > cache.response.results.length) {
211
- start = cache.response.results.length
212
- } else {
213
- return Promise.resolve(cache.response)
214
- }
215
-
216
- const qs = {
217
- bundle,
218
- rows,
219
- start,
220
- }
221
- return this.fetchContent(qs, this.filters.selected, index).then(
222
- (response) => {
223
- cache.qs.start = qs.start
224
- cache.response.numFound = response.numFound
225
- cache.response.results.push(...response.results)
226
- return cache.response
227
- },
228
- )
229
- },
230
- getShuffledCards(cardBundles) {
231
- const shuffled = []
232
- const bundleWithMostCards = cardBundles.reduce(
233
- (a, b) => (a.results.length > b.results.length ? a : b),
234
- { results: [] },
235
- ).results.length
125
+ const cardsKey = computed(() => `cards-${props.id}`)
126
+ const { data: savedCards } = await useAsyncData(cardsKey, async () => {
127
+ await loadMoreCards(true)
128
+ return {
129
+ cards: JSON.parse(JSON.stringify(allCards.value)),
130
+ bundle: JSON.parse(JSON.stringify(bundleCache.value)),
131
+ }
132
+ })
236
133
 
237
- for (let i = 0; i < bundleWithMostCards; i++) {
238
- cardBundles.forEach((bundle) => {
239
- if (bundle.results[i]) {
240
- shuffled.push(bundle.results[i])
241
- }
242
- })
243
- }
134
+ watch(
135
+ () => savedCards.value,
136
+ (newVal, oldVal) => {
137
+ if (newVal && allCards.value === undefined) {
138
+ allCards.value = JSON.parse(JSON.stringify(savedCards.value.cards))
139
+ bundleCache.value = JSON.parse(JSON.stringify(savedCards.value.bundle))
140
+ displayLimit.value += props.initialDisplyLimit
141
+ hasMorePages.value = allCards.value.total > allCards.value.cards.length
142
+ displayedCards.value = allCards.value.cards.slice(0, displayLimit.value)
143
+ }
144
+ },
145
+ { immediate: true },
146
+ )
244
147
 
245
- const total = cardBundles.reduce((acc, bundle) => {
246
- return acc + bundle.numFound
247
- }, 0)
148
+ function initial() {
149
+ allCards.value = {
150
+ total: 0,
151
+ cards: [],
152
+ }
153
+ displayLimit.value = 0
154
+ hasMorePages.value = false
155
+ displayedCards.value = []
156
+ bundleCache.value = {}
157
+ }
158
+ async function fetchCards(currentDisplayedCards, allCards, addMoreBy, bundles) {
159
+ const shouldMakeNewFetchCall =
160
+ currentDisplayedCards.length + addMoreBy > allCards.cards.length
161
+ if (shouldMakeNewFetchCall) {
162
+ const cardBundles = await Promise.all(
163
+ bundles.map((bundle, index) => getBundle(bundle, addMoreBy, index)),
164
+ )
165
+ allCards = getShuffledCards(cardBundles)
248
166
 
249
- return { cards: shuffled, total }
250
- },
251
- loadFilters() {
252
- return this.fetchFilters().then((taxonomies) => {
253
- this.filters.taxonomies = taxonomies
254
- return Promise.resolve(taxonomies)
255
- })
167
+ if (
168
+ props.type === 'paragraph--cards_group_latest' ||
169
+ props.type === 'paragraph--browse_content'
170
+ ) {
171
+ allCards.cards = sortByDate(allCards.cards)
172
+ }
173
+ }
174
+ return allCards
175
+ }
176
+ async function loadMoreCards(init) {
177
+ const attrs = {
178
+ group: nuxtApp.$pageStore?.content?.title,
179
+ }
180
+ if (nuxtApp.$gtm && !init) {
181
+ nuxtApp.$gtm.push({ event: 'custom.interaction.showmore.click', ...attrs })
182
+ }
183
+ if (init) {
184
+ initial()
185
+ }
186
+ loading.value = true
187
+ // const addMoreBy = props.initialDisplyLimit
188
+ displayLimit.value += props.initialDisplyLimit
189
+ const bundles =
190
+ filters.value.availableBundles.length > 0
191
+ ? filters.value.availableBundles
192
+ : props.bundle
193
+ allCards.value = await fetchCards(
194
+ displayedCards.value,
195
+ allCards.value,
196
+ props.initialDisplyLimit, //addMoreBy,
197
+ bundles,
198
+ )
199
+ hasMorePages.value = allCards.value.total > allCards.value.cards.length
200
+ displayedCards.value = allCards.value.cards.slice(0, displayLimit.value)
201
+ loading.value = false
202
+ }
203
+ async function getBundle(bundle, addMoreBy, index) {
204
+ let start
205
+ const rows = addMoreBy
206
+ const cache = (bundleCache.value[bundle] = bundleCache.value[bundle] || {
207
+ response: {
208
+ results: [],
209
+ numFound: 0,
256
210
  },
257
- onFilter(filters) {
258
- this.bundleCache = {}
259
- Object.keys(filters).forEach((filter) => {
260
- this.filters.selected[filter] = filters[filter].map((obj) => obj.tid)
261
- })
262
- this.loadMoreCards(true)
211
+ qs: {
212
+ start,
263
213
  },
264
- onSwitcher(switchToBundle) {
265
- this.filters.selected = {}
266
- this.filters.availableBundles.length = 0
267
- if (switchToBundle) {
268
- this.filters.availableBundles.push(switchToBundle)
214
+ })
215
+ if (cache.qs.start === undefined) {
216
+ start = 0
217
+ } else if (cache.response.numFound > cache.response.results.length) {
218
+ start = cache.response.results.length
219
+ } else {
220
+ return Promise.resolve(cache.response)
221
+ }
222
+ const qs = {
223
+ bundle,
224
+ rows,
225
+ start,
226
+ }
227
+ let response = await props.fetchContent(qs, filters.value.selected)
228
+ cache.qs.start = qs.start
229
+ cache.response.numFound = response.numFound
230
+ cache.response.results.push(...response.results)
231
+ return cache.response
232
+ }
233
+ function getShuffledCards(cardBundles) {
234
+ const shuffled = []
235
+ const bundleWithMostCards = cardBundles.reduce(
236
+ (a, b) => (a.results.length > b.results.length ? a : b),
237
+ { results: [] },
238
+ ).results.length
239
+
240
+ for (let i = 0; i < bundleWithMostCards; i++) {
241
+ cardBundles.forEach((bundle) => {
242
+ if (bundle.results[i]) {
243
+ shuffled.push(bundle.results[i])
269
244
  }
270
- this.loadMoreCards(true)
271
- },
272
- async reset() {
273
- this.bundleCache = {}
274
- this.filters.selected = {}
275
- this.filters.availableBundles.length = 0
276
- await this.loadMoreCards(true)
277
- },
278
- sortByDate(cards) {
279
- const sorted = cards.sort((a, b) => {
280
- return new Date(b.dateSort) - new Date(a.dateSort)
281
- })
282
- return sorted
283
- },
284
- },
245
+ })
246
+ }
247
+
248
+ const total = cardBundles.reduce((acc, bundle) => {
249
+ return acc + bundle.numFound
250
+ }, 0)
251
+
252
+ return { cards: shuffled, total }
253
+ }
254
+ const onFilter = (fltrs) => {
255
+ bundleCache.value = {}
256
+ Object.keys(fltrs).forEach((filter) => {
257
+ filters.value.selected[filter] = fltrs[filter].map((obj) => obj.tid)
258
+ })
259
+ loadMoreCards(true)
260
+ }
261
+ const onSwitcher = (switchToBundle) => {
262
+ filters.value.selected = {}
263
+ filters.value.availableBundles.length = 0
264
+ if (switchToBundle) {
265
+ filters.value.availableBundles.push(switchToBundle)
266
+ }
267
+ loadMoreCards(true)
268
+ }
269
+ const reset = async () => {
270
+ bundleCache.value = {}
271
+ filters.value.selected = {}
272
+ filters.value.availableBundles.length = 0
273
+ await loadMoreCards(true)
274
+ }
275
+ function sortByDate(cards) {
276
+ const sorted = cards.sort((a, b) => {
277
+ return new Date(b.dateSort) - new Date(a.dateSort)
278
+ })
279
+ return sorted
285
280
  }
286
281
  </script>
287
282
  <style lang="scss" scoped>
@@ -3,17 +3,17 @@ import arRecord from './index.vue'
3
3
  const arData =
4
4
  {
5
5
  title: 'Ventia Utility Services Pty Limited',
6
- fullAddress: 'MITCHAM VIC 3132',
7
- workPhone: '0438531164',
6
+ fullAddress: 'MITCHAM 3132',
7
+ // workPhone: '0438531164',
8
8
  mobilePhone: '0438531164',
9
9
  email: 'daniel.dehaan@ventia.com',
10
10
  website: 'http://www.ventia.com.au',
11
11
  contact1: 'Daniel DeHaan',
12
- phone1: '0438531164',
13
- email1: 'daniel.dehaan@ventia.com',
14
- mobile1: '0438531164',
15
- serviceCategory: 'Class B - Restricted - Asbestos Removalists',
16
- services: 'Bituminous coal tar coatings,Non-friable Asbestos Cement Water Pipes and Associated Fittings ONLY,Non-friable Asbetos Containing Bituminous Coating on Mild Steel Pipes',
12
+ // phone1: '0438531164',
13
+ // email1: 'daniel.dehaan@ventia.com',
14
+ // mobile1: '0438531164',
15
+ serviceCategory: 'Class B - Non-friable',
16
+ // services: 'Bituminous coal tar coatings,Non-friable Asbestos Cement Water Pipes and Associated Fittings ONLY,Non-friable Asbetos Containing Bituminous Coating on Mild Steel Pipes',
17
17
  }
18
18
 
19
19
 
@@ -14,26 +14,23 @@
14
14
  {{ item.title }}
15
15
  </a>
16
16
  </column>
17
- <column md="2" sm="12" class="address">
17
+ <column md="3" sm="12" class="address">
18
18
  <div class="label">Location</div>
19
19
  <a v-if="item.fullAddress" target="_blank" :href="gMapLink"
20
20
  ><span class="sr-only visually-hidden">Address</span>
21
21
  {{ item.fullAddress }}
22
22
  </a>
23
23
  </column>
24
- <column md="2" sm="12" class="coldata longstring">
24
+ <column md="3" sm="12" class="coldata longstring">
25
25
  <div class="label">Email</div>
26
26
  <a v-if="item.email" target="_blank" :href="`mailto:${item.email}`"
27
27
  ><span class="sr-only visually-hidden">Email address</span>
28
28
  {{ item.email }}
29
29
  </a>
30
30
  </column>
31
- <column md="3" sm="12" class="coldata longstring">
32
- <div class="label">Website</div>
33
- <a v-if="item.website" target="_blank" :href="`${item.website}`"
34
- ><span class="sr-only visually-hidden">Website address</span>
35
- {{ item.website }}
36
- </a>
31
+ <column md="2" sm="12" class="coldata">
32
+ <div class="label">Contact</div>
33
+ {{ item.contact1 }}
37
34
  </column>
38
35
  <column md="2" sm="12" class="coldata">
39
36
  <div class="label">Phone</div>
@@ -61,33 +58,34 @@
61
58
  <div style="padding-top: 20px">
62
59
  <hr />
63
60
  </div>
64
- <!-- Contacts, if any -->
65
- <div v-if="validContacts">
61
+ <!-- Website, if any -->
62
+
63
+ <div v-if="item.website">
66
64
  <row>
67
65
  <column>
68
- <h4>Contact Information</h4>
66
+ <h4>Website</h4>
69
67
  </column>
70
68
  </row>
71
- <row v-if="item.contact1 !== ''">
72
- <column sm="2" class="label"> Contact </column>
73
- <column sm="4" class="dir-additional-records">
74
- {{ item.contact1 }}
75
- </column>
69
+ <row v-if="item.website !== ''">
70
+ <a v-if="item.website" target="_blank" :href="`${item.website}`"
71
+ ><span class="sr-only visually-hidden">Website address</span>
72
+ {{ item.website }}
73
+ </a>
76
74
  </row>
77
- <row v-if="item.phone1 !== ''">
75
+ <!-- <row v-if="item.phone1 !== ''">
78
76
  <column sm="2" class="label"> Phone </column>
79
77
  <column sm="4" class="dir-additional-records">
80
78
  {{ item.phone1 }}
81
79
  </column>
82
- </row>
83
- <row v-if="item.mobile1 !== ''">
80
+ </row> -->
81
+ <row v-if="item.mobile1">
84
82
  <column sm="2" class="label"> Mobile </column>
85
83
  <column sm="4" class="dir-additional-records">
86
84
  {{ item.mobile1 }}
87
85
  </column>
88
86
  </row>
89
- <row v-if="item.email1 !== ''">
90
- <column sm="2" class="label"> Email </column>
87
+ <row v-if="item.email1">
88
+ <column sm="2" class="label" > Email </column>
91
89
  <column sm="4" class="dir-additional-records">
92
90
  {{ item.email1 }}
93
91
  </column>
@@ -99,7 +97,7 @@
99
97
  <h4>{{ item.serviceCategory }}</h4>
100
98
  </column>
101
99
  </row>
102
- <row class="dir-additional-records">
100
+ <!-- <row class="dir-additional-records">
103
101
  <column>
104
102
  <ul>
105
103
  <li v-for="serv in item.services.split(',')" :key="serv.id">
@@ -107,7 +105,7 @@
107
105
  </li>
108
106
  </ul>
109
107
  </column>
110
- </row>
108
+ </row> -->
111
109
  </div>
112
110
  </div>
113
111
  </container>