BxBaseStudioAgentsVectorStore.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioAgentsVectorStore extends BxDolStudioAgentsVectorStore
  11. {
  12. protected $_sUrlPage;
  13. protected $_sFieldName;
  14. public function __construct ($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct ($aOptions, $oTemplate);
  17. $this->_sUrlPage = BX_DOL_URL_STUDIO . 'agents.php?page=vector_store';
  18. $this->_sFieldName = 'name';
  19. }
  20. public function getPageJsObject()
  21. {
  22. return 'oBxDolStudioPageAgents';
  23. }
  24. public function performActionEdit()
  25. {
  26. $sAction = 'edit';
  27. $iId = $this->_getId();
  28. $aVectorStore = $this->_oDb->getVectorStoreById($iId);
  29. $aForm = $this->_getFormEdit($sAction, $aVectorStore);
  30. $oForm = new BxTemplFormView($aForm);
  31. $oForm->initChecker();
  32. if($oForm->isSubmittedAndValid()) {
  33. if($oForm->update($iId) === false)
  34. return echoJson(['msg' => _t('_sys_txt_error_occured')]);
  35. return echoJson(['grid' => $this->getCode(false), 'blink' => $iId]);
  36. }
  37. $sFormId = $oForm->getId();
  38. $sForm = $oForm->getCode(true);
  39. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sFormId . '_popup_' . $sAction, _t('_sys_agents_vector_store_popup_edit'), $this->_oTemplate->parseHtmlByName('agents_automator_form.html', [
  40. 'form_id' => $sFormId,
  41. 'form' => $sForm,
  42. 'object' => $this->_sObject,
  43. 'action' => $sAction
  44. ]));
  45. return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  46. }
  47. protected function _delete ($mixedId)
  48. {
  49. $mixedResult = parent::_delete($mixedId);
  50. if($mixedResult)
  51. $this->_oDb->deleteAutomatorHelpers(['helper_id' => (int)$mixedId]);
  52. return $mixedResult;
  53. }
  54. protected function _getForm($sAction = '', $aVectorStore = [])
  55. {
  56. $sJsObject = $this->getPageJsObject();
  57. if (empty($aVectorStore['params_user'])) {
  58. $aVectorStore['params_user'] = $aVectorStore['params'];
  59. }
  60. $data = json_decode($aVectorStore['params_user'], true);
  61. $aVectorStore['params_user'] = json_encode($data, JSON_PRETTY_PRINT);
  62. return [
  63. 'form_attrs' => [
  64. 'id' => 'bx_std_agents_helpers_' . $sAction,
  65. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=sys_studio_agents_vector_store&a=' . $sAction,
  66. 'method' => 'post',
  67. ],
  68. 'params' => array (
  69. 'db' => array(
  70. 'table' => 'sys_agents_vector_store',
  71. 'key' => 'id',
  72. 'submit_name' => 'do_submit',
  73. ),
  74. ),
  75. 'inputs' => [
  76. 'topk' => [
  77. 'type' => 'text',
  78. 'name' => 'topk',
  79. 'caption' => '_sys_agents_vector_store_field_topk',
  80. 'required' => true,
  81. 'value' => !empty($aVectorStore['topk']) ? $aVectorStore['topk'] : '',
  82. 'db' => [
  83. 'pass' => 'Int'
  84. ]
  85. ],
  86. 'params_user' => [
  87. 'type' => 'textarea',
  88. 'name' => 'params_user',
  89. 'caption' => '_sys_agents_vector_store_field_params',
  90. 'required' => false,
  91. 'value' => !empty($aVectorStore['params_user']) ? $aVectorStore['params_user'] : '',
  92. 'checker' => [
  93. 'func' => 'Json',
  94. 'params' => ['allow_empty' => true],
  95. 'error' => _t('_sys_agents_vector_store_field_params_err'),
  96. ],
  97. 'db' => [
  98. 'pass' => 'All'
  99. ]
  100. ],
  101. 'submit' => $this->_getFormControls(),
  102. ]
  103. ];
  104. }
  105. protected function _getFormEdit($sAction, $aVectorStore = [])
  106. {
  107. $aForm = $this->_getForm($sAction, $aVectorStore);
  108. $aForm['form_attrs']['action'] .= '&id=' . $aVectorStore['id'];
  109. return $aForm;
  110. }
  111. }
  112. /** @} */