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

Commit

Permalink
feat(backport, filters): Merge pull request #123 from shuklina/RGTC-2170
Browse files Browse the repository at this point in the history
[Backport][RGTC-2170] Create Limit by location for AF
  • Loading branch information
podarok authored Dec 20, 2021
2 parents 6f3bd30 + 6ca8dae commit adb4801
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openy_activity_finder.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ openy_activity_finder_search:
- core/jquery.cookie

activity_finder_4:
version: 4.0.12
version: 4.0.13
js:
openy_af4_vue_app/dist/activity_finder_4.umd.min.js: { minified: true }
css:
Expand Down
1 change: 1 addition & 0 deletions openy_activity_finder.module
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function openy_activity_finder_theme() {
'filters_section_config' => [],
'limit_by_category' => [],
'exclude_by_category' => [],
'exclude_by_location' => [],
'legacy_mode' => FALSE,
'weeks_filter' => FALSE,
'hide_home_branch_block' => FALSE,
Expand Down
2 changes: 1 addition & 1 deletion openy_af4_vue_app/dist/activity_finder_4.umd.min.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion openy_af4_vue_app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
:daxko="daxko"
:bs-version="bsVersion"
:exclude-by-category="excludeByCategory"
:exclude-by-location="excludeByLocation"
@filterChange="onFilterChange($event, hideModal)"
@clearFilters="clearFilters(hideModal)"
/>
Expand Down Expand Up @@ -130,6 +131,7 @@
:facets="data.facets.locations"
:first-step="selectedPath === 'selectLocations'"
:home-branch-id="homeBranchId"
:exclude-by-location="excludeByLocation"
@nextStep="nextStep('selectLocations')"
/>
<SelectActivities
Expand Down Expand Up @@ -331,6 +333,10 @@ export default {
type: Boolean,
required: true
},
excludeByLocation: {
type: Array,
required: true
},
weeksFilter: {
type: Boolean,
required: true
Expand Down Expand Up @@ -502,7 +508,8 @@ export default {
page: this.selectedPage,
sort: this.selectedSort,
keywords: this.searchKeywords,
exclude: this.excludeByCategory.join(',')
exclude: this.excludeByCategory.join(','),
excludeloc: this.excludeByLocation.join(',')
}
if (this.daxko && this.selectedPage > 1 && this.daxkoPages[this.selectedPage]) {
Expand Down
5 changes: 5 additions & 0 deletions openy_af4_vue_app/src/components/filters/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
v-model="selectedLocations"
:locations="locations"
:facets="data.facets.locations"
:exclude-by-location="excludeByLocation"
/>
</Fieldset>
</div>
Expand Down Expand Up @@ -197,6 +198,10 @@ export default {
type: Array,
required: true
},
excludeByLocation: {
type: Array,
required: true
},
bsVersion: {
type: Number,
required: true
Expand Down
40 changes: 39 additions & 1 deletion openy_af4_vue_app/src/components/filters/Locations.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="locations-filter-component">
<Foldable
v-for="(item_type, index) in locations"
v-for="(item_type, index) in filteredLocations"
:key="id + '-location-type-' + index"
:label="item_type.label"
:collapse-id="id + '-toggle-' + index"
Expand Down Expand Up @@ -46,13 +46,51 @@ export default {
facets: {
type: Array,
required: true
},
excludeByLocation: {
type: Array,
required: true
}
},
data() {
return {
selectedLocations: this.value
}
},
computed: {
filteredLocations() {
if (!this.excludeByLocation.length) {
return this.locations
}
const filteredLocations = {}
this.locations.forEach((locationGroup, key) => {
// Filter out excluded locations.
if (!this.excludeByLocation.length) {
filteredLocations[key] = locationGroup
return
}
let checkIsArray = Array.isArray(locationGroup.value)
let results = new Object()
if (!checkIsArray) {
let filteredLocationIndex = Object.keys(locationGroup.value).filter(key => {
return !this.excludeByLocation.includes(locationGroup.value[key].value.toString())
})
filteredLocationIndex.forEach(locationIndex => {
results[locationIndex] = locationGroup.value[locationIndex]
})
} else {
results = locationGroup.value.filter(item => {
return !this.excludeByLocation.includes(item.value.toString())
})
}
filteredLocations[key] = {
...locationGroup,
value: results
}
})
return filteredLocations
}
},
watch: {
value() {
this.selectedLocations = this.value
Expand Down
34 changes: 33 additions & 1 deletion openy_af4_vue_app/src/components/steps/SelectLocations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export default {
homeBranchId: {
type: String,
default: null
},
excludeByLocation: {
type: Array,
required: true
}
},
data() {
Expand All @@ -92,7 +96,7 @@ export default {
},
computed: {
filteredLocations() {
if (!this.firstStep) {
if (!this.firstStep && !this.excludeByLocation.length) {
return this.locations
}
Expand All @@ -102,6 +106,34 @@ export default {
filteredLocations[key] = this.locations[key]
}
}
if (!this.excludeByLocation.length) {
return this.locations
}
this.locations.forEach((locationGroup, key) => {
// Filter out excluded locations.
if (!this.excludeByLocation.length) {
filteredLocations[key] = locationGroup
return
}
let checkIsArray = Array.isArray(locationGroup.value)
let results = new Object()
if (!checkIsArray) {
let filteredLocationIndex = Object.keys(locationGroup.value).filter(key => {
return !this.excludeByLocation.includes(locationGroup.value[key].value.toString())
})
filteredLocationIndex.forEach(locationIndex => {
results[locationIndex] = locationGroup.value[locationIndex]
})
} else {
results = locationGroup.value.filter(item => {
return !this.excludeByLocation.includes(item.value.toString())
})
}
filteredLocations[key] = {
...locationGroup,
value: results
}
})
return filteredLocations
},
filtersSelected() {
Expand Down
23 changes: 23 additions & 0 deletions src/Plugin/Block/ActivityFinder4Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function defaultConfiguration() {
'label_display' => 'visible',
'limit_by_category' => [],
'exclude_by_category' => [],
'exclude_by_location' => [],
'legacy_mode' => 0,
'weeks_filter' => 0,
'hide_home_branch_block' => 0,
Expand Down Expand Up @@ -172,6 +173,7 @@ public function build() {
'#filters_section_config' => $backend->getFiltersSectionConfig(),
'#limit_by_category' => $conf['limit_by_category'],
'#exclude_by_category' => $conf['exclude_by_category'],
'#exclude_by_location' => $conf['exclude_by_location'],
'#legacy_mode' => (bool) $conf['legacy_mode'],
'#weeks_filter' => (bool) $conf['weeks_filter'],
'#hide_home_branch_block' => (bool) $conf['hide_home_branch_block'],
Expand Down Expand Up @@ -215,6 +217,24 @@ public function blockForm($form, FormStateInterface $form_state) {
'#size' => 100,
'#maxlength' => 2048,
];
$base_by_location = [
'#type' => 'entity_autocomplete',
'#description' => $this->t('Separate multiple values by comma. Search for title from Branch, Camp, Facility types.'),
'#target_type' => 'node',
'#tags' => TRUE,
'#selection_settings' => [
'target_bundles' => ['branch', 'camp', 'facility'],
],
'#size' => 100,
'#maxlength' => 2048,
];

$form['exclude_by_location'] = $base_by_location + [
'#title' => $this->t('Exclude by location'),
'#default_value' => $conf['exclude_by_location']
? $this->entityTypeManager->getStorage('node')->loadMultiple($conf['exclude_by_location'])
: NULL,
];
$form['limit_by_category'] = $base_by_category + [
'#title' => $this->t('Limit by category'),
'#default_value' => $conf['limit_by_category']
Expand Down Expand Up @@ -273,6 +293,9 @@ public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['exclude_by_category'] = $form_state->getValue('exclude_by_category')
? array_column($form_state->getValue('exclude_by_category'), 'target_id')
: [];
$this->configuration['exclude_by_location'] = $form_state->getValue('exclude_by_location')
? array_column($form_state->getValue('exclude_by_location'), 'target_id')
: [];
$this->configuration['legacy_mode'] = $form_state->getValue('legacy_mode');
$this->configuration['weeks_filter'] = $form_state->getValue('weeks_filter');
$this->configuration['hide_home_branch_block'] = $form_state->getValue('hide_home_branch_block');
Expand Down
2 changes: 2 additions & 0 deletions templates/openy-activity-finder-4-block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* - relevance_sort_option
* - limit_by_category
* - exclude_by_category
* - exclude_by_location
* - legacy_mode
* - weeks_filter
* - background_image
Expand Down Expand Up @@ -50,6 +51,7 @@
:default-sort-option="{{ default_sort_option|json_encode }}"
:relevance-sort-option="{{ relevance_sort_option|json_encode }}"
:limit-by-category="{{ limit_by_category|json_encode }}"
:exclude-by-location="{{ exclude_by_location|json_encode }}"
:exclude-by-category="{{ exclude_by_category|json_encode }}"
:legacy-mode="{{ legacy_mode|json_encode }}"
:weeks-filter="{{ weeks_filter|json_encode }}"
Expand Down

0 comments on commit adb4801

Please sign in to comment.