Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 0af2210

Browse files
BoykoAlexghillert
authored andcommitted
Move bootstrap tooltip attachment into Joint JS view markup rendering
* Override `render()` instead of `renderMarkup()` to have ports rendered and tooltips applied to ports too
1 parent e1d3bb2 commit 0af2210

File tree

2 files changed

+73
-63
lines changed

2 files changed

+73
-63
lines changed

ui/app/scripts/stream/services/render-service.js

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -667,27 +667,27 @@ define(function(require) {
667667
}
668668
}
669669

670-
function initializeNewNode(node, context) {
670+
function initializeNewNode(view) {
671+
var node = view.model;
671672
var metadata = node.attr('metadata');
672-
var view = context.paper.findViewByModel(node);
673673
if (metadata) {
674-
var isPalette = view && (context.graph.attributes.type === joint.shapes.flo.PALETTE_TYPE);
675-
674+
var paper = view.paper;
675+
var isPalette = paper.model.get('type') === joint.shapes.flo.PALETTE_TYPE;
676676
if (metadata.name === 'tap') {
677-
refreshVisuals(node, 'props/name', context.paper);
677+
refreshVisuals(node, 'props/name', paper);
678678
} else if (metadata.name === 'destination') {
679-
refreshVisuals(node, 'props/name', context.paper);
679+
refreshVisuals(node, 'props/name', paper);
680680
} else {
681-
refreshVisuals(node, 'node-name', context.paper);
681+
refreshVisuals(node, 'node-name', paper);
682682
}
683683

684684
if (!isPalette) {
685-
refreshVisuals(node, 'stream-name', context.paper);
685+
refreshVisuals(node, 'stream-name', paper);
686686
}
687687

688688
// Attach angular style tooltip to a app view
689689
if (view) {
690-
if (context.graph.attributes.type === joint.shapes.flo.CANVAS_TYPE) {
690+
if (paper.model.attributes.type === joint.shapes.flo.CANVAS_TYPE) {
691691
attachCanvasAppTooltip(view);
692692
} else if (isPalette) {
693693
attachPaletteAppTooltip(view);
@@ -697,72 +697,64 @@ define(function(require) {
697697
}
698698

699699
/**
700-
* Sets some initialization data on the decoration Joint JS model element
700+
* Sets some initialization data on the decoration Joint JS view object
701701
*
702-
* @param decoration Joint JS model object for decoration
703-
* @param context The context of the object (corresponding Joint JS graph and paper objects)
702+
* @param view Joint JS view object for decoration
704703
*/
705-
function initializeNewDecoration(decoration, context) {
706-
// Find the Joint JS view object giveb the model. View object should exist by now.
707-
var view = context.paper.findViewByModel(decoration);
704+
function initializeNewDecoration(view) {
708705
// Attach angular-bootstrap-ui tooltip to error marker
709-
if (view && decoration.attr('./kind') === 'error') {
706+
if (view.model.attr('./kind') === 'error') {
710707
attachErrorMarkerTooltip(view);
711708
}
712709
}
713710

714711
/**
715-
* Sets some initialization data on the handle Joint JS model element
712+
* Sets some initialization data on the handle Joint JS view object
716713
*
717-
* @param handle Joint JS model object for handle
718-
* @param context The context of the object (corresponding Joint JS graph and paper objects)
714+
* @param view Joint JS view object for handle
719715
*/
720-
function initializeNewHandle(handle, context) {
721-
// Find the Joint JS view object giveb the model. View object should exist by now.
722-
var view = context.paper.findViewByModel(handle);
723-
if (view) {
716+
function initializeNewHandle(view) {
717+
var handle = view.model;
718+
// Attach angular-bootstrap-ui tooltip to handles
724719

725-
// Attach angular-bootstrap-ui tooltip to handles
720+
// For some reason angular-bootstrap-ui 0.13.4 tooltip app doesn't detect mouseleave for handles
721+
// Therefore we track mouselave (or mouseout in Joint JS terms) and hide tooltip ourselves
722+
var scope = $rootScope.$new(true);
723+
scope.disabled = false;
726724

727-
// For some reason angular-bootstrap-ui 0.13.4 tooltip app doesn't detect mouseleave for handles
728-
// Therefore we track mouselave (or mouseout in Joint JS terms) and hide tooltip ourselves
729-
var scope = $rootScope.$new(true);
725+
// Enable tooltip when the mouse is over the shape
726+
view.on('cell:mouseover', function () {
727+
// Enable tooltip
730728
scope.disabled = false;
729+
// Occurs outside of angular digest cycle, so trigger angular listeners update
730+
scope.$digest();
731+
});
731732

732-
// Enable tooltip when the mouse is over the shape
733-
view.on('cell:mouseover', function() {
734-
// Enable tooltip
735-
scope.disabled = false;
736-
// Occurs outside of angular digest cycle, so trigger angular listeners update
737-
scope.$digest();
738-
});
739-
740-
// Hide tooltip if mouse pointer has left the shape. Angular 0.13.4 fails to detect it for handles properly :-(
741-
view.on('cell:mouseout', function() {
742-
// Disable tooltip
743-
scope.disabled = true;
744-
// Occurs outside of angular digest cycle, so trigger angular listeners update
745-
scope.$digest();
746-
});
733+
// Hide tooltip if mouse pointer has left the shape. Angular 0.13.4 fails to detect it for handles properly :-(
734+
view.on('cell:mouseout', function () {
735+
// Disable tooltip
736+
scope.disabled = true;
737+
// Occurs outside of angular digest cycle, so trigger angular listeners update
738+
scope.$digest();
739+
});
747740

748-
// Hide tooltip if handle has been clicked.
749-
// The 'cell:pointerup' event is important! None of the others work properly
750-
view.on('cell:pointerup', function() {
751-
// Disable tooltip
752-
scope.disabled = true;
753-
// Occurs outside of angular digest cycle, so trigger angular listeners update
754-
scope.$digest();
755-
});
741+
// Hide tooltip if handle has been clicked.
742+
// The 'cell:pointerup' event is important! None of the others work properly
743+
view.on('cell:pointerup', function() {
744+
// Disable tooltip
745+
scope.disabled = true;
746+
// Occurs outside of angular digest cycle, so trigger angular listeners update
747+
scope.$digest();
748+
});
756749

757-
if (handle.attr('./kind') === 'remove') {
758-
attachBootstrapTextTooltip(view.el, scope, 'Remove Element', 'bottom', 500);
759-
// All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
760-
$compile(view.el)(scope);
761-
} else if (handle.attr('./kind') === 'properties') {
762-
attachBootstrapTextTooltip(view.el, scope, 'Edit Properties', 'bottom', 500);
763-
// All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
764-
$compile(view.el)(scope);
765-
}
750+
if (handle.attr('./kind') === 'remove') {
751+
attachBootstrapTextTooltip(view.el, scope, 'Remove Element', 'bottom', 500);
752+
// All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
753+
$compile(view.el)(scope);
754+
} else if (handle.attr('./kind') === 'properties') {
755+
attachBootstrapTextTooltip(view.el, scope, 'Edit Properties', 'bottom', 500);
756+
// All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
757+
$compile(view.el)(scope);
766758
}
767759
}
768760

@@ -808,6 +800,26 @@ define(function(require) {
808800
});
809801
}
810802

803+
function getNodeView() {
804+
return joint.dia.ElementView.extend({
805+
options: joint.util.deepSupplement({
806+
}, joint.dia.ElementView.prototype.options),
807+
808+
render: function() {
809+
joint.dia.ElementView.prototype.render.apply(this, arguments);
810+
var type = this.model.get('type');
811+
if (type === joint.shapes.flo.NODE_TYPE) {
812+
initializeNewNode(this);
813+
} else if (type === joint.shapes.flo.DECORATION_TYPE) {
814+
initializeNewDecoration(this);
815+
} else if (type === joint.shapes.flo.HANDLE_TYPE) {
816+
initializeNewHandle(this);
817+
}
818+
}
819+
820+
});
821+
}
822+
811823
function handleLinkSourceChanged(link, paper) {
812824
var graph = paper.model;
813825
var newSourceId = link.get('source').id;
@@ -979,10 +991,8 @@ define(function(require) {
979991
'createLink': createLink,
980992
'createHandle': createHandle,
981993
'createDecoration': createDecoration,
982-
'initializeNewNode': initializeNewNode,
983-
'initializeNewDecoration': initializeNewDecoration,
984-
'initializeNewHandle': initializeNewHandle,
985994
'getLinkView': getLinkView,
995+
'getNodeView': getNodeView,
986996
'layout': layout,
987997
'initializeNewLink': initializeNewLink,
988998
'handleLinkEvent': handleLinkEvent,

ui/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"moment": "2.8.4",
2323
"angular-utils-pagination": "0.11.0",
2424
"d3": "3.5.5",
25-
"spring-flo": "0.5.0"
25+
"spring-flo": "git://github.com/spring-projects/spring-flo#master"
2626
},
2727
"devDependencies": {
2828
"angular-mocks": "1.3.5",

0 commit comments

Comments
 (0)