Merged in caleeli/processmaker/HOR-472 (pull request #3940)

HOR-472
This commit is contained in:
Julio Cesar Laura Avendaño
2016-03-24 09:07:44 -04:00
7 changed files with 367 additions and 77 deletions

View File

@@ -149,6 +149,7 @@ class Ajax
$options[] = Array('text' => G::LoadTranslation('ID_CASE_HISTORY'), 'fn' => 'caseHistory');
$options[] = Array('text' => G::LoadTranslation('ID_HISTORY_MESSAGE_CASE'), 'fn' => 'messageHistory');
$options[] = Array('text' => G::LoadTranslation('ID_DYNAFORMS'), 'fn' => 'dynaformHistory');
$options[] = Array('text' => G::LoadTranslation('ID_DYNAFORM_HISTORY'), 'fn' => 'changeLogHistory');
$options[] = Array('text' => G::LoadTranslation('ID_UPLOADED_DOCUMENTS'), 'fn' => 'uploadedDocuments');
$options[] = Array('text' => G::LoadTranslation('ID_GENERATED_DOCUMENTS'), 'fn' => 'generatedDocuments');
@@ -407,6 +408,25 @@ class Ajax
G::RenderPage('publish', 'extJs');
}
public function changeLogHistory()
{
global $G_PUBLISH;
G::loadClass('configuration');
$idHistory = sprintf(
'%s_%s_%s',
$_SESSION['PROCESS'],
$_SESSION['APPLICATION'],
$_SESSION['TASK']
);
$oHeadPublisher = & headPublisher::getSingleton();
$conf = new Configurations();
$oHeadPublisher->addExtJsScript('cases/caseChangeLog', true); //adding a javascript file .js
$oHeadPublisher->addContent('cases/caseChangeLog'); //adding a html file .html.
$oHeadPublisher->assign('ID_HISTORY', $idHistory);
G::RenderPage('publish', 'extJs');
}
public function uploadedDocuments()
{
if (!isset($_SESSION['USER_LOGGED'])) {
@@ -687,6 +707,19 @@ class Ajax
print G::json_encode($result);
}
public function changeLogAjax()
{
$changeLog = new ProcessMaker\BusinessModel\Cases\ChangeLog();
$idHistory = $_REQUEST["idHistory"];
$idHistoryArray = explode("_", $idHistory);
$proUid = $idHistoryArray[0];
$appUid = $idHistoryArray[1];
$tasUid = $idHistoryArray[2];
$start = isset($_REQUEST['start']) ? (int) $_REQUEST['start']: 0;
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']: 15;
echo G::json_encode($changeLog->getChangeLog($appUid, $proUid, $tasUid, $start, $limit));
}
public function changeLogTab()
{
if (!isset($_SESSION['USER_LOGGED'])) {

View File

@@ -0,0 +1,181 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
use Propel;
use StdClass;
use G;
use Cases;
use AppDocument;
use Dynaform;
use Exception;
use Task;
/**
* Return the ChangeLog of a Dynaform
*/
class ChangeLog
{
/**
* List of variables that should not be considered
* @var string[]
*/
private $reserved = [
'TASK',
'INDEX',
'DYN_CONTENT_HISTORY'
];
/**
* Map of variables and its values
* @var mixed[]
*/
private $values = [];
/**
* List of variables changes
* @var object[]
*/
private $tree;
/**
* List of assigned permissions
* @var string[]
*/
private $permissions = [];
public function getChangeLog($appUid, $proUid, $tasUid, $start, $limit)
{
$this->loadPermissions($appUid, $proUid, $tasUid);
$result = $this->getResultSet($appUid);
$totalCount = $this->readRecords($result, $start, $limit);
return ['data' => $this->tree, 'totalCount' => $totalCount];
}
private function getResultSet($appUid)
{
$conn = Propel::getConnection('workflow');
$sql = 'SELECT APP_HISTORY.*, USERS.USR_USERNAME FROM APP_HISTORY'
.' LEFT JOIN USERS ON(APP_HISTORY.USR_UID=USERS.USR_UID)'
.' WHERE APP_UID=? ORDER BY HISTORY_DATE ASC';
$stmt = $conn->prepareStatement($sql);
$stmt->set(1, $appUid);
if (!$stmt->executeQuery()) {
throw Exception(G::LoadTranslation('ID_MSG_AJAX_FAILURE'));
}
return $stmt->getResultSet();
}
private function readRecords($result, $start = 0, $limit = 15)
{
$index = 0;
while ($result->next()) {
$row = $result->getRow();
$data = unserialize($row['HISTORY_DATA']);
if ($this->isEmpty($data)) {
continue;
}
if ($index < $start) {
$index += $this->updateData(
$data, $row, $this->hasPermission($row['DYN_UID']), false);
continue;
}
$a = $this->updateData($data, $row,
$this->hasPermission($row['DYN_UID']), true);
$limit-= $a;
$index+= $a;
}
return $index;
}
private function isEmpty($data)
{
foreach ($data as $key => $value) {
if (array_search($key, $this->reserved) !== false) {
continue;
}
return false;
}
return true;
}
private function updateData($data, $row, $hasPermission, $addToTree = false)
{
$i = 0;
foreach ($data as $key => $value) {
if (array_search($key, $this->reserved) !== false) {
continue;
}
if ($hasPermission && (!isset($this->values[$key]) || $this->values[$key]
!== $value)) {
if ($addToTree) {
$node = new StdClass();
$node->field = $key;
$previousValue = !isset($this->values[$key]) ? null : $this->values[$key];
$node->previousValue = (string) $previousValue;
$node->currentValue = (string) $value;
$node->previousValueType = gettype($previousValue);
$node->currentValueType = gettype($value);
$node->record = $this->getHistoryTitle($row);
$this->tree[] = $node;
}
$i++;
}
$this->values[$key] = $value;
}
return $i;
}
private function getHistoryTitle($row)
{
return $this->getObjectTitle($row['TAS_UID'], 'TASK')
.' / '.$this->getObjectTitle($row['DYN_UID'], $row['OBJ_TYPE'])
.' / '.G::LoadTranslation('ID_LAN_UPDATE_DATE').': '.$row['HISTORY_DATE']
.' / '.G::LoadTranslation('ID_USER').': '.$row['USR_USERNAME'];
}
private function getObjectTitle($uid, $objType)
{
switch ($objType) {
case 'DYNAFORM':
$obj = new Dynaform();
$obj->Load($uid);
$title = $obj->getDynTitle();
break;
case 'OUTPUT_DOCUMENT':
case 'INPUT_DOCUMENT':
$obj = new AppDocument();
$obj->load($uid);
$title = $obj->getDynTitle();
break;
case 'TASK':
$obj = new Task();
$obj->load($uid);
$title = $obj->getTasTitle();
break;
default:
$title = $uid;
}
return $title;
}
private function loadPermissions($APP_UID, $PRO_UID, $TAS_UID)
{
G::LoadClass('case');
$oCase = new Cases();
$oCase->verifyTable();
$this->permissions = $oCase->getAllObjects(
$PRO_UID, $APP_UID, $TAS_UID, $_SESSION['USER_LOGGED']
);
}
private function hasPermission($uid)
{
foreach ($this->permissions as $type => $ids) {
if (array_search($uid, $ids) !== false) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,18 @@
<link rel="stylesheet" type="text/css" href="/css/classic.css" />
<style type="text/css">
html{
color:black !important;
}
body{
color:black !important;
}
button.typeButton{
border-radius: 4px;
background-color: white;
border: 1px solid rgb(192, 192, 192);
font-size: 11px;
color: rgb(192, 192, 192);
}
</style>
<div id="processes-panel" width="80%" />

View File

@@ -0,0 +1,98 @@
Ext.onReady(function () {
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Ext.QuickTips.init();
var store;
var viewport = new Ext.Viewport({
layout: 'border',
items: [
new Ext.grid.GridPanel({
region: 'center',
"width": "100%",
"height": 300,
"stateful": true,
"stateId": "stateGrid",
"enableColumnHide": false,
"view": new Ext.grid.GroupingView({
forceFit: true,
enableGroupingMenu: false
}),
"store": store = new Ext.data.GroupingStore({
pageSize: 15,
fields: [
{name: 'record'},
{name: 'field'},
{name: 'previousValue'},
{name: 'currentValue'},
{name: 'previousValueType'},
{name: 'currentValueType'},
{name: 'task'},
{name: 'updateDate'},
{name: 'user'}
],
groupField: 'record',
remoteSort: true,
proxy: new Ext.data.HttpProxy({
url: 'ajaxListener?action=changeLogAjax&idHistory=' + ID_HISTORY,
reader: new Ext.data.JsonReader({
fields: [
{name: 'record'},
{name: 'field'},
{name: 'previousValue'},
{name: 'currentValue'},
{name: 'previousValueType'},
{name: 'currentValueType'},
{name: 'task'},
{name: 'updateDate'},
{name: 'user'}
],
root: 'data',
totalProperty: 'totalCount'
}),
})
}),
"colModel": new Ext.grid.ColumnModel({
"columns": [
{
header: _('ID_FIELD_NAME'),
width: 120,
sortable: false,
dataIndex: 'field'
},
{
header: _('ID_PREV_VALUES'),
flex: 1,
sortable: false,
dataIndex: 'previousValue',
renderer: function (value, p, record) {
return ' <button disabled="disabled" class="typeButton">'
+ record.data.previousValueType
+ '</button> ' + value;
}
},
{
header: _('ID_CURRENT_VALUES'),
flex: 1,
sortable: false,
dataIndex: 'currentValue',
renderer: function (value, p, record) {
return ' <button disabled="disabled" class="typeButton">'
+ record.data.currentValueType
+ '</button> ' + value;
}
},
{
header: '',
width: 1,
sortable: false,
hidden: true,
hideable: true,
dataIndex: 'record'
}
]})
})
]
});
store.load();
});

View File

@@ -288,37 +288,6 @@
}),
store: store,
tbar:[
{
text:_("ID_DYNAFORM_HISTORY"),
id:'changueLogFormRadioId',
iconCls: 'button_menu_ext',
icon: '/images/ext/gray/shapes/hourglass.png',
handler: function(){
var rowSelected = processesGrid.getSelectionModel().getSelected();
if( rowSelected ){
window.parent.historyGridListChangeLogGlobal.idHistory = rowSelected.data.ID_HISTORY;
window.parent.historyGridListChangeLogGlobal.tasTitle = rowSelected.data.TAS_TITLE;
var idHistory = window.parent.historyGridListChangeLogGlobal.idHistory;
window.parent.Actions.tabFrame('changeLogTab'+idHistory);
}
else{
Ext.Msg.show({
title:'',
msg: TRANSLATIONS.ID_NO_SELECTION_WARNING,
buttons: Ext.Msg.INFO,
fn: function(){},
animEl: 'elId',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
}
},
disabled:false
},
{
xtype: 'tbfill'
}

View File

@@ -403,52 +403,6 @@
}),
store: store,
tbar:[
{
text:_("ID_DYNAFORM_HISTORY"),
id:'sendMailMessageFormRadioId',
iconCls: 'button_menu_ext',
icon: '/images/ext/gray/shapes/hourglass.png',
handler: function(){
var rowSelected = processesGrid.getSelectionModel().getSelected();
if( rowSelected ){
//!dataGrid
//historyDynaformGridGlobal construct
historyDynaformGridHistoryGlobal.PRO_UID = rowSelected.data.PRO_UID;
historyDynaformGridHistoryGlobal.APP_UID = rowSelected.data.APP_UID;
historyDynaformGridHistoryGlobal.TAS_UID = rowSelected.data.TAS_UID;
historyDynaformGridHistoryGlobal.DYN_UID = rowSelected.data.DYN_UID;
historyDynaformGridHistoryGlobal.DYN_TITLE = rowSelected.data.DYN_TITLE;
var PRO_UID = historyDynaformGridHistoryGlobal.PRO_UID;
var APP_UID = historyDynaformGridHistoryGlobal.APP_UID;
var TAS_UID = historyDynaformGridHistoryGlobal.TAS_UID;
var DYN_UID = historyDynaformGridHistoryGlobal.DYN_UID;
var DYN_TITLE = historyDynaformGridHistoryGlobal.DYN_TITLE;
historyDynaformGridHistory();
}
else{
Ext.Msg.show({
title:'',
msg: TRANSLATIONS.ID_NO_SELECTION_WARNING,
buttons: Ext.Msg.INFO,
fn: function(){},
animEl: 'elId',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
}
},
disabled:false
},
{
xtype: 'tbseparator'
},

View File

@@ -780,6 +780,43 @@ Ext.onReady(function(){
});
}
Actions.changeLogHistory = function ()
{
Ext.Ajax.request({
url: 'ajaxListener',
params: {action: 'verifySession'},
success: function (result, request) {
var data = Ext.util.JSON.decode(result.responseText);
if (data.lostSession) {
Ext.Msg.show({
title: _('ID_ERROR'),
msg: data.message,
animEl: 'elId',
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
fn: function (btn) {
try
{
prnt = parent.parent;
top.location = top.location;
} catch (err)
{
parent.location = parent.location;
}
}
});
} else {
Actions.tabFrame('changeLogHistory');
}
},
failure: function (result, request) {
if (typeof (result.responseText) != 'undefined') {
Ext.MessageBox.alert(_('ID_FAILED'), result.responseText);
}
}
});
}
Actions.uploadedDocuments = function()
{
Ext.Ajax.request({