{"size": 8433, "ext": "js", "max_stars_repo_path": "src/main/webapp/js/jsPlumb_depview.js", "max_stars_repo_name": "basil/depgraph-view-plugin", "max_stars_repo_stars_event_min_datetime": "2015-07-29T00:08:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T13:46:05.000Z", "max_issues_repo_path": "src/main/webapp/js/jsPlumb_depview.js", "max_issues_repo_name": "basil/depgraph-view-plugin", "max_issues_repo_issues_event_min_datetime": "2015-05-15T07:57:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:08:46.000Z", "max_forks_repo_path": "src/main/webapp/js/jsPlumb_depview.js", "max_forks_repo_name": "basil/depgraph-view-plugin", "max_forks_repo_forks_event_min_datetime": "2015-05-15T07:41:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T13:03:40.000Z"}
{"max_stars_count": 12, "max_issues_count": 13, "max_forks_count": 28, "avg_line_length": 44.619047619, "max_line_length": 126, "alphanum_fraction": 0.4162219851}
;
(function() {
    function escapeId(id) {
        // replace all characters except numbers and letters
        // As soon as someone opens a bug that they have a problem with a name conflict
        // rethink the strategy
        return id.replace(/[^a-zA-Z0-9]/g,'-');
    }
    
    function stripName(name) {
    	if(window.depview.projectNameStripRegex) {
    		match = window.depview.projectNameStripRegex.exec(name);
    		if(match && match[window.depview.projectNameStripRegexGroup]){
    			return match[window.depview.projectNameStripRegexGroup];
    		}
    		return name;
    	}
    }    

    function getJobDiv(jobName) {
        return jQuery('#' + escapeId(jobName));
    }

    window.depview = {
        paper: jQuery("#paper"),
        colordep: '#FF0000', // red
        colorcopy: '#32CD32', // green
        init : function() {
            jsPlumb.importDefaults({
                Connector : ["StateMachine", { curviness: 10 }],// Straight, Flowchart, Straight, Bezier
                // default to blue at one end and green at the other
                EndpointStyles : [ {
                    fillStyle : '#225588'
                }, {
                    fillStyle : '#558822'
                } ],
                // blue endpoints 7px; green endpoints 7px.
                Endpoints : [ [ "Dot", {
                    radius : 5
                } ], [ "Dot", {
                    radius : 5
                } ] ],
                Anchors : [ "Continuous", "Continuous" ],
                // def for new connector (drag n' drop)
                // - line 2px
                PaintStyle : {
                    lineWidth : 2,
                    strokeStyle : window.depview.colordep,
                    joinstyle:"round"},
                // the overlays to decorate each connection with. note that the
                // label overlay uses a function to generate the label text; in
                // this case it returns the 'labelText' member that we set on each
                // connection in the 'init' method below.
                ConnectionOverlays : [ [ "Arrow", {
                    location : 1.0,
                    foldback:0.5
                } ] ],
                ConnectionsDetachable:false
            });
            jQuery.getJSON('graph.json', function(data) {

                var top = 3;
                var space = 150;
                var xOverall = 90;

                var clusters = data["clusters"];
                // iterate clusters
                jQuery.each(clusters, function(i, cluster) {
                    jQuery.each(cluster.nodes, function(i,node) {
                        var nodeString = '<div>'
                        if (window.depview.editEnabled) {
                            nodeString = nodeString + '<div class="ep"/>';
                        }
                        nodeString = nodeString + '<a href="' + node.url + '">' + stripName(node.name) + '</a></div>'
                        var jnode = jQuery(nodeString);
                        var width = jnode.addClass('window').
                            attr('id', escapeId(node.name)).
                            attr('data-jobname', node.fullName).
                            css('top', node.y + top).
                            css('left', node.x).
                            appendTo(window.depview.paper).width();
                        jnode.css('left', node.x - width/2 + xOverall);
                    })
                    top = top + cluster.vSize + space
                });
                // definitions for drag/drop connections
                jQuery(".ep").each(function(idx, current) {
                    var p = jQuery(current).parent()
                    if(window.depview.editEnabled) {
	                    jsPlumb.makeSource(current, {
	                        parent: p,
	                        scope: "dep"
	                    });
                    }
                })
                jsPlumb.makeTarget(jsPlumb.getSelector('.window'), {scope: "dep"});

                var edges = data["edges"];
                jQuery.each(edges, function(i, edge) {
                    from = getJobDiv(edge["from"]);
                    to = getJobDiv(edge["to"]);
                    // creates/defines the look and feel of the loaded connections: red="dep", green="copy"
                    var connection;
                    var connOptions = {
                        source : from,
                        target : to,
                        scope: edge["type"],
                        paintStyle:{lineWidth : 2}
                    }
                    if("copy" == edge["type"]){
                        connOptions.paintStyle.strokeStyle = window.depview.colorcopy;
                        connOptions.overlays = [[ "Label", { label: "copy", id: from+'.'+to } ]];
                        connection = jsPlumb.connect(connOptions);
                    } else {
                        connOptions.paintStyle.strokeStyle = window.depview.colordep;
                        connection = jsPlumb.connect(connOptions);
                        // only allow deletion of "dep" connections
                        if(window.depview.editEnabled) {
	                        connection.bind("click", function(conn) {
	                            var sourceJobName = conn.source.attr('data-jobname');
	                            var targetJobName = conn.target.attr('data-jobname')
                                jQuery.ajax({
                                    url : encodeURI('edge/' + sourceJobName + '/'    + targetJobName),
                                    type : 'DELETE',
                                    success : function(response) {
                                        jsPlumb.detach(conn);
                                    },
                                    error: function (request, status, error) {
                                        alert(status+": "+error);
                                    }
                                });
	                        });
                        }
                    }
                });

                if(window.depview.editEnabled) {
	                jsPlumb.bind("jsPlumbConnection", function(info) {
	                    var connections = jsPlumb.getConnections({ scope: "dep", source: info.sourceId, target: info.targetId });
	                    if ((info.sourceId == info.targetId) || connections.length > 1) {
	                        jsPlumb.detach(info);
	                        return;
	                    }
	                    jQuery.ajax({
	                           url: encodeURI('edge/'+info.source.attr('data-jobname') +'/'+info.target.attr('data-jobname')),
	                           type: 'PUT',
	                           success: function( response ) {
//                                 alert('Load was performed.');
	                           },
	                           error: function (request, status, error) {
	                                alert(status+": "+error);
	                                jsPlumb.detach(info);
	                           }
	                    });
	                    // allow deletion of newly created connection
	                    info.connection.bind("click", function(conn) {
	                        var sourceJobName = conn.source.attr('data-jobname');
	                        var targetJobName = conn.target.attr('data-jobname');
                            jQuery.ajax({
                                url : encodeURI('edge/' + sourceJobName + '/'    + targetJobName),
                                type : 'DELETE',
                                success : function(response) {
                                    jsPlumb.detach(conn);
                                },
                                error: function (request, status, error) {
                                    alert(status+": "+error);
                                }
                            });
	                    });
	                });
                }

                // make all the window divs draggable
                jsPlumb.draggable(jsPlumb.getSelector(".window"));
            });
        }
    };
})();

// start jsPlumb
jsPlumb.bind("ready", function() {
    // chrome fix.
    document.onselectstart = function () { return false; };

    jsPlumb.setRenderMode(jsPlumb.SVG);
    depview.init();
});

