@worksafevictoria/wcl7.5 1.1.0-beta.73 → 1.1.0-beta.75

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.
@@ -5,7 +5,7 @@
5
5
  <single-taxonomy
6
6
  v-for="(t, i) in computedPropFilters"
7
7
  :key="i"
8
- :ref="`${t.record_id}`"
8
+ :ref="elRef[`${t.record_id}`]"
9
9
  :data="t"
10
10
  :results="filteredList.length"
11
11
  :loading="isFiltering"
@@ -42,8 +42,8 @@
42
42
  ? chart.filter === 'primary'
43
43
  ? by_primary()
44
44
  : chart.filter === 'months'
45
- ? by_months()
46
- : compare()
45
+ ? by_months()
46
+ : compare()
47
47
  : noData()
48
48
  "
49
49
  :options="chart.options"
@@ -54,264 +54,252 @@
54
54
  </container>
55
55
  </template>
56
56
 
57
- <script>
57
+ <script setup>
58
58
  import { GChart } from 'vue-google-charts'
59
- import Container from '../../Containers/Container/index.vue'
59
+ import Container from '../../Containers/Container/index.vue'
60
60
  import Column from '../../Containers/Column/index.vue'
61
61
  import Row from '../../Containers/Row/index.vue'
62
62
  import FilterButton from '../../Common/FilterButton/index.vue' // Reset
63
63
  import SingleTaxonomy from '../../Global/DirectoryFilters/SingleTaxonomy/index.vue'
64
64
  import { BFormGroup, BFormSelect } from 'bootstrap-vue-next'
65
+ import { defineProps, computed, toRefs, ref } from 'vue'
65
66
 
