diff --git a/config/zentaopms.php b/config/zentaopms.php index 4c7e58c970..2a5b2138c6 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -377,6 +377,8 @@ define('TABLE_PRIVLANG', '`' . $config->db->prefix . 'privlang`'); define('TABLE_PRIVMANAGER', '`' . $config->db->prefix . 'privmanager`'); define('TABLE_PRIVRELATION', '`' . $config->db->prefix . 'privrelation`'); +define('TABLE_PROMPT', '`' . $config->db->prefix . 'prompt`'); + $config->objectTables['product'] = TABLE_PRODUCT; $config->objectTables['productplan'] = TABLE_PRODUCTPLAN; $config->objectTables['story'] = TABLE_STORY; diff --git a/db/update18.4.sql b/db/update18.4.sql new file mode 100644 index 0000000000..7cad64ff8b --- /dev/null +++ b/db/update18.4.sql @@ -0,0 +1,23 @@ +CREATE TABLE IF NOT EXISTS `zt_prompt` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL, + `desc` text DEFAULT NULL, + `model` mediumint(8) unsigned DEFAULT NULL, + `module` varchar(30) DEFAULT NULL, + `source` text DEFAULT NULL, + `targetForm` varchar(30) DEFAULT NULL, + `purpose` text DEFAULT NULL, + `elaboration` text DEFAULT NULL, + `role` text DEFAULT NULL, + `characterization` text DEFAULT NULL, + `status` enum('draft','active','replaced') NOT NULL DEFAULT 'draft', + `parent` mediumint(8) unsigned DEFAULT NULL, + `successor` mediumint(8) unsigned DEFAULT NULL, + `revision` mediumint(8) unsigned DEFAULT NULL, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) DEFAULT NULL, + `editedDate` datetime DEFAULT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/module/ai/config.php b/module/ai/config.php index b44ab2687f..4d2ec89668 100644 --- a/module/ai/config.php +++ b/module/ai/config.php @@ -29,3 +29,6 @@ foreach($config->ai->openai->contentTypeMapping as $contentType => $apis) { foreach($apis as $api) $config->ai->openai->contentType[$api] = $contentType; } + +$config->ai->createprompt = new stdclass(); +$config->ai->createprompt->requiredFields = 'name'; diff --git a/module/ai/control.php b/module/ai/control.php index 32b8272be3..bea18e6ac4 100644 --- a/module/ai/control.php +++ b/module/ai/control.php @@ -12,9 +12,9 @@ class ai extends control { /** * List models. - * + * * TODO: not fully implemented yet, currently shows the only model config. - * + * * @access public * @return void */ @@ -39,7 +39,7 @@ class ai extends control /** * Edit model configuration, store in system.ai settings. - * + * * @access public * @return void */ @@ -73,7 +73,7 @@ class ai extends control /** * Test connection to API endpoint. - * + * * @access public * @return void */ @@ -81,7 +81,7 @@ class ai extends control { $modelConfig = fixer::input('post')->get(); $this->ai->setConfig($modelConfig); - + $result = $this->ai->complete('test', 1); // Test completing 'test' with length of 1. if($result === false) return $this->send(array('result' => 'fail', 'message' => $this->lang->ai->models->testConnectionResult->fail)); @@ -90,19 +90,49 @@ class ai extends control /** * List prompts. - * + * * @param string $module * @param string $status * @access public * @return void */ - public function prompts($module = '', $status = '') + public function prompts($module = '', $status = '', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) { + /* Set pager and order. */ + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + $order = common::appendOrder($orderBy); + + $this->view->prompts = $this->ai->getPrompts($module, $status, $order, $pager); $this->view->module = $module; $this->view->status = $status; - $this->view->prompts = $this->ai->getPrompts($module, $status); + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; $this->view->title = $this->lang->ai->prompts->common; $this->view->position[] = $this->lang->ai->prompts->common; + + $this->display(); + } + + /** + * Create a prompt. + * + * @access public + * @return void + */ + public function createPrompt() + { + if(strtolower($this->server->request_method) == 'post') + { + $prompt = fixer::input('post')->get(); + $this->ai->createPrompt($prompt); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return print(js::closeModal('parent.parent')); // TODO: jump to step 2 of creation process. + } + + $this->view->title = $this->lang->ai->prompts->create; + $this->view->position[] = $this->lang->ai->prompts->common; $this->display(); } -} \ No newline at end of file +} diff --git a/module/ai/lang/de.php b/module/ai/lang/de.php index 423f8dc84e..d59597e5d1 100644 --- a/module/ai/lang/de.php +++ b/module/ai/lang/de.php @@ -10,14 +10,28 @@ */ $lang->ai->common = 'AI'; +/* Definitions of table columns, used to sprintf error messages to dao::$errors. */ +$lang->prompt = new stdclass(); +$lang->prompt->name = 'Name'; +$lang->prompt->desc = 'Description'; + +$lang->ai->nextStep = 'Next'; + $lang->ai->prompts = new stdclass(); -$lang->ai->prompts->common = 'Prompts'; -$lang->ai->prompts->emptyList = 'There is no prompts yet.'; -$lang->ai->prompts->create = 'Create a prompt'; +$lang->ai->prompts->common = 'Prompt'; +$lang->ai->prompts->emptyList = 'No prompts yet.'; +$lang->ai->prompts->create = 'Create Prompt'; +$lang->ai->prompts->id = 'ID'; +$lang->ai->prompts->name = 'Name'; +$lang->ai->prompts->description = 'Description'; +$lang->ai->prompts->createdBy = 'Creator'; +$lang->ai->prompts->createdDate = 'Created Date'; +$lang->ai->prompts->targetForm = 'Target Form'; +$lang->ai->prompts->funcDesc = 'Function Description'; $lang->ai->prompts->statuses = array(); $lang->ai->prompts->statuses[''] = 'All'; -// $lang->ai->prompts->statuses['draft'] = 'Draft'; +$lang->ai->prompts->statuses['draft'] = 'Draft'; $lang->ai->prompts->modules = array(); $lang->ai->prompts->modules[''] = 'All'; diff --git a/module/ai/lang/en.php b/module/ai/lang/en.php index ed164fca1a..2cd57e6b7e 100644 --- a/module/ai/lang/en.php +++ b/module/ai/lang/en.php @@ -10,14 +10,28 @@ */ $lang->ai->common = 'AI'; +/* Definitions of table columns, used to sprintf error messages to dao::$errors. */ +$lang->prompt = new stdclass(); +$lang->prompt->name = 'Name'; +$lang->prompt->desc = 'Description'; + +$lang->ai->nextStep = 'Next'; + $lang->ai->prompts = new stdclass(); -$lang->ai->prompts->common = 'Prompts'; -$lang->ai->prompts->emptyList = 'There is no prompts yet.'; -$lang->ai->prompts->create = 'Create a prompt'; +$lang->ai->prompts->common = 'Prompt'; +$lang->ai->prompts->emptyList = 'No prompts yet.'; +$lang->ai->prompts->create = 'Create Prompt'; +$lang->ai->prompts->id = 'ID'; +$lang->ai->prompts->name = 'Name'; +$lang->ai->prompts->description = 'Description'; +$lang->ai->prompts->createdBy = 'Creator'; +$lang->ai->prompts->createdDate = 'Created Date'; +$lang->ai->prompts->targetForm = 'Target Form'; +$lang->ai->prompts->funcDesc = 'Function Description'; $lang->ai->prompts->statuses = array(); $lang->ai->prompts->statuses[''] = 'All'; -// $lang->ai->prompts->statuses['draft'] = 'Draft'; +$lang->ai->prompts->statuses['draft'] = 'Draft'; $lang->ai->prompts->modules = array(); $lang->ai->prompts->modules[''] = 'All'; diff --git a/module/ai/lang/fr.php b/module/ai/lang/fr.php index 563f4882bc..77bf2eb4a9 100644 --- a/module/ai/lang/fr.php +++ b/module/ai/lang/fr.php @@ -10,14 +10,28 @@ */ $lang->ai->common = 'AI'; +/* Definitions of table columns, used to sprintf error messages to dao::$errors. */ +$lang->prompt = new stdclass(); +$lang->prompt->name = 'Name'; +$lang->prompt->desc = 'Description'; + +$lang->ai->nextStep = 'Next'; + $lang->ai->prompts = new stdclass(); -$lang->ai->prompts->common = 'Prompts'; -$lang->ai->prompts->emptyList = 'There is no prompts yet.'; -$lang->ai->prompts->create = 'Create a prompt'; +$lang->ai->prompts->common = 'Prompt'; +$lang->ai->prompts->emptyList = 'No prompts yet.'; +$lang->ai->prompts->create = 'Create Prompt'; +$lang->ai->prompts->id = 'ID'; +$lang->ai->prompts->name = 'Name'; +$lang->ai->prompts->description = 'Description'; +$lang->ai->prompts->createdBy = 'Creator'; +$lang->ai->prompts->createdDate = 'Created Date'; +$lang->ai->prompts->targetForm = 'Target Form'; +$lang->ai->prompts->funcDesc = 'Function Description'; $lang->ai->prompts->statuses = array(); $lang->ai->prompts->statuses[''] = 'All'; -// $lang->ai->prompts->statuses['draft'] = 'Draft'; +$lang->ai->prompts->statuses['draft'] = 'Draft'; $lang->ai->prompts->modules = array(); $lang->ai->prompts->modules[''] = 'All'; diff --git a/module/ai/lang/zh-cn.php b/module/ai/lang/zh-cn.php index e66c82e629..6ad9a5db93 100644 --- a/module/ai/lang/zh-cn.php +++ b/module/ai/lang/zh-cn.php @@ -10,14 +10,28 @@ */ $lang->ai->common = 'AI'; +/* Definitions of table columns, used to sprintf error messages to dao::$errors. */ +$lang->prompt = new stdclass(); +$lang->prompt->name = '名称'; +$lang->prompt->desc = '描述'; + +$lang->ai->nextStep = '下一步'; + $lang->ai->prompts = new stdclass(); -$lang->ai->prompts->common = '提词'; -$lang->ai->prompts->emptyList = '暂时没有提词。'; -$lang->ai->prompts->create = '创建提词'; +$lang->ai->prompts->common = '提词'; +$lang->ai->prompts->emptyList = '暂时没有提词。'; +$lang->ai->prompts->create = '创建提词'; +$lang->ai->prompts->id = 'ID'; +$lang->ai->prompts->name = '名称'; +$lang->ai->prompts->description = '描述'; +$lang->ai->prompts->createdBy = '创建者'; +$lang->ai->prompts->createdDate = '创建时间'; +$lang->ai->prompts->targetForm = '表单'; +$lang->ai->prompts->funcDesc = '功能描述'; $lang->ai->prompts->statuses = array(); $lang->ai->prompts->statuses[''] = '全部'; -// $lang->ai->prompts->statuses['draft'] = '草稿'; +$lang->ai->prompts->statuses['draft'] = '草稿'; $lang->ai->prompts->modules = array(); $lang->ai->prompts->modules[''] = '所有分组'; diff --git a/module/ai/model.php b/module/ai/model.php index c79bc50f34..40baf4fecd 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ class aiModel extends model { /** * Model config. - * + * * @var object * @access public */ @@ -36,7 +36,7 @@ class aiModel extends model /** * Set model config, used for testing. - * + * * @param object $config * @access public * @return void @@ -94,7 +94,7 @@ class aiModel extends model /** * Get proxy type. - * + * * @param string $proxyType * @access private * @return int|false @@ -301,16 +301,45 @@ class aiModel extends model /** * Get list of prompts. - * - * TODO: implement this. - * + * + * TODO: fully implement this. + * * @param string $module * @param string $status * @access public * @return array */ - public function getPrompts($module = '', $status = '') + public function getPrompts($module = '', $status = '', $order = 'id_desc', $pager = null) { - return array(); + return $this->dao->select('*')->from(TABLE_PROMPT) + ->where('1=1') + ->beginIF(!empty($module))->andWhere('module')->eq($module)->fi() + ->beginIF(!empty($status))->andWhere('status')->eq($status)->fi() + ->orderBy($order) + ->page($pager) + ->fetchAll(); + } + + /** + * Create a prompt. + * + * TODO: fully implement this. + * + * @param object $prompt + * @access public + * @return int|false returns prompt id on success, false on fail + */ + public function createPrompt($prompt) + { + $prompt->createdDate = helper::now(); + $prompt->createdBy = $this->app->user->account; + + $this->dao->insert(TABLE_PROMPT) + ->data($prompt) + ->autoCheck() + ->batchCheck($this->config->ai->createprompt->requiredFields, 'notempty') + ->exec(); + + return dao::isError() ? false : $this->dao->lastInsertID(); } } diff --git a/module/ai/view/createprompt.html.php b/module/ai/view/createprompt.html.php new file mode 100644 index 0000000000..5c8bf3cd3c --- /dev/null +++ b/module/ai/view/createprompt.html.php @@ -0,0 +1,54 @@ + + * @package ai + * @link https://www.zentao.net + */ +?> + +ai->createprompt->requiredFields);?> +
ai->prompts->emptyList;?> - createLink('ai', 'createprompt'), " " . $lang->ai->prompts->create, '', "class='btn btn-info'");?> + createLink('ai', 'createprompt'), " " . $lang->ai->prompts->create, '', "class='btn btn-info iframe'");?>
| ai->prompts->id);?> | +ai->prompts->name);?> | +ai->prompts->createdBy);?> | +ai->prompts->createdDate);?> | +ai->prompts->targetForm);?> | +ai->prompts->funcDesc;?> | +actions;?> | +
|---|---|---|---|---|---|---|
| id;?> | ++ name;?> + status == 'draft') echo "{$this->lang->ai->prompts->statuses[$prompt->status]}";?> + | +createdBy;?> | +createdDate;?> | +targetForm;?> | +desc;?> | ++ ', '', "class='btn'"); + echo html::a('#', '', '', "class='btn'"); + echo html::a('#', '', '', "class='btn'"); + echo html::a('#', '', '', "class='btn'"); + echo html::a('#', '', '', "class='btn'"); + ?> + | +