Spoolman icon indicating copy to clipboard operation
Spoolman copied to clipboard

[Feature] - Add export buttons to lists

Open vikavorkin opened this issue 1 year ago • 17 comments

Hi, The default print QC codes dialog wasn't enough for me, trying to print labels using my brother label forces me to use their software.

The simplest thing was to export the data to a CSV and go from there. Using the default export functionality of refinedev simply dumps the raw table data to a CSV file, this can be customized but it was enough for me.

The only issue I'm seeing is the QR code generation for those who may try to use the CSV, the code generates it as web+spoolman:s-${spool.id} but it's somewhat not known to the user.

Some pictures in dark and light modes. image image

vikavorkin avatar Nov 11 '23 01:11 vikavorkin

Re-done my commits to include the correct author name and email.

vikavorkin avatar Nov 14 '23 09:11 vikavorkin

Example spools CSV exported from my instance

id registered first_used filament.id filament.registered filament.name filament.vendor.id filament.vendor.registered filament.vendor.name filament.material filament.price filament.density filament.diameter filament.weight filament.spool_weight filament.settings_extruder_temp filament.settings_bed_temp filament.color_hex remaining_weight used_weight remaining_length used_length archived
1 2023-11-03T11:51:39Z 2023-11-01T11:45:28.752000Z 1 2023-11-03T11:44:00Z Red PLA+ 1 2023-11-03T11:39:17Z Elegoo PLA+ 55.08 1.25 1.75 1000 171 215 60 FF0000 635 365 211201.85754300823 121399.49291842205 FALSE
2 2023-11-03T11:52:58Z 2023-11-03T15:07:58Z 1 2023-11-03T11:44:00Z Red PLA+ 1 2023-11-03T11:39:17Z Elegoo PLA+ 55.08 1.25 1.75 1000 171 215 60 FF0000 52.18969275155939 947.8103072484406 17358.362289335775 315242.9881720945 FALSE
3 2023-11-03T11:53:29Z undefined 2 2023-11-03T11:47:32Z Gray PLA+ 1 2023-11-03T11:39:17Z Elegoo PLA+ 51.5 1.25 1.75 1000 171 215 60 717171 961 39 319629.8977934345 12971.452667995782 FALSE
4 2023-11-03T11:54:16Z undefined 2 2023-11-03T11:47:32Z Gray PLA+ 1 2023-11-03T11:39:17Z Elegoo PLA+ 51.5 1.25 1.75 1000 171 215 60 717171 1000 0 332601.35046143027 0 FALSE

vikavorkin avatar Nov 14 '23 17:11 vikavorkin

This is really nice, something I've been thinking of doing myself. Looks like a simple and clean implementation as well, great job :)

I noticed a few minor issues regarding missing columns:

  • The vendor comment seems to be missing when I export on the vendors page. However I see the filament.vendor.comment when I export from spool or filament page, not sure what's up with that
  • The filament comment is missing when I export from the spools page. However I see it when I export from the filaments page.

Donkie avatar Nov 25 '23 10:11 Donkie

@Donkie After some investigation I found the issue regarding the missing columns.

The CSV export is outdated (uses a version from 5 years ago), it has a bug where the headers for the data come from the keys of the first object in the data array Source code of export-to-csv This issue is fixed in the next bugfix version (commit)

I can't specify the headers manually currently, the API will not return non-set fields (it will return an empty string if you set and unset it).

Currently I have few options

  1. Wait for it to be fixed - opened a bug for refine to fix this - https://github.com/refinedev/refine/issues/5317
  2. Change the API to always include all the fields defined, even with null values.
  3. Look for a workaround on the client-side.

I will go with option 2 for now, I will try to see how seamless it can be (without affecting the DB).

vikavorkin avatar Nov 26 '23 17:11 vikavorkin

@Donkie I saw that response_model_exclude_none is set for all request handler returning, un-setting it would resolve my issue.

Is there a reason why response_model_exclude_none is set?

vikavorkin avatar Nov 26 '23 18:11 vikavorkin

Looks like option 1 is on its way, so I think we can merge this and then update when its available.

Regarding your question, that was just a design choice I made, to discard nullable fields entirely if they are not set.

Donkie avatar Nov 29 '23 05:11 Donkie

Going by your answer, after fixing the issue the excel will have empty values, for rows without a comment for ex. Do you prefer an empty string to fill them or a null value? By default empty cells are filled with null string image

vikavorkin avatar Nov 29 '23 16:11 vikavorkin

Empty cell is more preferable imo

Donkie avatar Nov 29 '23 20:11 Donkie

@vikavorkin are you waiting for me to do something here to continue?

Donkie avatar Dec 17 '23 15:12 Donkie

The refine fix is scheduled for January, not sure how Spoolman will handle the update, I guess it would be ok.

For now I can bring the CSV generation to Spoolman for now just to avoid the issues described, dropping it once refine's fix is released.

What you the think?

vikavorkin avatar Dec 18 '23 09:12 vikavorkin

I think it would be cool if you can get the CSV generation into Spoolman, then we're less dependent on refine

Donkie avatar Dec 18 '23 19:12 Donkie

Hi @Donkie, sorry for the delay, didn't have much time for contribution. I will try to have some basic export working at the weekend. Sorry for keeping it hanging.

vikavorkin avatar Dec 26 '23 10:12 vikavorkin

No worries, take your time :)

Donkie avatar Dec 26 '23 11:12 Donkie

@vikavorkin any update on this? Would be nice if manufacturers of filament can share a whole database of filaments :-) best

P-C-R avatar Feb 02 '24 19:02 P-C-R

@vikavorkin or @Donkie what is missing for merge?

P-C-R avatar Feb 06 '24 13:02 P-C-R

Hi @P-C-R I didn't have time to work on this fix in the past couple of months, occupied with personal things.

From what I saw, refine released my fix to the export in https://github.com/refinedev/refine/releases/tag/%40refinedev/core%404.47.0 You can try and upgrade to it but this may have side effects.

Regarding the sharing of spool data by manufacturers, this is out of scope for this PR. It would be awesome to have a global repository for available spools, closes thing I know of is the empty spool weight wiki.

vikavorkin avatar Feb 08 '24 07:02 vikavorkin

Regarding the sharing of spool data by manufacturers, this is out of scope for this PR. It would be awesome to have a global repository for available spools, closes thing I know of is the empty spool weight wiki.

@vikavorkin @P-C-R work has started on a unified filament database here: https://github.com/Donkie/SpoolmanDB

StuSerious avatar May 27 '24 12:05 StuSerious