Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Show diagram in partial view (Read 17445 times)
mandz
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Mar 12th, 2013
Show diagram in partial view
Jul 15th, 2013 at 4:14am
Print Post  
I'm trying to create a one page app and in order to do that I started using partial views.  I got my diagram working on a normal view, but can't get the partial view to show the diagram (same code was copied to the partial view).  Is there any special tricks that I should know about?  Here is my code:

Code
Select All
public ActionResult _ProcessTasks(int? id)
        {
            ViewBag.ID = id;
            id = (id == 0 ? null : id);

            IEnumerable<ProcessFlowViewModel> flows = _processFlowRepository.GetChildrenFlows(id).ConvertToProcessFlowViewList();
            IEnumerable<ProcessTaskViewModel> tasks = _processTaskRepository.GetChildrenTasks(id).ConvertToProcessTaskViewList();

            string viewName = "diagramView";
            string overviewName = "overView";
            string nodelistName = "nodeList";

            ViewBag.DiagramView = SetupDiagram(viewName, tasks, flows);
            ViewBag.Overview = SetupOverview(overviewName, viewName);
            ViewBag.NodeListView = SetupNodeList(nodelistName);
            ViewBag.Tasks = new JavaScriptSerializer().Serialize(tasks);
            ViewBag.Flows = new JavaScriptSerializer().Serialize(flows);

            return PartialView();
        } 



Partial view:

Code (HTML)
Select All
@using LinearGradientBrush = MindFusion.Drawing.LinearGradientBrush;

@Html.Hidden("ID", (int?)ViewBag.ID)

    <input type="hidden" id="diagramData" data-nodes="@ViewBag.Tasks" data-links="@ViewBag.Flows" />

    <div class="editbar">
        <input id="edit" type="submit" value="Edit"/>
        <input id="endEdit" type="submit" value="End edit"/>
    </div>

    <div style="width:700px;height:700px; border:1px solid black;">
        @Html.DiagramView((DiagramView)ViewBag.DiagramView)
    </div>

    <div style="width:200px; height:200px; position:relative; top:-702px; left:710px; border:1px solid black;">
        @Html.Overview((Overview)ViewBag.Overview)
    </div>

    <div style="width:200px; height:498px; position:relative; border:1px solid black; top:-702px; left:710px;" >
        @Html.NodeListView((NodeListView)ViewBag.NodeListView)
    </div>
 



DiagramView, Overview and NodeListView has values at the end of the action code.  Could someone please help?  Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #1 - Jul 15th, 2013 at 7:07am
Print Post  
That might not be loading the diagram script files. Try adding them to your partial view HTML code:

Code
Select All
@Scripts.Render("~/Scripts/MicrosoftAjax.js")
@Scripts.Render("~/Scripts/MindFusion.Diagramming.js") 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mandz
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Mar 12th, 2013
Re: Show diagram in partial view
Reply #2 - Jul 16th, 2013 at 2:20am
Print Post  
Thanks Stoyan, but it doesn't seem to make a difference.  I already had this in my _layout.cshtml page:

Code (HTML)
Select All
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MindFusion.Diagramming.js")" type="text/javascript"></script> 



What else could I be doing wrong?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #3 - Jul 16th, 2013 at 7:10am
Print Post  
Partial views work fine in our tests. Please attach a sample project that shows the problem.
  
Back to top
 
IP Logged
 
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Re: Show diagram in partial view
Reply #4 - Aug 1st, 2013 at 12:31pm
Print Post  
Hi,

       It is also not working from our side. We have properly included Script references to Microsoft Ajax and MindFusion script files.

       What we suspect is in partial view, there is no $(document).ready(function{}()); or body onload and the script required to draw the diagram is not getting executed. Maybe we are wrong. Could you please advise us?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #5 - Aug 1st, 2013 at 3:59pm
Print Post  
Ok, here's one of the sample projects modified to load the diagram code from a partial view DiagramPart.chtml, which is called from Index.cshtml via @Html.Partial("DiagramPart"). Please let me know what we should change to see the problem.

https://mindfusion.eu/_samples/MvcAnchorPoints.zip
  
Back to top
 
IP Logged
 
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Re: Show diagram in partial view
Reply #6 - Aug 15th, 2013 at 9:08am
Print Post  
Dear Stoyo,

The flow to render partial view is a bit different from our side. We are using Ajax calls to Controller action method, which returns a partial view. That partial view (as HTML) is received at the Jquery side and appended to a DIV container.

We have modified the sample project you provided to demonstrate our case. Please take a look and thanks a lot in advance for all the help!

Link to download the project: https://dl.dropboxusercontent.com/u/183597933/AnchorPoints_Ajax.zip

Warm Regards,

Chris
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #7 - Aug 19th, 2013 at 5:32am
Print Post  
Hi,

The problem is that the diagram's initialization code does not run if you simply append the result string to the page. After the vacations our MVC developer will add some helper method to let you initialize dynamically added diagrams. Until then, you could extract and run the init code from your Ajax handler:

