jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.65k stars 722 forks source link

How can I globally save the data? #335

Closed Yusufzai closed 2 years ago

Yusufzai commented 2 years ago

Currently I am saving data for each widget with a save button which has widget ID.

What I want?

I have created a button with the name Save All.

When pressed it will save the all the data.

jerosoler commented 2 years ago

Hi

const dataExported = editor.export();
console.log(dataExported);

I understand that what you want is this.

Yusufzai commented 2 years ago

Dear Jero

Thanks for your reply :)

I think I am not clear to you.

I already have two save buttons -

  1. Save - This button functionality is to save individual widgets that is currently selected.
  2. Save All - This button functionality is to save all the widget that are currently present on the canvas.

So I want the Second Button (i.e. Save All) functionality as I have already implemented First Button (i.e. Save) functionality.

jerosoler commented 2 years ago

With editor.export() you can get all the data that is on the canvas. Or filter the information you want.

Yusufzai commented 2 years ago

Dear Jero

Thanks for your reply :)

But, I have just completed my code and it works perfectly

On click of the second button i.e. Save All Button

var GlobalSave = document.querySelectorAll('.global-save-fields');

for (let index = 0; index < GlobalSave.length; index++) {

    GlobalSave[index].addEventListener('click', function() {

        DataLength = editor.drawflow.drawflow.Home.data;

        Object.keys(DataLength).map(function(k){

            dataValue_k = DataLength[k];
            dataAgent_k = k;

            getDataName = dataValue_k.name;

            switch (getDataName) {

                case 'widget-name':
                          // My Code to update data
                    break;

            }

        })

    })
}
jerosoler commented 2 years ago

Perfect! 👍