Skip to content

added preview in admin area#9

Open
ggoffy wants to merge 2 commits intoXoopsModules25x:masterfrom
ggoffy:master
Open

added preview in admin area#9
ggoffy wants to merge 2 commits intoXoopsModules25x:masterfrom
ggoffy:master

Conversation

@ggoffy
Copy link
Copy Markdown
Contributor

@ggoffy ggoffy commented Apr 11, 2026

Summary by CodeRabbit

  • New Features

    • Added slideshow preview in the admin interface with per-preview assets and rendering.
  • Style

    • Replaced legacy admin icon images with Font Awesome buttons; updated preview modal styling.
  • Refactor

    • Unified slideshow data structure for templates (params + images) and added support for slideshow assets.
  • Documentation

    • Updated changelog and pluralized admin list labels for clarity.
  • Chores

    • Added assets storage field and adjusted DB migration files.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

Adds an admin "slideshow preview" flow, extends the Slideshow model with an assets field, updates SlideshowHandler to return unified slideshow payloads (params/assets/images) and preview mode, adapts templates to the new structure, updates DB schema, UI templates, CSS, and bumps module version.

Changes

Cohort / File(s) Summary
Admin Controller
admin/category.php
Added case 'preview' to validate category, load slideshow elements (with assets/preview flags), handle missing/invalid cases, inject slideshow-specific assets for BT3/BT5, generate preview identifier, and render preview template with block payload.
Slideshow Domain & Handler
class/Slideshow.php, class/SlideshowHandler.php
Added assets initVar to Slideshow; extended getSlideshowElements(int $catId,int $display,bool $assets=false,bool $preview=false): array; preview bypasses display/status filtering; assets JSON optionally decoded; return shape changed to include block['images'], block['params'], and block['assets'].
Templates — Slideshow Renderers
templates/wgslider_slideshow_*.tpl (e.g., .../bt3.tpl, bt5.tpl, default.tpl, splide.tpl, swiper.tpl)
Switched data sources from $wgs_params/$block to $block.params and $block['images']; updated loops, conditionals, and JS init options to read from block.params.
Templates — Admin UI
templates/admin/wgslider_admin_category.tpl, templates/admin/wgslider_admin_image.tpl, templates/admin/wgslider_admin_slideshow.tpl
Replaced image icons with Font Awesome in grouped xo-buttons; standardized URL query formatting (plain &); added category preview link and preview rendering section in category admin template.
Assets / Styling
assets/css/admin/style.css
Adjusted modal close button position (right: 5px) and added .wgs-preview-container styles with max-width: 800px for preview layout.
Database Schema
sql/mysql.sql
Added assets column (VARCHAR(2000) NOT NULL DEFAULT '') to wgslider_slideshow table.
Removed Migrations
sql/wgslider_1.0.0_migrate.yml, sql/wgslider_1_0_0_migrate.yml
Deleted previous YAML migration definitions that declared wgslider_category, wgslider_image, and wgslider_slideshow table schemas.
Metadata & Docs
xoops_version.php, language/english/admin.php, docs/changelog.txt
Bumped module version to 1.0.1 and release date; pluralized three admin list language strings; added changelog entry for slideshow preview.

Sequence Diagram

sequenceDiagram
    actor Admin
    participant Controller as admin/category.php
    participant Handler as SlideshowHandler
    participant Model as Slideshow
    participant DB as Database
    participant Theme as xoTheme
    participant View as Template Engine

    Admin->>Controller: Request preview (op=preview&id=CAT_ID)
    Controller->>Handler: getSlideshowElements(CAT_ID, display, assets=true, preview=true)
    Handler->>DB: query images & slideshow rows (preview may bypass filters)
    DB-->>Handler: slideshow row(s) + images
    Handler->>Model: decode params/assets, build block['images'], block['params'], block['assets']
    Handler-->>Controller: return ['slsTpl'=>..., 'block'=>...]
    alt BT3 or BT5 slideshow
        Controller->>Theme: add CSS assets (from block.assets)
        Controller->>Theme: add JS assets (from block.assets)
    end
    Controller->>Controller: gen preview identifier (md5(uniqid(catId,...)))
    Controller->>View: assign vars (block, preview=true, identifier, urls, slsTpl)
    View->>View: render wgslider_admin_category.tpl (includes db:slideshow tpl)
    View-->>Admin: rendered preview page
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 A preview hops into the sun,
Slides and assets now neatly spun,
Nested arrays in carrot rows,
Templates bloom where magic grows,
Version up — a joyful run! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'added preview in admin area' accurately summarizes the main change: a new preview feature was added to the admin category view, which is the primary objective across most of the modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
class/SlideshowHandler.php (1)

167-233: ⚠️ Potential issue | 🟡 Minor

Potential undefined variable when no images exist.

When $imageCount is 0, the $block variable is never initialized before being accessed at lines 230-231. This could cause an undefined variable warning or error.

🐛 Proposed fix to initialize $block
     public function getSlideshowElements(int $catId, int $display, bool $assets = false, bool $preview = false): array
     {
         $helper = \XoopsModules\Wgslider\Helper::getInstance();
         $imageHandler = $helper->getHandler('Image');
         $categoryHandler = $helper->getHandler('Category');
+        $block = [];

         $categoryObj = $categoryHandler->get($catId);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@class/SlideshowHandler.php` around lines 167 - 233, The method
getSlideshowElements can return with $block uninitialized when no images exist;
initialize $block early (e.g., set $block = ['images' => []]; and ensure
$block['params'] and $block['assets'] are set even if $imageCount is 0) before
the image query so later code and the return ['slsTpl' => $slsTpl, 'block' =>
$block] always reference a defined array; update getSlideshowElements to create
$block (and ensure $slsParams/$slsAssets are defined) immediately after building
$slsParams/$slsAssets so all return paths are safe.
🧹 Nitpick comments (1)
xoops_version.php (1)

33-33: Version bump looks good, but consider updating release_date.

The version is correctly bumped to 1.0.1. Note that release_date on line 45 and release on line 65 still reference the old date (2026/02/28). Consider updating these to 2026/04/10 to match the changelog entry.

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

In `@xoops_version.php` at line 33, Update the package metadata to match the new
version by changing the 'release_date' and 'release' fields to the new date;
specifically locate the 'release_date' key and the 'release' key in
xoops_version.php (they currently have '2026/02/28') and set both to
'2026/04/10' so the metadata matches the 1.0.1 changelog entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@templates/wgslider_slideshow_bt3.tpl`:
- Around line 14-20: The carousel indicators loop is iterating over $block
(which contains params, assets, images) instead of the image list, producing
extra indicators; change the Smarty foreach in the indicators block to iterate
over $block.images (the same collection used by the slides loop) and keep the
loop name (e.g., name="loop") so that smarty.foreach.loop.index and the
data-target "#myCarousel{$wgslider_identifier}" remain valid; ensure the
condition still checks $block.params.show_indicator before rendering.

In `@templates/wgslider_slideshow_bt5.tpl`:
- Around line 4-8: The carousel indicator loop is iterating over the whole
$block wrapper instead of the slide list, causing one indicator per top-level
key; change the foreach to iterate over the slide array (e.g., foreach
$block.images as $slider_image or foreach $block['images'] as $slider_image
depending on Smarty usage) and keep the existing references to
$smarty.foreach.loop.index and the active check (== 0) so indicators match
slides correctly.
- Around line 45-49: The pause property in the bootstrap.Carousel initialization
is incorrectly wrapped in additional quotes; remove the extra literal quotes
around the pause value so it uses the `@json_encode` output directly (consistent
with wrap and keyboard). Update the pause line in the new bootstrap.Carousel(el,
{ ... }) block to stop surrounding
<{$block.params.pause|default:'hover'|@json_encode}> with quotes so the filter
emits a valid JS literal instead of a quoted string.

---

Outside diff comments:
In `@class/SlideshowHandler.php`:
- Around line 167-233: The method getSlideshowElements can return with $block
uninitialized when no images exist; initialize $block early (e.g., set $block =
['images' => []]; and ensure $block['params'] and $block['assets'] are set even
if $imageCount is 0) before the image query so later code and the return
['slsTpl' => $slsTpl, 'block' => $block] always reference a defined array;
update getSlideshowElements to create $block (and ensure $slsParams/$slsAssets
are defined) immediately after building $slsParams/$slsAssets so all return
paths are safe.

---

Nitpick comments:
In `@xoops_version.php`:
- Line 33: Update the package metadata to match the new version by changing the
'release_date' and 'release' fields to the new date; specifically locate the
'release_date' key and the 'release' key in xoops_version.php (they currently
have '2026/02/28') and set both to '2026/04/10' so the metadata matches the
1.0.1 changelog entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2ebcbf62-a4eb-4a55-a5a6-3ba8bbb7b7e7

📥 Commits

Reviewing files that changed from the base of the PR and between 887c63d and 49e4161.

📒 Files selected for processing (18)
  • admin/category.php
  • assets/css/admin/style.css
  • class/Slideshow.php
  • class/SlideshowHandler.php
  • docs/changelog.txt
  • language/english/admin.php
  • sql/mysql.sql
  • sql/wgslider_1.0.0_migrate.yml
  • sql/wgslider_1_0_0_migrate.yml
  • templates/admin/wgslider_admin_category.tpl
  • templates/admin/wgslider_admin_image.tpl
  • templates/admin/wgslider_admin_slideshow.tpl
  • templates/wgslider_slideshow_bt3.tpl
  • templates/wgslider_slideshow_bt5.tpl
  • templates/wgslider_slideshow_default.tpl
  • templates/wgslider_slideshow_splide.tpl
  • templates/wgslider_slideshow_swiper.tpl
  • xoops_version.php
💤 Files with no reviewable changes (2)
  • sql/wgslider_1.0.0_migrate.yml
  • sql/wgslider_1_0_0_migrate.yml

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)
class/SlideshowHandler.php (1)

167-175: PHPStan flags potential method calls on bool return.

The static analysis tool flags that $helper->getHandler('Image') and $helper->getHandler('Category') can return bool|XoopsObjectHandler|XoopsPersistableObjectHandler, and calling ->get(), ->getCount(), ->getAll() on a bool would fail. While in practice these handlers are always valid in this module's context, consider adding type assertions or @var annotations to suppress the warnings cleanly.

💡 Optional: Add type annotations
 public function getSlideshowElements(int $catId, int $display, bool $assets = false, bool $preview = false): array
 {
     $helper = \XoopsModules\Wgslider\Helper::getInstance();
+    /** `@var` \XoopsModules\Wgslider\ImageHandler $imageHandler */
     $imageHandler    = $helper->getHandler('Image');
+    /** `@var` \XoopsModules\Wgslider\CategoryHandler $categoryHandler */
     $categoryHandler = $helper->getHandler('Category');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@class/SlideshowHandler.php` around lines 167 - 175, The helper->getHandler
calls in getSlideshowElements can return bool per PHPStan; add explicit type
assertions or `@var` annotations to silence warnings and guard usage: after
$helper = \XoopsModules\Wgslider\Helper::getInstance(); assert or annotate that
$imageHandler is the Image handler and $categoryHandler is the Category handler
(e.g. `@var` \XoopsModules\Wgslider\ImageHandler $imageHandler and `@var`
\XoopsModules\Wgslider\CategoryHandler $categoryHandler) or perform runtime
checks (if ($imageHandler === false) throw/new error) before calling ->get(),
->getCount(), ->getAll() so PHPStan no longer thinks methods might be invoked on
bool.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@admin/category.php`:
- Around line 78-96: The preview case calls
$slideshowHandler->getSlideshowElements but never instantiates
$slideshowHandler; instantiate it the same way as in the list case by calling
$helper->getHandler('Slideshow') (or reuse an existing slideshow handler
variable) before calling getSlideshowElements in the preview branch so
$slideshowHandler is defined when getSlideshowElements($catId, 0, true, true) is
invoked.

---

Nitpick comments:
In `@class/SlideshowHandler.php`:
- Around line 167-175: The helper->getHandler calls in getSlideshowElements can
return bool per PHPStan; add explicit type assertions or `@var` annotations to
silence warnings and guard usage: after $helper =
\XoopsModules\Wgslider\Helper::getInstance(); assert or annotate that
$imageHandler is the Image handler and $categoryHandler is the Category handler
(e.g. `@var` \XoopsModules\Wgslider\ImageHandler $imageHandler and `@var`
\XoopsModules\Wgslider\CategoryHandler $categoryHandler) or perform runtime
checks (if ($imageHandler === false) throw/new error) before calling ->get(),
->getCount(), ->getAll() so PHPStan no longer thinks methods might be invoked on
bool.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d005dd71-7ac8-4953-923e-d35077c7fc67

📥 Commits

Reviewing files that changed from the base of the PR and between 49e4161 and 2a7f81f.

📒 Files selected for processing (5)
  • admin/category.php
  • class/SlideshowHandler.php
  • templates/wgslider_slideshow_bt3.tpl
  • templates/wgslider_slideshow_bt5.tpl
  • xoops_version.php
✅ Files skipped from review due to trivial changes (1)
  • xoops_version.php

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