Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during import #58

Closed
cage81 opened this issue Oct 26, 2020 · 17 comments
Closed

Error during import #58

cage81 opened this issue Oct 26, 2020 · 17 comments
Assignees
Labels

Comments

@cage81
Copy link

cage81 commented Oct 26, 2020

addNodeImport (dataNode, precanvas) {

Hi Jero, I'm trying to import drawflow data i saved in current storage (Vuex) but I'm getting this error (screenshot attached):

Uncaught TypeError: Cannot read property 'options' of undefined

Screenshot 2020-10-26 at 18 23 31

If it could be useful, I'm not using options during nodes creation (I tried to set it to empty object or null, but it gave me same error). Any help? Could it be e bug?

@jerosoler jerosoler self-assigned this Oct 26, 2020
@jerosoler
Copy link
Owner

Hello

editor.start()???

Can vuex transform the object?

Try:

var exportvalue = null;
exportvalue = editor.export();
editor.import(exportvalue);

This gives you an error?

Can you show the values of vuex and editor.export() in console, are they the same?

@jerosoler jerosoler added the Vue label Oct 26, 2020
@cage81
Copy link
Author

cage81 commented Oct 27, 2020

Can vuex transform the object?

  • It seems that this is not the case

Try:

var exportvalue = null;
exportvalue = editor.export();
editor.import(exportvalue);
  • No, no error with this. I also tried to store the exportvalue in the Vuex and then import it from the Vuex and it works if I do it consecutively. But if I try to store drawflow's data in the Vuex (in the Vue's beforeRouteLeave method) and then reload drawflow's data (in the Vue's beforeRouteEnter method) I receive the error I showed you...I'm investigating about it...

Can you show the values of vuex and editor.export() in console, are they the same?

  • Yes, they are the same.

@jerosoler
Copy link
Owner

The only thing that occurs to me seeing that the word is marked is "options".

Are the nodes registered?

How are you registering the nodes?

What does the following code show you before importing?

console.log(editor.noderegister);

@cage81
Copy link
Author

cage81 commented Oct 27, 2020