66
- export default {
67
- name: 'Chart',
68
- components: {
69
- Row,
70
- Column,
71
- Container,
72
- GChart,
73
- FilterButton,
74
- SingleTaxonomy,
75
- BFormGroup,
76
- BFormSelect
77
- },
78
- props: {
79
- statsData: { type: Array, default: () => [] },
80
- filterFields: { type: Array, default: () => [] },
81
- chart: { type: Object, default: () => {} }
82
- },
83
- data() {
67
+ const props = defineProps({
68
+ statsData: { type: Array, default: () => [] },
69
+ filterFields: { type: Array, default: () => [] },
70
+ chart: { type: Object, default: () => {} },
71
+ })
72
+
73
+ const { statsData, filterFields, chart } = toRefs(props)
74
+
75
+ const hideReset = ref(true)
76
+ const isFiltering = ref(false)
77
+ const filters = ref({
78
+ taxonomies: [],
79
+ selected: {},
80
+ availableBundles: [],
81
+ })
82
+ const graphSelected = ref(null)
83
+ const chartHeight = ref(
84
+ chart.value.options.height ? chart.value.options.height : 600,
85
+ )
86
+ const elRef = ref({})
87
+
88
+ const graphOptions = computed(() => {
89
+ return filterFields.value.slice(1).map((field) => {
90
+ if (!graphSelected.value) {
91
+ graphSelected.value = field.record_id
92
+ }
93
+ return { value: field.record_id, text: field.name }
94
+ })
95
+ })
96
+
97
+ const computedPropFilters = computed(() => {
98
+ let fields = filterFields.value.map((field) => {
99
+ let terms = null
100
+ if (field.date) {
101
+ terms = statsData.value
102
+ .map((item) => item[field.record_id].split('/')[2]) // Date field get year
103
+ .filter((value, index, self) => self.indexOf(value) === index)
104
+ .map((value) => {
105
+ return { tid: value, name: value, preselected: false }
106
+ })
107
+ .sort((a, b) => a.name.localeCompare(b.name))
108
+ } else {
109
+ terms = statsData.value
110
+ .map((item) => item[field.record_id])
111
+ .filter((value, index, self) => self.indexOf(value) === index)
112
+ .map((value) => {
113
+ return { tid: value, name: value, preselected: false }
114
+ })
115
+ .sort((a, b) => a.name.localeCompare(b.name))
116
+ }
84
117
  return {
85
- hideReset: true,
86
- isFiltering: false,
87
- filters: {
88
- taxonomies: [],
89
- selected: {},
90
- availableBundles: []
91
- },
92
- graphSelected: null,
93
- chartHeight: this.chart.options.height ? this.chart.options.height : 600
118
+ name: field.name,
119
+ record_id: field.record_id,
120
+ terms,
94
121
  }
95
- },
96
- computed: {
97
- graphOptions: function() {
98
- return this.filterFields.slice(1).map((field) => {
99
- if (!this.graphSelected) {
100
- this.graphSelected = field.record_id
101
- }
102
- return { value: field.record_id, text: field.name }
103
- })
104
- },
105
- computedPropFilters: function() {
106
- let fields = this.filterFields.map((field) => {
107
- let terms = null
108
- if (field.date) {
109
- terms = this.statsData
110
- .map((item) => item[field.record_id].split('/')[2]) // Date field get year
111
- .filter((value, index, self) => self.indexOf(value) === index)
112
- .map((value) => {
113
- return { tid: value, name: value, preselected: false }
114
- })
115
- .sort((a, b) => a.name.localeCompare(b.name))
122
+ })
123
+ return fields
124
+ })
125
+
126
+ const filteredList = computed(() => {
127
+ let filterKeys = Object.keys(filters.value.selected).map((key) => key)
128
+ let list = statsData.value.filter((element) => {
129
+ let include = true
130
+ for (var i = 0, n = filterKeys.length; i < n; ++i) {
131
+ if (filters.value.selected[filterKeys[i]].length > 0) {
132
+ let filterType = filterFields.value.find(
133
+ (item) => item.record_id === filterKeys[i],
134
+ )
135
+ if (filterType.date) {
136
+ // Filter by year
137
+ if (
138
+ filters.value.selected[filterKeys[i]].indexOf(
139
+ element[filterKeys[i]].split('/')[2],
140
+ ) === -1
141
+ ) {
142
+ include = false
143
+ }
116
144
  } else {
117
- terms = this.statsData
118
- .map((item) => item[field.record_id])
119
- .filter((value, index, self) => self.indexOf(value) === index)
120
- .map((value) => {
121
- return { tid: value, name: value, preselected: false }
122
- })
123
- .sort((a, b) => a.name.localeCompare(b.name))
124
- }
125
- return {
126
- name: field.name,
127
- record_id: field.record_id,
128
- terms
129
- }
130
- })
131
- return fields
132
- },
133
- filteredList: function() {
134
- let filterKeys = Object.keys(this.filters.selected).map((key) => key)
135
- let list = this.statsData.filter((element) => {
136
- let include = true
137
- for (var i = 0, n = filterKeys.length; i < n; ++i) {
138
- if (this.filters.selected[filterKeys[i]].length > 0) {
139
- let filterType = this.filterFields.find(
140
- (item) => item.record_id === filterKeys[i]
141
- )
142
- if (filterType.date) {
143
- // Filter by year
144
- if (
145
- this.filters.selected[filterKeys[i]].indexOf(
146
- element[filterKeys[i]].split('/')[2]
147
- ) === -1
148
- ) {
149
- include = false
150
- }
151
- } else {
152
- if (
153
- this.filters.selected[filterKeys[i]].indexOf(
154
- element[filterKeys[i]]
155
- ) === -1
156
- ) {
157
- include = false
158
- }
159
- }
145
+ if (
146
+ filters.value.selected[filterKeys[i]].indexOf(
147
+ element[filterKeys[i]],
148
+ ) === -1
149
+ ) {
150
+ include = false
160
151
  }
161
152
  }
162
- if (include) {
163
- return element
164
- }
165
- })
166
- return list
167
- }
168
- },
169
- methods: {
170
- onFilter(filters) {
171
- this.hideReset = false
172
- const allFiltersUnselected = Object.values(this.$refs).every(
173
- (taxonomy) => {
174
- return Object.values(taxonomy[0].selectedFilters).every(
175
- (filter) => filter.filter((item) => !item.preselected).length === 0
176
- )
177
- }
178
- )
179
- if (allFiltersUnselected) {
180
- this.hideReset = true
181
153
  }
182
- Object.keys(filters).forEach((filter) => {
183
- this.filters.selected[filter] = filters[filter].map((obj) => obj.tid)
184
- })
185
- },
186
- reset() {
187
- this.hideReset = true
188
- Object.keys(this.$refs).forEach((key) => {
189
- this.$refs[key][0].reset()
190
- })
191
- this.filters.selected = {}
192
- },
193
- by_primary() {
194
- let primaryFilter = this.filterFields[0]
195
- let data = [[primaryFilter.name, this.chart.header]]
196
- let keys = {}
154
+ }
155
+ if (include) {
156
+ return element
157
+ }
158
+ })
159
+ return list
160
+ })
197
161
 
198
- this.filteredList.forEach((element) => {
199
- // Work off primary field
200
- let group = null
201
- if (primaryFilter.date) {
202
- group = `${element[primaryFilter.record_id].split('/')[2]} `
203
- } else {
204
- group = element[primaryFilter.record_id]
205
- }
162
+ const onFilter = (filterParam) => {
163
+ hideReset.value = false
164
+ const allFiltersUnselected = Object.values(elRef.value).every((taxonomy) => {
165
+ return Object.values(taxonomy[0].selectedFilters).every(
166
+ (filter) => filter.filter((item) => !item.preselected).length === 0,
167
+ )
168
+ })
169
+ if (allFiltersUnselected) {
170
+ hideReset.value = true
171
+ }
172
+ Object.keys(filterParam).forEach((filter) => {
173
+ filters.value.selected[filter] = filterParam[filter].map((obj) => obj.tid)
174
+ })
175
+ }
176
+ const reset = () => {
177
+ hideReset.value = true
178
+ Object.keys(elRef).forEach((key) => {
179
+ elRef[key][0].reset()
180
+ })
181
+ filters.value.selected = {}
182
+ }
183
+ const by_primary = () => {
184
+ let primaryFilter = filterFields.value[0]
185
+ let data = [[primaryFilter.name, chart.value.header]]
186
+ let keys = {}
206
187
 
207
- if (group in keys) {
208
- keys[group]++
209
- } else {
210
- keys[group] = 1
211
- }
212
- })
213
- Object.keys(keys).forEach((item) => {
214
- data.push([item, keys[item]])
215
- })
216
- if (this.chart.type === 'BarChart') {
217
- this.chart.options.height = data[0].length * 200
218
- } else {
219
- this.chart.options.height = this.chartHeight
220
- }
221
- return data
222
- },
223
- by_months() {
224
- let primaryFilter = this.filterFields[0]
225
- if (!primaryFilter.date) {
226
- return ['Requires date in primary field']
227
- }
228
- let data = [
229
- ['Month'],
230
- ['Jan'],
231
- ['Feb'],
232
- ['Mar'],
233
- ['Apr'],
234
- ['May'],
235
- ['Jun'],
236
- ['Jul'],
237
- ['Aug'],
238
- ['Sep'],
239
- ['Oct'],
240
- ['Nov'],
241
- ['Dec']
242
- ]
243
- let years = this.filteredList
244
- .map((item) => item[primaryFilter.record_id].split('/')[2])
245
- .filter((value, index, self) => self.indexOf(value) === index)
246
- data[0].push(...years)
247
- for (var i = 1, n = data.length; i < n; ++i) {
248
- for (var j = 0, m = years.length; j < m; ++j) {
249
- data[i].push(0)
250
- }
251
- }
252
- this.filteredList.forEach((element) => {
253
- let year = element[primaryFilter.record_id].split('/')[2]
254
- let month = element[primaryFilter.record_id].split('/')[1]
255
- data[month][data[0].indexOf(year)]++
256
- })
257
- for (var i = 2; i < data.length; i++) {
258
- for (var j = 1; j < data[i].length; j++) {
259
- data[i][j] = data[i][j] + data[i - 1][j]
260
- }
261
- }
262
- if (this.chart.type === 'BarChart') {
263
- this.chart.options.height = data[0].length * 200
264
- } else {
265
- this.chart.options.height = this.chartHeight
266
- }
267
- return data
268
- },
269
- compare() {
270
- let primaryFilter = this.filterFields[0]
271
- let comparison = this.filteredList
272
- .map((item) => item[this.graphSelected])
273
- .filter((value, index, self) => self.indexOf(value) === index)
274
- .sort((a, b) => a.localeCompare(b))
275
- let data = [['Year', ...comparison]]
276
- let keys = {}
277
- this.filteredList.forEach((element) => {
278
- let group = null
279
- if (primaryFilter.date) {
280
- group = `${element[primaryFilter.record_id].split('/')[2]} `
281
- } else {
282
- group = element[primaryFilter.record_id]
283
- }
284
- if (group in keys) {
285
- } else {
286
- keys[group] = {}
287
- comparison.forEach((co) => {
288
- keys[group][co] = 0
289
- })
290
- }
291
- keys[group][element[this.graphSelected]]++
292
- })
293
- Object.keys(keys).forEach((key) => {
294
- data.push([key, ...Object.entries(keys[key]).map(([k, v]) => v)])
188
+ filteredList.value.forEach((element) => {
189
+ // Work off primary field
190
+ let group = null
191
+ if (primaryFilter.date) {
192
+ group = `${element[primaryFilter.record_id].split('/')[2]} `
193
+ } else {
194
+ group = element[primaryFilter.record_id]
195
+ }
196
+
197
+ if (group in keys) {
198
+ keys[group]++
199
+ } else {
200
+ keys[group] = 1
201
+ }
202
+ })
203
+ Object.keys(keys).forEach((item) => {
204
+ data.push([item, keys[item]])
205
+ })
206
+ if (chart.value.type === 'BarChart') {
207
+ chart.value.options.height = data[0].length * 200
208
+ } else {
209
+ chart.value.options.height = chartHeight.value
210
+ }
211
+ return data
212
+ }
213
+ const by_months = () => {
214
+ let primaryFilter = filterFields.value[0]
215
+ if (!primaryFilter.date) {
216
+ return ['Requires date in primary field']
217
+ }
218
+ let data = [
219
+ ['Month'],
220
+ ['Jan'],
221
+ ['Feb'],
222
+ ['Mar'],
223
+ ['Apr'],
224
+ ['May'],
225
+ ['Jun'],
226
+ ['Jul'],
227
+ ['Aug'],
228
+ ['Sep'],
229
+ ['Oct'],
230
+ ['Nov'],
231
+ ['Dec'],
232
+ ]
233
+ let years = filteredList.value
234
+ .map((item) => item[primaryFilter.record_id].split('/')[2])
235
+ .filter((value, index, self) => self.indexOf(value) === index)
236
+ data[0].push(...years)
237
+ for (var i = 1, n = data.length; i < n; ++i) {
238
+ for (var j = 0, m = years.length; j < m; ++j) {
239
+ data[i].push(0)
240
+ }
241
+ }
242
+ filteredList.value.forEach((element) => {
243
+ let year = element[primaryFilter.record_id].split('/')[2]
244
+ let month = element[primaryFilter.record_id].split('/')[1]
245
+ data[month][data[0].indexOf(year)]++
246
+ })
247
+ for (var i = 2; i < data.length; i++) {
248
+ for (var j = 1; j < data[i].length; j++) {
249
+ data[i][j] = data[i][j] + data[i - 1][j]
250
+ }
251
+ }
252
+ if (chart.value.type === 'BarChart') {
253
+ chart.value.options.height = data[0].length * 200
254
+ } else {
255
+ chart.value.options.height = chartHeight.value
256
+ }
257
+ return data
258
+ }
259
+ const compare = () => {
260
+ let primaryFilter = filterFields.value[0]
261
+ let comparison = filteredList.value
262
+ .map((item) => item[graphSelected.value])
263
+ .filter((value, index, self) => self.indexOf(value) === index)
264
+ .sort((a, b) => a.localeCompare(b))
265
+ let data = [['Year', ...comparison]]
266
+ let keys = {}
267
+ filteredList.value.forEach((element) => {
268
+ let group = null
269
+ if (primaryFilter.date) {
270
+ group = `${element[primaryFilter.record_id].split('/')[2]} `
271
+ } else {
272
+ group = element[primaryFilter.record_id]
273
+ }
274
+ if (group in keys) {
275
+ } else {
276
+ keys[group] = {}
277
+ comparison.forEach((co) => {
278
+ keys[group][co] = 0
295
279
  })
296
- if (this.chart.type === 'BarChart') {
297
- this.chart.options.height = data[0].length * 200
298
- } else {
299
- this.chart.options.height = this.chartHeight
300
- }
301
- return data
302
- },
303
- noData() {
304
- return [
305
- [
306
- { label: 'Results', type: 'string' },
307
- { label: 'Results', type: 'number' },
308
- { role: 'style', type: 'string' },
309
- { role: 'annotation', type: 'string' }
310
- ],
311
- ['', 0, null, 'No results found']
312
- ]
313
280
  }
281
+ keys[group][element[graphSelected.value]]++
282
+ })
283
+ Object.keys(keys).forEach((key) => {
284
+ data.push([key, ...Object.entries(keys[key]).map(([k, v]) => v)])
285
+ })
286
+ if (chart.value.type === 'BarChart') {
287
+ chart.value.options.height = data[0].length * 200
288
+ } else {
289
+ chart.value.options.height = chartHeight.value
314
290
  }
291
+ return data
292
+ }
293
+ const noData = () => {
294
+ return [
295
+ [
296
+ { label: 'Results', type: 'string' },
297
+ { label: 'Results', type: 'number' },
298
+ { role: 'style', type: 'string' },
299
+ { role: 'annotation', type: 'string' },
300
+ ],
301
+ ['', 0, null, 'No results found'],
302
+ ]
315
303
  }
316
304
  </script>
317
305
 
@@ -28,15 +28,15 @@
28
28
  :show-divider="false"
29
29
  :header-size="'large'"
30
30
  class="tabbed-card"
31
- :class="card === selectedCard ? 'isSelected' : ''"
31
+ :class="checkSelectedCard(card) ? 'isSelected' : ''"
32
32
  :card-padding="'small'"
33
33
  :card-header-title="card.title"
34
- :caret="card === selectedCard ? 'up' : 'down'"
34
+ :caret="checkSelectedCard(card) ? 'up' : 'down'"
35
35
  :caret-position="'bottom'"
36
36
  :rtl="rtl || card.rtl"
37
37
  :description="card.text"
38
38
  :button-role="'link'"
39
- :is-selected="card === selectedCard"
39
+ :is-selected="checkSelectedCard(card)"
40
40
  :is-expandable="true"
41
41
  />
42
42
  </template>
@@ -65,7 +65,6 @@
65
65
  </template>
66
66
 
67
67
  <script>
68
- import { toRaw } from 'vue'
69
68
  import CardGrid from './../../Common/CardGrid/index.vue'
70
69
  import CardGridItem from './../../Common/CardGridItem/index.vue'
71
70
  import Column from './../../Containers/Column/index.vue'
@@ -152,10 +151,11 @@ export default {
152
151
  let end = start + this.cols
153
152
  return rows.slice(start, end)
154
153
  },
154
+ checkSelectedCard(card) {
155
+ return JSON.stringify(card) === JSON.stringify(this.selectedCard);
156
+ },
155
157
  setCurrentRow(rowIndex, card) {
156
- const rawCard = toRaw(this.selectedCard);
157
- const sameCardSelected =
158
- card.selectedCard.title === rawCard?.title || !card.selectedCard.title
158
+ const sameCardSelected = this.checkSelectedCard(card.selectedCard) || !card.selectedCard
159
159
 
160
160
  this.selectedCard = null
161
161
  this.selectedRow = null