Skip to content

Sort alert transport by name#14464

Merged
murrant merged 5 commits intolibrenms:masterfrom
SourceDoctor:alert_transport_sort
Oct 25, 2022
Merged

Sort alert transport by name#14464
murrant merged 5 commits intolibrenms:masterfrom
SourceDoctor:alert_transport_sort

Conversation

@SourceDoctor
Copy link
Copy Markdown
Member

Sort Alert Transports by Name

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.

@Jellyfrog
Copy link
Copy Markdown
Member

this sorts in php instead of the database

@SourceDoctor
Copy link
Copy Markdown
Member Author

so how to change?

@PipoCanaja
Copy link
Copy Markdown
Contributor

PipoCanaja commented Oct 17, 2022

so how to change?

You can look at orderby SQL statement, and the way to use it in Eloquent :
https://laravel.com/docs/9.x/queries#orderby

@Jellyfrog
Copy link
Copy Markdown
Member

Its orderBy in eloquent, and I highly doubt you can pass those flags to it, guessing it only accepts desc/asc

@SourceDoctor
Copy link
Copy Markdown
Member Author

Its orderBy in eloquent, and I highly doubt you can pass those flags to it, guessing it only accepts desc/asc

\App\Models\AlertTransport::orderBy('transport_name', 'asc')->all()

seems not to work. Some ideas?


// Iterate through each alert transport
foreach (\App\Models\AlertTransport::all() as $transport) {
foreach (\App\Models\AlertTransport::sortBy('transport_name', SORT_NATURAL | SORT_FLAG_CASE)->all() as $transport) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
foreach (\App\Models\AlertTransport::sortBy('transport_name', SORT_NATURAL | SORT_FLAG_CASE)->all() as $transport) {
foreach (\App\Models\AlertTransport::all()->sortBy('transport_name', SORT_NATURAL | SORT_FLAG_CASE) as $transport) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In PHP, if proper numeric sorting is important.

@murrant murrant added the WebUI label Oct 20, 2022

// Iterate through each alert transport
foreach (\App\Models\AlertTransport::all() as $transport) {
foreach (\App\Models\AlertTransport::sortBy('transport_name', SORT_NATURAL | SORT_FLAG_CASE)->all() as $transport) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
foreach (\App\Models\AlertTransport::sortBy('transport_name', SORT_NATURAL | SORT_FLAG_CASE)->all() as $transport) {
foreach (\App\Models\AlertTransport::orderBy('transport_name')->get() as $transport) {

In MySQL, it is a little more efficient at the sort.

@murrant murrant changed the title sort alert transport by name Sort alert transport by name Oct 20, 2022
@murrant murrant merged commit 505abd7 into librenms:master Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants