Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/holiday timeframe multiselect #1296

Merged
merged 68 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6ca85ed
Frontend of multi-select timeframes
hansmorb Jun 20, 2023
ef90284
multiselect logic
markus-mw Jun 20, 2023
dc80418
migrated over more from experiment branch
hansmorb Jun 20, 2023
265a8a2
Merge branch 'enhancement/unit-tests-cache' into feature/holiday-time…
hansmorb Jun 22, 2023
0c0af04
added tests for multi-tfs
hansmorb Jun 22, 2023
b15c412
fixed unit tests
hansmorb Jun 23, 2023
e81e479
fixed multi-select js (now exclusively for holidays)
hansmorb Jun 23, 2023
0429a98
rollback accidental php version change
hansmorb Jun 23, 2023
b2384c2
added hooks to update multi selection on dynamic selections
hansmorb Jun 23, 2023
e385520
added deprecation warning
hansmorb Jun 23, 2023
d48c02d
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Jun 23, 2023
f9701ad
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Jul 9, 2023
6516d25
removed unused function
hansmorb Jul 9, 2023
4dabc83
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Jul 27, 2023
2cca26a
fixed confusing wording
hansmorb Jul 27, 2023
c83839e
ran grunt
hansmorb Jul 27, 2023
a6d8e70
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Aug 10, 2023
025c0b0
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Sep 3, 2023
a9dfe6e
added methods to get multiple items & locations from one tf
hansmorb Sep 3, 2023
9c1671d
added tests to get multiple items & locations from one tf
hansmorb Sep 3, 2023
b9b4bd7
more tests for timeframes with multi-assigned items / locations
hansmorb Sep 3, 2023
ec8d0f2
modified export to support multiply applied timeframes
hansmorb Sep 3, 2023
f6ffc83
fixed caching issues for tfs with multiple assignments
hansmorb Sep 3, 2023
65735c4
grunt after merge
hansmorb Sep 3, 2023
9983a9a
marked what needs to be done before #507
hansmorb Sep 3, 2023
3a3dfb9
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Sep 7, 2023
63ba5b1
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Oct 2, 2023
0d784ae
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Oct 25, 2023
51be190
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Oct 30, 2023
9ae943c
moved upgrade function & added test (failing)
hansmorb Oct 30, 2023
4b4b0b5
added selection mode to tf creation in tests
hansmorb Oct 30, 2023
da6003d
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Nov 6, 2023
f067ffc
wip: fixed some tests
hansmorb Nov 6, 2023
b3d4880
fix rest of tests
hansmorb Nov 7, 2023
4e6c401
fix broken migration function (thanks tests)
hansmorb Nov 8, 2023
1a50276
made timeframe export multi-item / multi-location timeframes as one r…
hansmorb Nov 8, 2023
8a645cc
remove unnecessary changes
hansmorb Nov 8, 2023
0d085c5
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Nov 8, 2023
b285b07
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Nov 13, 2023
a38b57f
grunt after merge
hansmorb Nov 13, 2023
fc2be01
installed npm before running grunt
hansmorb Nov 13, 2023
ed65b88
Adds also a test for the location taxonomy query
datengraben Nov 14, 2023
4cc3ea1
Wrong taxonomy registered
datengraben Nov 14, 2023
b429902
add hook to trigger update on term deletion
hansmorb Nov 16, 2023
fd7dd29
additional test coverage
hansmorb Nov 16, 2023
6e2ce7f
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Nov 21, 2023
ca36463
grunt after merge
hansmorb Nov 21, 2023
3dd4d3b
fixed term sanitization & added test
hansmorb Dec 7, 2023
d270812
refined test
hansmorb Dec 13, 2023
55427d1
fixed typo
hansmorb Dec 13, 2023
8c76659
fixed assigning multiple items to bookable tfs by accident
hansmorb Dec 13, 2023
19a0c71
make sure, that multi-ids are always deleted for all non-holiday tfs
hansmorb Dec 13, 2023
d5ae245
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Dec 13, 2023
498e648
added type annotations
hansmorb Dec 18, 2023
73de505
added methods for just getting ids from timeframes
hansmorb Dec 18, 2023
7ed6c7b
added check for getLocations() with just one location
hansmorb Dec 18, 2023
3bc6742
repair new itemIDS, locationIDs functions
hansmorb Dec 18, 2023
a6f823d
use getter function for postID instead of magic property
hansmorb Dec 18, 2023
c4638d7
added (failing) test for getting multiple item / location ids from mu…
hansmorb Dec 18, 2023
8eedb53
fixed failing to get all IDs from multi-select TFs
hansmorb Dec 18, 2023
a6d7590
added tests for option getters
hansmorb Dec 19, 2023
7ccc229
added extra tests for deleted locations/items
hansmorb Dec 19, 2023
585d4eb
unify output of getLocations() and getItems() to always be an array
hansmorb Dec 19, 2023
0d2384e
fixed documentation
hansmorb Feb 7, 2024
37f8ee7
change meta-key of multiselect to something more legible
hansmorb Feb 7, 2024
f603247
Merge branch 'master' into feature/holiday-timeframe-multiselect
hansmorb Feb 7, 2024
103ea21
Add phpdoc and indentation
datengraben Feb 8, 2024
ccd5efb
renamed variable
hansmorb Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions assets/admin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
const REPETITION_WEEKLY = "w";
const REPETITION_MONTHLY = "m";
const REPETITION_YEARLY = "y";
const SELECTION_MANUAL = 0;
const SELECTION_CATEGORY = 1;
const SELECTION_ALL = 2;
const timeframeRepetitionInput = $("#timeframe-repetition");
const locationSelectionInput = $("#location-select");
const itemSelectionInput = $("#item-select");
if (timeframeForm.length) {
const timeframeRepetitionInput = $("#timeframe-repetition");
const typeInput = $("#type");
Expand All @@ -251,6 +257,12 @@
const linkSendEntireTimeframeCodes = $("#email-booking-codes-list-all");
const linkSendCurrentMonth = $("#email-booking-codes-list-current");
const linkSendNextMonth = $("#email-booking-codes-list-next");
const singleLocationSelection = $(".cmb2-id-location-id");
const multiLocationSelection = $(".cmb2-id-location-ids");
const singleItemSelection = $(".cmb2-id-item-id");
const multiItemSelection = $(".cmb2-id-item-ids");
const categoryLocationSelection = $(".cmb2-id-location-category-ids");
const categoryItemSelection = $(".cmb2-id-item-category-ids");
const holidayField = $(".cmb2-id--cmb2-holiday");
const holidayInput = $("#timeframe_manual_date");
const manualDatePicker = $("#cmb2_multiselect_datepicker");
Expand Down Expand Up @@ -280,6 +292,28 @@
$(this).prop("checked", false);
});
};
const migrateSingleSelection = () => {
datengraben marked this conversation as resolved.
Show resolved Hide resolved
if (typeInput.val() != HOLIDAYS_ID) {
return;
}
const singleSelectionOption = singleItemSelection.find("option:selected");
hansmorb marked this conversation as resolved.
Show resolved Hide resolved
if (singleSelectionOption.prop("value")) {
const multiItemSelectionOption = multiItemSelection.find(`input[value=${singleSelectionOption.prop("value")}]`);
if (multiItemSelectionOption) {
multiItemSelectionOption.prop("checked", true);
}
singleSelectionOption.prop("selected", false);
}
const singleLocationSelectionOption = singleLocationSelection.find("option:selected");
if (singleLocationSelectionOption.prop("value")) {
const multiLocationSelectionOption = multiLocationSelection.find(`input[value=${singleLocationSelectionOption.prop("value")}]`);
if (multiLocationSelectionOption) {
multiLocationSelectionOption.prop("checked", true);
}
singleLocationSelectionOption.prop("selected", false);
}
};
migrateSingleSelection();
const handleTypeSelection = function() {
const selectedType = $("option:selected", typeInput).val();
const selectedRepetition = $("option:selected", timeframeRepetitionInput).val();
Expand All @@ -296,10 +330,70 @@
holidayField.hide();
}
}
if (selectedType == HOLIDAYS_ID) {
itemSelectionInput.show();
locationSelectionInput.show();
migrateSingleSelection();
} else {
itemSelectionInput.hide();
locationSelectionInput.hide();
}
};
handleTypeSelection();
typeInput.change(function() {
handleTypeSelection();
handleItemSelection();
handleLocationSelection();
});
const handleLocationSelection = function() {
const selectedType = $("option:selected", typeInput).val();
if (selectedType == HOLIDAYS_ID) {
singleLocationSelection.hide();
const selectedOption = $("option:selected", locationSelectionInput).val();
if (selectedOption == SELECTION_MANUAL) {
multiLocationSelection.show();
categoryLocationSelection.hide();
} else if (selectedOption == SELECTION_CATEGORY) {
categoryLocationSelection.show();
multiLocationSelection.hide();
} else if (selectedOption == SELECTION_ALL) {
multiLocationSelection.hide();
categoryLocationSelection.hide();
}
} else {
singleLocationSelection.show();
multiLocationSelection.hide();
categoryLocationSelection.hide();
}
};
handleLocationSelection();
locationSelectionInput.change(function() {
handleLocationSelection();
});
const handleItemSelection = function() {
const selectedType = $("option:selected", typeInput).val();
if (selectedType == HOLIDAYS_ID) {
singleItemSelection.hide();
const selectedOption = $("option:selected", itemSelectionInput).val();
if (selectedOption == SELECTION_MANUAL) {
multiItemSelection.show();
categoryItemSelection.hide();
} else if (selectedOption == SELECTION_CATEGORY) {
categoryItemSelection.show();
multiItemSelection.hide();
} else if (selectedOption == SELECTION_ALL) {
multiItemSelection.hide();
categoryItemSelection.hide();
}
} else {
singleItemSelection.show();
multiItemSelection.hide();
categoryItemSelection.hide();
}
};
handleItemSelection();
itemSelectionInput.change(function() {
handleItemSelection();
});
const handleFullDaySelection = function() {
const selectedRep = $("option:selected", timeframeRepetitionInput).val();
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/js/admin.min.js

Large diffs are not rendered by default.

128 changes: 126 additions & 2 deletions assets/admin/js/src/timeframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
const REPETITION_MONTHLY = "m";
const REPETITION_YEARLY = "y";

// the assigned numbers for the location selection input
const SELECTION_MANUAL = 0;
const SELECTION_CATEGORY = 1;
const SELECTION_ALL = 2;

const timeframeRepetitionInput = $('#timeframe-repetition');
const locationSelectionInput = $('#location-select');
const itemSelectionInput = $('#item-select');

if (timeframeForm.length) {
const timeframeRepetitionInput = $('#timeframe-repetition');
const typeInput = $('#type');
Expand Down Expand Up @@ -72,14 +81,19 @@
const linkSendNextMonth = $('#email-booking-codes-list-next');


const singleLocationSelection = $('.cmb2-id-location-id');
const multiLocationSelection = $(".cmb2-id-location-ids");
const singleItemSelection = $('.cmb2-id-item-id');
const multiItemSelection = $(".cmb2-id-item-ids");
const categoryLocationSelection = $('.cmb2-id-location-category-ids');
const categoryItemSelection = $('.cmb2-id-item-category-ids');
const holidayField = $('.cmb2-id--cmb2-holiday');
const holidayInput = $('#timeframe_manual_date');
const manualDatePicker = $("#cmb2_multiselect_datepicker");
const manualDateField = $('.cmb2-id-timeframe-manual-date');
const maxDaysSelect = $('#timeframe-max-days');
const advanceBookingDays = $('#timeframe-advance-booking-days');
const bookingStartDayOffset = $('#booking-startday-offset');
const bookingConfigurationTitle = $('#title-bookings-config');
const bookingStartDayOffset = $('#booking-startday-offset');const bookingConfigurationTitle = $('#title-bookings-config');
const allowUserRoles = $('#allowed_user_roles');
const repSet = [repConfigTitle, fullDayInput, startTimeInput, endTimeInput, weekdaysInput, repetitionStartInput, repetitionEndInput, gridInput];
const noRepSet = [fullDayInput, startTimeInput, endTimeInput, gridInput, repetitionStartInput, repetitionEndInput];
Expand Down Expand Up @@ -116,6 +130,38 @@
});
}