Code
Select All
$.ajax({
    type: "POST",
    async: true,
    url: url,
    success: function (result) {
        $('#partial-view-container').empty();
        $('#partial-view-container').append(result);
        var codeStart = result.indexOf('var c = document.createElement');
        var codeEnd = result.indexOf('});');
        var code = result.substring(codeStart, codeEnd);
        eval(code);
    },
    error: function (error) {
        console.error(error);
    }
});
} 



Alternatively, you could keep a (possibly hidden initially) diagram in the main view, and make your Ajax methods pass only diagram's Json data - send ToJson result from server and load it by calling diagram.fromJson from the success handler.

I hope that helps,
Stoyan
« Last Edit: Aug 19th, 2013 at 7:07am by Stoyo »  
Back to top
 
IP Logged
 
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Re: Show diagram in partial view
Reply #8 - Sep 3rd, 2013 at 3:27pm
Print Post  
Hi Stotyo,

Thank you very much for the suggestion. It works well.

We are having another issue. That eval(code) always fails whenever we run it for second time. For example, after one ajax call, we draw the diagram. The user clicks on a menu, hence issues another ajax call. The backend side is all OK, returning a proper diagram object. It's all fine until it reaches that eval(code) portion. Once eval(code) is run, it throws the following error:

Unhandled exception at line 1, column 128012 in eval code

0x800a138f - JavaScript runtime error: Unable to get property 'origin' of undefined or null reference

