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

0191-WebUI-Add-NaturalSortOrderInControlTabs #2904

Conversation

jp112sdl
Copy link
Contributor

@jp112sdl jp112sdl commented Nov 6, 2024

Description

Sortiert die Listen in Status und Bedienung => Geräte / Gewerke / Räume nach Natural Sort Order (https://en.wikipedia.org/wiki/Natural_sort_order)

Related Issue

#2897

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Alternate Designs

Possible Drawbacks

Diese Änderung benötigt ReGaHss R1.00.0388.0245+ da erst hier die notwendigen Optionen für die SortByName() Funktion umgesetzt sind.

Verification Process

Release Notes

Contributing checklist

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING and LICENSE document.
  • I fully agree to distribute my changes under Apache 2.0 license.

Summary by CodeRabbit

  • New Features

    • Introduced natural sorting for control tabs, improving the organization of channel items.
    • Added new HTML pages for managing device and control channels with enhanced filtering and sorting options.
    • Implemented user-specific views and access rights management for channel visibility.
  • Bug Fixes

    • Improved user experience by ensuring only authorized channels are displayed based on user settings.

@jens-maus jens-maus added 💡 enhancement-ideas New feature or change request 🏷️ WebUI This refs the WebUI component labels Nov 6, 2024
@jens-maus jens-maus added this to the next release milestone Nov 6, 2024
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes introduce a natural sorting feature for control tabs in the WebUI by modifying the sorting method calls across several HTML files. The SortByName method is updated to include parameters for ascending order and natural sorting in hdevichannels.htm, hroomchannels.htm, and hfuncchannels.htm. Additionally, new JavaScript functionality is added to manage user-specific views, enhance filtering options, and ensure visibility based on user permissions. The overall structure includes tables for displaying channel information with improved sorting and filtering capabilities.

Changes

File Path Change Summary
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hdevichannels.htm Introduced a new HTML page for device channels with natural sorting, filtering options, and user-specific views.
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hfuncchannels.htm Added JavaScript for managing control channels with natural sorting and enhanced filtering functionality.
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm Implemented JavaScript for control tabs with natural sorting and user-specific view management.

Suggested labels

WebUI


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 8

🧹 Outside diff range and nitpick comments (11)
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs.patch (2)

24-31: Consider extracting common sorting logic.

The sorting implementation is identical across multiple files. Consider extracting this into a shared utility function to maintain consistency and reduce code duplication.

+ // In a shared utility file (e.g., sorting.js)
+ function applySortByName(viewIds, ascending, natural) {
+   viewIds.SortByName(ascending, natural);
+   firstSort = true;
+ }

1-31: Implementation successfully adds natural sort order across control tabs.

The changes consistently implement natural sorting across device, function, and room channels, fulfilling the PR objectives. A few suggestions for improvement:

  1. Consider adding comments explaining the sorting parameters and their effects
  2. Update user documentation to describe the new sorting behavior
  3. Consider adding a configuration option to enable/disable natural sorting as a user preference
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hfuncchannels.htm (3)

210-218: Use object literal notation in JavaScript for better readability.

When creating new objects in JavaScript, prefer using {} over new Object() for simplicity and performance benefits.

Modify the script generation:

- Write("chn = new Object();");
+ Write("chn = {};");

This change makes the code more concise and adheres to modern JavaScript practices.


260-266: Optimize jQuery selector usage for improved performance.

Using [name='hssType'] as a selector can be inefficient if many elements share this attribute. Consider adding a class or using a more specific selector.

Example:

- <span name='hssType' class='hidden'>...
+ <span class='hssType hidden'>...

Update the jQuery selector accordingly:

- jQuery("[name='hssType']").each(function(index, elm) {
+ jQuery(".hssType").each(function(index, elm) {

153-156: Simplify conditional statements for better readability.

The if...else block can be refactored to reduce code repetition and enhance clarity.

Refactored code:

- if( oUser && oUser.UserLevel() == iulAdmin ) {
-   Write("<td class='GrayBkg CLASS04007' onclick='DeviceListPage.showConfiguration(event, \"CHANNEL\", "#chn.ID()#");' onmouseover='this.className=\"DeviceListRow_Highlight\";' onmouseout='this.className=\"DeviceListRow\";'>");
- } else {
-   Write("<td class='GrayBkg'>");
- }
+ string tdClass = 'GrayBkg';
+ string tdAttributes = '';
+ if( oUser && oUser.UserLevel() == iulAdmin ) {
+   tdClass = tdClass # ' CLASS04007';
+   tdAttributes = " onclick='DeviceListPage.showConfiguration(event, \"CHANNEL\", "#chn.ID()#");' onmouseover='this.className=\"DeviceListRow_Highlight\";' onmouseout='this.className=\"DeviceListRow\";'";
+ }
+ Write("<td class='"#tdClass#"' "#tdAttributes#">");
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm (3)

19-19: Ensure natural sort order is applied consistently

At line 19, the SortByName method is called without specifying the natural sort order parameters. To maintain consistency with the updated sorting functionality, consider applying natural sorting here as well.

Apply this change:

-oTmpArray.SortByName();
+oTmpArray.SortByName(soAsc, stNatural);

215-215: Prefer object literals over new Object()

At line 215, the code uses chn = new Object();. It is recommended to use object literals {} for better performance and readability.

Apply this change:

-chn = new Object();
+chn = {};

Also, update similar instances where new Object() is used.


31-33: Correct comment syntax for better readability

The comments in lines 31-33 use ! as a delimiter, which might not be standard. Replace ! with the appropriate comment syntax to improve code clarity.

For example:

-! This prevents that a channel linked with a system variable is visible in the room list
-! The Weather-Channel e. g. is of the type VARDP.
-! bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );
+// This prevents a channel linked with a system variable from being visible in the room list
+// The Weather-Channel, for example, is of the type VARDP.
+// bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hdevichannels.htm (3)

1-1: Remove unnecessary xmlns attribute from <script> tag

The xmlns="http://www.w3.org/1999/html" attribute in the <script> tag is unnecessary and may cause issues with script execution. The xmlns attribute is typically not used in <script> elements in HTML documents.


52-56: Update sort function calls to include natural sorting

The onclick handlers for the table headers use IseSort(arChns,'name',true);. To incorporate natural sorting, consider updating these function calls to pass the natural sort parameter, ensuring consistency with the sorting implemented in UserTempViewIDs().SortByName(soAsc,stNatural);.


284-287: Clarify or remove commented-out sorting function

The code within the if(firstSort) block writes a commented-out function call //IseSort(arChns,'name',true);. If this is intentional for debugging or future use, consider adding a comment explaining its purpose. Otherwise, remove it to prevent confusion.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b7be46e and d285f7c.

⛔ Files ignored due to path filters (3)
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hdevichannels.htm.orig is excluded by !**/*.orig
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hfuncchannels.htm.orig is excluded by !**/*.orig
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm.orig is excluded by !**/*.orig
📒 Files selected for processing (4)
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs.patch (1 hunks)
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hdevichannels.htm (1 hunks)
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hfuncchannels.htm (1 hunks)
  • buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm (1 hunks)
🔇 Additional comments (5)
buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs.patch (2)

14-21: Ensure backwards compatibility of modified sort behavior.

The modification to SortByName adds parameters that might affect existing sorting behavior. Please verify that this change maintains the expected order for existing use cases.

Consider adding unit tests to verify the sorting behavior with different combinations of soAsc and stNatural parameters.


4-10: Verify initialization of sorting parameters.

The new sorting call uses soAsc and stNatural parameters, but their initialization isn't visible in the provided context. Please ensure these variables are properly defined before this code block.

buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hfuncchannels.htm (1)

19-19: Confirm the availability of soAsc and stNatural constants.

The call to SortByName(soAsc, stNatural); introduces natural sorting. Ensure that the constants soAsc and stNatural are defined in this context to prevent any runtime errors due to undefined variables.

To verify, you can run the following script:

buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm (2)

254-255: Verify existence of divHTR in the DOM

In lines 254-255, new iseSubMenuControl references "divHTR". Check that an element with the ID divHTR exists in the DOM to ensure the submenu functions correctly.


33-34: Verify the exclusion of OT_VARDP from the condition

The original condition included both OT_VARDP and OT_ALARMDP, but line 34 now only checks for OT_ALARMDP. Ensure that excluding OT_VARDP is intentional, as this might affect the visibility of certain channels linked with system variables like the Weather-Channel.

To confirm whether any channels of type OT_VARDP should be excluded, run the following script:

✅ Verification successful

Based on the search results, I can now provide a definitive response about the exclusion of OT_VARDP from the condition.

The exclusion of OT_VARDP is intentional and correct

The change to only check for OT_ALARMDP and exclude OT_VARDP is intentional and has been consistently applied across multiple files in the codebase. The commented code explains that this prevents channels linked with system variables (like the Weather-Channel) from being visible in the room list, which was the previous behavior that needed to be changed.

Key evidence:

  • The same change pattern appears in multiple control view files:
    • hroomchannels.htm
    • hfuncchannels.htm
    • devices.htm
  • The comment explicitly states: "This prevents that a channel linked with a system variable is visible in the room list. The Weather-Channel e.g. is of the type VARDP."
  • The change is part of a larger patch (0191-WebUI-Add-NaturalSortOrderInControlTabs) that improves the UI organization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find channels that are of type OT_VARDP linked to data points.

# Expected result: List of channels of type OT_VARDP, if any.

ast-grep --pattern $'object oTmpDP = dom.GetObject($_);\nif( oTmpDP ) {\n  $$$\n  bIsSysVarDP = oTmpDP.IsTypeOf( OT_VARDP );\n  $$$\n}'

Length of output: 10235


Script:

#!/bin/bash
# Let's try a different approach to find references to OT_VARDP in the codebase
# First, let's check the specific file content
cat "buildroot-external/patches/occu/0191-WebUI-Add-NaturalSortOrderInControlTabs/occu/WebUI/www/rega/pages/tabs/control/hroomchannels.htm"

# Then search for other similar patterns in the codebase
rg "OT_VARDP" -A 2 -B 2

Length of output: 229099

Call("/pages/tabs/control/function.fn::ShowExtDesc()");

if (showExtDesc == false) {
Write(chn.Name()#"<br/><br><span name='hssType' class='hidden'>${chType_"#chn.HssType()#"}</span>");
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Escape channel names to prevent potential XSS vulnerabilities.

Displaying chn.Name() without proper escaping may lead to cross-site scripting (XSS) if channel names contain malicious input.

[security]

Update the code to escape chn.Name():

- Write(chn.Name()#"<br/><br><span name='hssType' class='hidden'>${chType_"#chn.HssType()#"}</span>");
+ Write(HtmlEncode(chn.Name())#"<br/><br><span name='hssType' class='hidden'>${chType_"#chn.HssType()#"}</span>");

Ensure HtmlEncode or an equivalent function properly escapes special HTML characters.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +134 to +136

string oDevHssType = oDev.HssType();
integer chNumber = chn.ChnNumber();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks for device objects to prevent runtime errors.

When accessing oDev.HssType(), there is a risk of a null reference if oDev is null. This could cause runtime exceptions.

Implement a null check before accessing oDev properties:

- string oDevHssType = oDev.HssType();
- integer chNumber = chn.ChnNumber();
+ if (oDev) {
+   string oDevHssType = oDev.HssType();
+   integer chNumber = chn.ChnNumber();
+ } else {
+   Write("<!-- Device object is null -->");
+ }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +31 to +34
! This prevents that a channel linked with a system variable is visible in the function list
! The Weather-Channel e. g. is of the type VARDP.
! bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );
bIsSysVarDP = oTmpDP.IsTypeOf( OT_ALARMDP ) ;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Re-evaluate the exclusion of OT_VARDP from system variable checks.

Previously, channels linked with system variables of types OT_VARDP and OT_ALARMDP were excluded. The updated code only checks for OT_ALARMDP, potentially including OT_VARDP channels unintentionally.

Consider restoring the original condition to exclude both types:

- bIsSysVarDP = oTmpDP.IsTypeOf( OT_ALARMDP ) ;
+ bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );

Please verify if excluding OT_VARDP is still necessary for the correct functionality.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
! This prevents that a channel linked with a system variable is visible in the function list
! The Weather-Channel e. g. is of the type VARDP.
! bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );
bIsSysVarDP = oTmpDP.IsTypeOf( OT_ALARMDP ) ;
! This prevents that a channel linked with a system variable is visible in the function list
! The Weather-Channel e. g. is of the type VARDP.
! bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );
bIsSysVarDP = ( oTmpDP.IsTypeOf( OT_VARDP ) || oTmpDP.IsTypeOf( OT_ALARMDP ) );

}
}
}
oUser.UserTempViewIDs().SortByName(soAsc,stNatural);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Define soAsc and stNatural before use

At line 43, oUser.UserTempViewIDs().SortByName(soAsc, stNatural); uses soAsc and stNatural, but these variables are not defined in the provided code. Please ensure they are properly defined to prevent runtime errors.

For example, you might define them as:

var soAsc = true; // or appropriate value
var stNatural = true; // or appropriate value for natural sorting

Comment on lines +224 to +225
Write("if (!fltHR.objPassFilter(chn ))");
Write("hide(chn['trid']);");
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Initialize fltHR before usage

The variable fltHR is used in fltHR.objPassFilter(chn), but there is no prior initialization in this file. Ensure that fltHR is defined and initialized appropriately to avoid JavaScript errors.

jQuery("#ftName").focus();
});

jQuery("[name='attention']").data('powertip', '<div>'+translateKey("lblSeeServiceMessage")+'</div>').powerTip();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure content is sanitized to prevent XSS vulnerabilities

At line 260, dynamic content is added using translateKey("lblSeeServiceMessage"). Verify that the returned content is properly sanitized before insertion to prevent potential cross-site scripting (XSS) attacks.

}
}
}
oUser.UserTempViewIDs().SortByName(soAsc,stNatural);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure soAsc and stNatural variables are defined

The variables soAsc and stNatural used in oUser.UserTempViewIDs().SortByName(soAsc,stNatural); are not defined within this code segment. Please ensure these variables are defined or imported appropriately to prevent runtime errors.

Comment on lines +196 to +202
Write("<tr id='"#trId#"'>");
if( oUser && oUser.UserLevel() == iulAdmin ) {
Write("<td class='GrayBkg CLASS03905' name='devName' onclick='DeviceListPage.showConfiguration(event, \"CHANNEL\", "#chn.ID()#");' onmouseover='this.className=\"DeviceListRow_Highlight\";' onmouseout='this.className=\"DeviceListRow\";'>");
} else {
Write("<td class='GrayBkg' name='devName'>");
}

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure proper encoding to prevent XSS vulnerabilities

When dynamically generating HTML content with user or channel names, such as in chn.Name(), ensure that the values are properly encoded or sanitized to prevent cross-site scripting (XSS) attacks.

@jens-maus jens-maus merged commit ea03815 into jens-maus:master Nov 6, 2024
8 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 7, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement-ideas New feature or change request 🏷️ WebUI This refs the WebUI component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Status und Bedienung -> Gewerke" - Sortierung/Reihenfolge (A-Z/0-9) fehlerhaft
2 participants