HOR-472 Change log de dynaforms obtiene un orden extraño de los cambios

+ Refactor of ChangeLog History
This commit is contained in:
davidcallizaya
2016-03-23 22:02:07 -04:00
parent 7b54442386
commit a0c813b3e4
7 changed files with 378 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,27 @@ class Ajax
G::RenderPage('publish', 'extJs');
}
public function changeLogHistory()
{
error_log('AAAAA!!!!!');
//ACA VIENEN MIS CAMBIOS!!!
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 +709,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,188 @@
<?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
* http://localhost:8083/sysworkflow/en/neoclassic/cases/casesHistoryDynaformPage_Ajax?actionAjax=showDynaformListHistory&PRO_UID=23134954556f0727c3fde11063016937&APP_UID=93748078756f16cd8e665b7099829333&TAS_UID=16304814956f0729495da25001454322&DYN_UID=12434578956f07308e54d44056464541
* http://localhost:8083/sysworkflow/en/neoclassic/cases/ajaxListener?action=changeLogTab&idHistory=23134954556f0727c3fde11063016937_48789444056f0747d7e2e19034608525_16304814956f0729495da25001454322
*/
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');
$stmt = $conn->createStatement();
$sql = 'SELECT APP_HISTORY.*, USERS.USR_USERNAME FROM APP_HISTORY LEFT JOIN USERS ON(APP_HISTORY.USR_UID=USERS.USR_UID)'
. ' WHERE APP_UID="'.$appUid.'" ORDER BY HISTORY_DATE ASC';
if (!$stmt->execute($sql)) {
throw Exception('Unable to read history');
}
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;
error_log("+$a = $index / $limit");
if ($limit < 0) {
$index+=1;
break;
}
}
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;
}
// error_log($key);
$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,11 @@
<link rel="stylesheet" type="text/css" href="/css/classic.css" />
<style type="text/css">
html{
color:black !important;
}
body{
color:black !important;
}
</style>
<div id="processes-panel" width="80%" />

View File

@@ -0,0 +1,106 @@
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: '/sysworkflow/en/neoclassic/cases/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 value +
' <button disabled="disabled">'
+ record.data.previousValueType + '</button>';
}
},
{
header: _('ID_CURRENT_VALUES'),
flex: 1,
sortable: false,
dataIndex: 'currentValue',
renderer: function (value, p, record) {
return value +
' <button disabled="disabled">'
+ record.data.currentValueType + '</button>';
}
},
{
header: '',
width: 1,
sortable: false,
hidden: true,
hideable: true,
dataIndex: 'record'
}
]}),
bbar: new Ext.PagingToolbar({
pageSize: 20,
store: store,
displayInfo: true,
displayMsg: _('ID_GRID_PAGE_DISPLAYING_ITEMS'),
emptyMsg: "",
items: []
})
})
]
});
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,44 @@ 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({