Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
613ea05a
Commit
613ea05a
authored
Jun 24, 2014
by
Thibaut Frain
Committed by
Jérome Perrin
Aug 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use mixin_gadget.js in jsplumb
parent
4801018c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
115 deletions
+112
-115
dream/platform/src2/jsplumb/index.html
dream/platform/src2/jsplumb/index.html
+1
-0
dream/platform/src2/jsplumb/jsplumb.js
dream/platform/src2/jsplumb/jsplumb.js
+110
-115
dream/platform/src2/toolbox/index.html
dream/platform/src2/toolbox/index.html
+1
-0
No files found.
dream/platform/src2/jsplumb/index.html
View file @
613ea05a
...
...
@@ -21,6 +21,7 @@
<
/div
>
</script>
<script
src=
"../dream/mixin_gadget.js"
></script>
<script
src=
"jsplumb.js"
></script>
</head>
<body>
...
...
dream/platform/src2/jsplumb/jsplumb.js
View file @
613ea05a
...
...
@@ -17,9 +17,9 @@
* along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* ==========================================================================*/
/*global RSVP, rJS, $, jsPlumb, Handlebars*/
/*global RSVP, rJS, $, jsPlumb, Handlebars
, DOMParser, initGadgetMixin
*/
/*jslint unparam: true */
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
)
{
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
initGadgetMixin
)
{
"
use strict
"
;
/*jslint nomen: true*/
...
...
@@ -67,13 +67,13 @@
}
function
convertToAbsolutePosition
(
gadget
,
x
,
y
)
{
var
zoom_level
=
(
gadget
.
pr
ivate
.
preference_container
.
zoom_level
||
1.0
)
*
var
zoom_level
=
(
gadget
.
pr
ops
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
canvas_size_x
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
canvas_size_x
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
size_y
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
floor
(
y
*
(
canvas_size_y
-
size_y
))
+
"
px
"
,
left
=
Math
.
floor
(
x
*
(
canvas_size_x
-
size_x
))
+
"
px
"
;
...
...
@@ -81,13 +81,13 @@
}
function
convertToRelativePosition
(
gadget
,
x
,
y
)
{
var
zoom_level
=
(
gadget
.
pr
ivate
.
preference_container
.
zoom_level
||
1.0
)
*
var
zoom_level
=
(
gadget
.
pr
ops
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
canvas_size_x
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
canvas_size_x
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
#main
'
).
width
(),
canvas_size_y
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
#main
'
).
height
(),
size_x
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
.dummy_window
'
).
width
()
*
zoom_level
,
size_y
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
size_y
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
.dummy_window
'
).
height
()
*
zoom_level
,
top
=
Math
.
max
(
Math
.
min
(
y
.
replace
(
'
px
'
,
''
)
/
(
canvas_size_y
-
size_y
),
1
),
0
),
...
...
@@ -97,13 +97,13 @@
}
function
updateElementCoordinate
(
gadget
,
node_id
,
coordinate
)
{
var
element_id
=
gadget
.
pr
ivate
.
node_container
[
node_id
].
element_id
,
coordinates
=
gadget
.
pr
ivate
.
preference_container
.
coordinates
||
{},
var
element_id
=
gadget
.
pr
ops
.
node_container
[
node_id
].
element_id
,
coordinates
=
gadget
.
pr
ops
.
preference_container
.
coordinates
||
{},
element
,
relative_position
;
if
(
coordinate
===
undefined
)
{
coordinate
=
{};
element
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
"
#
"
+
element_id
);
element
=
$
(
gadget
.
pr
ops
.
element
).
find
(
"
#
"
+
element_id
);
relative_position
=
convertToRelativePosition
(
gadget
,
element
.
css
(
'
left
'
),
...
...
@@ -113,16 +113,16 @@
coordinate
.
left
=
relative_position
[
0
];
}
coordinates
[
node_id
]
=
coordinate
;
gadget
.
pr
ivate
.
preference_container
.
coordinates
=
coordinates
;
gadget
.
pr
ops
.
preference_container
.
coordinates
=
coordinates
;
onDataChange
();
return
coordinate
;
}
function
draggable
(
gadget
)
{
var
jsplumb_instance
=
gadget
.
pr
ivate
.
jsplumb_instance
,
var
jsplumb_instance
=
gadget
.
pr
ops
.
jsplumb_instance
,
stop
=
function
(
element
)
{
updateElementCoordinate
(
gadget
,
getNodeId
(
gadget
.
pr
ivate
.
node_container
,
gadget
.
pr
ops
.
node_container
,
element
.
target
.
id
));
};
...
...
@@ -159,7 +159,7 @@
}
function
initJsPlumb
(
gadget
)
{
var
jsplumb_instance
=
gadget
.
pr
ivate
.
jsplumb_instance
;
var
jsplumb_instance
=
gadget
.
pr
ops
.
jsplumb_instance
;
jsplumb_instance
.
setRenderMode
(
jsplumb_instance
.
SVG
);
jsplumb_instance
.
importDefaults
({
...
...
@@ -201,14 +201,14 @@
// return undefined;
// });
// split in 2 methods ? one for events one for manip
gadget
.
pr
ivate
.
updateConnectionData
gadget
.
pr
ops
.
updateConnectionData
=
function
(
connection
,
remove
,
edge_data
)
{
if
(
remove
)
{
delete
gadget
.
pr
ivate
.
edge_container
[
connection
.
id
];
delete
gadget
.
pr
ops
.
edge_container
[
connection
.
id
];
}
else
{
gadget
.
pr
ivate
.
edge_container
[
connection
.
id
]
=
[
getNodeId
(
gadget
.
pr
ivate
.
node_container
,
connection
.
sourceId
),
getNodeId
(
gadget
.
pr
ivate
.
node_container
,
connection
.
targetId
),
gadget
.
pr
ops
.
edge_container
[
connection
.
id
]
=
[
getNodeId
(
gadget
.
pr
ops
.
node_container
,
connection
.
sourceId
),
getNodeId
(
gadget
.
pr
ops
.
node_container
,
connection
.
targetId
),
edge_data
||
{}
];
}
...
...
@@ -219,23 +219,23 @@
// and update the list of connections on screen.
// jsplumb_instance
// .bind("connection", function (info, originalEvent) {
// gadget.pr
ivate
.updateConnectionData(info.connection);
// gadget.pr
ops
.updateConnectionData(info.connection);
// });
// jsplumb_instance
// .bind("connectionDetached", function (info, originalEvent) {
// gadget.pr
ivate
.updateConnectionData(info.connection, true);
// gadget.pr
ops
.updateConnectionData(info.connection, true);
// });
onDataChange
();
draggable
(
gadget
);
}
function
updateNodeStyle
(
gadget
,
element_id
)
{
var
zoom_level
=
(
gadget
.
pr
ivate
.
preference_container
.
zoom_level
||
1.0
)
*
var
zoom_level
=
(
gadget
.
pr
ops
.
preference_container
.
zoom_level
||
1.0
)
*
1.1111
,
element
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
"
#
"
+
element_id
),
element
=
$
(
gadget
.
pr
ops
.
element
).
find
(
"
#
"
+
element_id
),
new_value
;
$
.
each
(
gadget
.
pr
ivate
.
style_attr_list
,
function
(
i
,
j
)
{
new_value
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
'
.dummy_window
'
).
css
(
j
)
$
.
each
(
gadget
.
pr
ops
.
style_attr_list
,
function
(
i
,
j
)
{
new_value
=
$
(
gadget
.
pr
ops
.
element
).
find
(
'
.dummy_window
'
).
css
(
j
)
.
replace
(
'
px
'
,
''
)
*
zoom_level
+
'
px
'
;
element
.
css
(
j
,
new_value
);
});
...
...
@@ -296,63 +296,63 @@
// }
// function setZoom(gadget, zoom_level) {
// $.each(gadget.pr
ivate
.style_attr_list, function (i, j) {
// var new_value = $(gadget.pr
ivate
.element).find('.dummy_window')
// $.each(gadget.pr
ops
.style_attr_list, function (i, j) {
// var new_value = $(gadget.pr
ops
.element).find('.dummy_window')
// .css(j).replace('px', '') * zoom_level + 'px';
// $(gadget.pr
ivate
.element).find('.window').css(j, new_value);
// $(gadget.pr
ops
.element).find('.window').css(j, new_value);
// });
// }
// function zoom_in(gadget) {
// var zoom_level = (gadget.pr
ivate
.preference_container.zoom_level || 1.0) *
// var zoom_level = (gadget.pr
ops
.preference_container.zoom_level || 1.0) *
// 1.1111;
// setZoom(gadget, zoom_level);
// gadget.pr
ivate
.preference_container.zoom_level = zoom_level;
// gadget.pr
ops
.preference_container.zoom_level = zoom_level;
// onDataChange();
// redraw(gadget);
// }
// function zoom_out(gadget) {
// var zoom_level = (gadget.pr
ivate
.preference_container.zoom_level || 1.0) *
// var zoom_level = (gadget.pr
ops
.preference_container.zoom_level || 1.0) *
// 0.9;
// setZoom(gadget, zoom_level);
// gadget.pr
ivate
.preference_container.zoom_level = zoom_level;
// gadget.pr
ops
.preference_container.zoom_level = zoom_level;
// onDataChange();
// redraw(gadget);
// }
// function removeElement(gadget, node_id) {
// var element_id = gadget.pr
ivate
.node_container[node_id].element_id;
// gadget.pr
ivate
.jsplumb_instance.removeAllEndpoints(
// $(gadget.pr
ivate
.element).find("#" + element_id)
// var element_id = gadget.pr
ops
.node_container[node_id].element_id;
// gadget.pr
ops
.jsplumb_instance.removeAllEndpoints(
// $(gadget.pr
ops
.element).find("#" + element_id)
// );
// $(gadget.pr
ivate
.element).find("#" + element_id).remove();
// delete gadget.pr
ivate
.node_container[node_id];
// delete gadget.pr
ivate
.preference_container.coordinates[node_id];
// $.each(gadget.pr
ivate
.edge_container, function (k, v) {
// $(gadget.pr
ops
.element).find("#" + element_id).remove();
// delete gadget.pr
ops
.node_container[node_id];
// delete gadget.pr
ops
.preference_container.coordinates[node_id];
// $.each(gadget.pr
ops
.edge_container, function (k, v) {
// if (node_id === v[0] || node_id === v[1]) {
// delete gadget.pr
ivate
.edge_container[k];
// delete gadget.pr
ops
.edge_container[k];
// }
// });
// onDataChange();
// }
function
updateElementData
(
gadget
,
node_id
,
data
)
{
var
element_id
=
gadget
.
pr
ivate
.
node_container
[
node_id
].
element_id
,
var
element_id
=
gadget
.
pr
ops
.
node_container
[
node_id
].
element_id
,
new_id
=
data
.
id
;
if
(
data
.
name
)
{
$
(
gadget
.
pr
ivate
.
element
).
find
(
"
#
"
+
element_id
).
text
(
data
.
name
)
$
(
gadget
.
pr
ops
.
element
).
find
(
"
#
"
+
element_id
).
text
(
data
.
name
)
.
append
(
'
<div class="ep"></div></div>
'
);
gadget
.
pr
ivate
.
node_container
[
node_id
].
name
=
data
.
name
;
gadget
.
pr
ops
.
node_container
[
node_id
].
name
=
data
.
name
;
}
delete
data
.
id
;
$
.
extend
(
gadget
.
pr
ivate
.
node_container
[
node_id
],
data
.
data
);
$
.
extend
(
gadget
.
pr
ops
.
node_container
[
node_id
],
data
.
data
);
if
(
new_id
&&
new_id
!==
node_id
)
{
gadget
.
pr
ivate
.
node_container
[
new_id
]
=
gadget
.
pr
ivate
.
node_container
[
node_id
];
delete
gadget
.
pr
ivate
.
node_container
[
node_id
];
$
.
each
(
gadget
.
pr
ivate
.
edge_container
,
function
(
k
,
v
)
{
gadget
.
pr
ops
.
node_container
[
new_id
]
=
gadget
.
pr
ops
.
node_container
[
node_id
];
delete
gadget
.
pr
ops
.
node_container
[
node_id
];
$
.
each
(
gadget
.
pr
ops
.
edge_container
,
function
(
k
,
v
)
{
if
(
v
[
0
]
===
node_id
)
{
v
[
0
]
=
new_id
;
}
...
...
@@ -360,25 +360,25 @@
v
[
1
]
=
new_id
;
}
});
gadget
.
pr
ivate
.
preference_container
.
coordinates
[
new_id
]
=
gadget
.
pr
ivate
.
preference_container
.
coordinates
[
node_id
];
delete
gadget
.
pr
ivate
.
preference_container
.
coordinates
[
node_id
];
gadget
.
pr
ops
.
preference_container
.
coordinates
[
new_id
]
=
gadget
.
pr
ops
.
preference_container
.
coordinates
[
node_id
];
delete
gadget
.
pr
ops
.
preference_container
.
coordinates
[
node_id
];
}
onDataChange
();
}
// function clearAll(gadget) {
// $.each(gadget.pr
ivate
.node_container, function (node_id) {
// $.each(gadget.pr
ops
.node_container, function (node_id) {
// removeElement(gadget, node_id);
// });
// // delete anything if still remains
// $(gadget.pr
ivate
.element).find("#main").children().remove();
// gadget.pr
ivate
.node_container = {};
// gadget.pr
ivate
.edge_container = {};
// gadget.pr
ivate
.preference_container = {};
// gadget.pr
ivate
.general_container = {};
// gadget.pr
ivate
.initGeneralProperties();
// gadget.pr
ivate
.prepareDialogForGeneralProperties();
// $(gadget.pr
ops
.element).find("#main").children().remove();
// gadget.pr
ops
.node_container = {};
// gadget.pr
ops
.edge_container = {};
// gadget.pr
ops
.preference_container = {};
// gadget.pr
ops
.general_container = {};
// gadget.pr
ops
.initGeneralProperties();
// gadget.pr
ops
.prepareDialogForGeneralProperties();
// }
function
addEdge
(
gadget
,
edge_id
,
edge_data
)
{
...
...
@@ -393,37 +393,37 @@
label
:
data
.
title
}]];
}
connection
=
gadget
.
pr
ivate
.
jsplumb_instance
.
connect
({
source
:
getElementId
(
gadget
.
pr
ivate
.
node_container
,
source_id
),
target
:
getElementId
(
gadget
.
pr
ivate
.
node_container
,
target_id
),
connection
=
gadget
.
pr
ops
.
jsplumb_instance
.
connect
({
source
:
getElementId
(
gadget
.
pr
ops
.
node_container
,
source_id
),
target
:
getElementId
(
gadget
.
pr
ops
.
node_container
,
target_id
),
Connector
:
[
"
Bezier
"
,
{
curviness
:
75
}
],
overlays
:
overlays
});
// call again updateConnectionData to set the connection data that
// was not passed to the connection hook
gadget
.
pr
ivate
.
updateConnectionData
(
connection
,
0
,
data
);
gadget
.
pr
ops
.
updateConnectionData
(
connection
,
0
,
data
);
}
// function setPreferences(gadget, preferences) {
// gadget.pr
ivate
.preference_container = preferences;
// var zoom_level = gadget.pr
ivate
.preference_container.zoom_level || 1.0;
// gadget.pr
ops
.preference_container = preferences;
// var zoom_level = gadget.pr
ops
.preference_container.zoom_level || 1.0;
// setZoom(gadget, zoom_level);
// }
// function setGeneralProperties(gadget, properties) {
// gadget.pr
ivate
.general_container = properties;
// gadget.pr
ops
.general_container = properties;
// onDataChange();
// }
// function updateGeneralProperties(gadget, properties) {
// $.extend(gadget.pr
ivate
.general_container, properties);
// $.extend(gadget.pr
ops
.general_container, properties);
// onDataChange();
// }
function
newElement
(
gadget
,
element
,
option
)
{
element
.
name
=
element
.
name
||
option
.
name
;
addElementToContainer
(
gadget
.
pr
ivate
.
node_container
,
element
);
var
render_element
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
"
#main
"
),
addElementToContainer
(
gadget
.
pr
ops
.
node_container
,
element
);
var
render_element
=
$
(
gadget
.
pr
ops
.
element
).
find
(
"
#main
"
),
coordinate
=
element
.
coordinate
,
box
,
absolute_position
;
...
...
@@ -441,7 +441,7 @@
"
title
"
:
element
.
name
||
element
.
id
,
"
id
"
:
element
.
id
}));
box
=
$
(
gadget
.
pr
ivate
.
element
).
find
(
"
#
"
+
element
.
element_id
);
box
=
$
(
gadget
.
pr
ops
.
element
).
find
(
"
#
"
+
element
.
element_id
);
absolute_position
=
convertToAbsolutePosition
(
gadget
,
coordinate
.
left
,
...
...
@@ -456,57 +456,52 @@
gadget_klass
.
ready
(
function
(
g
)
{
g
.
private
=
{
node_container
:
{},
edge_container
:
{},
preference_container
:
{},
style_attr_list
:
[
'
width
'
,
'
height
'
,
'
padding-top
'
,
'
line-height
'
]
};
g
.
props
.
node_container
=
{};
g
.
props
.
edge_container
=
{};
g
.
props
.
preference_container
=
{};
g
.
props
.
style_attr_list
=
[
'
width
'
,
'
height
'
,
'
padding-top
'
,
'
line-height
'
];
})
.
declareMethod
(
'
render
'
,
function
(
data
)
{
this
.
pr
ivate
.
data
=
JSON
.
parse
(
data
);
this
.
pr
ivate
.
jsplumb_instance
=
jsPlumb
.
getInstance
();
this
.
pr
ops
.
data
=
JSON
.
parse
(
data
);
this
.
pr
ops
.
jsplumb_instance
=
jsPlumb
.
getInstance
();
})
.
declareMethod
(
'
getData
'
,
function
()
{
return
JSON
.
stringify
({
"
nodes
"
:
this
.
pr
ivate
.
node_container
,
"
edges
"
:
this
.
pr
ivate
.
edge_container
,
"
preference
"
:
this
.
pr
ivate
.
preference_container
"
nodes
"
:
this
.
pr
ops
.
node_container
,
"
edges
"
:
this
.
pr
ops
.
edge_container
,
"
preference
"
:
this
.
pr
ops
.
preference_container
});
})
.
declareMethod
(
'
startService
'
,
function
()
{
var
g
adget
=
this
,
preference
=
g
adget
.
private
.
data
.
preference
!==
undefined
?
g
adget
.
private
.
data
.
preference
:
{},
var
g
=
this
,
preference
=
g
.
props
.
data
.
preference
!==
undefined
?
g
.
props
.
data
.
preference
:
{},
coordinates
=
preference
.
coordinates
;
return
gadget
.
getElement
()
.
then
(
function
(
el
)
{
gadget
.
private
.
element
=
el
;
initJsPlumb
(
gadget
);
$
.
each
(
gadget
.
private
.
data
.
nodes
,
function
(
key
,
value
)
{
if
(
coordinates
===
undefined
||
coordinates
[
key
]
===
undefined
)
{
value
.
coordinate
=
{
'
top
'
:
0.0
,
'
left
'
:
0.0
};
}
else
{
value
.
coordinate
=
coordinates
[
key
];
}
value
.
id
=
key
;
newElement
(
gadget
,
value
);
if
(
value
.
data
)
{
// backward compatibility
updateElementData
(
gadget
,
key
,
{
data
:
value
.
data
});
}
});
$
.
each
(
gadget
.
private
.
data
.
edges
,
function
(
key
,
value
)
{
addEdge
(
gadget
,
key
,
value
);
g
.
props
.
main
=
g
.
props
.
element
.
querySelector
(
'
#main
'
);
initJsPlumb
(
g
);
$
.
each
(
g
.
props
.
data
.
nodes
,
function
(
key
,
value
)
{
if
(
coordinates
===
undefined
||
coordinates
[
key
]
===
undefined
)
{
value
.
coordinate
=
{
'
top
'
:
0.0
,
'
left
'
:
0.0
};
}
else
{
value
.
coordinate
=
coordinates
[
key
];
}
value
.
id
=
key
;
newElement
(
g
,
value
);
if
(
value
.
data
)
{
// backward compatibility
updateElementData
(
g
,
key
,
{
data
:
value
.
data
});
redraw
(
gadget
);
});
});
}(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
));
}(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
DOMParser
,
initGadgetMixin
));
dream/platform/src2/toolbox/index.html
View file @
613ea05a
...
...
@@ -19,6 +19,7 @@
<
/div
>
</script>
<script
src=
"../dream/mixin_gadget.js"
></script>
<script
src=
"toolbox.js"
></script>
</head>
<body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment