Manta icon indicating copy to clipboard operation
Manta copied to clipboard

Export data as CSV

Open brrd opened this issue 7 years ago • 24 comments

Is it a bug or a feature request?

  • [ ] It's a bug.
  • [x] I'm requesting a new feature.

Which version are you using?

  • [ ] macOS
  • [x] Windows
  • [ ] Linux

Which is the version/distribution of the OS?

Win10 64 bits

Describe your issue

First of all, thank for this very promising app.

IMO adding a way to export invoices data in a human-readable format (such as CSV) would make the app more reliable for users, who don't want to loose their data if the app is discontinued one day.

Adding a way to perform this export automatically (each time an invoice is saved, for example), or with a command which could be included in a cron job, would be even better, since it would allow to backup data periodically.

brrd avatar Dec 15 '17 11:12 brrd

This is a great idea! Thanks!

hql287 avatar Dec 15 '17 12:12 hql287

yeah, while I really like having control of my data, it would be nice to be able to sync the invoices through dropbox or similar (hence the need for an export format)

relevant: https://twitter.com/levelsio/status/940548460847144960

mathieudutour avatar Dec 15 '17 12:12 mathieudutour

Im new to contributing and have never worked with Electron before so please be gentle :smile:

I tried to look into this, using pouchdb-replication-stream and node-memorystream to convert the PouchDB to JSON in memory before writing to a file (Export / backup).

Im using dialog.showOpenDialog(...) and dialog.showSaveDialog(...) for opening and saving files.

There are two pouchDB's (contacts and invoices) and I think it is more user friendly if we merge these into one export file rather than two so I merge both into one JSON object in memory before I use csvjson to convert JSON to CSV and write it to a file. (This is working so far)

The Problem occured when I want to import this exported CSV file because I must first convert it to JSON. When using csvjson the input JSON and output JSON are not the same :disappointed:

So the question: Do you know of any JSON to CSV - CSV to JSON packages? or should we write our own script?

AlphaStyle avatar Dec 25 '17 14:12 AlphaStyle

@AlphaStyle Hey, sorry for the delayed response. Any updates on this so far?

hql287 avatar Jan 04 '18 10:01 hql287

I have to admit I haven't done much since last time I wrote. I was hoping someone could provide me with this magical package that will fix my JSON->CSV | CSV->JSON issues.

As of right now I can export everything to one single CSV file. (The import logic is there, just not working cause of CSV->JSON is not correct).

I guess I could try and write my own CSV-JSON converter, but I'm not the most experienced coder :smile: But could be good practice though :+1:

AlphaStyle avatar Jan 04 '18 13:01 AlphaStyle

So JSON to CSV is fine but you need some help with CSV to JSON?

hql287 avatar Jan 04 '18 13:01 hql287

I guess I could try and write my own CSV-JSON converter, but I'm not the most experienced coder 😄 But could be good practice though 👍

Definitely a good exercise, and you'll help lots of other fellow developers with it 👍

hql287 avatar Jan 04 '18 13:01 hql287

Yes, CSV to JSON. The PouchDB JSON dump is what I think people refer to as complex nested object with arrays. So csvjson package does something wrong when it covert CSV to JSON.

Maybe I could try and contribute to csvjson instead of starting from scratch.

AlphaStyle avatar Jan 04 '18 14:01 AlphaStyle

@AlphaStyle What about https://www.npmjs.com/package/csv-to-pouch module?

brrd avatar Jan 04 '18 14:01 brrd

But you'll only need CSV to JSON for importing data, correct? If yes, how about making this 2 separated PRs, one for export, one for import. I can use the export module for https://github.com/hql287/Manta/issues/124

hql287 avatar Jan 04 '18 14:01 hql287

Unfortunately csv-to-pouch won't work for my approach because Manta uses two PouchDB's (Invoices and Contacts) and csv-to-pouch does not return the JSON, only add it directly to PouchDB (please correct me if I am wrong).

I am hoping we can continue to have only one exported CSV file to maintain the simplicity for the end-user.

Maybe I should provide more information / pictures of my issue so people can know exactly what I am strugling with :smile:

I might have it all wrong though, maybe I am over thinking it. PouchDB dump, here you can see an example of the JSON I get from PouchDB dump. In theory all I need is the docs objects because they are the ones with the important content, but as of right now I save EVERYTHING.

AlphaStyle avatar Jan 04 '18 15:01 AlphaStyle

@hql287 Ok, let me just double check it works and then I will PR it :)

AlphaStyle avatar Jan 04 '18 15:01 AlphaStyle

oh dumping the entire pouchdb probably won't work: a csv is more or less an array of JSON objects.

So what you really want is only the docs. We don't really about all the metadata (I would even remove the _rev from the docs).

Then the csvjson will probably work

mathieudutour avatar Jan 04 '18 15:01 mathieudutour

So what you really want is only the docs

👍 This is what I would do, too.

hql287 avatar Jan 04 '18 15:01 hql287

Im only storing the docs now. Still not working the way I want it :/ I updated everything to fit in with the recent changes since last time I developed.

Do I need permission to make a pull request or am I doing something realy wrong?

AlphaStyle avatar Jan 04 '18 20:01 AlphaStyle

if you have a fork, no.

What does your JSON look like?

mathieudutour avatar Jan 04 '18 20:01 mathieudutour

I really wanna do a pull request so you guys can see for yourself :smile:

ERROR: Permission to hql287/Manta.git denied to Alphastyle. Please make sure you have the correct access rights and the repository exists

I have never experienced this :disappointed:

AlphaStyle avatar Jan 04 '18 20:01 AlphaStyle

I have never experienced this 😞

Well, then you're in luck today, haha.

Kidding aside, here's how you would do it:

  • Create a fork of this repo
  • Work on the PR locally on your machine
  • Back to this repo home page and create a new PR
  • Click on the compare across forks compare across forks
  • The base fork should be this repo dev branch and the head fork should be the PR branch on your fork.
  • GitHub will diff the 2 branches and let you know if it's possible to create the PR

hql287 avatar Jan 05 '18 05:01 hql287

I have never experienced this 😞

Don't worry, we all start somewhere. GitHub also has a detailed guide on how to create a PR from a fork.

hql287 avatar Jan 05 '18 06:01 hql287

I am sorry for super late reply! I do appreciate your patient and wisdom :smile:

I did not know about the fork approach. I will read the guide and make a PR :smile:

AlphaStyle avatar Jan 11 '18 14:01 AlphaStyle

I think @mathieudutour has a point. CSV is ok for human readability, and its fine to export it with a click on a button. But additionally some realtime json export to a folder set in the settings of the app, would be what i'm more interested in. So that you can watch the folder for filechanges with whatever syncing tool you'r using :)

And automatically importing/syning the files on app start, if they exist.

Opinions?

ghost avatar Mar 01 '18 23:03 ghost

But additionally some realtime json export to a folder set in the settings of the app, would be what i'm more interested in. So that you can watch the folder for filechanges with whatever syncing tool you'r using :)

Sounds interesting. One of the reasons that I chose pouchDB was because of its ability to sync with a remote server. But this should be a separate feature and deserve its own PR.

@AlphaStyle has already been working on this for some time. You might want to take a look here: https://github.com/hql287/Manta/pull/143.

hql287 avatar Mar 02 '18 05:03 hql287

But this should be a separate feature and deserve its own PR.

Absolutely! Just wanted some feedback before starting a new feature request :)

ghost avatar Mar 02 '18 12:03 ghost

Sure, will get back to this after I'm done with releasing a v1.1.3

hql287 avatar Mar 02 '18 13:03 hql287