/**
* "Moves" selection from single item /location selection to multiselect.
* Currently only for holidays.
*/
const migrateSingleSelection = () => {

if (typeInput.val() != HOLIDAYS_ID) {
return;
}
// get single selection
const singleSelectionOption = singleItemSelection.find('option:selected');
hansmorb marked this conversation as resolved.
Show resolved Hide resolved

// if it has a value, remove selection from single select and activate checkbox in multiselect
if(singleSelectionOption.prop('value')) {
const multiItemSelectionOption = multiItemSelection.find(`input[value=${singleSelectionOption.prop('value')}]`);
if(multiItemSelectionOption) {
multiItemSelectionOption.prop('checked', true);
}
singleSelectionOption.prop('selected', false);
}

const singleLocationSelectionOption = singleLocationSelection.find('option:selected');
if (singleLocationSelectionOption.prop('value')) {
const multiLocationSelectionOption = multiLocationSelection.find(`input[value=${singleLocationSelectionOption.prop('value')}]`);
if(multiLocationSelectionOption) {
multiLocationSelectionOption.prop('checked', true);
}
singleLocationSelectionOption.prop('selected', false);
}
}
migrateSingleSelection();

/**
* Shows/hides max day selection and user role restriction depending on timeframe type (for bookings).
*/
Expand All @@ -135,10 +181,88 @@
holidayField.hide();
}
}