Part of the code snippet here:
this.inplaceTextBox.value=C;this.inplaceTextBox.onkeyup=this.onInplaceKeyUp;this
.inplaceTextBox.style.position="absolute";this.inplaceTextBox.style.zIndex=2;thi
s.setInplaceEditBounds(w);this.inplaceTextBox.style.border="1px solid #5C87B2";document.body.appendChild(this.inplaceTextBox);var B=this;setTimeout(function(){return B.focusInput.apply(B)},100);this.nowEditing=true},inplaceKeyUp:function(v){if(v.
keyCode==27){this.endEdit(false)}},setInplaceEditBounds:function(w){var v=b.Utils.getBounds(this.get_element());this.inplaceEditBounds=new f(v.x-(this.scroller?this.scroller.scrollLeft:0)+this.scale*this.bounds.x+this.s
cale*w.x,v.y-(this.scroller?this.scroller.scrollTop:0)+this.scale*this.bounds.y+
this.scale*w.y,this.scale*w.width,this.scale*w.height);this.inplaceTextBox.style
.left=this.inplaceEditBounds.x+"px";this.inplaceTextBox.style.top=this.inplaceEd
itBounds.y+"px";this.inplaceTextBox.style.width=this.inplaceEditBounds.width+"px
";this.inplaceTextBox.style.height=this.inplaceEditBounds.height+"px"},focusInpu
t:function(){this.inplaceTextBox.focus()},endEdit:function(w){if(!this.nowEditin
g){return}var v=this.inplaceObject.getTextToEdit();var z=this.inplaceTextBox.value;this.inplaceTextBox.style.visibility="hidden";docume
nt.body.removeChild(this.inplaceTextBox);this.inplaceTextBox=null;var A=this.inplaceObject;this.inplaceObject=null;this.nowEditing=false;if(w){A.setEd
itedText(z);if(b.DiagramNode.isInstanceOfType(A)){this.raiseEvent(b.Events.nodeT
extEdited,new b.NodeEventArgs({node:A,oldText:v,newText:z}))}else{if(b.DiagramLink.isInstanceO
fType(A)){this.raiseEvent(b.Events.linkTextEdited,new b.LinkEventArgs({link:A,oldText:v,newText:z}))}}}},onResize:function(){if(!this.
nowEditing){return}var v=this.clientToDoc(this.lastCursorPos);var z=this.inplaceObject.getTextToEdit();var w=this.inplaceObject.getEditRect(v);this.setInplaceEditBounds(w)},clearAll:funct
ion(){this.selection.clear();for(var w=0,v=this.items.length;w<v;w++){var z=this.items[0];Array.remove(this.items,z);this.onItemRemoved(z)}this.nodes=[];this.links=[]},addItem:function(v){if(Array.contains(this.items,v)){return}if(b.DiagramNode.i
sInstanceOfType(v)){this.nodes.push(v);v.updateAnchorVisibility4()}else{

//here is the problematic part
if(!Array.contains(this.items,v.origin)&&(v.origin==null||!b.DummyNode.isInstanc
eOfType(v.origin)))

{return}if(!Array.contains(this.items,v.destination)&&(v.destination==null||!b.D
ummyNode.isInstanceOfType(v.destination))){return}this.links.push(v);v.updateNod
eCollections()}if(v.getZIndex()===undefined){v.setZIndex(this.items.length)}Arra
y.add(this.items,v);this.onItemAdded(v)},removeItem:function(v){if(!v){return}th
is.selection.removeItem(v);this.removeFromCollection(v);this.removeFromZOrder(v)
;if(b.DiagramNode.isInstanceOfType(v)){v.deleteLinks();v.detach();if(v.obstacle)
{this.routeLinksAt([v.getBounds()])}}else{v.destinationConnection.removeLinkFromNode();v.originConnection.removeLi
nkFromNode()}v.onRemove()},removeFromCollection:function(v){if(b.DiagramNode.isI
nstanceOfType(v)){Array.remove(this.nodes,v)}else{Array.remove(this.links,v)}},r
emoveFromZOrder:function(v){Array.remove(this.items,v);this.onItemRemoved(v)},de
leteItem:function(v){if(v!=null&&this.raiseDeleting(v)){this.removeItem(v)}},del
eteSelection:function(){var A=this.selection.links;for(var w=0,v=A.length;w<v;w++)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #9 - Sep 3rd, 2013 at 5:36pm
Print Post  
Hi,

What methods does the browser's debugger show in the callstack when you get that error?

Stoyan
  
Back to top
 
IP Logged
 
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Re: Show diagram in partial view
Reply #10 - Sep 4th, 2013 at 7:21am
Print Post  
Hi Stoyo,

Below are the methods in order:

Firstly,
  eval code, eval code(8), line 1
Secondly,
  fromJson, eval code (1), line 1 (code snippet **)
Then
  addItem, eval code (1), line 1 (code snippet ***)



**
                var v=[];
                if(E.items instanceof Object){
                    for(var z in E.items){
                        if(E.items[z]){
                            if(E.items[z].type.indexOf("Node")>-1){
                                var D=this.loadItem(E.items[z],v);
                                v[E.items[z].instanceId]=D;
                                this.addItem(D);
                                if(E.items[z].selected){
                                    this.selection.addItem(D)
                                }
                               
                            }
                           
                        }
                        
                    }



***
        ,addItem:function(v){
            if(Array.contains(this.items,v)){
                return
            }
            if(b.DiagramNode.isInstanceOfType(v)){
                this.nodes.push(v);
                v.updateAnchorVisibility4()
            }
            else{
                if(!Array.contains(this.items,v.origin)&&(v.origin==null||!b.DummyNode.isInstanc
eOfType(v.origin))){
                    return
                }
                if(!Array.contains(this.items,v.destination)&&(v.destination==null||!b.DummyNode
.isInstanceOfType(v.destination))){
                    return
                }
                this.links.push(v);
                v.updateNodeCollections()
            }
            if(v.getZIndex()===undefined){
                v.setZIndex(this.items.length)
            }
            Array.add(this.items,v);
            this.onItemAdded(v)
        }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #11 - Sep 4th, 2013 at 2:11pm
Print Post  
Hi,

Our developer's guess is that this will happen if the diagram does not know the type of an item currently being loaded from JSON. Are you using any custom node or link types in your diagrams? What steps should we follow to reproduce the error with your sample project above?

We'll try to add some built-in methods for partial rendering in the next couple of days so you won't have to call eval.

Stoyan
  
Back to top
 
IP Logged
 
Chris B.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: May 30th, 2013
Re: Show diagram in partial view
Reply #12 - Sep 4th, 2013 at 4:14pm
Print Post  
Hi Stoyo,

Please use the project from the download link. We were able to replicate the exact issue. When we generate the diagram for the first time, it's fine. The second time always gives us error.

Download link:
https://dl.dropboxusercontent.com/u/183597933/MindFusionPartialTest.zip

We will really be grateful if you can provide us a solution soon since our side is rushing for a tight deadline this time. We have purchased MindFusion ASP.Net MVC version last week. Thanks for all the help since from the start.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #13 - Sep 5th, 2013 at 7:42am
Print Post  
Hi,

The problem seems to happen because the .js files do not load correctly when you add the script elements dynamically to the page. Move this code to the outer html page or to the layout file and it should work:

Code
Select All
@Scripts.Render("~/Scripts/MicrosoftAjax.js","~/Scripts/MindFusion.Diagramming.js") 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Show diagram in partial view
Reply #14 - Sep 5th, 2013 at 1:15pm
Print Post  
On the personal messages page (linked at top of the forum) you can find an updated version that adds support for partial rendering. The DiagramView, Overview and NodeListView Html helpers now have overloads that let you generate separate initialization functions instead of registering page_load code. E.g. you can create an initDiagram() function like this:

Code
Select All
<td>@Html.DiagramView(((DiagramView)ViewBag.DiagramView).SetWidth(600).SetHeight(600), "initDiagram")</td> 



and then replace the eval code in success handler with a call to initDiagram:

Code
Select All
initDiagram();

//var codeStart = result.indexOf('var c = document.createElement');
//var codeEnd = result.indexOf('});');
//var code = result.substring(codeStart, codeEnd);
//eval(code); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint