diff --git a/localization/en/chore_types.php b/localization/en/chore_types.php index b1f23d14..aec9851b 100644 --- a/localization/en/chore_types.php +++ b/localization/en/chore_types.php @@ -2,5 +2,8 @@ return array( 'manually' => 'Manually', - 'dynamic-regular' => 'Dynamic regular' + 'dynamic-regular' => 'Dynamic regular', + 'daily' => 'Daily', + 'weekly' => 'Weekly', + 'monthly' => 'Monthly' ); diff --git a/localization/en/demo_data.php b/localization/en/demo_data.php index d30cc5df..fb471ea8 100644 --- a/localization/en/demo_data.php +++ b/localization/en/demo_data.php @@ -86,5 +86,8 @@ return array( 'French' => 'French', 'Turkish' => 'Turkish', 'Spanish' => 'Spanish', - 'Russian' => 'Russian' + 'Russian' => 'Russian', + 'The thing which happens on the 5th of every month' => 'The thing which happens on the 5th of every month', + 'The thing which happens daily' => 'The thing which happens daily', + 'The thing which happens on Mondays and Wednesdays' => 'The thing which happens on Mondays and Wednesdays' ); diff --git a/localization/en/strings.php b/localization/en/strings.php index 92649ed6..4e009c4e 100644 --- a/localization/en/strings.php +++ b/localization/en/strings.php @@ -371,5 +371,14 @@ return array( 'Average shelf life' => 'Average shelf life', 'Spoil rate' => 'Spoil rate', 'Show more' => 'Show more', - 'Show less' => 'Show less' + 'Show less' => 'Show less', + 'The amount must be between #1 and #2' => 'The amount must be between #1 and #2', + 'Day of month' => 'Day of month', + 'Monday' => 'Monday', + 'Tuesday' => 'Tuesday', + 'Wednesday' => 'Wednesday', + 'Thursday' => 'Thursday', + 'Friday' => 'Friday', + 'Saturday' => 'Saturday', + 'Sunday' => 'Sunday' ); diff --git a/migrations/0065.sql b/migrations/0065.sql new file mode 100644 index 00000000..f1557277 --- /dev/null +++ b/migrations/0065.sql @@ -0,0 +1,29 @@ +ALTER TABLE chores +ADD period_config TEXT; + +DROP VIEW chores_current; +CREATE VIEW chores_current +AS +SELECT + h.id AS chore_id, + MAX(l.tracked_time) AS last_tracked_time, + CASE h.period_type + WHEN 'manually' THEN '2999-12-31 23:59:59' + WHEN 'dynamic-regular' THEN DATETIME(MAX(l.tracked_time), '+' || CAST(h.period_days AS TEXT) || ' day') + WHEN 'daily' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), '+1 day') + WHEN 'weekly' THEN + CASE + WHEN period_config LIKE '%sunday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 0') + WHEN period_config LIKE '%monday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 1') + WHEN period_config LIKE '%tuesday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 2') + WHEN period_config LIKE '%wednesday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 3') + WHEN period_config LIKE '%thursday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 4') + WHEN period_config LIKE '%friday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 5') + WHEN period_config LIKE '%saturday%' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), 'weekday 6') + END + WHEN 'monthly' THEN DATETIME(IFNULL(MAX(l.tracked_time), DATETIME('now', 'localtime')), '+1 month', 'start of month', '+' || CAST(h.period_days - 1 AS TEXT) || ' day') + END AS next_estimated_execution_time +FROM chores h +LEFT JOIN chores_log l + ON h.id = l.chore_id +GROUP BY h.id, h.period_days; diff --git a/public/viewjs/choreform.js b/public/viewjs/choreform.js index d1298eea..44d24d04 100644 --- a/public/viewjs/choreform.js +++ b/public/viewjs/choreform.js @@ -57,6 +57,15 @@ $('#chore-form input').keydown(function(event) } }); +var checkboxValues = $("#period_config").val().split(","); +for (var i = 0; i < checkboxValues.length; i++) +{ + if (!checkboxValues[i].isEmpty()) + { + $("#" + checkboxValues[i]).prop('checked', true); + } +} + $('#name').focus(); Grocy.FrontendHelpers.ValidateForm('chore-form'); @@ -70,13 +79,36 @@ $('.input-group-chore-period-type').on('change', function(e) var periodType = $('#period_type').val(); var periodDays = $('#period_days').val(); - if (periodType === 'dynamic-regular') + $(".period-type-input").addClass("d-none"); + $(".period-type-" + periodType).removeClass("d-none"); + $('#chore-period-type-info').text(""); + $("#period_config").val(""); + + if (periodType === 'manually') { - $('#chore-period-type-info').text(L('This means it is estimated that a new execution of this chore is tracked #1 days after the last was tracked', periodDays.toString())); - $('#chore-period-type-info').removeClass('d-none'); + // } - else + else if (periodType === 'dynamic-regular') { - $('#chore-period-type-info').addClass('d-none'); + $("label[for='period_days']").text(L("Period days")); + $("#period_days").attr("min", "0"); + $("#period_days").attr("max", "9999"); + $("#period_days").parent().find(".invalid-feedback").text(L('This cannot be negative')); + $('#chore-period-type-info').text(L('This means it is estimated that a new execution of this chore is tracked #1 days after the last was tracked', periodDays.toString())); + } + else if (periodType === 'daily') + { + // + } + else if (periodType === 'weekly') + { + $("#period_config").val($(".period-type-weekly input:checkbox:checked").map(function () { return this.value; }).get().join(",")); + } + else if (periodType === 'monthly') + { + $("label[for='period_days']").text(L("Day of month")); + $("#period_days").attr("min", "1"); + $("#period_days").attr("max", "31"); + $("#period_days").parent().find(".invalid-feedback").text(L('The amount must be between #1 and #2', "0", "31")); } }); diff --git a/services/ChoresService.php b/services/ChoresService.php index cacc4af6..c18bb921 100644 --- a/services/ChoresService.php +++ b/services/ChoresService.php @@ -6,6 +6,9 @@ class ChoresService extends BaseService { const CHORE_TYPE_MANUALLY = 'manually'; const CHORE_TYPE_DYNAMIC_REGULAR = 'dynamic-regular'; + const CHORE_TYPE_DAILY = 'daily'; + const CHORE_TYPE_weekly = 'weekly'; + const CHORE_TYPE_monthly = 'monthly'; public function GetCurrent() { diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 457251e5..9a885f81 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -100,6 +100,9 @@ class DemoDataGeneratorService extends BaseService INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Changed towels in the bathroom')}', 'manually', 5); --1 INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Cleaned the kitchen floor')}', 'dynamic-regular', 7); --2 INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('Lawn mowed in the garden')}', 'dynamic-regular', 21); --3 + INSERT INTO chores (name, period_type, period_days) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens on the 5th of every month')}', 'monthly', 5); --4 + INSERT INTO chores (name, period_type) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens daily')}', 'daily'); --5 + INSERT INTO chores (name, period_type, period_config) VALUES ('{$localizationService->LocalizeForSqlString('The thing which happens on Mondays and Wednesdays')}', 'weekly', 'monday,wednesday'); --6 INSERT INTO batteries (name, description, used_in) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}1', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2023', '{$localizationService->LocalizeForSqlString('TV remote control')}'); --1 INSERT INTO batteries (name, description, used_in) VALUES ('{$localizationService->LocalizeForSqlString('Battery')}2', '{$localizationService->LocalizeForSqlString('Warranty ends')} 2022', '{$localizationService->LocalizeForSqlString('Alarm clock')}'); --2 @@ -210,6 +213,9 @@ class DemoDataGeneratorService extends BaseService $choresService->TrackChore(2, date('Y-m-d H:i:s', strtotime('-10 days'))); $choresService->TrackChore(2, date('Y-m-d H:i:s', strtotime('-20 days'))); $choresService->TrackChore(3, date('Y-m-d H:i:s', strtotime('-17 days'))); + $choresService->TrackChore(4, date('Y-m-d H:i:s', strtotime('-10 days'))); + $choresService->TrackChore(5, date('Y-m-d H:i:s', strtotime('+0 days'))); + $choresService->TrackChore(6, date('Y-m-d H:i:s', strtotime('-10 days'))); $batteriesService = new BatteriesService(); $batteriesService->TrackChargeCycle(1, date('Y-m-d H:i:s', strtotime('-200 days'))); diff --git a/views/choreform.blade.php b/views/choreform.blade.php index 5bb99ba8..d928de31 100644 --- a/views/choreform.blade.php +++ b/views/choreform.blade.php @@ -50,9 +50,43 @@ 'min' => '0', 'additionalCssClasses' => 'input-group-chore-period-type', 'invalidFeedback' => $L('This cannot be negative'), - 'hintId' => 'chore-period-type-info' + 'hintId' => 'chore-period-type-info', + 'additionalGroupCssClasses' => 'period-type-input period-type-dynamic-regular period-type-monthly' )) +