Skip to content

Dev#588

Merged
dbarzin merged 4 commits intomainfrom
dev
Mar 18, 2026
Merged

Dev#588
dbarzin merged 4 commits intomainfrom
dev

Conversation

@dbarzin
Copy link
Copy Markdown
Owner

@dbarzin dbarzin commented Mar 18, 2026

Summary by CodeRabbit

  • New Features

    • Added a weekly periodicity option with automatic expansion into multiple weekly entries.
  • Improvements

    • Localized "Weekly" in English, German and French.
    • Improved periodicity handling and stricter validation for periodicity values.
    • Enhanced action list display with bold titles and icon-based type indicators.
    • Expanded generation of repeated items to handle weekly and monthly schedules more explicitly.
  • Chores

    • Version bumped to 2026.03.16.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 18, 2026

Walkthrough

Adds a weekly periodicity option (-1) across controllers, views, and translations; expands control history logic to generate weekly repetitions; refactors some controller queries and authorization checks to helper methods; and bumps project version metadata.

Changes

Cohort / File(s) Summary
Action Controller
app/Http/Controllers/ActionController.php
Switched Action retrieval to Action::query()->find($id) (query builder pattern) instead of Action::find($id).
Control Controller & Measure Controller
app/Http/Controllers/ControlController.php, app/Http/Controllers/MeasureController.php
Added weekly periodicity handling (-1) in validation and history expansion; updated next-date and plan_date logic for weekly vs monthly; replaced role numeric checks with helper methods (isAdmin(), isUser(), isAPI(), isAuditee()); modernized query patterns (Model::query()->...).
Home / Expanded Controls
app/Http/Controllers/HomeController.php
Refactored expanded-controls generation to branch for realisation_date === null, adding a weekly expansion path (multiple weekly clones, 7-day increments) alongside monthly expansion.
Views: Controls & Measures
resources/views/controls/create.blade.php, resources/views/controls/edit.blade.php, resources/views/controls/make.blade.php, resources/views/controls/plan.blade.php, resources/views/controls/show.blade.php, resources/views/measures/plan.blade.php
Added weekly option (value=-1) to periodicity selects; updated display logic to render the weekly translation when periodicity is -1; adjusted some option values/order.
Views: Actions
resources/views/actions/index.blade.php
Adjusted markup for action title and replaced inline type/status paragraphs with a centered icon span approach for action types.
Translations
resources/lang/en/common.php, resources/lang/fr/common.php, resources/lang/de/common.php
Added 'weekly' translation entries: English Weekly, French Hebdomadaire, German wöchentlich.
Meta / Version
package.json, version.txt
Bumped project version from 2026.03.04 to 2026.03.16.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Web as Web Controller
    participant DB as Database
    participant Renderer

    User->>Web: Request controls listing (GET /controls)
    Web->>DB: Fetch controls (with periodicity, realisation_date)
    DB-->>Web: Return controls
    alt control.realisation_date is null and periodicity == -1
        Web->>Web: Expand into weekly clones (add 7 days per clone)
        Web->>DB: (optional) materialize/prepare cloned entries
    else control.realisation_date is null and periodicity > 0
        Web->>Web: Expand into monthly clones (add periodicity months)
    end
    Web->>Renderer: Render controls list (including clones)
    Renderer-->>User: HTML response with weekly/monthly items
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hop with -1 joy and cheer,

