-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: DRY flowview filters layout wrapper #246
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
Draft
somethingwithproof
wants to merge
2
commits into
Cacti:develop
Choose a base branch
from
somethingwithproof:fix/dry-layout-245
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | This program is free software; you can redistribute it and/or | | ||
| | modify it under the terms of the GNU General Public License | | ||
| | as published by the Free Software Foundation; either version 2 | | ||
| | of the License, or (at your option) any later version. | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| require_once __DIR__ . '/../ui_helpers.php'; | ||
|
|
||
| $events = []; | ||
| $request_vars = []; | ||
|
|
||
| function top_header() { | ||
| global $events; | ||
| $events[] = 'top'; | ||
| } | ||
|
|
||
| function bottom_footer() { | ||
| global $events; | ||
| $events[] = 'bottom'; | ||
| } | ||
|
|
||
| function isset_request_var($key) { | ||
| global $request_vars; | ||
| return isset($request_vars[$key]); | ||
| } | ||
|
|
||
| function test_renderer() { | ||
| global $events; | ||
| $events[] = 'render'; | ||
| } | ||
|
|
||
| function assert_same($expected, $actual, $message) { | ||
| if ($expected !== $actual) { | ||
| fwrite(STDERR, $message . PHP_EOL); | ||
| fwrite(STDERR, 'Expected: ' . json_encode($expected) . PHP_EOL); | ||
| fwrite(STDERR, 'Actual: ' . json_encode($actual) . PHP_EOL); | ||
| exit(1); | ||
| } | ||
| } | ||
|
|
||
| function assert_regex($pattern, $subject, $message) { | ||
| if (!preg_match($pattern, $subject)) { | ||
| fwrite(STDERR, $message . PHP_EOL); | ||
| exit(1); | ||
| } | ||
| } | ||
|
|
||
| flowview_filters_render_with_layout('test_renderer'); | ||
| assert_same(['top', 'render', 'bottom'], $events, 'Default wrapper should render with layout.'); | ||
|
|
||
| $events = []; | ||
| $request_vars['embed'] = 1; | ||
| flowview_filters_render_with_layout('test_renderer', true); | ||
| assert_same(['render'], $events, 'Embed-aware wrapper should skip layout when embed is set.'); | ||
|
|
||
| $events = []; | ||
| flowview_filters_render_with_layout('test_renderer', false); | ||
| assert_same(['top', 'render', 'bottom'], $events, 'Non-embed wrapper should keep layout even when embed is set.'); | ||
|
|
||
| $source = file_get_contents(__DIR__ . '/../flowview_filters.php'); | ||
| if ($source === false) { | ||
| fwrite(STDERR, 'Unable to read flowview_filters.php' . PHP_EOL); | ||
| exit(1); | ||
| } | ||
|
|
||
| assert_regex( | ||
| "/flowview_filters_render_with_layout\\(\\s*'edit_filter'\\s*,\\s*true\\s*\\)\\s*;/", | ||
| $source, | ||
| 'Expected edit action to use shared layout helper.' | ||
| ); | ||
|
|
||
| assert_regex( | ||
| "/flowview_filters_render_with_layout\\(\\s*'show_filters'\\s*\\)\\s*;/", | ||
| $source, | ||
| 'Expected default action to use shared layout helper.' | ||
| ); | ||
|
|
||
| echo "OK\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | This program is free software; you can redistribute it and/or | | ||
| | modify it under the terms of the GNU General Public License | | ||
| | as published by the Free Software Foundation; either version 2 | | ||
| | of the License, or (at your option) any later version. | | ||
| | | | ||
| | This program is distributed in the hope that it will be useful, | | ||
| | but WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | ||
| | GNU General Public License for more details. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDTool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| if (!function_exists('flowview_filters_render_with_layout')) { | ||
| function flowview_filters_render_with_layout(callable $renderer, $respect_embed = false) { | ||
| $should_wrap = (!$respect_embed || !isset_request_var('embed')); | ||
|
|
||
| if ($should_wrap) { | ||
| top_header(); | ||
| } | ||
|
|
||
| $renderer(); | ||
|
|
||
| if ($should_wrap) { | ||
| bottom_footer(); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in
9f37b1d: expandedui_helpers.phpto the standard full Cacti header block used by this plugin.