v2.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'dropdown' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'btn' . DS . 'v1.php';
  5. class visionSwitcher extends wg
  6. {
  7. public static function getPageCSS()
  8. {
  9. return <<<CSS
  10. #versionSwitchBtn > .icon, .vision-icon {display: flex; width: 18px; height: 18px; border-radius: var(--radius-md); align-items: center; justify-content: center; background: rgba(var(--color-inverse-rgb), .1); opacity: .7;}
  11. #versionSwitchBtn > .icon, .selected .vision-icon {background: var(--color-primary-500); color: #fff; opacity: 1;}
  12. #versionSwitchBtn > .icon::before, .vision-icon::before {transform: scale(.8);}
  13. #visionSwitchMenu {display: none; min-width: 240px; border-radius: var(--radius-md); --menu-bg: transparent}
  14. .vision-vision-menu-main {width: 240px}
  15. #visionSwitchMenu.show {display: flex; flex-direction: column;}
  16. #visionSwitchMenu .vision-icon {width: 20px; height: 20px; opacity: 1}
  17. #visionSwitchMenu .menu-heading {font-weight: normal}
  18. #visionSwitchMenu .vision-workspace-menu {width: 280px; display: flex; align-items: stretch;}
  19. #visionSwitchMenu .vision-workspace-menu.is-expanded {width: 560px;}
  20. #visionSwitchMenu .vision-workspace-menu > * {min-width: 0;}
  21. CSS;
  22. }
  23. public static function getPageJS()
  24. {
  25. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v2.js');
  26. }
  27. /**
  28. * @var mixed[]
  29. */
  30. public $icons = array
  31. (
  32. 'lite' => 'target',
  33. 'rnd' => 'remote',
  34. 'or' => 'or',
  35. 'manager' => 'manager',
  36. 'ipd' => 'ipd'
  37. );
  38. /**
  39. * @param string $vision
  40. */
  41. protected function getVisionIcon($vision)
  42. {
  43. return isset($this->icons[$vision]) ? $this->icons[$vision] : 'bars';
  44. }
  45. protected function buildVisionTips()
  46. {
  47. global $config, $lang;
  48. if(!empty($config->global->hideVisionTips)) return null;
  49. return div
  50. (
  51. setClass('vision-tips primary rounded-lg w-72 p-4 absolute left-0 z-100 flex items-center'),
  52. style::bottom(60),
  53. div(setClass('flex-auto'), $lang->visionTips),
  54. btn
  55. (
  56. set::type('light-outline'),
  57. on::click()->do
  58. (
  59. '$this.closest(".vision-tips").remove()',
  60. '$.post($.createLink("my", "ajaxSaveVisionTips"), {fields: 1})'
  61. ),
  62. $lang->IKnow
  63. ),
  64. div
  65. (
  66. setClass('bg-inherit w-0.5 h-8 absolute'),
  67. style::bottom(-31)->left(64),
  68. div
  69. (
  70. setClass('w-2.5 h-2.5 rounded-full border-2 relative border-primary bg-canvas'),
  71. style::left(-4)->top(32)
  72. )
  73. )
  74. );
  75. }
  76. protected function build()
  77. {
  78. global $lang, $app, $config;
  79. if(!isset($app->user)) return;
  80. $user = $app->user;
  81. if(!isset($user->visions)) $user->visions = trim($config->visions, ',');
  82. $currentVision = $app->config->vision;
  83. $userVisions = array_filter(explode(',', $user->visions));
  84. /* The standalone lite version removes the lite interface button */
  85. if(trim($config->visions, ',') == 'lite') return;
  86. /* Append the current vision to the user visions to switch vision. */
  87. if(count($userVisions) == 1 && current($userVisions) != $currentVision)
  88. {
  89. $userVisions[] = $currentVision;
  90. }
  91. $visions = [];
  92. foreach($userVisions as $vision)
  93. {
  94. $visions[] = ['key' => $vision, 'icon' => $this->getVisionIcon($vision), 'text' => isset($lang->visionList[$vision]) ? $lang->visionList[$vision] : $vision];
  95. }
  96. $spaces = [];
  97. /* Only show the workspace switcher in the RND vision and not in the XuanXuan client. */
  98. if($currentVision == 'rnd' && !str_contains($_SERVER['HTTP_USER_AGENT'], 'xuanxuan'))
  99. {
  100. if(hasPriv('product', 'all')) $spaces[] = ['key' => 'product', 'icon' => 'product', 'text' => $lang->workspaceList['product'], 'fetcher' => createLink('product', 'ajaxGetDropMenu', 'productID=0&module=product&method=browse&extra=story')];
  101. if(hasPriv('project', 'browse')) $spaces[] = ['key' => 'project', 'icon' => 'project', 'text' => $lang->workspaceList['project'], 'fetcher' => createLink('project', 'ajaxGetDropMenu', 'projectID=0')];
  102. if(hasPriv('execution', 'task')) $spaces[] = ['key' => 'execution', 'icon' => 'run', 'text' => $lang->workspaceList['execution'], 'fetcher' => createLink('execution', 'ajaxGetDropMenu', 'objectID=0')];
  103. }
  104. return array
  105. (
  106. dropdown
  107. (
  108. set::placement('top-start'),
  109. set::target('#visionSwitchMenu'),
  110. set::triggerProps(['maxHeight' => 400]),
  111. btn
  112. (
  113. setClass('ghost'),
  114. set::id('versionSwitchBtn'),
  115. set::text($lang->visionList[$currentVision]),
  116. set::icon($this->getVisionIcon($currentVision)),
  117. set::caret('up')
  118. )
  119. ),
  120. $this->buildVisionTips(),
  121. zui::visionSwitchMenu
  122. (
  123. set::_id('visionSwitchMenu'),
  124. set::visions($visions),
  125. set::currentVision($currentVision),
  126. set::spaces($spaces),
  127. set::switchVisionText($lang->switchVision),
  128. set::switchWorkspaceText($lang->switchWorkspace)
  129. ),
  130. pageJS(<<<JS
  131. window.getUserVisions = () => '{$user->visions}'.split(',');
  132. window.getCurrentVision = () => '{$currentVision}';
  133. JS
  134. )
  135. );
  136. }
  137. }