//we migrate the single selection to the multiselect (new holiday timeframes do not have a single selection anymore)
if (selectedType == HOLIDAYS_ID) {
itemSelectionInput.show();
locationSelectionInput.show();
migrateSingleSelection();
} else {
itemSelectionInput.hide();
locationSelectionInput.hide();
}
}
handleTypeSelection();
typeInput.change(function () {
handleTypeSelection();
handleItemSelection();
handleLocationSelection();
});

/**
* Shows/hides selection options for locations
*/
const handleLocationSelection = function () {
const selectedType = $("option:selected", typeInput).val();
//disable the mass selection for all timeframes except holidays
if (selectedType == HOLIDAYS_ID) {
singleLocationSelection.hide();
//handle different selection types
const selectedOption = $("option:selected", locationSelectionInput).val();
if (selectedOption == SELECTION_MANUAL) {
multiLocationSelection.show();
categoryLocationSelection.hide();
} else if (selectedOption == SELECTION_CATEGORY){
categoryLocationSelection.show();
multiLocationSelection.hide();
}
else if (selectedOption == SELECTION_ALL) {
multiLocationSelection.hide();
categoryLocationSelection.hide();
}
}
else {
singleLocationSelection.show();
multiLocationSelection.hide();
categoryLocationSelection.hide();
}
};
handleLocationSelection();
locationSelectionInput.change(function () {
handleLocationSelection();
});

