Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) In My Javascript diagramming, Am unable to set Undo/Redo functionality. (Read 120 times)
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Jan 3rd, 2025 at 5:52am
Print Post  
Am using javascript Diagramming in Angular 13 application, I have integrated undo/Redo functions with function but it not working but in logs prints as "No actions to undo."  Here are my functions am i doing anything wrong !!

initializeDiagram() {
    const element = document.getElementById('diagram');
 
    if (element instanceof HTMLCanvasElement) {
      this.diagramView = DiagramView.create(element);
    } else {
      console.error("Element with ID 'diagram' is not a canvas or does not exist.");
      return;
    }
 
    // DiagramView Configuration
    this.diagramView.licenseKey = this.licenseKey;
    this.diagramView.allowInplaceEdit = true;
    this.diagramView.routeLinks = true;
    this.diagramView.showGrid = true;
    this.diagramView.allowUndo = true;
    this.diagramView.behavior = Diagramming.Behavior.Modify;
    this.diagramView.behavior = Diagramming.Behavior.DrawLinks;
 
    // Initialize Diagram
    this.diagram = this.diagramView.diagram;
    this.diagram.width = 1300;
    this.diagram.height = 600;
 
    // Enable UndoManager
    if (this.diagram.undoManager) {
      this.diagram.undoManager.enabled = true;
      this.diagram.undoManager.maxUndoLevels = 50; // Optional
      console.log("UndoManager enabled");
    } else {
      console.error("UndoManager is not available in the diagram object.");
    }
 
    // Debugging: Log UndoManager state after operations
    this.diagram.addEventListener(Events.nodeCreated, () => this.logUndoRedoState());
    this.diagram.addEventListener(Events.nodeModified, () => this.logUndoRedoState());
    this.diagram.addEventListener(Events.nodeDeleted, () => this.logUndoRedoState());
    this.diagram.addEventListener(Events.linkCreated, () => this.logUndoRedoState());
    this.diagram.addEventListener(Events.linkDeleted, () => this.logUndoRedoState());
 
    // Initialize Undo/Redo Buttons
    this.initializeUndoRedoButtons();
 
    // Attach zoom and other controls
    this.initializeZoomControls();
  }

initializeUndoRedoButtons() {
    const undoButton = document.getElementById("undoButton");
    const redoButton = document.getElementById("redoButton");
 
    if (undoButton) {
      undoButton.addEventListener("click", () => {
        if (this.diagram.undoManager?.canUndo()) {
          this.diagram.undoManager.undo();
          console.log("Undo performed.");
        } else {
          console.warn("No actions to undo.");
        }
      });
    }
 
    if (redoButton) {
      redoButton.addEventListener("click", () => {
        if (this.diagram.undoManager?.canRedo()) {
          this.diagram.undoManager.redo();
          console.log("Redo performed.");
        } else {
          console.warn("No actions to redo.");
        }
      });
    }
  }
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #1 - Jan 3rd, 2025 at 7:26am
Print Post  
I don't think there's DiagramView.allowUndo property in the API. Try setting Diagram.undoEnabled instead:

https://www.mindfusion.eu/onlinehelp/jsdiagram/P_MindFusion_Diagramming_Diagram_...

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #2 - Jan 3rd, 2025 at 7:53am
Print Post  
Hi Slavcho,

Even i have tried this.diagramView.undoEnabled = true;, But still its not working, is there any alternative or Method i can try?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #3 - Jan 3rd, 2025 at 7:55am
Print Post  
Hi Avinash,

It's a property of the Diagram object. Try setting this.diagram.undoEnabled = true;

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #4 - Jan 3rd, 2025 at 8:09am
Print Post  
Thank you, Its working only for the nodes created, Undo will not work for links created and text added inside nodes?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #5 - Jan 3rd, 2025 at 8:45am
Print Post  
Undoing interactively drawn links seems to work in my test. In what way are you creating them?
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #6 - Jan 3rd, 2025 at 9:28am
Print Post  
Yes links Undo/Redo is working at my end too, Is it possible to undo text inside nodes??
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #7 - Jan 3rd, 2025 at 1:47pm
Print Post  
New scripts here should undo inplace-edited texts -

https://mindfusion.eu/_beta/jsdiag451.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #8 - Jan 6th, 2025 at 7:32am
Print Post  
Thank you Slavcho, I'll check it out and let know if its working.
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #9 - Jan 7th, 2025 at 5:21am
Print Post  
Hi Slavcho,  Am confused going through the scripts you have share, can you please guide me where should i place this script. I got jsdiag451 folder after downloading, should i have to place in my node_modules or somewhere!! can you please help me out.

Thanks in advance
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #10 - Jan 7th, 2025 at 8:50am
Print Post  
Hi,

Here's the diagramming package in node_modules format, you can overwrite the folder under node_modules/@mindfusion:

https://mindfusion.eu/_beta/modules_451.zip

Assuming the other dependent packages there (common, graphs, etc) are from v4.5 of the diagram.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Nov 12th, 2024
Re: In My Javascript diagramming, Am unable to set Undo/Redo functionality.
Reply #11 - Jan 7th, 2025 at 9:10am
Print Post  
Thank you Slavcho, its's Working  Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint