browse.ui.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Get by id for gantt.
  3. */
  4. function getByIdForGantt(list, id)
  5. {
  6. for (var i = 0; i < list.length; i++)
  7. {
  8. if (list[i].key == id) return list[i].label || "";
  9. }
  10. return id;
  11. }
  12. function initGantt()
  13. {
  14. const columns = [
  15. {name: 'text', width: '*', tree: true, resize: true, min_width:120, width:200},
  16. this.options.productType != 'normal' ? {name: 'branch', align: 'center', resize: true, width: 100} : null,
  17. {name: 'status', align: 'center', resize: true, width: 90},
  18. {name: 'start_date', align: 'center', resize: true, width: 90},
  19. {name: 'end_date', align: 'center', resize: true, width: 90},
  20. {name: 'requirements', align: 'center', resize: true, width: 90},
  21. window.config.vision == 'or' ? {name: 'actions', align: 'center', resize: true, width: 130, min_width: 130} : null,
  22. ].filter(Boolean);
  23. columns[columns.length - 1].resize = false;
  24. this.setConfig(
  25. {
  26. order_branch : this.options.ganttType !== 'assignedTo',
  27. drag_progress : false,
  28. drag_links : false,
  29. drag_move : false,
  30. drag_resize : true,
  31. smart_rendering : true,
  32. smart_scales : true,
  33. static_background: true,
  34. show_task_cells : false,
  35. row_height : 32,
  36. min_column_width : 40,
  37. grid_width : 600,
  38. details_on_create: false,
  39. scales : [{unit: "year", step: 1, format: "%Y"}, {unit: 'month', step: 1, format: '%M'}],
  40. scale_height : 18 * this.gantt.config.scales.length,
  41. duration_unit : 'day',
  42. columns : columns,
  43. });
  44. const gridDateToStr = this.gantt.date.date_to_str('%Y-%m-%d');
  45. this.setTemplates({
  46. task_end_date: function(data)
  47. {
  48. return this.gantt.templates.task_date(new Date(date.valueOf() - 1));
  49. },
  50. grid_date_format: function(date, column)
  51. {
  52. if(column === 'end_date') return gridDateToStr(new Date(date.valueOf()));
  53. return gridDateToStr(date);
  54. },
  55. task_class: function(start, end, task)
  56. {
  57. return 'pri-' + (task.pri || 0);
  58. },
  59. rightside_text: function(start, end, task)
  60. {
  61. if(typeof task.owner_id == 'undefined') return;
  62. return getByIdForGantt(this.gantt.serverList('userList'), task.owner_id);
  63. },
  64. grid_row_class: function(start, end, task)
  65. {
  66. if(task.type == 'task') return 'task-item';
  67. },
  68. link_class: function(link)
  69. {
  70. const types = gantt.config.links;
  71. if(link.type == types.finish_to_start) return 'finish_to_start';
  72. if(link.type == types.start_to_start) return 'start_to_start';
  73. if(link.type == types.finish_to_finish) return 'finish_to_finish';
  74. if(link.type == types.start_to_finish) return 'start_to_finish';
  75. },
  76. tooltip_text: function(start, end, task) {return '';},
  77. grid_folder: function(item) {return '';},
  78. grid_file: function(item) {return '';},
  79. });
  80. const date2Str = this.gantt.date.date_to_str(this.gantt.config.task_date);
  81. const today = new Date();
  82. this.addMarker({
  83. start_date: today,
  84. css: "today",
  85. text: this.options.todayTips,
  86. title: this.options.todayTips + ": " + date2Str(today)
  87. });
  88. this.attachEvent('onTaskClick', function(id, e)
  89. {
  90. if($(e.srcElement).hasClass('icon-magic')) return false;
  91. if($(e.srcElement).hasClass('icon-trash')) return false;
  92. if($(e.srcElement).find('a').length > 0) return false;
  93. if(e.target.tagName == 'I' || e.target.tagName == 'A') return false;
  94. if($(e.srcElement).hasClass('gantt_close') || $(e.srcElement).hasClass('gantt_open')) return false;
  95. /* The id of task item is like executionID-taskID. e.g. 1507-37829, 37829 is task id. */
  96. const mapID = id;
  97. if(!isNaN(mapID) && mapID > 0) openUrl($.createLink('roadmap', 'view', 'mapID=' + mapID, 'html'));
  98. });
  99. this.on('mouseleave', () =>
  100. {
  101. setTimeout(function(){$('.gantt_tooltip').remove()}, 100);
  102. });
  103. }
  104. window.setGanttOptions = function(_, options)
  105. {
  106. options = $.extend({onInit: initGantt}, options, options.roadmaps);
  107. return options;
  108. };
  109. window.enterGanttFullscreen = function()
  110. {
  111. zui.toggleFullscreen('#mainContainer');
  112. getGantt().gantt.expand();
  113. };
  114. window.getGantt = function()
  115. {
  116. return $('#ganttView').zui('gantt');
  117. };
  118. window.zoomTasks = function(value)
  119. {
  120. const gantt = getGantt().gantt;
  121. if(value == 'month') gantt.config.scales = [{unit: "year", step: 1, format: "%Y"}, {unit: 'month', step: 1, format: '%M'}];
  122. if(value == 'year') gantt.config.scales = [{unit: "year", step: 1, format: "%Y"}];
  123. if(value == 'quarter')
  124. {
  125. gantt.config.scales = [{unit: "year", step: 1, format: "%Y"}, {unit: "quarter", step: 1, format: function (date)
  126. {
  127. var dateToStr = gantt.date.date_to_str("%M");
  128. var endDate = gantt.date.add(gantt.date.add(date, 3, "month"), -1, "day");
  129. return dateToStr(date) + " - " + dateToStr(endDate);
  130. }}];
  131. }
  132. gantt.render();
  133. };