workflow-editor.utils.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. function linkWidgets(fromId, toId) {
  17. var _from = $("#wdg_" + (typeof fromId == "function" ? fromId() : fromId));
  18. var _to = $("#wdg_" + (typeof toId == "function" ? toId() : toId));
  19. if (_from.length > 0 && _to.length > 0) {
  20. var _fromCenter = {
  21. x: _from.position().left + _from.outerWidth() / 2,
  22. y: _from.position().top + _from.outerHeight() + 3
  23. }
  24. var _toCenter = {
  25. x: _to.position().left + _to.outerWidth() / 2,
  26. y: _to.position().top - 5
  27. }
  28. var _curveCoords = {};
  29. if (_fromCenter.x == _toCenter.x) {
  30. _curveCoords.x = _fromCenter.x;
  31. _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
  32. } else {
  33. if (_fromCenter.x > _toCenter.x) {
  34. _fromCenter.x = _fromCenter.x - 5;
  35. _toCenter.x = _toCenter.x + 5;
  36. } else {
  37. _fromCenter.x = _fromCenter.x + 5;
  38. _toCenter.x = _toCenter.x - 5;
  39. }
  40. _curveCoords.x = _fromCenter.x - (_fromCenter.x - _toCenter.x) / 4;
  41. _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
  42. }
  43. $(document.body).curvedArrow({
  44. p0x: _fromCenter.x,
  45. p0y: _fromCenter.y,
  46. p1x: _curveCoords.x,
  47. p1y: _curveCoords.y,
  48. p2x: _toCenter.x,
  49. p2y: _toCenter.y,
  50. lineWidth: 2,
  51. size: 10,
  52. strokeStyle: viewModel.isEditing() ? '#e5e5e5' : '#dddddd'
  53. });
  54. }
  55. }
  56. function drawArrows() {
  57. $("canvas").remove();
  58. if (viewModel.oozieColumns()[0].rows().length > 3) {
  59. var _links = viewModel.workflow.linkMapping();
  60. Object.keys(_links).forEach(function(id) {
  61. if (_links[id].length > 0) {
  62. _links[id].forEach(function(nextId) {
  63. linkWidgets(id, nextId);
  64. });
  65. }
  66. });
  67. }
  68. }
  69. function toggleProperties(widget) {
  70. if (widget.oozieMovable()) {
  71. var _el = $("#wdg_" + widget.id());
  72. if (!widget.ooziePropertiesExpanded()) {
  73. setLastExpandedWidget(widget);
  74. _el.find(".prop-editor").show();
  75. widget.ooziePropertiesExpanded(true);
  76. } else {
  77. if (widget.oozieExpanded()) {
  78. exposeOverlayClickHandler();
  79. } else {
  80. _el.find(".prop-editor").hide();
  81. widget.ooziePropertiesExpanded(false);
  82. }
  83. }
  84. $(document).trigger("drawArrows");
  85. }
  86. }
  87. var _linkMappingTimeout = -1;
  88. $(document).on("drawArrows", function(){
  89. window.clearTimeout(_linkMappingTimeout);
  90. if (typeof renderChangeables != 'undefined'){
  91. _linkMappingTimeout = window.setTimeout(renderChangeables, 25);
  92. }
  93. });
  94. $(document).on("removeArrows", function(){
  95. $("canvas").remove();
  96. });