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

Fix fact sorting for uptime #591

Merged
merged 9 commits into from
Jan 19, 2022
Merged

Conversation

jgrammen-agilitypr
Copy link
Contributor

an attempted fix that doesnt appear to work, and may have consequences for other pages

@coveralls
Copy link

Coverage Status

Coverage remained the same at 82.252% when pulling e66d691 on jgrammen-agilitypr:master into 974c51a on voxpupuli:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 82.252% when pulling e66d691 on jgrammen-agilitypr:master into 974c51a on voxpupuli:master.

@gdubicki
Copy link
Member

Hi @jgrammen-agilitypr ! I think that you almost have it working.

I would just add an if to apply the code that you have added here but only if the fact name is "uptime".

To do that you could add an extra boolean parameter to the datatable_init macro, like a "natural_time_delta_sort", false by default.

And the value of this flag could be passed from the def fact().

@codecov
Copy link

codecov bot commented Jan 5, 2022

Codecov Report

Merging #591 (8d38167) into master (c34f65b) will decrease coverage by 0.05%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #591      +/-   ##
==========================================
- Coverage   82.77%   82.72%   -0.06%     
==========================================
  Files          12       12              
  Lines         900      903       +3     
==========================================
+ Hits          745      747       +2     
- Misses        155      156       +1     
Impacted Files Coverage Δ
puppetboard/app.py 78.30% <66.66%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c34f65b...8d38167. Read the comment docs.

@jgrammen-agilitypr
Copy link
Contributor Author

jgrammen-agilitypr commented Jan 5, 2022

ok, I have rebased on voxpupuli:master
I have added the script to the static folder for offline mode.
the datatable_init flag has been created and is being used in the template
but I could not figure out the change tot he def fact() function, some more guidance on what do do here would be appreciated

@gdubicki
Copy link
Member

gdubicki commented Jan 5, 2022

Thanks @jgrammen-agilitypr !

I meant that I imagine that we want to enable the natural time delta sorting only for the specific facts, like "uptime".

So in the def fact() (see the code here) we should pass an extra parameter like natural_time_delta_sort to the 'fact.html' template. The value of natural_time_delta_sort should be boolean saying the the fact is one of those that are natural-time-delta-sortable.

And then we can pass this parameter as a value for natural_time_delta_sort in the datatable_init macro call here.

@jgrammen-agilitypr
Copy link
Contributor Author

ok, I made more adjustments, moved the natural_time_delta_sort around. and made an attempt at modifying the fact function.

puppetboard/app.py Show resolved Hide resolved
puppetboard/templates/_macros.html Outdated Show resolved Hide resolved
@gdubicki
Copy link
Member

Almost there @jgrammen-agilitypr, check out my comments please.

@jgrammen-agilitypr
Copy link
Contributor Author

I made my best attempt at correcting your 2 comments. Thank you for your patience with me as I struggle through this.

1. Provide the natural_time_delta with a default value for the macro
 to work on other views than /fact/...
2. Set "natural-time-delta" type in "columnDefs", like documented.
3. Modify natural-time-delta.js to make it work for our case where:
a) the value is in fact <a> element - take non-formatted value from
the newly added "title" field.
b) process values like "3:45 hours".
Also refactor this script to make the code easier to understand.
4. As we use natural-time-delta only in /fact/... view, load the new
script only there.
@gdubicki
Copy link
Member

gdubicki commented Jan 17, 2022

I made it work with my commit, @jgrammen-agilitypr. Please check out its commit message to know what I changed. 🙂

Please just rebase and in my opinion then it will be ready to merge. ☺️

(We also think that in the long term we should rather switch to DataTables plugins to:

  • detect the type of our values, f.e. IP address,
  • sort the columns based on the detected type, f.e. IP addresses numerically.
    Then we won't have to have almost anything in the Python code. I am just worried that DataTables type detection & sorting plugins don't go in hand with custom renders - see that we had to read the raw value to sort with from the "title" field.

Update: we should switch to https://datatables.net/manual/data/orthogonal-data.)

@jgrammen-agilitypr
Copy link
Contributor Author

My branch has been rebased on the 'voxpupuli:master' branch. If you would prefer that I abandon this work and and make some attempt at datatables orthogonal data, just let me know

@gdubicki
Copy link
Member

I prefer to be pragmatic, so in my opinion if we have a working feature here and the code is ok, then we should merge, release it and let ourselves and the community already use what you did.

If you have the time and will to start working on a more mature and universal solution then please go ahead and to it in a separate PR.

But I am not the only (de facto) maintainer here - what are your opinions, @bastelfreak / @mterzo / @corey-hammerton ?

@gdubicki gdubicki changed the title Attempt to fix fact sorting for uptime Fix fact sorting for uptime Jan 18, 2022
@gdubicki gdubicki merged commit af2d2da into voxpupuli:master Jan 19, 2022
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.

4 participants