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

[webui] sort ports in VLANs blade #15960

Merged
merged 3 commits into from May 4, 2024
Merged

Conversation

Npeca75
Copy link
Contributor

@Npeca75 Npeca75 commented Apr 20, 2024

sort ports in VLANs blade

before:
gi1/0/1,gi1/0/10,gi1/0/2,gi1/0/23,gi1/0/24,gi1/0/3,gi1/0/4,gi1/0/5,gi1/0/6,gi1/0/7,gi1/0/8,gi1/0/9,Po1,te1/0/2,te1/0/3,te1/0/4

after:
gi1/0/1,gi1/0/2,gi1/0/3,gi1/0/4,gi1/0/5,gi1/0/6,gi1/0/7,gi1/0/8,gi1/0/9,gi1/0/10,gi1/0/23,gi1/0/24,te1/0/2,te1/0/3,te1/0/4,Po1

Please give a short description what your pull request is for

DO NOT DELETE THE UNDERLYING TEXT

Please note

Please read this information carefully. You can run ./lnms dev:check to check your code before submitting.

  • Have you followed our code guidelines?
  • If my Pull Request does some changes/fixes/enhancements in the WebUI, I have inserted a screenshot of it.
  • If my Pull Request makes discovery/polling/yaml changes, I have added/updated test data.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926
After you are done testing, you can remove the changes with ./scripts/github-remove. If there are schema changes, you can ask on discord how to revert.

sort ports in VLANs blade

before:
gi1/0/1,gi1/0/10,gi1/0/2,gi1/0/23,gi1/0/24,gi1/0/3,gi1/0/4,gi1/0/5,gi1/0/6,gi1/0/7,gi1/0/8,gi1/0/9,Po1,te1/0/2,te1/0/3,te1/0/4

after:
gi1/0/1,gi1/0/2,gi1/0/3,gi1/0/4,gi1/0/5,gi1/0/6,gi1/0/7,gi1/0/8,gi1/0/9,gi1/0/10,gi1/0/23,gi1/0/24,te1/0/2,te1/0/3,te1/0/4,Po1

Signed-off-by: Peca Nesovanovic <peca.nesovanovic@sattrakt.com>
@Npeca75
Copy link
Contributor Author

Npeca75 commented Apr 20, 2024

before:
lnms1

after:
lnms2

Copy link
Member

@murrant murrant left a comment

Choose a reason for hiding this comment

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

Sort should be done in the controller.

@Npeca75 Npeca75 requested a review from murrant April 20, 2024 16:57
@Npeca75
Copy link
Contributor Author

Npeca75 commented Apr 20, 2024

Sort should be done in the controller.

hmm, something is wrong
if i sort this way, port names are sorted correctly, but ... order of vlan id's are messed
1,100,2,22,3,4 etc

any idea ?

@PipoCanaja
Copy link
Contributor

Sort should be done in the controller.

hmm, something is wrong if i sort this way, port names are sorted correctly, but ... order of vlan id's are messed 1,100,2,22,3,4 etc

any idea ?

Does not look messed to me, only lexicographic and not numeric.

Could you try this option :
->sortBy('vlanid', SORT_NUMERIC);

https://www.php.net/manual/en/array.constants.php

@Npeca75
Copy link
Contributor Author

Npeca75 commented Apr 22, 2024

Could you try this option : ->sortBy('vlanid', SORT_NUMERIC);

hmmm
$data = $portVlan->sortBy(['vlan', 'asc'], ['port', 'asc'])->groupBy('vlan');
this will sort vlan ids correctly, but ports are messed up (back to square one 🙁 )
for some strange reason, sortBy does not honor second param in array
[gi1/0/1] (U), [gi1/0/2] (U), [gi1/0/24], [gi1/0/3] (U)

$data = $portVlan->sortBy('port')->groupBy('vlan');
this will place ports in correct order, but order of vlan ids are messed up

since MySQL could not do natural sorting on ifName, ifDescr, i tried every possible trick, like
ORDER BY LENGTH(alphanumeric), alphanumeric
but in mixed environment (gi1/0/10, te1/0/1) it will produce strange result ...

my only idea is to:

  1. do sort in blade (you rejected this approach)
  2. do sorting in controller with PHP
    array_multisort(array_column($portsDB, 'ifName'), SORT_ASC, SORT_NATURAL, array_column($portsDB, 'ifDescr'), SORT_ASC, SORT_NATURAL, $portsDB);
    this line is tested and working as expected
    then create collection from array and pass to blade

Maybe my logic/knowledge is limited, so you have better idea

@murrant
Copy link
Member

murrant commented Apr 26, 2024

@Npeca75 to sort the sub arrays use map like this $portVlan->groupBy('vlan')->map->sort('ifIndex')

@Npeca75
Copy link
Contributor Author

Npeca75 commented May 2, 2024

@Npeca75 to sort the sub arrays use map like this $portVlan->groupBy('vlan')->map->sort('ifIndex')

hi @murrant , @PipoCanaja
sorry for late reply
this did the trick

->get()->sortBy(['vlan', 'port']);

lnms2

@murrant murrant merged commit 2ff5728 into librenms:master May 4, 2024
8 checks passed
@Npeca75 Npeca75 deleted the sortvlans branch May 4, 2024 08:58
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.

None yet

3 participants