Skip to content
This repository was archived by the owner on Sep 27, 2022. It is now read-only.

Commit 070f0be

Browse files
authored
Merge pull request #157 from froboy/MAINTAIN-191-limit-by-category
Implement "limit by category" in AF4
2 parents 34d1819 + 6cac0c4 commit 070f0be

File tree

8 files changed

+79
-22
lines changed

8 files changed

+79
-22
lines changed

openy_af4_vue_app/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v14.18.1

openy_af4_vue_app/dist/activity_finder_4.umd.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openy_af4_vue_app/package-lock.json

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openy_af4_vue_app/src/App.vue

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
:filters-section-config="filtersSectionConfig"
4949
:daxko="daxko"
5050
:bs-version="bsVersion"
51+
:limit-by-category="limitByCategory"
5152
:exclude-by-category="excludeByCategory"
5253
:exclude-by-location="excludeByLocation"
5354
@filterChange="onFilterChange($event, hideModal)"
@@ -141,6 +142,7 @@
141142
:facets="data.facets.field_activity_category"
142143
:first-step="selectedPath === 'selectActivities'"
143144
:multiple="!daxko"
145+
:limit-by-category="limitByCategory"
144146
:exclude-by-category="excludeByCategory"
145147
@nextStep="nextStep('selectActivities')"
146148
/>
@@ -185,6 +187,7 @@
185187
:filters-section-config="filtersSectionConfig"
186188
:daxko="daxko"
187189
:bs-version="bsVersion"
190+
:limit-by-category="limitByCategory"
188191
:exclude-by-category="excludeByCategory"
189192
:exclude-by-location="excludeByLocation"
190193
filters-mode="instant"
@@ -509,6 +512,7 @@ export default {
509512
page: this.selectedPage,
510513
sort: this.selectedSort,
511514
keywords: this.searchKeywords,
515+
limit: this.limitByCategory.join(','),
512516
exclude: this.excludeByCategory.join(','),
513517
excludeloc: this.excludeByLocation.join(',')
514518
}
@@ -857,6 +861,7 @@ export default {
857861
.request({
858862
params: {
859863
locations: this.homeBranchId,
864+
limit: this.searchParams.limit,
860865
exclude: this.searchParams.exclude
861866
}
862867
})

openy_af4_vue_app/src/components/filters/Activities.vue

+18-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export default {
5656
type: Boolean,
5757
default: true
5858
},
59+
limitByCategory: {
60+
type: Array,
61+
required: true
62+
},
5963
excludeByCategory: {
6064
type: Array,
6165
required: true
@@ -68,21 +72,27 @@ export default {
6872
},
6973
computed: {
7074
filteredActivities() {
71-
if (!this.excludeByCategory.length) {
75+
if (!this.excludeByCategory.length && !this.limitByCategory.length) {
7276
return this.activities
7377
}
7478
7579
const filteredActivities = {}
7680
this.activities.forEach((activityGroup, key) => {
77-
// Filter out excluded categories.
78-
if (!this.excludeByCategory.length) {
79-
filteredActivities[key] = activityGroup
80-
return
81-
}
82-
8381
const filteredValue = activityGroup.value.filter(item => {
84-
return !this.excludeByCategory.includes(item.value.toString())
82+
let r = false
83+
// Items must pass both tests, so we intentionally do not ELSE these.
84+
// If there are excludes, the item must NOT be excluded.
85+
if (this.excludeByCategory.length) {
86+
r = !this.excludeByCategory.includes(item.value.toString())
87+
}
88+
// If there are limits, ONLY items in the limit list are included.
89+
if (this.limitByCategory.length) {
90+
r = this.limitByCategory.includes(item.value.toString())
91+
}
92+
return r
8593
})
94+
// If there are no filtered values then the activityGroup is empty,
95+
// and we should not add it to the filteredActivities array.
8696
if (!filteredValue.length) {
8797
return
8898
}

openy_af4_vue_app/src/components/filters/Filters.vue

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
:activities="activities"
6060
:facets="data.facets.field_activity_category"
6161
:multiple="!daxko"
62+
:limit-by-category="limitByCategory"
6263
:exclude-by-category="excludeByCategory"
6364
/>
6465
</Fieldset>
@@ -194,6 +195,10 @@ export default {
194195
type: Boolean,
195196
default: false
196197
},
198+
limitByCategory: {
199+
type: Array,
200+
required: true
201+
},
197202
excludeByCategory: {
198203
type: Array,
199204
required: true

openy_af4_vue_app/src/components/steps/SelectActivities.vue

+18-8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export default {
8585
type: Boolean,
8686
default: true
8787
},
88+
limitByCategory: {
89+
type: Array,
90+
required: true
91+
},
8892
excludeByCategory: {
8993
type: Array,
9094
required: true
@@ -97,7 +101,7 @@ export default {
97101
},
98102
computed: {
99103
filteredActivities() {
100-
if (!this.firstStep && !this.excludeByCategory.length) {
104+
if (!this.firstStep && !this.excludeByCategory.length && !this.limitByCategory.length) {
101105
return this.activities
102106
}
103107
@@ -108,15 +112,21 @@ export default {
108112
return
109113
}
110114
111-
// Filter out excluded categories.
112-
if (!this.excludeByCategory.length) {
113-
filteredActivities[key] = activityGroup
114-
return
115-
}
116-
117115
const filteredValue = activityGroup.value.filter(item => {
118-
return !this.excludeByCategory.includes(item.value.toString())
116+
let r = false
117+
// Items must pass both tests, so we intentionally do not ELSE these.
118+
// If there are excludes, the item must NOT be excluded.
119+
if (this.excludeByCategory.length) {
120+
r = !this.excludeByCategory.includes(item.value.toString())
121+
}
122+
// If there are limits, ONLY items in the limit list are included.
123+
if (this.limitByCategory.length) {
124+
r = this.limitByCategory.includes(item.value.toString())
125+
}
126+
return r
119127
})
128+
// If there are no filtered values then the activityGroup is empty,
129+
// and we should not add it to the filteredActivities array.
120130
if (!filteredValue.length) {
121131
return
122132
}

src/OpenyActivityFinderSolrBackend.php

+18
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ public function doSearchRequest($parameters) {
240240
$query->addCondition('field_category_program', $program_types, 'IN');
241241
}
242242

243+
// Limit categories.
244+
$limit_nids = [];
245+
if (!empty($parameters['limit'])) {
246+
$limit_nids = explode(',', $parameters['limit']);
247+
}
248+
$limit_nids_config = explode(',', $this->config->get('limit'));
249+
$limit_nids = array_merge($limit_nids, $limit_nids_config);
250+
$limit_categories = [];
251+
foreach ($limit_nids as $nid) {
252+
if (empty($category_program_info[$nid]['title'])) {
253+
continue;
254+
}
255+
$limit_categories[] = $nid;
256+
}
257+
if ($limit_categories) {
258+
$query->addCondition('field_activity_category', $limit_categories, 'IN');
259+
}
260+
243261
// Ensure to exclude categories.
244262
$exclude_nids = [];
245263
if (!empty($parameters['exclude'])) {

0 commit comments

Comments
 (0)