RaythaHQ / raytha

Raytha is a powerful CMS with an easy-to-use interface and fast performance. It offers custom content types, a template engine, and various access controls. It supports multiple storage providers and an automatically generated REST API. Upgrade your development workflow with Raytha.
MIT License
144 stars 30 forks source link

Support `Import from CSV` option #81

Closed apexdodge closed 11 months ago

apexdodge commented 1 year ago

79 is a pre-req

Add a new item in this dropdown box: Import from CSV

image

The header column in the CSV should match the DeveloperName of the field it should map to.

There should be two options:

smd-11 commented 11 months ago

Hey @apexdodge, I would like to work on this.

apexdodge commented 11 months ago

@smd-11 Thank you very much.

Here is a draft of the spec. Let me know your feedback.

1) Add a link below Export to CSV named Import from CSV image

2) Only show link if user as Edit permission on the content type.

3) This takes the user to a UI with a radio field of the following options and must select one option.

4) File upload field accepts .csv file.

5) User posts the form.

6) Application layer takes in the data, runs validation, and inserts appropriately, updating a status on progress (runs in background).

7) User is redirected to a status screen very similar to that of Export to CSV to see how well the import is progressing.

Once we agree on spec, we can talk about more how best to implement this from a technical perspective.

smd-11 commented 11 months ago

I am good

apexdodge commented 11 months ago

@smd-11 Okay great. We can split the task up into 2 parts. We can start with part 1 which I think is the harder of the two actually, the backend.

1) Create a new Command called BeginImportContentItemsFromCsv https://github.com/RaythaHQ/raytha/tree/main/src/Raytha.Application/ContentItems/Commands. Can use the BeginExportContentItemsToCsv command as a starting place.

2) The Command should probably take in the following attributes:

3) The Handler can actually look a lot like ExportToCsv's handler.

4) BackgroundTask for this should be a lot simpler ExportToCsv's. Most of the logic there can be written from scratch but follow this pattern:

Challenges in this step

Some advice, up to you:

Thank you again for your interest and let me know if you have any questions or concerns.

smd-11 commented 11 months ago

Hey @apexdodge ,getting exception at line 49 in QueueHostedService.cs :

May i know what the above file does.

The requested operation requires an element of type 'Number', but the target element has type 'String'.

Can you help with this?

image

apexdodge commented 11 months ago

@smd-11 This code is responsible for seeing if there were any requests to process a background task, and if there is, it will begin that execution.

I suspect there might be an issue with the BackgroundTask class you may have created as shown here: https://docs.raytha.com/articles/background_tasks.html#create-a-class-that-implements-the-iexecutebackgroundtask-interface -- perhaps a mismatch in pulling the arguments out.

Can you share your BeginImportContentItemsFromCsv file to this point? I think it might help uncover the issue.

smd-11 commented 11 months ago

resolved issue.... was using byte instead of byte[]

smd-11 commented 11 months ago

@apexdodge are these fields enough to be there in csv file.

Id,Template,title,content,contenttype ,Content item detail view,Test Data,This is test data,pages

apexdodge commented 11 months ago

@smd-11

Good questions 👍🏻 .

contenttype column is not needed because when you click Import from CSV, we are doing it from a View that is already scoped to the content type (hence the ViewId, which we can use to get the contenttype):

image

The rest are good.

One change on this:

image

I think this should be the Template's developer name, not label. You can find the developer name of a template like so:

image

Then you can use something like below (doing it from memory)

var template = _db.WebTemplates.FirstOrDefault(p => p.DeveloperName == templateDeveloperName)

Hope that helps! Let me know if you have any other questions.

smd-11 commented 11 months ago

Hey @apexdodge, pushed code to https://github.com/smd-11/raytha/tree/excfix.

smd-11 commented 11 months ago

Will create PR if everything is fine

apexdodge commented 11 months ago

@smd-11

Excellent work. There is one place that needs fixing.

image

We cannot hard code these since users define their own content types and create their own fields. So we are expecting the columns in the CSV to match developer names as shown here:

image

So you can create your own fields first in the user interface, specify the developer name, and then use CSV import with column names that match those developer names so that you can bulk import data.

Let me know if that makes sense.

smd-11 commented 11 months ago

yeah will update code accordingly

smd-11 commented 11 months ago

Hi @apexdodge , updated code at https://github.com/smd-11/raytha/tree/excfix .Have a look and let me know if any changes required

smd-11 commented 11 months ago

@apexdodge

A few queries:

apexdodge commented 11 months ago

@smd-11, yes good questions.

Let me know if anything isn't clear from that, I can happily explain.

smd-11 commented 11 months ago

@apexdodge created PR for this.

apexdodge commented 11 months ago

@smd-11 Excellent, thank you. I will review this weekend.

apexdodge commented 11 months ago

Branch release-v1.1.2 has been published and I did a little bit of code clean up and testing. It works quite well.

Tomorrow I will merge into main and write up the documentation.

apexdodge commented 11 months ago

Released with v1.1.2!