-
-
Notifications
You must be signed in to change notification settings - Fork 441
FE: Easier icon add in Settings #1773 #1779
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -351,6 +351,26 @@ function addViaPopupForm(element) { | |
| settingsChanged(); | ||
| } | ||
|
|
||
| // --------------------------------------------------------- | ||
| // Commit a value as a new interactive option on a target select, | ||
| // shared by addList (typed value) and addIconViaModal (pasted/encoded value) | ||
| function appendListOption(toId, value, label = value) { | ||
| const newOption = $("<option class='interactable-option'></option>") | ||
| .attr("value", value) | ||
| .text(label); | ||
|
|
||
| // add new option | ||
| $(`#${toId}`).append(newOption); | ||
|
|
||
| // Initialize interaction options only for the newly added option | ||
| initListInteractionOptions(newOption); | ||
|
|
||
| // flag something changes to prevent navigating from page | ||
| settingsChanged(); | ||
|
|
||
| return newOption; | ||
| } | ||
|
|
||
| // --------------------------------------------------------- | ||
| // Add item to list | ||
| function addList(element, clearInput = true) { | ||
|
|
@@ -361,23 +381,33 @@ function addList(element, clearInput = true) { | |
|
|
||
| console.log(`fromId | toId | input : ${fromId} | ${toId} | ${input}`); | ||
|
|
||
| const newOption = $("<option class='interactable-option'></option>") | ||
| .attr("value", input) | ||
| .text(input); | ||
|
|
||
| // add new option | ||
| $(`#${toId}`).append(newOption); | ||
| appendListOption(toId, input); | ||
|
|
||
| // clear input | ||
| if (clearInput) { | ||
| $(`#${fromId}`).val(""); | ||
| } | ||
| } | ||
|
|
||
| // Initialize interaction options only for the newly added option | ||
| initListInteractionOptions(newOption); | ||
|
|
||
| // flag something changes to prevent navigating from page | ||
| settingsChanged(); | ||
| // --------------------------------------------------------- | ||
| // Add a new icon to a target select by pasting raw SVG/Font-Awesome HTML | ||
| // in a modal and base64-encoding it automatically, instead of requiring | ||
| // the value to already be base64-encoded in the (hidden) input. | ||
| function addIconViaModal(button) { | ||
| const toId = $(button).attr("my-input-to"); | ||
|
|
||
| showModalInput( | ||
| '<i class="fa fa-square-plus pointer"></i> ' + getString('DevDetail_button_AddIcon'), | ||
| getString('DevDetail_button_AddIcon_Help'), | ||
| getString('Gen_Cancel'), | ||
| getString('Gen_Okay'), | ||
| () => { | ||
| const raw = $('#modal-input-textarea').val(); | ||
| const encoded = btoa(raw.replace(/"/g, "'")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Do not mutate the pasted HTML before encoding it.
🤖 Prompt for AI Agents🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🤖 get_repo_knowledge executed:
Length of output: 32128 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- changed hunk ---'
git diff -- front/js/settings_utils.js
printf '%s\n' '--- target context ---'
sed -n '350,440p' front/js/settings_utils.js
printf '%s\n' '--- related base64 and icon references ---'
rg -n -C 3 'addIconViaModal|btoa|atob|base64|icon' front --glob '*.js' --glob '*.php' | head -n 240Repository: netalertx/NetAlertX Length of output: 20361 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- all relevant symbols ---'
rg -n -C 5 'addIconViaModal|updateAllIconPreviews|atob\(|btoa\(|devIcon|NEWDEV_devIcon|ICON' front server test --glob '*.js' --glob '*.php' --glob '*.py' --glob '*.json' | head -n 320
printf '%s\n' '--- settings utility structure ---'
wc -l front/js/settings_utils.js
ast-grep outline front/js/settings_utils.js | head -n 160Repository: netalertx/NetAlertX Length of output: 27122 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- exact icon preview and decoder definitions ---'
rg -n -C 8 'updateAllIconPreviews|updateIconPreview|icon_base64|atob|decode.*base64|Base64' . --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' | head -n 260
printf '%s\n' '--- settings schema and icon option wiring ---'
rg -n -C 8 'NEWDEV_devIcon|devIcon|addIconViaModal|my-input-to' front server back --glob '!*.map' | head -n 320Repository: netalertx/NetAlertX Length of output: 44089 Handle non-Latin-1 input before calling
🤖 Prompt for AI Agents |
||
| appendListOption(toId, encoded); | ||
|
Comment on lines
+405
to
+407
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- settings_utils.js ---'
sed -n '340,430p' front/js/settings_utils.js
printf '%s\n' '--- icon-related references ---'
rg -n -i --glob '*.{js,php,html}' 'addIconViaModal|modal-input-textarea|atob|icon.*(html|svg)|decode.*base64|base64.*decode|innerHTML|insertAdjacentHTML' frontRepository: netalertx/NetAlertX Length of output: 50376 🏁 Script executed: #!/bin/bash
set -eu
sed -n '1,140p' /tmp/coderabbit-shell-logs/shell-output-LR0GcK
printf '%s\n' '--- focused references outside bundled libraries ---'
rg -n -i --glob '!front/lib/**' --glob '!**/*.min.js' --glob '*.{js,php,html}' 'addIconViaModal|modal-input-textarea|\batob\s*\(|\bbtoa\s*\(|icon.*(html|svg)|decode.*base64|base64.*decode|innerHTML|insertAdjacentHTML' frontRepository: netalertx/NetAlertX Length of output: 16321 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- icon modal storage and preview ---'
sed -n '610,715p' front/js/ui_components.js
printf '%s\n' '--- settings option initialization and decoding ---'
sed -n '735,825p' front/js/settings_utils.js
printf '%s\n' '--- relevant setting markup/callers ---'
rg -n -C 4 --glob '!front/lib/**' --glob '!**/*.min.js' 'addIconViaModal|my-input-to=.*icon|CUSTPROP_icon|devIcon|iconHtml' front/settings.php front/js front/php/components front/deviceDetails*.phpRepository: netalertx/NetAlertX Length of output: 27608 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- addIconViaModal callers and icon-setting construction ---'
rg -n -C 5 --glob '!front/lib/**' --glob '!**/*.min.js' 'addIconViaModal\s*\(|updateIconPreview\s*\(|DevDetail_button_AddIcon|showIconSelection\s*\(' .
printf '%s\n' '--- settings metadata for icon options ---'
rg -n -i -C 4 --glob '!front/lib/**' --glob '!**/*.min.js' 'icon.*(option|base64|select)|base64.*icon|devIcon' front/php front/settings.php front/js/settings_utils.jsRepository: netalertx/NetAlertX Length of output: 50375 XSS Reachability: External Sanitize pasted icon HTML before rendering.
🤖 Prompt for AI Agents |
||
| }, | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| // --------------------------------------------------------- | ||
|
|
||
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add validation immediately after the new functions.
appendListOptionandaddIconViaModaladd new behavior, but no test case or validation follows either function. Cover option creation, interaction initialization, modal confirmation and cancellation, mixed quotes, and non-Latin-1 input.As per coding guidelines:
**/*.{py,js,php}: Never provide a solution without proof of correctness. Write test cases or validation immediately after writing functions.Also applies to: 396-410
🤖 Prompt for AI Agents
Source: Coding guidelines