/**
* Shows/hides selection options for items
*/
const handleItemSelection = function () {
const selectedType = $("option:selected", typeInput).val();
//disable the mass selection for all timeframes except holidays (for now)
if (selectedType == HOLIDAYS_ID) {
singleItemSelection.hide();
//handle different selection types
const selectedOption = $("option:selected", itemSelectionInput).val();
if (selectedOption == SELECTION_MANUAL) {
multiItemSelection.show();
categoryItemSelection.hide();
} else if (selectedOption == SELECTION_CATEGORY){
categoryItemSelection.show();
multiItemSelection.hide();
}
else if (selectedOption == SELECTION_ALL) {
multiItemSelection.hide();
categoryItemSelection.hide();
}
}
else {
singleItemSelection.show();
multiItemSelection.hide();
categoryItemSelection.hide();
}
};
handleItemSelection();
itemSelectionInput.change(function () {
handleItemSelection();
});

/**
Expand Down
28 changes: 22 additions & 6 deletions src/Helper/Wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ public static function getRelatedPostsIdsForTimeframe($postId): array {
$timeframe = new Timeframe($postId);
$ids = [$postId];

if($timeframe->getItem()) {
$ids[] = $timeframe->getItem()->ID;
$items = $timeframe->getItems();
if( $items ) {
foreach ($items as $item) $ids[] = $item->ID;
}
if($timeframe->getLocation()) {
$ids[] = $timeframe->getLocation()->ID;

$locations = $timeframe->getLocations();
if( $locations ) {
foreach ($locations as $location) $ids[] = $location->ID;
}

return $ids;
Expand Down Expand Up @@ -246,16 +249,29 @@ public static function getTags($posts, array $items = [], array $locations = [])
public static function getLocationAndItemIdsFromPosts($posts): array {
$itemsAndLocations = [];
array_walk($posts, function ($timeframe) use (&$itemsAndLocations) {
$itemsAndLocations[] = get_post_meta(
$items = get_post_meta(
$timeframe->ID,
Timeframe::META_ITEM_ID,
true
);
$itemsAndLocations[] = get_post_meta(
// depends on single or multiselect
if(is_array($items)) {
foreach ($items as $item) $itemsAndLocations[] = $item;
} else {
$itemsAndLocations[] = $items;
}

$locations = get_post_meta(
$timeframe->ID,
Timeframe::META_LOCATION_ID,
true
);
// depends on single or multiselect
if(is_array($locations)) {
foreach ($locations as $location) $itemsAndLocations[] = $location;
} else {
$itemsAndLocations[] = $locations;
}
});
return array_map('intval', $itemsAndLocations);
}
Expand Down
Loading