prompts.html.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace zin;
  3. $viewType = $this->cookie->aiPromptsViewType ? $this->cookie->aiPromptsViewType : 'card';
  4. featureBar(set::current($status), set::linkParams("module={$module}&status={key}"));
  5. toolbar
  6. (
  7. item(set(array
  8. (
  9. 'type' => 'btnGroup',
  10. 'items' => array(
  11. array(
  12. 'icon' => 'format-list-bulleted',
  13. 'class' => 'btn-icon switchButton' . ($viewType == 'list' ? ' text-primary' : ''),
  14. 'data-type' => 'list',
  15. 'hint' => $lang->ai->prompts->viewTypeList['list']
  16. ),
  17. array(
  18. 'icon' => 'cards-view',
  19. 'class' => 'btn-icon switchButton' . ($viewType == 'card' ? ' text-primary' : ''),
  20. 'data-type' => 'card',
  21. 'hint' => $lang->ai->prompts->viewTypeList['card']
  22. )
  23. )
  24. ))),
  25. $this->config->edition != 'open' && common::hasPriv('ai', 'createprompt') ? item(set(array(
  26. 'class' => 'primary',
  27. 'icon' => 'plus',
  28. 'text' => $lang->ai->prompts->create,
  29. 'url' => inlink('createprompt'),
  30. 'data-toggle' => 'modal',
  31. 'data-size' => 'sm'
  32. ))) : null
  33. );
  34. $cols = $config->ai->dtable->prompts;
  35. $prompts = initTableData($prompts, $cols, $this->ai);
  36. foreach($prompts as $prompt)
  37. {
  38. if($prompt->targetForm)
  39. {
  40. $targetFormPath = explode('.', $prompt->targetForm);
  41. if(count($targetFormPath) == 2) $prompt->targetFormLabel = $prompt->targetForm == 'empty.empty' ? $lang->ai->targetForm[$targetFormPath[0]][$targetFormPath[1]] : $lang->ai->targetForm[$targetFormPath[0]]['common'] . ' / ' . $lang->ai->targetForm[$targetFormPath[0]][$targetFormPath[1]];
  42. }
  43. }
  44. $userListMap = array();
  45. foreach($userList as $user)
  46. {
  47. $userListMap[$user->account] = $user;
  48. }
  49. unset($lang->ai->prompts->modules['']);
  50. $moduleList = $this->config->edition == 'open' ? array_intersect_key($lang->ai->prompts->modules, array_flip($promptModules)) : $lang->ai->prompts->modules;
  51. $moduleTree = array();
  52. $index = 1;
  53. $activeKey = 0;
  54. foreach($moduleList as $moduleKey => $moduleName)
  55. {
  56. $item = new stdClass();
  57. $item->id = $index;
  58. $item->parent = 0;
  59. $item->name = $moduleName;
  60. $item->url = inlink('prompts', "module=$moduleKey");
  61. if($moduleKey == $module) $activeKey = $item->id;
  62. $moduleTree[] = $item;
  63. $index++;
  64. }
  65. sidebar
  66. (
  67. moduleMenu
  68. (
  69. set::showDisplay(false),
  70. set::modules($moduleTree),
  71. set::activeKey($activeKey),
  72. set::closeLink(inlink('prompts'))
  73. )
  74. );
  75. $buildDropdown = function($prompt) use ($config)
  76. {
  77. $items = array();
  78. if(!empty($prompt->actions))
  79. {
  80. foreach($prompt->actions as $action)
  81. {
  82. $actionName = $action['name'];
  83. $disabled = $action['disabled'];
  84. if(!isset($config->ai->actionList[$actionName])) continue;
  85. $actionConfig = $config->ai->actionList[$actionName];
  86. $item = array(
  87. 'text' => $actionConfig['text'],
  88. 'disabled' => $disabled
  89. );
  90. if(isset($actionConfig['url']))
  91. {
  92. if(is_array($actionConfig['url']))
  93. {
  94. $params = str_replace('{id}', (string)$prompt->id, $actionConfig['url']['params']);
  95. $item['url'] = helper::createLink($actionConfig['url']['module'], $actionConfig['url']['method'], $params);
  96. }
  97. else
  98. {
  99. $item['url'] = str_replace(
  100. array('{id}', '{module}', '{targetForm}'),
  101. array((string)$prompt->id, $prompt->module, $prompt->targetForm),
  102. $actionConfig['url']
  103. );
  104. }
  105. }
  106. if(isset($actionConfig['className'])) $item['innerClass'] = $actionConfig['className'];
  107. if(isset($actionConfig['data-toggle'])) $item['data-toggle'] = $actionConfig['data-toggle'];
  108. if(isset($actionConfig['data-size'])) $item['data-size'] = $actionConfig['data-size'];
  109. if(isset($actionConfig['data-confirm'])) $item['data-confirm'] = $actionConfig['data-confirm'];
  110. if(isset($actionConfig['data-app'])) $item['data-app'] = $actionConfig['data-app'];
  111. $items[] = $item;
  112. }
  113. }
  114. if(empty($items)) return null;
  115. return dropdown(
  116. btn(
  117. setClass('ghost size-sm card-action-btn'),
  118. set::icon('ellipsis-v')
  119. ),
  120. set::items($items),
  121. set::placement('bottom-end'),
  122. set::caret(false)
  123. );
  124. };
  125. $promptCard = function($prompt) use ($lang, $buildDropdown, $userListMap)
  126. {
  127. $creator = isset($userListMap[$prompt->createdBy]) ? $userListMap[$prompt->createdBy] : null;
  128. $creatorName = $creator ? $creator->realname : $prompt->createdBy;
  129. $draftTag = $prompt->status === 'draft'
  130. ? span(
  131. setClass('draft-tag'),
  132. $lang->ai->prompts->statuses['draft']
  133. )
  134. : null;
  135. return div(
  136. setClass('prompt-card'),
  137. a(
  138. set::href(inlink('promptview', "id={$prompt->id}")),
  139. h3(
  140. setClass('card-title'),
  141. set::title($prompt->name),
  142. span($prompt->name),
  143. $draftTag
  144. ),
  145. div(
  146. setClass('card-description'),
  147. set::title($prompt->desc),
  148. $prompt->desc
  149. ),
  150. div(
  151. setClass('card-meta'),
  152. div(
  153. setClass('creator'),
  154. avatar(
  155. set::size('sm'),
  156. set::text($creatorName),
  157. $creator && !empty($creator->avatar) ? set::src($creator->avatar) : null
  158. ),
  159. span($creatorName)
  160. ),
  161. span(
  162. setClass('created-date'),
  163. sprintf($lang->ai->prompts->createdDate . ':%s', substr($prompt->createdDate, 0, 10))
  164. )
  165. )
  166. ),
  167. $buildDropdown($prompt)
  168. );
  169. };
  170. function renderCardView($promptCard, $prompts)
  171. {
  172. return div(
  173. setClass('page-prompts'),
  174. div(
  175. setClass('prompts-container'),
  176. array_map($promptCard, $prompts)
  177. ),
  178. div(
  179. setClass('pager-container'),
  180. pager(set(usePager()))
  181. )
  182. );
  183. }
  184. function renderListView($cols, $prompts, $users, $module, $status, $orderBy, $pager, $lang)
  185. {
  186. return dtable
  187. (
  188. set::cols($cols),
  189. set::data($prompts),
  190. set::userMap($users),
  191. set::orderBy($orderBy),
  192. set::sortLink(inlink('prompts', "module={$module}&status={$status}&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}")),
  193. set::footPager(usePager()),
  194. set::emptyTip($lang->ai->prompts->emptyList)
  195. );
  196. }
  197. if($viewType == 'list')
  198. {
  199. renderListView($cols, $prompts, $users, $module, $status, $orderBy, $pager, $lang);
  200. }
  201. else
  202. {
  203. renderCardView($promptCard, $prompts);
  204. }