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
7327a128
Commit
7327a128
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
Enable drag and drop from toolbox to jsplumb graph
parent
613ea05a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
154 additions
and
61 deletions
+154
-61
dream/platform/src2/dream/Input_viewProductionLine.js
dream/platform/src2/dream/Input_viewProductionLine.js
+9
-7
dream/platform/src2/dream/mixin_promise.js
dream/platform/src2/dream/mixin_promise.js
+5
-2
dream/platform/src2/jsplumb/index.html
dream/platform/src2/jsplumb/index.html
+4
-2
dream/platform/src2/jsplumb/jsplumb.js
dream/platform/src2/jsplumb/jsplumb.js
+99
-29
dream/platform/src2/toolbox/index.html
dream/platform/src2/toolbox/index.html
+5
-2
dream/platform/src2/toolbox/toolbox.css
dream/platform/src2/toolbox/toolbox.css
+1
-0
dream/platform/src2/toolbox/toolbox.js
dream/platform/src2/toolbox/toolbox.js
+31
-19
No files found.
dream/platform/src2/dream/Input_viewProductionLine.js
View file @
7327a128
...
...
@@ -41,16 +41,18 @@
})
.
declareMethod
(
"
startService
"
,
function
()
{
var
g
=
this
;
var
g
=
this
,
graph
;
return
g
.
getDeclaredGadget
(
"
productionline_graph
"
)
.
push
(
function
(
graph
)
{
return
graph
.
startService
();
})
.
push
(
function
()
{
return
g
.
getDeclaredGadget
(
"
productionline_toolbox
"
);
.
push
(
function
(
graph_gadget
)
{
graph
=
graph_gadget
;
return
g
.
getDeclaredGadget
(
'
productionline_toolbox
'
);
})
.
push
(
function
(
toolbox
)
{
return
toolbox
.
startService
();
return
RSVP
.
all
([
graph
.
startService
(),
toolbox
.
startService
()
]);
});
});
}(
window
,
rJS
,
RSVP
));
dream/platform/src2/dream/mixin_promise.js
View file @
7327a128
...
...
@@ -3,7 +3,8 @@
(
function
(
window
,
RSVP
,
FileReader
)
{
"
use strict
"
;
window
.
loopEventListener
=
function
(
target
,
type
,
useCapture
,
callback
)
{
window
.
loopEventListener
=
function
(
target
,
type
,
useCapture
,
callback
,
allowDefault
)
{
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
...
...
@@ -28,7 +29,9 @@
handle_event_callback
=
function
(
evt
)
{
evt
.
stopPropagation
();
evt
.
preventDefault
();
if
(
allowDefault
!==
true
)
{
evt
.
preventDefault
();
}
cancelResolver
();
callback_promise
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
dream/platform/src2/jsplumb/index.html
View file @
7327a128
...
...
@@ -11,7 +11,7 @@
<script
src=
"../<%= copy.renderjs.relative_dest %>"
></script>
<script
src=
"../<%= curl.jsplumbjs.relative_dest %>"
></script>
<script
src=
"../<%= copy.handlebars.relative_dest %>"
></script>
<script
id=
"node-template"
type=
"text/x-handlebars-template"
>
<
div
class
=
"
window {{class}}
"
id
=
"
{{element_id}}
"
...
...
@@ -20,8 +20,10 @@
<
div
class
=
"
ep
"
><
/div
>
<
/div
>
</script>
<script
src=
"../dream/mixin_gadget.js"
></script>
<script
src=
"../dream/mixin_promise.js"
></script>
<script
src=
"jsplumb.js"
></script>
</head>
<body>
...
...
dream/platform/src2/jsplumb/jsplumb.js
View file @
7327a128
...
...
@@ -17,16 +17,19 @@
* along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* ==========================================================================*/
/*global RSVP, rJS, $, jsPlumb, Handlebars, DOMParser, initGadgetMixin*/
/*global RSVP, rJS, $, jsPlumb, Handlebars, initGadgetMixin,
loopEventListener, DOMParser*/
/*jslint unparam: true */
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
initGadgetMixin
)
{
(
function
(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
initGadgetMixin
,
loopEventListener
,
DOMParser
)
{
"
use strict
"
;
/*jslint nomen: true*/
var
gadget_klass
=
rJS
(
window
),
node_template_source
=
gadget_klass
.
__template_element
.
getElementById
(
'
node-template
'
).
innerHTML
,
node_template
=
Handlebars
.
compile
(
node_template_source
);
node_template
=
Handlebars
.
compile
(
node_template_source
),
domParser
=
new
DOMParser
();
function
getNodeId
(
node_container
,
element_id
)
{
var
node_id
;
...
...
@@ -53,13 +56,13 @@
// return (option.short_id || element_type) + n;
// }
//
function generateElementId(gadget_element) {
//
var n = 1;
//
while ($(gadget_element).find('#DreamNode_' + n).length > 0) {
//
n += 1;
//
}
//
return 'DreamNode_' + n;
//
}
function
generateElementId
(
gadget_element
)
{
var
n
=
1
;
while
(
$
(
gadget_element
).
find
(
'
#DreamNode_
'
+
n
).
length
>
0
)
{
n
+=
1
;
}
return
'
DreamNode_
'
+
n
;
}
function
onDataChange
()
{
//$.publish("Dream.Gui.onDataChange", g.private.getData());
...
...
@@ -251,24 +254,24 @@
node_container
[
element
.
id
]
=
element_data
;
}
function
redraw
(
gadget
)
{
var
coordinates
=
gadget
.
private
.
preference_container
.
coordinates
||
{},
absolute_position
,
element
;
$
.
each
(
coordinates
,
function
(
node_id
,
v
)
{
absolute_position
=
convertToAbsolutePosition
(
gadget
,
v
.
left
,
v
.
top
);
element
=
$
(
gadget
.
private
.
element
).
find
(
'
#
'
+
getElementId
(
gadget
.
private
.
node_container
,
node_id
)
);
element
.
css
(
'
top
'
,
absolute_position
[
1
]);
element
.
css
(
'
left
'
,
absolute_position
[
0
]);
gadget
.
private
.
jsplumb_instance
.
repaint
(
element
);
});
}
//
function redraw(gadget) {
// var coordinates = gadget.props
.preference_container.coordinates || {},
//
absolute_position,
//
element;
//
$.each(coordinates, function (node_id, v) {
//
absolute_position = convertToAbsolutePosition(
//
gadget,
//
v.left,
//
v.top
//
);
// element = $(gadget.props
.element).find(
// '#' + getElementId(gadget.props
.node_container, node_id)
//
);
//
element.css('top', absolute_position[1]);
//
element.css('left', absolute_position[0]);
// gadget.props
.jsplumb_instance.repaint(element);
//
});
//
}
// function positionGraph(gadget) {
// $.ajax(
...
...
@@ -434,6 +437,9 @@
coordinate
);
}
if
(
element
.
element_id
===
undefined
)
{
element
.
element_id
=
generateElementId
(
gadget
.
props
.
element
);
}
/*jslint nomen: true*/
render_element
.
append
(
node_template
({
"
class
"
:
element
.
_class
.
replace
(
'
.
'
,
'
-
'
),
...
...
@@ -454,6 +460,60 @@
onDataChange
();
}
function
waitForDragover
(
gadget
)
{
return
loopEventListener
(
gadget
.
props
.
main
,
'
dragover
'
,
false
,
function
()
{
return
undefined
;
}
);
}
function
waitForDrop
(
gadget
)
{
var
target
=
gadget
.
props
.
element
.
querySelector
(
'
#main
'
),
callback
;
function
canceller
()
{
if
(
callback
!==
undefined
)
{
target
.
removeEventListener
(
'
drop
'
,
callback
,
false
);
}
}
function
nonResolvableTrap
(
resolve
,
reject
)
{
callback
=
function
(
evt
)
{
var
element
=
domParser
.
parseFromString
(
evt
.
dataTransfer
.
getData
(
'
text/html
'
),
'
text/html
'
).
querySelector
(
"
.tool
"
),
offset
=
$
(
gadget
.
props
.
main
).
offset
(),
box_top
=
evt
.
clientY
-
offset
.
top
+
"
px
"
,
box_left
=
evt
.
clientX
-
offset
.
left
+
"
px
"
,
element_class
=
element
.
id
.
replace
(
'
-
'
,
'
.
'
),
relative_position
=
convertToRelativePosition
(
gadget
,
box_left
,
box_top
);
newElement
(
gadget
,
{
coordinate
:
{
left
:
relative_position
[
0
],
top
:
relative_position
[
1
]
},
"
_class
"
:
element_class
,
"
name
"
:
element_class
});
};
target
.
addEventListener
(
'
drop
'
,
callback
,
false
);
}
return
new
RSVP
.
Promise
(
nonResolvableTrap
,
canceller
);
}
initGadgetMixin
(
gadget_klass
);
gadget_klass
.
ready
(
function
(
g
)
{
g
.
props
.
node_container
=
{};
...
...
@@ -503,5 +563,15 @@
updateElementData
(
g
,
key
,
{
data
:
value
.
data
});
}
});
$
.
each
(
g
.
props
.
data
.
edges
,
function
(
key
,
value
)
{
addEdge
(
g
,
key
,
value
);
});
return
RSVP
.
all
([
waitForDragover
(
g
),
waitForDrop
(
g
)
]);
});
}(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
DOMParser
,
initGadgetMixin
));
}(
RSVP
,
rJS
,
$
,
jsPlumb
,
Handlebars
,
initGadgetMixin
,
loopEventListener
,
DOMParser
));
dream/platform/src2/toolbox/index.html
View file @
7327a128
...
...
@@ -13,13 +13,16 @@
<script
id=
"tool-template"
type=
"text/x-handlebars-template"
>
<
div
id
=
"
{{key}}
"
class
=
"
tool {{key}}
"
>
class
=
"
tool {{key}}
"
draggable
=
"
true
"
>
{{
name
}}
<
ul
/>
<
/div
>
</script>
<script
src=
"../dream/mixin_gadget.js"
></script>
<script
src=
"../dream/mixin_promise.js"
></script>
<script
src=
"toolbox.js"
></script>
</head>
<body>
...
...
dream/platform/src2/toolbox/toolbox.css
View file @
7327a128
...
...
@@ -28,6 +28,7 @@
border-radius
:
5px
;
text-align
:
center
;
padding-top
:
1.3em
;
cursor
:
move
;
}
.Dream-Source
,
.Dream-BatchSource
{
...
...
dream/platform/src2/toolbox/toolbox.js
View file @
7327a128
/*global window, document, RSVP, rJS, Handlebars*/
(
function
(
window
,
document
,
RSVP
,
rJS
,
Handlebars
)
{
/*global window, document, RSVP, rJS, Handlebars
, initGadgetMixin
*/
(
function
(
window
,
document
,
RSVP
,
rJS
,
Handlebars
,
initGadgetMixin
)
{
"
use strict
"
;
/*jslint nomen: true*/
var
gadget_klass
=
rJS
(
window
),
...
...
@@ -7,38 +7,50 @@
.
getElementById
(
'
tool-template
'
).
innerHTML
,
tool_template
=
Handlebars
.
compile
(
tool_template_source
);
function
waitForDragstart
(
tool
)
{
/*jslint unparam: true*/
var
callback
=
function
(
evt
)
{
evt
.
dataTransfer
.
setData
(
'
text/html
'
,
tool
.
outerHTML
);
};
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
tool
.
addEventListener
(
'
dragstart
'
,
callback
,
false
);
},
function
()
{
tool
.
removeEventListener
(
'
dragstart
'
,
callback
,
false
);
});
}
initGadgetMixin
(
gadget_klass
);
gadget_klass
.
declareAcquiredMethod
(
"
getConfigurationDict
"
,
"
getConfigurationDict
"
)
.
declareMethod
(
"
render
"
,
function
()
{
var
g
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
g
.
getConfigurationDict
();
})
.
push
(
function
(
config
)
{
g
.
tools_container
=
document
.
createElement
(
'
div
'
);
g
.
tools_container
.
className
=
'
tools-container
'
;
Object
.
keys
(
config
).
forEach
(
function
(
key
)
{
var
name
=
config
[
key
].
name
||
key
.
split
(
'
-
'
)[
1
];
return
g
.
getConfigurationDict
()
.
push
(
function
(
config_dict
)
{
var
tools_container
=
document
.
createElement
(
'
div
'
);
tools_container
.
className
=
'
tools-container
'
;
Object
.
keys
(
config_dict
).
forEach
(
function
(
key
)
{
var
name
=
config_dict
[
key
].
name
||
key
.
split
(
'
-
'
)[
1
];
if
(
key
!==
'
Dream-Configuration
'
)
{
g
.
tools_container
.
innerHTML
+=
tool_template
({
tools_container
.
innerHTML
+=
tool_template
({
key
:
key
,
name
:
name
});
}
});
g
.
props
.
element
.
querySelector
(
'
.tools
'
)
.
appendChild
(
tools_container
);
});
})
.
declareMethod
(
'
startService
'
,
function
()
{
var
g
=
this
;
return
g
.
getElement
().
then
(
function
(
element
)
{
element
.
querySelector
(
'
.tools
'
)
.
appendChild
(
g
.
tools_container
);
});
var
promiseArray
=
[];
[].
forEach
.
call
(
this
.
props
.
element
.
querySelectorAll
(
'
.tool
'
),
function
(
tool
)
{
promiseArray
.
push
(
waitForDragstart
(
tool
));
});
return
RSVP
.
all
(
promiseArray
);
});
}(
window
,
document
,
RSVP
,
rJS
,
Handlebars
));
}(
window
,
document
,
RSVP
,
rJS
,
Handlebars
,
initGadgetMixin
));
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