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

implemented option to configre counting of overbooked non bookable days #1147

Merged
merged 52 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
fb0e0bc
implemented option to configre counting of overbooked non bookable days
markus-mw May 20, 2022
acda51e
Merge branch 'master' into feature/issue-702
hansmorb Jul 6, 2023
5ff36bc
added front-end implementation of handling chains of locked days
hansmorb Jul 6, 2023
6f07566
litepicker implementation of counting max days
hansmorb Jul 6, 2023
495d164
updated compiled litepicker
hansmorb Jul 7, 2023
27755c3
fixed litepicker still counting days when disabled
hansmorb Jul 27, 2023
d7acf7a
added global location settings
hansmorb Jul 27, 2023
bce74bc
Merge branch 'master' into feature/issue-702
hansmorb Jul 27, 2023
c58f9b1
grunt after merge
hansmorb Jul 27, 2023
82c2f8d
fixed litepicker to count holidays same as locked days
hansmorb Jul 28, 2023
f6220a4
updated litepicker with display fix
hansmorb Jul 29, 2023
d4efc4a
updated litepicker with translation fix
hansmorb Jul 29, 2023
cea3b3d
Merge branch 'master' into feature/issue-702
hansmorb Aug 10, 2023
e8362ce
recompiled litepicker
hansmorb Aug 10, 2023
2fb16c9
added debug console output
hansmorb Aug 10, 2023
6751d46
removed debug var again
hansmorb Aug 10, 2023
225900f
Merge branch 'master' into feature/issue-702
hansmorb Aug 16, 2023
aa19fab
grunt afer merge
hansmorb Aug 16, 2023
19b06bc
Merge branch 'master' into feature/issue-702
hansmorb Aug 17, 2023
9b7ee82
grunt after merge
hansmorb Aug 17, 2023
8b3a596
Merge branch 'master' into feature/issue-702
hansmorb Aug 28, 2023
8bd4456
update packages after merge
hansmorb Aug 28, 2023
1f50e96
grunt after merge
hansmorb Aug 28, 2023
f3694fd
Merge branch 'master' into feature/issue-702
hansmorb Sep 7, 2023
15fb0aa
fixed compass version to avoid vulnerable dependencies
hansmorb Sep 7, 2023
fece62c
renamed variable to be less ambiguous
hansmorb Sep 9, 2023
977b6b0
updated litepicker
hansmorb Sep 11, 2023
7701710
updated litepicker
hansmorb Sep 19, 2023
5a942c6
Merge branch 'master' into feature/issue-702
hansmorb Sep 25, 2023
9c0eb1b
Merge branch 'master' into feature/issue-702
hansmorb Sep 25, 2023
4afd860
Merge branch 'master' into feature/issue-702
hansmorb Sep 27, 2023
ccb6e59
added a few more posts & expanded to use fixtures
hansmorb Sep 27, 2023
0a95539
ignore screenshots
hansmorb Sep 27, 2023
a4b7a2e
added messy tests for litepicker overbooking
hansmorb Sep 27, 2023
ec6b746
refactored overbooking tests
hansmorb Sep 27, 2023
cc1b6fe
fix comment
hansmorb Oct 7, 2023
1b3cb7c
made unit tests time independent
hansmorb Oct 8, 2023
1045f74
Merge branch 'feature/issue-702' of github.com:wielebenwir/commonsboo…
hansmorb Oct 8, 2023
4f60e47
Merge branch 'master' into feature/issue-702
hansmorb Oct 18, 2023
5b250d8
fixed compass version to avoid vulnerable dependencies
hansmorb Oct 18, 2023
43a54e7
chores after merge
hansmorb Oct 18, 2023
bd45972
Merge branch 'master' into feature/issue-702
hansmorb Oct 19, 2023
a66ba00
chores after merge
hansmorb Oct 19, 2023
58aeae9
e2e test now compatible /w Kasimir theme
hansmorb Oct 19, 2023
24b5696
updated litepicker
hansmorb Oct 22, 2023
01bf29a
made location of global location settings more clear
hansmorb Oct 27, 2023
4f6354c
added metabox creation for CPT to e2e tests
hansmorb Oct 27, 2023
a6f2f6b
create screenshot of every settings page in e2e test
hansmorb Oct 27, 2023
90635db
just assert existence (rest is manual)
hansmorb Oct 27, 2023
2033ebf
fixed viewport so screenshots show more
hansmorb Oct 28, 2023
f3441fe
Revert "fixed viewport so screenshots show more"
hansmorb Oct 28, 2023
c8edb4d
added to-do for incomplete screenshot
hansmorb Oct 30, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules
.phpunit.*
assets/packaged
src/Wordpress/.DS_Store
tests/cypress/screenshots
/vendor
/build
src/.DS_Store
Expand Down
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ module.exports = function (grunt) {
],
tasks: [
'uglify:dev', 'babel'
]
],
options: {
livereload: true
}
}
}
});
Expand Down
59 changes: 59 additions & 0 deletions assets/admin/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
(function($) {
"use strict";
$(function() {
const hideFieldset = function(set) {
$.each(set, function() {
$(this).parents(".cmb-row").hide();
});
};
const showFieldset = function(set) {
$.each(set, function() {
$(this).parents(".cmb-row").show();
});
};
const useGlobalSettings = $("#_cb_use_global_settings");
const allowLockDaysCheckbox = $("#_cb_allow_lockdays_in_range");
const countLockedDaysCheckbox = $("#_cb_count_lockdays_in_range");
const countAmountLockedDays = $("#_cb_count_lockdays_maximum");
const handleCountLockedDays = function() {
if (countLockedDaysCheckbox.prop("checked")) {
showFieldset(countAmountLockedDays);
} else {
hideFieldset(countAmountLockedDays);
}
};
handleCountLockedDays();
countLockedDaysCheckbox.change(function() {
handleCountLockedDays();
});
const handleAllowLockDays = function() {
if (allowLockDaysCheckbox.prop("checked")) {
showFieldset(countLockedDaysCheckbox);
handleCountLockedDays();
} else {
hideFieldset(countLockedDaysCheckbox);
hideFieldset(countAmountLockedDays);
}
};
handleAllowLockDays();
allowLockDaysCheckbox.change(function() {
handleAllowLockDays();
});
const handleUseGlobalSettings = function() {
if (useGlobalSettings.prop("checked")) {
hideFieldset(allowLockDaysCheckbox);
hideFieldset(countLockedDaysCheckbox);
hideFieldset(countAmountLockedDays);
} else {
showFieldset(allowLockDaysCheckbox);
showFieldset(countLockedDaysCheckbox);
handleCountLockedDays();
}
};
handleUseGlobalSettings();
useGlobalSettings.change(function() {
handleUseGlobalSettings();
});
});
})(jQuery);

(function($) {
"use strict";
$(function() {
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions assets/admin/js/src/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(function ($) {
'use strict';
$(function () {

/**
* Hides set-elements.
* @param set
*/
const hideFieldset = function (set) {
$.each(set, function () {
$(this).parents('.cmb-row').hide();
});
};

/**
* Show set-elements.
* @param set
*/
const showFieldset = function (set) {
$.each(set, function () {
$(this).parents('.cmb-row').show();
});
};

const useGlobalSettings = $('#_cb_use_global_settings');
const allowLockDaysCheckbox = $('#_cb_allow_lockdays_in_range');
const countLockedDaysCheckbox = $('#_cb_count_lockdays_in_range');
const countAmountLockedDays = $('#_cb_count_lockdays_maximum');

const handleCountLockedDays = function () {
if (countLockedDaysCheckbox.prop('checked')) {
showFieldset(countAmountLockedDays);
} else {
hideFieldset(countAmountLockedDays);
}
};
handleCountLockedDays();
countLockedDaysCheckbox.change(function () {
handleCountLockedDays();
});

const handleAllowLockDays = function () {
if (allowLockDaysCheckbox.prop('checked')) {
showFieldset(countLockedDaysCheckbox);
handleCountLockedDays();
} else {
hideFieldset(countLockedDaysCheckbox);
hideFieldset(countAmountLockedDays);
}
}
handleAllowLockDays();
allowLockDaysCheckbox.change(function () {
handleAllowLockDays();
} );

//hide settings if global settings are used
const handleUseGlobalSettings = function () {
if (useGlobalSettings.prop('checked')) {
hideFieldset(allowLockDaysCheckbox);
hideFieldset(countLockedDaysCheckbox);
hideFieldset(countAmountLockedDays);
}
else {
showFieldset(allowLockDaysCheckbox);
showFieldset(countLockedDaysCheckbox);
handleCountLockedDays();
}
}
handleUseGlobalSettings();
useGlobalSettings.change(function () {
handleUseGlobalSettings();
});

});
})(jQuery);
2,761 changes: 1,367 additions & 1,394 deletions assets/public/js/public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/public/js/public.min.js

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions assets/public/js/src/lib/litepicker.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assets/public/js/src/litepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ document.addEventListener("DOMContentLoaded", function (event) {
"scrollToDate": true,
"inlineMode": true,
"firstDay": 1,
"countLockedDays": globalCalendarData['countLockDaysInRange'],
"countLockedDaysMax": globalCalendarData['countLockDaysMaxDays'],
"lang": globalCalendarData['lang'],
"numberOfMonths": numberOfMonths,
"numberOfColumns": numberOfColumns,
Expand Down Expand Up @@ -298,6 +300,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
"days": globalCalendarData['days'],
"maxDays": globalCalendarData['maxDays'],
"lockDays": globalCalendarData['lockDays'],
"countLockedDays": globalCalendarData['countLockDaysInRange'],
"bookedDays": globalCalendarData['bookedDays'],
"partiallyBookedDays": globalCalendarData['partiallyBookedDays'],
"highlightedDays": globalCalendarData['highlightedDays'],
Expand Down
14 changes: 14 additions & 0 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ function commonsbooking_filter_from_cmb2( $field_args ) {
}
}

/**
* Only return default value if we don't have a post ID (in the 'post' query variable)
*
* @param bool $default On/Off (true/false)
* @return mixed Returns true or '', the blank default
*/
function cmb2_set_checkbox_default_for_new_post() {
return isset( $_GET['post'] )
// No default value.
? ''
// Default to true.
: true;
}

/**
* Recursive sanitation for text or array
*
Expand Down
6 changes: 6 additions & 0 deletions includes/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
'default' => __( 'Here you can leave a comment about your booking. This will be sent to the station.', 'commonsbooking' ),
),
)
),
'globalLocationSettings' => array(
'title' => __( "Global location settings", 'commonsbooking' ),
'desc' => commonsbooking_sanitizeHTML( __( 'These settings are used for all locations. You can overwrite these settings for each location in the location settings.', 'commonsbooking' ) ),
'id' => 'globalLocationSettings',
'fields' => Location::getOverbookingSettingsMetaboxes()
)
)
),
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"grunt": "^1.4.1",
"grunt-babel": "^8.0.0",
"grunt-cli": "^1.4.3",
"grunt-contrib-compass": "^0.8.0",
"grunt-contrib-compass": "0.8.0",
"grunt-contrib-concat": "^2.0.0",
"grunt-contrib-jshint": "^3.1.1",
"grunt-contrib-nodeunit": "^5.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,12 @@ public static function filterAdminBodyClass( $classes ) {
*/
public static function registerCustomPostTypes() {
foreach ( self::getCustomPostTypes() as $customPostType ) {
register_post_type( $customPostType::getPostType(), $customPostType->getArgs() );
$cptArgs = $customPostType->getArgs();
//make export possible when using WP_DEBUG, this allows us to use the export feature for creating new E2E tests
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$cptArgs['can_export'] = true;
}
register_post_type( $customPostType::getPostType(), $cptArgs );
$customPostType->initListView();
$customPostType->initHooks();
}
Expand Down
42 changes: 36 additions & 6 deletions src/View/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use CommonsBooking\Model\Day;
use CommonsBooking\Model\Week;
use CommonsBooking\Plugin;
use CommonsBooking\Settings\Settings;
use CommonsBooking\Wordpress\CustomPostType\Item;
use CommonsBooking\Wordpress\CustomPostType\Location;
use CommonsBooking\Wordpress\CustomPostType\Timeframe;
Expand Down Expand Up @@ -486,17 +487,46 @@ public static function prepareJsonResponse(
'highlightedDays' => [],
'maxDays' => null,
'disallowLockDaysInRange' => true,
'countLockDaysInRange' => true,
'advanceBookingDays' => $advanceBookingDays,
];

if ( count( $locations ) === 1 ) {
// are overbooking allowed in location options?
$allowLockedDaysInRange = get_post_meta(
$locations[0],
COMMONSBOOKING_METABOX_PREFIX . 'allow_lockdays_in_range',
true
);
$jsonResponse['disallowLockDaysInRange'] = $allowLockedDaysInRange !== 'on';
$useGlobalSettings = get_post_meta( $locations[0], COMMONSBOOKING_METABOX_PREFIX . 'use_global_settings', true ) === 'on';
if ( $useGlobalSettings ) {
$allowLockedDaysInRange = Settings::getOption('commonsbooking_options_general', COMMONSBOOKING_METABOX_PREFIX . 'allow_lockdays_in_range');
}
else {
$allowLockedDaysInRange = get_post_meta(
$locations[0],
COMMONSBOOKING_METABOX_PREFIX . 'allow_lockdays_in_range',
true
);
}
$jsonResponse['disallowLockDaysInRange'] = ! ( $allowLockedDaysInRange === 'on' );

// should overbooked non bookable days be counted into maxdays selection?
if ( $useGlobalSettings ) {
$countLockedDaysInRange = Settings::getOption('commonsbooking_options_general', COMMONSBOOKING_METABOX_PREFIX . 'count_lockdays_in_range');
}
else {
$countLockedDaysInRange = get_post_meta(
$locations[0],
COMMONSBOOKING_METABOX_PREFIX . 'count_lockdays_in_range',
true
);
}
$jsonResponse['countLockDaysInRange'] = $countLockedDaysInRange === 'on';

//if yes, what is the maximum amount of days they should count?
if ( $useGlobalSettings ) {
$countLockdaysMaximum = Settings::getOption('commonsbooking_options_general', COMMONSBOOKING_METABOX_PREFIX . 'count_lockdays_maximum');
}
else {
$countLockdaysMaximum = get_post_meta( $locations[0], COMMONSBOOKING_METABOX_PREFIX . 'count_lockdays_maximum', true );
}
$jsonResponse['countLockDaysMaxDays'] = (int) $countLockdaysMaximum;
}

/** @var Week $week */
Expand Down
Loading