zentaobiz.ui.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. zui.Graph.loadModule().then(
  2. function()
  3. {
  4. const g6 = zui.Graph.Module;
  5. const cardWidth = 300;
  6. const cardHeight = 62;
  7. const relationWidth = 60;
  8. g6.registerNode(
  9. 'tree-node',
  10. {
  11. drawShape: function drawShape(cfg, group) {
  12. const shape = group.addShape('rect', {
  13. attrs: {
  14. width: relationWidth,
  15. height: cardHeight,
  16. radius: 4
  17. },
  18. name: 'rect-shape'
  19. });
  20. if(cfg.nodeType == 'relation')
  21. {
  22. /* Relation DOM. */
  23. group.addShape('dom', {
  24. attrs: {
  25. y: 20,
  26. width: relationWidth,
  27. height: 20,
  28. 'html' : `
  29. <div class="bg-primary-50 text-center">
  30. <div class='text-primary px-1' title='${cfg.text}'>${cfg.text}</div>
  31. </div>`
  32. },
  33. name: 'relation-dom'
  34. });
  35. group.addShape('marker', {
  36. attrs: {
  37. x: relationWidth,
  38. y: 30,
  39. r: 6,
  40. cursor: 'pointer',
  41. symbol: cfg.collapsed ? G6.Marker.expand : G6.Marker.collapse,
  42. stroke: '#666',
  43. lineWidth: 1,
  44. fill: '#fff'
  45. },
  46. // must be assigned in G6 3.3 and later versions. it can be any string you want, but should be unique in a custom item type
  47. name: 'collapse-icon',
  48. });
  49. }
  50. else
  51. {
  52. shape.attr({
  53. width: cardWidth,
  54. height: cardHeight,
  55. stroke: '#d2d6e5',
  56. class: 'graph-card',
  57. fill: '#ffffff'
  58. });
  59. /* Title DOM. */
  60. let url = typeof(cfg.objectURL) != 'undefined' ? cfg.objectURL : '';
  61. if(cfg.objectType == 'release' || cfg.objectType == 'build' || cfg.objectType == 'mr') url = '';
  62. const title = cfg.id !== 'main' && url.length > 0 ? '<a class="item-title" href="' + url + '" data-toggle="modal" data-size="lg" title="' + cfg.objectTitle + '">#' + cfg.objectID + ' ' + cfg.objectTitle + '</a>' : '#' + cfg.objectID + ' ' + cfg.objectTitle;
  63. group.addShape('dom', {
  64. attrs: {
  65. width: cardWidth,
  66. height: 29,
  67. class: 'graph-card',
  68. 'html' : `
  69. <div class='p-1.5 objectBox' data-objecttype='${cfg.objectType}' data-objectid='${cfg.objectID}'>
  70. <span class="label label-id gray-300-outline size-sm rounded-full flex-none text-clip">${cfg.objectTypeName}</span>
  71. ${title}
  72. </div>`
  73. },
  74. name: 'title-dom'
  75. });
  76. /* Status DOM. */
  77. const objectStatus = cfg.objectStatus ? cfg.objectStatus : '';
  78. const statusName = cfg.statusName ? cfg.statusName : '';
  79. group.addShape('dom', {
  80. attrs: {
  81. x: 0,
  82. y: 30,
  83. width: 100,
  84. height: 25,
  85. class: 'graph-card',
  86. 'html' : `
  87. <div class='p-2'>
  88. <span class="status-${objectStatus}">${statusName}</span>
  89. </div>`
  90. },
  91. name: 'status-dom'
  92. });
  93. /* Avatar DOM. */
  94. if(cfg.objectAssign)
  95. {
  96. const $assignedToAvatar = cfg.objectAssign.length ? zui.UserAvatar.renderHTML({account: cfg.objectAssign, src: usersAvatar[cfg.objectAssign], size: 20}) : '';
  97. group.addShape('dom', {
  98. attrs: {
  99. x: 270,
  100. y: 35,
  101. width: 20,
  102. height: 20,
  103. class: 'graph-card',
  104. 'html' : `${$assignedToAvatar}`
  105. },
  106. name: 'avatar-dom'
  107. });
  108. }
  109. }
  110. return shape;
  111. },
  112. setState(name, value, item)
  113. {
  114. if(name === 'collapsed')
  115. {
  116. const marker = item.get('group').find((ele) => ele.get('name') === 'collapse-icon');
  117. const icon = value ? G6.Marker.expand : G6.Marker.collapse;
  118. marker.attr('symbol', icon);
  119. }
  120. },
  121. },
  122. 'single-node'
  123. );
  124. });
  125. window.getVGap = function(d)
  126. {
  127. return 25;
  128. }
  129. window.getHGap = function(d)
  130. {
  131. if(d.nodeType == "relation") return 80;
  132. return 200;
  133. }
  134. window.getSide = function()
  135. {
  136. return 'right';
  137. }
  138. waitDom('#zin_graph_' + graphID, function()
  139. {
  140. let $this = $(this);
  141. setTimeout(function()
  142. {
  143. let graph = $this.zui('Graph').instance;
  144. graph.on('node:click', function(e)
  145. {
  146. const node = e.item;
  147. if(!node) return;
  148. const model = node.getModel();
  149. if(e.target.get('name') === 'collapse-icon')
  150. {
  151. model.collapsed = !model.collapsed;
  152. graph.setItemState(node, 'collapsed', model.collapsed);
  153. graph.layout();
  154. }
  155. });
  156. }, 500);
  157. });
  158. $(document).off('click', 'path.graph-card,.graph-card :not(a)').on('click', 'path.graph-card,.graph-card :not(a)', function()
  159. {
  160. let $this = $(this);
  161. if(!$this.hasClass('objectBox')) $this = $this.closest('g').find('.objectBox');
  162. if($this.length == 0) return;
  163. let objectID = $this.data('objectid');
  164. let objectType = $this.data('objecttype');
  165. if(objectType == currentObjectType && objectID == currentObjectID) return;
  166. loadModal($.createLink('custom', 'showRelationGraph', 'objectID=' + objectID + '&objectType=' + objectType));
  167. });
  168. $(document).off('mouseenter', '.graph-card').on('mouseover', '.graph-card', function()
  169. {
  170. $(this).closest('g').find('path.graph-card').attr('fill', '#f5f5f5');
  171. });
  172. $(document).off('mouseleave', '.graph-card').on('mouseout', '.graph-card', function()
  173. {
  174. $(this).closest('g').find('path.graph-card').attr('fill', '#ffffff');
  175. });