weekly trails now bright and clear,
Controllers hum, dates leap by seven,
translations sing from earth to heaven,
a little rabbit stamps the plan—hop, repeat, again!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The pull request title 'Dev' is vague and generic, providing no meaningful information about the changeset. Rename the title to something descriptive that summarizes the main changes, such as 'Add weekly periodicity option to controls and measures' or 'Implement -1 weekly periodicity value across the application'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/Http/Controllers/HomeController.php`:
- Around line 422-444: The weekly expansion loop in HomeController (the for loop
using for ($i = 1; $i <= 32; $i++) that clones $control and sets plan_date via
Carbon::parse(...)->addDays($i * 7)) is inconsistent with the similar loop in
ControlController (which uses $i <= 52); update HomeController to use the same
iteration count as ControlController (change 32 to 52) or, if the shorter
horizon is intentional, add a concise inline comment next to the for (...) in
HomeController explaining why 32 weeks is used (e.g., "dashboard shows shorter
projection than history view") so the difference is explicit and maintainable.

In `@resources/views/actions/index.blade.php`:
- Around line 105-117: The HTML closing tags are out of order around the cell
that renders icons for $action->type; move the </center> so it closes before the
</td> (i.e., ensure the <center> wrapper encloses the `@if/`@elseif/@endif span
block and is closed, then close the table cell), and verify the indentation
around the `@if` block and spans (mif-warning/mif-eye/mif-thumbs-up) remains
correct so the HTML structure is valid.

In `@resources/views/controls/edit.blade.php`:
- Line 192: The select option in edit.blade.php for weekly recurrence has
value="2" but the code expects periodicity == -1; update the option to
value="-1" and keep the selection check using $control->periodicity == -1 so the
form submits the correct -1 value that ControlController (methods handling
periodicity checks and next-date logic) expects; verify consistency with
create.blade.php which already uses value="-1".

In `@resources/views/controls/plan.blade.php`:
- Around line 79-80: You changed the UI option for “once” from periodicity=1 to
0 but did not include a data migration or controller checks, which will cause
legacy rows with periodicity=1 to be misinterpreted as recurring; add a
reversible DB migration/backfill that updates existing records with
periodicity=1 to periodicity=0, update any controller logic in ControlController
and HomeController that currently checks periodicity (>0 or !==0) to explicitly
treat 0 as “once” (e.g., periodicity === 0) and 1 no longer special-case, and
add a small migration test and/or logging to ensure the backfill runs safely
during rollout.

In `@resources/views/measures/plan.blade.php`:
- Around line 121-124: The periodicity input is currently only marked required
in MeasureController and raw values are saved; add server-side allow-list
validation for the periodicity field in the MeasureController method that
handles the form submission (e.g., the store/update action) by adding an "in"
rule (or Rule::in([...])) allowing only the supported values -1, 0, 1, validate
before persisting, and ensure you use the validated value (or cast to int) when
assigning to $measure->periodicity so unallowed values cannot be saved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9a92e9bc-85fe-4137-9e67-dbe4005411ff

📥 Commits

Reviewing files that changed from the base of the PR and between 855c976 and 4f5269c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • app/Http/Controllers/ActionController.php
  • app/Http/Controllers/ControlController.php
  • app/Http/Controllers/HomeController.php
  • package.json
  • resources/lang/de/common.php
  • resources/lang/en/common.php
  • resources/lang/fr/common.php
  • resources/views/actions/index.blade.php
  • resources/views/controls/create.blade.php
  • resources/views/controls/edit.blade.php
  • resources/views/controls/make.blade.php
  • resources/views/controls/plan.blade.php
  • resources/views/controls/show.blade.php
  • resources/views/measures/plan.blade.php
  • version.txt

Comment on lines +422 to 444
if ($control->realisation_date === null) {
if ($control->periodicity === -1) {
for ($i = 1; $i <= 32; $i++) {
$repeatedControl = clone $control;
$repeatedControl->id = null;
$repeatedControl->score = null;
$repeatedControl->observations = null;
$repeatedControl->realisation_date = null;
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addDays($i * 7);
$expanded->push($repeatedControl);
}
}
else if ($control->periodicity > 0 && $control->periodicity <= 12) {
for ($i = 1; $i <= 12 / $control->periodicity; $i++) {
$repeatedControl = clone $control;
$repeatedControl->id = null;
$repeatedControl->score = null;
$repeatedControl->observations = null;
$repeatedControl->realisation_date = null;
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addMonthsNoOverflow($i * $control->periodicity);
$expanded->push($repeatedControl);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the weekly expansion iteration counts across both controllers

echo "=== HomeController weekly iterations ==="
rg -n "periodicity === -1" -A 5 app/Http/Controllers/HomeController.php

echo ""
echo "=== ControlController weekly iterations ==="
rg -n "periodicity === -1" -A 5 app/Http/Controllers/ControlController.php

Repository: dbarzin/deming

Length of output: 1439


Inconsistency: Weekly expansion uses 32 iterations (HomeController) vs 52 (ControlController).

Line 424 uses $i <= 32 (≈8 months of weekly projections), while ControlController line 797 uses $i <= 52 (52 weeks). Both expand weekly controls identically but project different time horizons.

Either align both to the same iteration count, or add an inline comment in both locations documenting why the difference is intentional (e.g., dashboard needs shorter future projection than history view).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Http/Controllers/HomeController.php` around lines 422 - 444, The weekly
expansion loop in HomeController (the for loop using for ($i = 1; $i <= 32;
$i++) that clones $control and sets plan_date via Carbon::parse(...)->addDays($i
* 7)) is inconsistent with the similar loop in ControlController (which uses $i
<= 52); update HomeController to use the same iteration count as
ControlController (change 32 to 52) or, if the shorter horizon is intentional,
add a concise inline comment next to the for (...) in HomeController explaining
why 32 weeks is used (e.g., "dashboard shows shorter projection than history
view") so the difference is explicit and maintainable.

Comment thread resources/views/actions/index.blade.php
Comment thread resources/views/controls/edit.blade.php Outdated
Comment on lines +79 to +80
<option value="0" {{ $control->periodicity==0 ? "selected" : ""}}>{{ trans('common.once') }}</option>
<option value="-1" {{ $control->periodicity==-1 ? "selected" : ""}}>{{ trans('common.weekly') }}</option>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Changing “once” from 1 to 0 needs a data migration/backfill plan.

With this UI remap, legacy rows using periodicity=1 can be treated as recurring monthly by controller logic (periodicity > 0 / periodicity !== 0 in app/Http/Controllers/ControlController.php and app/Http/Controllers/HomeController.php). That can create unintended future controls.

📦 Suggested rollout safeguard
+ // Add a one-time data migration/reconciliation step before enabling this mapping in production:
+ // 1) Identify legacy records that used `1` as "once"
+ // 2) Convert them to `0`
+ // 3) Keep true monthly records as `1`
+ // 4) Document the cutoff strategy in release notes
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@resources/views/controls/plan.blade.php` around lines 79 - 80, You changed
the UI option for “once” from periodicity=1 to 0 but did not include a data
migration or controller checks, which will cause legacy rows with periodicity=1
to be misinterpreted as recurring; add a reversible DB migration/backfill that
updates existing records with periodicity=1 to periodicity=0, update any
controller logic in ControlController and HomeController that currently checks
periodicity (>0 or !==0) to explicitly treat 0 as “once” (e.g., periodicity ===
0) and 1 no longer special-case, and add a small migration test and/or logging
to ensure the backfill runs safely during rollout.

Comment thread resources/views/measures/plan.blade.php
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/Http/Controllers/ControlController.php (1)

794-805: history() expansion may become heavy with many weekly controls.

Lines 797-805 add 52 synthetic rows per pending weekly control. Consider bounding expansion horizon (e.g., configurable months/weeks or pagination window) to keep memory/render time predictable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Http/Controllers/ControlController.php` around lines 794 - 805, The
history() expansion currently generates 52 weekly synthetic controls (inside the
block that checks $control->realisation_date === null and $control->periodicity
=== -1), which can blow up memory; change this to compute a bounded expansion
horizon (e.g., derive $maxWeeks from a configurable setting or request parameter
like config('controls.expansion_weeks', 12) converted to weeks or from a
pagination window) and loop only for $i = 1..$maxWeeks, or skip expansion when
outside the current pagination/time window; update the creation of
$repeatedControl and $repeatedControl->plan_date (still using
Carbon::parse($control->plan_date)->addDays($i * 7)) but iterate only up to the
calculated $maxWeeks so expansion is predictable and configurable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/Http/Controllers/ControlController.php`:
- Around line 1490-1499: The scheduling branch that sets $new_control->plan_date
for monthly periodicity uses
Carbon::parse($control->plan_date)->addMonths($control->periodicity)->toDateString(),
which is inconsistent with other scheduling paths; replace addMonths(...) with
addMonthsNoOverflow(...) so the code uses
Carbon::parse($control->plan_date)->addMonthsNoOverflow($control->periodicity)->toDateString()
to avoid end-of-month drift and match the other occurrences that use
addMonthsNoOverflow().

---

Nitpick comments:
In `@app/Http/Controllers/ControlController.php`:
- Around line 794-805: The history() expansion currently generates 52 weekly
synthetic controls (inside the block that checks $control->realisation_date ===
null and $control->periodicity === -1), which can blow up memory; change this to
compute a bounded expansion horizon (e.g., derive $maxWeeks from a configurable
setting or request parameter like config('controls.expansion_weeks', 12)
converted to weeks or from a pagination window) and loop only for $i =
1..$maxWeeks, or skip expansion when outside the current pagination/time window;
update the creation of $repeatedControl and $repeatedControl->plan_date (still
using Carbon::parse($control->plan_date)->addDays($i * 7)) but iterate only up
to the calculated $maxWeeks so expansion is predictable and configurable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4d16d804-4b86-4048-bcef-a8db3d4c9042

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5269c and 2bc8982.

📒 Files selected for processing (4)
  • app/Http/Controllers/ControlController.php
  • app/Http/Controllers/MeasureController.php
  • resources/views/actions/index.blade.php
  • resources/views/controls/edit.blade.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • resources/views/actions/index.blade.php

Comment on lines +1490 to +1499
if ($control->periodicity === -1)
// One week
$new_control->plan_date = Carbon::parse($control->plan_date)
->addDays(7)
->toDateString();
else
// Months
$new_control->plan_date = Carbon::parse($control->plan_date)
->addMonths($control->periodicity)
->toDateString();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify monthly increment method consistency in ControlController scheduling paths.
rg -n "addMonthsNoOverflow|addMonths\(" app/Http/Controllers/ControlController.php

Repository: dbarzin/deming

Length of output: 440


🏁 Script executed:

#!/bin/bash
# Get context around all addMonths/addMonthsNoOverflow calls to understand usage patterns
echo "=== Context around line 194 ==="
sed -n '185,210p' app/Http/Controllers/ControlController.php

echo -e "\n=== Context around line 815 ==="
sed -n '810,820p' app/Http/Controllers/ControlController.php

echo -e "\n=== Context around line 1385 ==="
sed -n '1380,1390p' app/Http/Controllers/ControlController.php

echo -e "\n=== Context around line 1498 ==="
sed -n '1490,1505p' app/Http/Controllers/ControlController.php

Repository: dbarzin/deming

Length of output: 2622


Use addMonthsNoOverflow() here to maintain consistency with other scheduling paths.

Line 1498 currently uses addMonths(), while the same scheduling operation at line 1385 and line 815 uses addMonthsNoOverflow(). This inconsistency can produce different next dates (particularly for end-of-month dates), causing schedule drift across different code paths.

🐛 Proposed fix
-                        $new_control->plan_date = Carbon::parse($control->plan_date)
-                            ->addMonths($control->periodicity)
-                            ->toDateString();
+                        $new_control->plan_date = Carbon::parse($control->plan_date)
+                            ->addMonthsNoOverflow($control->periodicity)
+                            ->toDateString();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Http/Controllers/ControlController.php` around lines 1490 - 1499, The
scheduling branch that sets $new_control->plan_date for monthly periodicity uses
Carbon::parse($control->plan_date)->addMonths($control->periodicity)->toDateString(),
which is inconsistent with other scheduling paths; replace addMonths(...) with
addMonthsNoOverflow(...) so the code uses
Carbon::parse($control->plan_date)->addMonthsNoOverflow($control->periodicity)->toDateString()
to avoid end-of-month drift and match the other occurrences that use
addMonthsNoOverflow().

@dbarzin dbarzin merged commit 3167e12 into main Mar 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant