* Add entry and webhook module.

This commit is contained in:
liugang
2017-10-19 10:41:29 +08:00
parent fe16db7484
commit 29cd0d4b4e
26 changed files with 1113 additions and 5 deletions
+9
View File
@@ -0,0 +1,9 @@
<?php
$config->webhook->create = new stdclass();
$config->webhook->create->requiredFields = 'name, url';
$config->webhook->edit = new stdclass();
$config->webhook->edit->requiredFields = 'name, url';
$config->webhook->requestType['post'] = 'post';
$config->webhook->requestType['get'] = 'get';
+127
View File
@@ -0,0 +1,127 @@
<?php
/**
* The control file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
class webhook extends control
{
/**
* Browse entries.
*
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
{
$pager = $this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->webhook->api . $this->lang->colon . $this->lang->webhook->list;
$this->view->entries = $this->webhook->getList($orderBy, $pager);
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->display();
}
/**
* Create an webhook.
*
* @access public
* @return void
*/
public function create()
{
if($_POST)
{
$webhookID = $this->webhook->create();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action')->create('webhook', $webhookID, 'created');
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->webhook->api . $this->lang->colon . $this->lang->webhook->create;
$this->display();
}
/**
* Edit an webhook.
*
* @param int $webhookID
* @access public
* @return void
*/
public function edit($webhookID)
{
if($_POST)
{
$changes = $this->webhook->update($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($changes)
{
$actionID = $this->loadModel('action')->create('webhook', $webhookID, 'edited');
$this->action->logHistory($actionID, $changes);
}
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->edit . $this->lang->colon . $webhook->name;
$this->view->webhook = $webhook;
$this->display();
}
/**
* Delete an webhook.
*
* @param int $webhookID
* @access public
* @return void
*/
public function delete($webhookID)
{
$this->webhook->delete($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
}
public function log($webhookID)
{
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->log . $this->lang->colon . $webhook->name;
$this->view->actions = $this->loadModel('action')->getList('webhook', $webhookID);
$this->display();
}
public function actions($webhookID)
{
if($_POST)
{
$this->webhook->saveActions($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->actions . $this->lang->colon . $webhook->name;
$this->view->actions = $this->webhook->getActions($webhookID);
$this->display();
}
public function ajaxGetActions($module)
{
}
}
+31
View File
@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();
+31
View File
@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();
+31
View File
@@ -0,0 +1,31 @@
<?php
$lang->webhook->common = 'webhook';
$lang->webhook->list = 'webhook列表';
$lang->webhook->api = '接口';
$lang->webhook->entry = '应用';
$lang->webhook->log = '日志';
$lang->webhook->action = '触发操作';
$lang->webhook->browse = '浏览webhook';
$lang->webhook->create = '添加webhook';
$lang->webhook->edit = '编辑webhook';
$lang->webhook->delete = '删除webhook';
$lang->webhook->id = 'ID';
$lang->webhook->name = '名称';
$lang->webhook->url = '请求地址';
$lang->webhook->requestType = '请求类型';
$lang->webhook->params = '参数';
$lang->webhook->desc = '描述';
$lang->webhook->createdBy = '由谁创建';
$lang->webhook->createdDate = '创建时间';
$lang->webhook->editedby = '最后编辑';
$lang->webhook->editedDate = '编辑时间';
$lang->webhook->saveSuccess = '保存成功';
$lang->webhook->confirmDelete = '您确认要删除该webhook吗?';
$lang->webhook->note = new stdClass();
$lang->webhook->note->name = '授权webhook名称';
$lang->webhook->note->url = '授权webhook地址';
$lang->webhook->note->params = '参数列表,以 & 隔开';
+100
View File
@@ -0,0 +1,100 @@
<?php
/**
* The model file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
class webhookModel extends model
{
/**
* Get an webhook by id.
*
* @param int $webhookID
* @access public
* @return array
*/
public function getById($webhookID)
{
return $this->dao->select('*')->from(TABLE_WEBHOOK)->where('id')->eq($webhookID)->fetch();
}
/**
* Get webhook list.
*
* @param string $orderBy
* @param obejct $pager
* @access public
* @return array
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
return $this->dao->select('*')->from(TABLE_WEBHOOK)->orderBy($orderBy)->page($pager)->fetchAll('id');
}
/**
* Create an webhook.
*
* @access public
* @return bool | int
*/
public function create()
{
$webhook = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->get();
$this->dao->insert(TABLE_WEBHOOK)->data($webhook)
->batchCheck($this->config->webhook->create->requiredFields, 'notempty')
->autoCheck()
->exec();
if(dao::isError()) return false;
return $this->dao->lastInsertId();
}
/**
* Update an webhook.
*
* @param int $webhookID
* @access public
* @return bool | array
*/
public function update($webhookID)
{
$oldEntry = $this->getById($webhookID);
$webhook = fixer::input('post')
->add('editedBy', $this->app->user->account)
->add('editedDate', helper::now())
->get();
$this->dao->update(TABLE_WEBHOOK)->data($webhook)
->batchCheck($this->config->webhook->edit->requiredFields, 'notempty')
->autoCheck()
->where('id')->eq($webhookID)
->exec();
if(dao::isError()) return false;
return common::createChanges($oldEntry, $webhook);
}
/**
* Delete an webhook.
*
* @param int $webhookID
* @param int $null
* @access public
* @return bool
*/
public function delete($webhookID, $null = null)
{
$this->dao->delete()->from(TABLE_WEBHOOK)->where('id')->eq($webhookID)->exec();
return !dao::isError();
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
/**
* The browse view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php';?>
<?php js::set('confirmDelete', $lang->webhook->confirmDelete);?>
<form id='ajaxForm' method='post'>
<table id='webhookList' class='table table-condensed table-hover table-striped tablesorter'>
<thead>
<tr>
<?php $vars = "orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
<th class='w-80px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->webhook->id);?></th>
<th class='w-200px'><?php common::printOrderLink('name', $orderBy, $vars, $lang->webhook->name);?></th>
<th class='w-200px'><?php common::printOrderLink('url', $orderBy, $vars, $lang->webhook->url);?></th>
<th class='w-100px'><?php common::printOrderLink('requestType', $orderBy, $vars, $lang->webhook->requestType);?></th>
<th class='w-200px'><?php common::printOrderLink('params', $orderBy, $vars, $lang->webhook->params);?></th>
<th><?php echo common::printOrderLink('desc', $orderBy, $vars, $lang->webhook->desc);?></th>
<th class='w-100px'><?php echo html::a('###', $lang->actions);?></th>
</tr>
</thead>
<tbody>
<?php foreach($entries as $webhook):?>
<tr>
<td class='text-center'><?php echo $webhook->id;?></td>
<td title='<?php echo $webhook->name;?>'><?php echo $webhook->name;?></td>
<td><?php echo $webhook->url;?></td>
<td title='<?php echo $webhook->requestType;?>'><?php echo $webhook->requestType;?></td>
<td title='<?php echo $webhook->params;?>'><?php echo $webhook->params;?></td>
<td title='<?php echo $webhook->desc;?>'><?php echo $webhook->desc;?></td>
<td class='text-right'>
<?php
common::printIcon('webhook', 'log', "webhookID=$webhook->id", '', 'list', 'file-text-o');
common::printIcon('webhook', 'action', "webhookID=$webhook->id", '', 'list', 'cog');
common::printIcon('webhook', 'edit', "webhookID=$webhook->id", '', 'list');
if(common::hasPriv('webhook', 'delete'))
{
$deleteURL = $this->createLink('webhook', 'delete', "webhookID=$webhook->id&confirm=yes");
echo html::a("javascript:ajaxDelete(\"$deleteURL\",\"webhookList\",confirmDelete)", '<i class="icon-remove"></i>', '', "title='{$lang->webhook->delete}' class='btn-icon'");
}
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='7'><?php $pager->show();?></td>
</tr>
</tfoot>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* The create view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->webhook->api;?></strong>
<small class="text-muted"> <?php echo $lang->webhook->create;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='webhookForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->webhook->name;?></th>
<td><?php echo html::input('name', '', "class='form-control' placeholder='{$lang->webhook->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', '', "class='form-control' placeholder='{$lang->webhook->note->url}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->webhook->requestType;?></th>
<td><?php echo html::select('requestType', $config->webhook->requestType, '', "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->params;?></th>
<td><?php echo html::input('params', '', "class='form-control' title='{$lang->webhook->note->params}' placeholder='{$lang->webhook->note->params}'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->desc;?></th>
<td><?php echo html::textarea('desc', '', "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* The edit view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->webhook->api;?></strong>
<small class="text-muted"> <?php echo $lang->webhook->edit;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='webhookForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->webhook->name;?></th>
<td><?php echo html::input('name', $webhook->name, "class='form-control' placeholder='{$lang->webhook->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', $webhook->url, "class='form-control' placeholder='{$lang->webhook->note->url}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->webhook->requestType;?></th>
<td><?php echo html::select('requestType', $config->webhook->requestType, $webhook->requestType, "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->params;?></th>
<td><?php echo html::input('params', $webhook->params, "class='form-control' title='{$lang->webhook->note->params}' placeholder='{$lang->webhook->note->params}'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->desc;?></th>
<td><?php echo html::textarea('desc', $webhook->desc, "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>
+29
View File
@@ -0,0 +1,29 @@
<?php
/**
* The header view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='featurebar'>
<ul class='nav'>
<?php
echo '<li id="entry">'; common::printLink('entry', 'browse', "", $lang->webhook->entry); echo '</li>';
echo '<li id="webhook">'; common::printLink('webhook', 'browse', "", $lang->webhook->common); echo '</li>';
?>
</ul>
<div class='actions'>
<div class='btn-group'>
<div class='btn-group' id='createActionMenu'>
<?php common::printIcon('webhook', 'create', '', '', 'button', '', '', 'btn-primary');?>
</div>
</div>
</div>
</div>
<script>$('#<?php echo $this->moduleName;?>').addClass('active')</script>