v1.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace zin;
  3. class gantt extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'id:string',
  10. 'ganttLang:array',
  11. 'canEdit:bool',
  12. 'canEditDeadline:bool',
  13. 'ganttFields:array',
  14. 'showChart?:bool',
  15. 'zooming?:string',
  16. 'users?:array',
  17. 'showFields?:string',
  18. 'exportFileName?:string',
  19. 'toolbar?:bool|array',
  20. 'options?:array'
  21. );
  22. /**
  23. * @var mixed[]
  24. */
  25. protected static $defaultProps = array(
  26. 'showChart' => true,
  27. 'zooming' => 'day'
  28. );
  29. public static function getPageCSS()
  30. {
  31. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  32. }
  33. public static function getPageJS()
  34. {
  35. global $app;
  36. $currentLang = $app->getClientLang();
  37. $js = file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  38. return $js;
  39. }
  40. public function getUserList()
  41. {
  42. $users = $this->prop('users');
  43. if(empty($users)) return array();
  44. $userList = array();
  45. foreach($users as $account => $realname)
  46. {
  47. $user = array();
  48. $user['key'] = $account;
  49. $user['label'] = $realname;
  50. $userList[] = $user;
  51. }
  52. return $userList;
  53. }
  54. protected function getToolbar()
  55. {
  56. $ganttLang = $this->prop('ganttLang');
  57. $toolbar = $this->prop('toolbar');
  58. if(empty($toolbar)) return null;
  59. $ganttToolbar = array();
  60. $ganttToolbar[] = btn
  61. (
  62. set::type('ghost'),
  63. set::icon('guide'),
  64. set::url('javascript:scrollToToday()'),
  65. set::hint($ganttLang->scrollToToday)
  66. );
  67. if($toolbar === true || (is_array($toolbar) && in_array('criticalPath', $toolbar)))
  68. {
  69. $ganttToolbar[] = btn
  70. (
  71. setID('criticalPath'),
  72. set::type('ghost'),
  73. set::icon('blame rotate-90'),
  74. set::url('javascript:updateCriticalPath()'),
  75. set::hint($ganttLang->showCriticalPath)
  76. );
  77. }
  78. if($toolbar === true || (is_array($toolbar) && in_array('fullscreen', $toolbar)))
  79. {
  80. $ganttToolbar[] = btn
  81. (
  82. setID('fullScreenBtn'),
  83. set::type('ghost'),
  84. set::icon('fullscreen'),
  85. set::hint($ganttLang->fullScreen)
  86. );
  87. }
  88. if($toolbar === true || (is_array($toolbar) && in_array('setting', $toolbar)))
  89. {
  90. $ganttToolbar[] = btn
  91. (
  92. set::type('ghost'),
  93. set::icon('cog-outline'),
  94. set::url($this->prop('settingLink')),
  95. setData(array('toggle' => 'modal', 'size' => '45%')),
  96. set::hint($ganttLang->ganttSetting)
  97. );
  98. }
  99. return div
  100. (
  101. setClass('absolute gantt-toolbar'),
  102. set::style(array('width' => '40px', 'top' => '0', 'right' => '-50px')),
  103. div(setClass('p-0.5 border border-gray-300'), $ganttToolbar)
  104. );
  105. }
  106. protected function build()
  107. {
  108. global $app;
  109. list($id, $zooming, $colsWidth, $showChart) = $this->prop(array('id', 'zooming', 'colsWidth', 'showChart'));
  110. if(empty($id)) $id = 'ganttView';
  111. if(empty($zooming)) $zooming = 'day';
  112. if(empty($colsWidth)) $colsWidth = '600';
  113. if($showChart !== false) $showChart = true;
  114. $colResize = $showChart;
  115. $ganttType = data('ganttType');
  116. $project = data('project');
  117. $showFields = $this->prop('showFields');
  118. $reviewPoints = ($project && $project->model == 'ipd') ? data('reviewPoints') : array();
  119. $ganttLang = $this->prop('ganttLang');
  120. $ganttFields = $this->prop('ganttFields');
  121. $toolbar = $this->prop('toolbar');
  122. $holidays = $this->prop('holidays');
  123. $options = $this->prop('options');
  124. if(is_string($options) && $options == '[]') $options = array();
  125. return div
  126. (
  127. jsVar('ganttID', $id),
  128. jsVar('projectID', $project ? $project->id : 0),
  129. jsVar('module', $app->rawModule),
  130. jsVar('method', $app->rawMethod),
  131. jsVar('jsRoot', $app->getWebRoot()),
  132. jsVar('ganttType', $ganttType),
  133. jsVar('showFields', empty($showFields) ? array() : explode(',', $showFields)),
  134. jsVar('showChart', $showChart),
  135. jsVar('colResize', $colResize),
  136. jsVar('userList', $this->getUserList()),
  137. jsVar('ganttLang', $ganttLang),
  138. jsVar('canGanttEdit', $this->prop('canEdit')),
  139. jsVar('canEditDeadline', $this->prop('canEditDeadline')),
  140. jsVar('ganttFields', $ganttFields),
  141. jsVar('zooming', $this->prop('zooming')),
  142. jsVar('options', $options),
  143. jsVar('exportFileName', $this->prop('exportFileName')),
  144. jsVar('weekend', $this->prop('weekend')),
  145. jsVar('holidays', is_array($holidays) ? array_values($holidays) : array()),
  146. jsVar('colsWidth', (float)$colsWidth),
  147. jsVar('height', (float)$this->prop('height')),
  148. jsVar('canViewReview', common::hasPriv('review', 'view')),
  149. jsVar('canViewTaskList', common::hasPriv('execution', 'task')),
  150. jsVar('canViewTask', common::hasPriv('task', 'view')),
  151. setID('ganttContainer'),
  152. on::click('.toggle-all-icon')->call('toggleAllTasks'),
  153. div
  154. (
  155. setClass('relative'),
  156. empty($toolbar) ? null : setStyle(array('width' => 'calc(100% - 50px)')),
  157. div(setID($id), setClass('gantt is-collapsed')),
  158. $this->getToolbar()
  159. ),
  160. div(setID('myCover'), div(setID('gantt_here'), setData('reviewpoints', json_encode($reviewPoints)))),
  161. modal
  162. (
  163. setID('changeDeadlineModal'),
  164. set::size('sm'),
  165. set::title($ganttLang->edit),
  166. inputGroup
  167. (
  168. $ganttFields['column_deadline'],
  169. datePicker(set::name('deadline')),
  170. formHidden('reviewID', ''),
  171. formHidden('projectID', ''),
  172. btn(setClass('primary'), $ganttLang->edit, on::click('saveDeadline'))
  173. )
  174. )
  175. );
  176. }
  177. }