puppetboard icon indicating copy to clipboard operation
puppetboard copied to clipboard

Button for exporting tables as csv

Open emlun007 opened this issue 8 years ago • 18 comments

Changes are made in layout.html and button libraries were added:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.16/b-1.4.2/b-html5-1.4.2/b-print-1.4.2/datatables.min.js"></script> 

emlun007 avatar Oct 19 '17 14:10 emlun007

@mterzo : Have you taken a look at this and can you comment on what is needed for it to be merged.

larsnaesbye avatar Oct 30 '17 10:10 larsnaesbye

CI is failing on the comment I made earlier. There are a bunch of JavaScript files added for local mode but I don’t see those files in the commits.

There was a major refactor of moving all the JavaScript to cacheable files instead of having all the JavaScript in HEAD of the html. We need make sure we don’t regress there.

mterzo avatar Oct 30 '17 14:10 mterzo

@mterzo , The javascripts that I added were for another commit where I am trying to solve the issue with the table sorting, so I will just remove the parts of the code that are not related to save button

emlun007 avatar Nov 06 '17 07:11 emlun007

Coverage Status

Coverage remained the same at 81.76% when pulling ca7d23864951681b54edc01597c45695dabf3397 on emlun007:master into c52f744cefda524873c33df9b76f6b33c6d59d80 on voxpupuli:master.

coveralls avatar Dec 08 '17 08:12 coveralls

Coverage Status

Coverage remained the same at 81.76% when pulling 868d11fb66f650da7db5ace6ec008db38f30311d on emlun007:master into c52f744cefda524873c33df9b76f6b33c6d59d80 on voxpupuli:master.

coveralls avatar Dec 21 '17 15:12 coveralls

I see the button and when I press it a file downloads.

But the file is empty. I don't see any errors in the javascript console log.

Does the csv contain data on your setup?

kirkins avatar Dec 21 '17 15:12 kirkins

Other thoughts

  1. Remove the favicon, it's cute but not related to this PR.
  2. Nice job with the drop shadow but you will have to fix the design on this. I recommend integrating the button into the existing navigation bar.

Here is a preview of the button for those who haven't run the code locally:

untitled

kirkins avatar Dec 21 '17 15:12 kirkins

The _macros.html is a different PR, same for favicon, I have no idea how the files got in this PR. The only change is in layout.html.

emlun007 avatar Dec 21 '17 15:12 emlun007

@kirkins , I updated layout.html with the version I am using. It works for chrome

emlun007 avatar Dec 21 '17 15:12 emlun007

Coverage Status

Coverage remained the same at 81.76% when pulling 4c57a2243dbc182e43f79521ef1321c3fd4819d2 on emlun007:master into c52f744cefda524873c33df9b76f6b33c6d59d80 on voxpupuli:master.

coveralls avatar Dec 21 '17 15:12 coveralls

@emlun007 common mistake. You're using your master branch for this PR. That means the PR will reflect the state of your master branch.

Currently that branch has changes for multiple intended PRs.

You'll want to make a separate branch for each PR.

kirkins avatar Dec 21 '17 15:12 kirkins

Coverage Status

Coverage remained the same at 81.76% when pulling fd32dcab1cba2400b46574a8e6c3e218b66d7878 on emlun007:master into c52f744cefda524873c33df9b76f6b33c6d59d80 on voxpupuli:master.

coveralls avatar Dec 21 '17 15:12 coveralls

Coverage Status

Coverage remained the same at 81.76% when pulling f9edc836deae394b416a84572637a9e66b9d72eb on emlun007:master into c52f744cefda524873c33df9b76f6b33c6d59d80 on voxpupuli:master.

coveralls avatar Dec 21 '17 15:12 coveralls

For style a better option might be just adding a CSV button to the menu:

untitled

<a id="export_data_button" class="item" href="#">CSV</a>

Then maybe add some logic to hide the button on pages it doesn't work with.

kirkins avatar Dec 21 '17 15:12 kirkins

The thing is, I have many options now, like CSV, Excel, PDF, Copy, Print so CSV button is just one of the options.

I was thinking of disabling button if the cells are empty, so the button will be gray and the pointer changes to a cross. It is a nice feature, just takes time to write code

emlun007 avatar Dec 21 '17 16:12 emlun007

I agree it is a nice feature. I don't think it can be released as is because people will see it on the first page, try, and think it's not working.

Also follow up on my menu suggestion. It might be a bit tricky because currently the menu is generated with:


      {%- for endpoint, caption in [
      ('index', 'Overview'),
      ('nodes', 'Nodes'),
      ('facts', 'Facts'),
      ('reports', 'Reports'),
      ('metrics', 'Metrics'),
      ('inventory', 'Inventory'),
      ('catalogs', 'Catalogs'),
      ('radiator', 'Radiator'),
      ('query', 'Query'),
] %}

Which doesn't seem to be able to take a value like ('#', 'CSV'), and has no room for the custom id.

kirkins avatar Dec 21 '17 16:12 kirkins

I have tried to modify default_settings.py that defines the menu, but if you use anything else than 'fact name', 'fact', it gives 505 error so I don't think you can change the menu structure.

The button should work on the all th and td rows. The table uses .dataTable th and .dataTable td as input and it might be the case for facts, but I am unsure how nodes table is populated. I'm not too good with template engines so any help is appreciated.

emlun007 avatar Dec 22 '17 06:12 emlun007

Are you interested in getting back to this PR, rebasing and making it work @emlun007?

gdubicki avatar Feb 22 '22 09:02 gdubicki