Are the nodes registered?

  • I register the node when I create them (on an add button's click)

How are you registering the nodes?

  • Look:
const options = null;
props = { title: 'Node title', nodeText: 'Write here...', nodeHasInput: true, canHaveInput: canHaveInput, canHaveOutput: canHaveOutput };
this.editor.registerNode('GenericNode', GenericNode, props, options);

What does the following code show you before importing?

console.log(editor.noderegister);
  • An empty object...

  • Let me explain better: editor.noderegister has the GenericNode in the beforeRouteLeave, but it's empty in the beforeRouteEnter method.

@jerosoler
Copy link
Owner

You have to register the nodes before importing.

When importing it does not find the GenericNode node

@cage81
Copy link
Author

cage81 commented Oct 27, 2020

You have to register the nodes before importing.

When importing it does not find the GenericNode node

Ok, registering the GenericNode before import it works. It was a my mistake, I think it's not clear in the Export/Import section...but you are very helpful: thanks!

As you can see, my node is called "generic" because I can have three node types: start node (can have outputs and content, but not inputs), intermediate nodes (with an input, content and outputs) and an end node (with only one input), it depends on the button's type user clicks (and content can be of two types). Obviously, to use my customized bodies, I'm going to rewrite the addNodeImport method...but how can I handle this three kind of node (to be registered) before import? Any suggestion? Thanks a lot!

@jerosoler
Copy link
Owner

If you only have 3 nodes. Register the nodes before import and voila.
If not, another option is to read the export file and see which nodes are registered.

I don't understand why you are going to override the addNodeImport method.

It all also depends on the content of the node.

@cage81
Copy link
Author

cage81 commented Oct 27, 2020

If you only have 3 nodes. Register the nodes before import and voila.

  • The node is only the GenericNode, but each one differs by its content (buttons or text) and if it can have input/outputs or not

If not, another option is to read the export file and see which nodes are registered.

  • I think I should try this...

I don't understand why you are going to override the addNodeImport method.

  • To set node's buttons label or text in the content

It all also depends on the content of the node.

  • Exactly, I customized a lot the node content (also to maintain an output for each content element)

@jerosoler
Copy link
Owner

Perfect!

I close the issue

@cage81
Copy link
Author

cage81 commented Oct 30, 2020

The only thing that occurs to me seeing that the word is marked is "options".

Are the nodes registered?

How are you registering the nodes?

What does the following code show you before importing?

console.log(editor.noderegister);

Nodes are registered but I still have the error "Cannot read property 'options' of undefined"

It should occur at this line:

...this.noderegister[dataNode.html].options

What does it should do? I have no options (empty object) when i register the nodes and empty object in the console.log(JSON.stringify(editor.noderegister));

If I save nodes without content and without connections, it works and it draw the separated nodes. When I change nodes content/connections I get the error.

I'm going crazy...

@jerosoler jerosoler reopened this Oct 30, 2020
@jerosoler
Copy link
Owner

Hello

You code:

const options = null;
props = { title: 'Node title', nodeText: 'Write here...', nodeHasInput: true, canHaveInput: canHaveInput, canHaveOutput: canHaveOutput };
this.editor.registerNode('GenericNode', GenericNode, props, options);

Try:

this.editor.registerNode('GenericNode', GenericNode, props);

The options no is required.

Can we see your code?

@jerosoler
Copy link
Owner

I just checked with Vue:

This code correct:

  mounted() {

    const id = document.getElementById("drawflow");
    this.editor = new Drawflow(id, Vue);
    const props = {};
    const options = {};
    this.editor.registerNode('NodeExample', NodeExample, props, options);
    this.editor.start();
    this.editor.import({"drawflow":{"Home":{"data":{"1":{"id":1,"name":"Name","data":{"action":"move","options":"up"},"class":"Class","html":"NodeExample","typenode":"vue","inputs":{"input_1":{"connections":[]},"input_2":{"connections":[]},"input_3":{"connections":[]}},"outputs":{"output_1":{"connections":[{"node":"2","output":"input_2"}]},"output_2":{"connections":[]}},"pos_x":10,"pos_y":200},"2":{"id":2,"name":"Name","data":{"action":"move2","options":"down"},"class":"Class","html":"NodeExample","typenode":"vue","inputs":{"input_1":{"connections":[]},"input_2":{"connections":[{"node":"1","input":"output_1"}]},"input_3":{"connections":[]}},"outputs":{"output_1":{"connections":[]},"output_2":{"connections":[]}},"pos_x":300,"pos_y":200}}}}});

This code produces your error: Node is not registered.

  mounted() {

    const id = document.getElementById("drawflow");
    this.editor = new Drawflow(id, Vue);
    const props = {};
    const options = {};
    // this.editor.registerNode('NodeExample', NodeExample, props, options);
    this.editor.start();
    this.editor.import({"drawflow":{"Home":{"data":{"1":{"id":1,"name":"Name","data":{"action":"move","options":"up"},"class":"Class","html":"NodeExample","typenode":"vue","inputs":{"input_1":{"connections":[]},"input_2":{"connections":[]},"input_3":{"connections":[]}},"outputs":{"output_1":{"connections":[{"node":"2","output":"input_2"}]},"output_2":{"connections":[]}},"pos_x":10,"pos_y":200},"2":{"id":2,"name":"Name","data":{"action":"move2","options":"down"},"class":"Class","html":"NodeExample","typenode":"vue","inputs":{"input_1":{"connections":[]},"input_2":{"connections":[{"node":"1","input":"output_1"}]},"input_3":{"connections":[]}},"outputs":{"output_1":{"connections":[]},"output_2":{"connections":[]}},"pos_x":300,"pos_y":200}}}}});

@cage81
Copy link
Author

cage81 commented Nov 2, 2020

Take a look at next answer...it was a my mistake.

@cage81
Copy link
Author

cage81 commented Nov 2, 2020

Ok, my mistake...as it was clear from the start. Sorry.

Problem was I modified the drawflow['Home'].data[nodeId].html in a piece of code.

Solving this issue, import works! It draws "empty nodes" (lets say without title, content, buttons/options)...I think I have to set properties, right?

@jerosoler
Copy link
Owner

Hello!

It should return the painted nodes. Unless when you load them you add some content.

@cage81
Copy link
Author

cage81 commented Nov 2, 2020

Hello!

It should return the painted nodes. Unless when you load them you add some content.

I'm going to override addNodeImport method because I have to set the input and output style.top position. Then I'll set the node content too. Thank you very much Mr. Jero!

Really cool library and a great developer support by the creator!

@cage81 cage81 closed this as completed Nov 2, 2020
@zaqisilverano
Copy link

zaqisilverano commented Jul 23, 2021

I got same issue, I check console and the node are registered. but still same error "Uncaught TypeError: Cannot read property 'options' of undefined". Do you know why?

This my code using vue typescript:

    const id = document.getElementById("pipelineCanvas");
    /* @ts-ignore */
    this.editor = new Drawflow(id, Vue);
    const props = { someProps: "some" };
    /* @ts-ignore */
    this.editor.registerNode("dataset",  BatchFileInput, props);
    this.editor.start();
    setTimeout(() => {
      this.editor.import({
        "drawflow": {
          "Home": {
            "data": {
              "1": {
                "id": 1,
                "name": "dataset",
                "data": {},
                "class": "BatchFileInput",
                "html": "BatchFileInput",
                "typenode": "vue",
                "inputs": {},
                "outputs": {
                  "output_1": {
                    "connections": []
                  }
                },
                "pos_x": 532,
                "pos_y": 207
              }
            }
          },
          "Sub": {
            "data": {
              "1": {
                "id": 1,
                "name": "dataset",
                "data": {},
                "class": "BatchFileInput",
                "html": "BatchFileInput",
                "typenode": "vue",
                "inputs": {},
                "outputs": {
                  "output_1": {
                    "connections": []
                  }
                },
                "pos_x": 832,
                "pos_y": 207
              }
            }
          }
        }
      })
    }, 300)
  }```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants