PMC-155-B

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-02-06 17:35:05 -04:00
parent 14d02602a7
commit 6f4032b475
3 changed files with 240 additions and 50 deletions

View File

@@ -1,7 +1,14 @@
<?php <?php
/** /**
* Method defined and copied from processmaker/workflow/engine/classes/class.configuration.php * Get default configuration for Cases List.
* *
* @param string $action
* @param int $translation
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
function casesListDefaultFieldsAndConfig($action, $translation = 1) function casesListDefaultFieldsAndConfig($action, $translation = 1)
{ {
@@ -322,6 +329,16 @@ function casesListDefaultFieldsAndConfig($action, $translation = 1)
return array("caseColumns" => $caseColumns, "caseReaderFields" => $caseReaderFields, "rowsperpage" => 20, "dateformat" => "M d, Y"); return array("caseColumns" => $caseColumns, "caseReaderFields" => $caseReaderFields, "rowsperpage" => 20, "dateformat" => "M d, Y");
} }
/**
* Get default configuration and verify if casesListDefaultFieldsAndConfig method exist.
*
* @param string $action
* @param int $translation
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function getDefaultConfig($action, $translation) function getDefaultConfig($action, $translation)
{ {
$config = new Configurations(); $config = new Configurations();
@@ -335,6 +352,16 @@ function getDefaultConfig($action, $translation)
return $arrayConfig; return $arrayConfig;
} }
/**
* Get default fields configuration.
*
* @param string $action
* @param int $translation
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function getDefaultFields($action, $translation) function getDefaultFields($action, $translation)
{ {
$config = new Configurations(); $config = new Configurations();
@@ -405,6 +432,16 @@ function getDefaultFields($action, $translation)
return $arrayField; return $arrayField;
} }
/**
* Set available fields.
*
* @param array $arrayAvailableField
* @param array $arrayField
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function setAvailableFields($arrayAvailableField, $arrayField) function setAvailableFields($arrayAvailableField, $arrayField)
{ {
$i = 0; $i = 0;
@@ -427,6 +464,16 @@ function setAvailableFields($arrayAvailableField, $arrayField)
return $arrayFieldResult; return $arrayFieldResult;
} }
/**
* Set Cases List fields.
*
* @param array $arrayCasesListField
* @param array $arrayField
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function setCasesListFields($arrayCasesListField, $arrayField) function setCasesListFields($arrayCasesListField, $arrayField)
{ {
$i = 0; $i = 0;
@@ -468,6 +515,7 @@ function setCasesListFields($arrayCasesListField, $arrayField)
* @global string $action * @global string $action
* @global array $confCasesList * @global array $confCasesList
* @global string $tabUid * @global string $tabUid
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php * @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration * @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
@@ -477,21 +525,21 @@ function fieldSet()
global $confCasesList; global $confCasesList;
global $tabUid; global $tabUid;
$confCasesList = (array) $confCasesList;
$result = [];
$sw1 = !empty($confCasesList);
$sw2 = $tabUid === "" || (!empty($tabUid) && !empty($confCasesList['PMTable']) && $confCasesList['PMTable'] === $tabUid);
if ($sw1 && $sw2) {
$result = $confCasesList;
} else {
$fields = getFieldsByTabUid($tabUid);
$arrayField = getDefaultFields($action, 0); $arrayField = getDefaultFields($action, 0);
$arrayConfig = getDefaultConfig($action, 0); $arrayConfig = getDefaultConfig($action, 0);
$generic = genericJsonResponse($tabUid, [], $arrayField, $arrayConfig["rowsperpage"], $arrayConfig["dateformat"]); $result = genericJsonResponse($tabUid, [], $arrayField, $arrayConfig["rowsperpage"], $arrayConfig["dateformat"]);
$result = $generic; $result['first']['data'] = getFieldsByTabUid($tabUid);
$result['first']['data'] = $fields;
$confCasesList = (array) $confCasesList;
if (!empty($confCasesList)) {
if (!empty($tabUid) && empty($confCasesList['PMTable'])) {
$confCasesList['PMTable'] = $tabUid;
$confCasesList['first']['data'] = getFieldsByTabUid($tabUid);
}
if (!empty($confCasesList['PMTable']) && empty($tabUid)) {
$result = $confCasesList;
}
} }
if (is_array($result) && isset($result['second']['data'])) { if (is_array($result) && isset($result['second']['data'])) {
@@ -502,6 +550,15 @@ function fieldSet()
echo G::json_encode($result); echo G::json_encode($result);
} }
/**
* Reset fields configuration.
*
* @global string $action
* @param int $translation
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function fieldReset($translation) function fieldReset($translation)
{ {
global $action; global $action;
@@ -514,6 +571,15 @@ function fieldReset($translation)
echo G::json_encode($result); echo G::json_encode($result);
} }
/**
* Complete a field.
*
* @global string $action
* @param int $translation
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function fieldComplete($translation) function fieldComplete($translation)
{ {
@@ -579,6 +645,15 @@ function fieldComplete($translation)
echo G::json_encode($result); echo G::json_encode($result);
} }
/**
* Reset field label.
*
* @global string $action
* @param int $translation
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function fieldLabelReset($translation) function fieldLabelReset($translation)
{ {
@@ -618,6 +693,15 @@ function fieldLabelReset($translation)
echo G::json_encode($result); echo G::json_encode($result);
} }
/**
* Save a field.
*
* @global object $conf
* @global string $action
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
function fieldSave() function fieldSave()
{ {
@@ -732,13 +816,19 @@ try {
} }
/** /**
* set the generic Json Response, using two array for the grid stores and a string for the pmtable name * Set the generic Json Response, using two array for the grid stores and a string for the pmtable name.
*
* @param string $pmtable * @param string $pmtable
* @param array $first * @param array $first
* @param array $second * @param array $second
* @return $response a json string * @param array $rowsPerPage
* @param string $dateFormat
* @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
function genericJsonResponse($pmtable, $first, $second, $rowsperpage, $dateFormat) function genericJsonResponse($pmtable, $first, $second, $rowsPerPage, $dateFormat)
{ {
$firstGrid['totalCount'] = count($first); $firstGrid['totalCount'] = count($first);
$firstGrid['data'] = $first; $firstGrid['data'] = $first;
@@ -748,7 +838,7 @@ function genericJsonResponse($pmtable, $first, $second, $rowsperpage, $dateForma
$result['first'] = $firstGrid; $result['first'] = $firstGrid;
$result['second'] = $secondGrid; $result['second'] = $secondGrid;
$result['PMTable'] = isset($pmtable) ? $pmtable : ''; $result['PMTable'] = isset($pmtable) ? $pmtable : '';
$result['rowsperpage'] = isset($rowsperpage) ? $rowsperpage : 20; $result['rowsperpage'] = isset($rowsPerPage) ? $rowsPerPage : 20;
$result['dateformat'] = isset($dateFormat) && $dateFormat != '' ? $dateFormat : 'M d, Y'; $result['dateformat'] = isset($dateFormat) && $dateFormat != '' ? $dateFormat : 'M d, Y';
return $result; return $result;
} }
@@ -757,6 +847,9 @@ function genericJsonResponse($pmtable, $first, $second, $rowsperpage, $dateForma
* Get row from PM Table. * Get row from PM Table.
* *
* @param string $tabUid * @param string $tabUid
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
function xgetFieldsFromPMTable($tabUid) function xgetFieldsFromPMTable($tabUid)
{ {
@@ -770,6 +863,9 @@ function xgetFieldsFromPMTable($tabUid)
* *
* @param string $tabUid * @param string $tabUid
* @return array * @return array
*
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
function getFieldsByTabUid($tabUid) function getFieldsByTabUid($tabUid)
{ {
@@ -800,10 +896,13 @@ function getFieldsByTabUid($tabUid)
} }
/** /**
* Calculate Grid index.
* *
* @param Array $fields * @param array $fields
* @return Array * @return array
* *
* @see workflow/engine/methods/cases/proxyPMTablesFieldList.php
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
function calculateGridIndex($fields) function calculateGridIndex($fields)
{ {

View File

@@ -330,6 +330,11 @@ class ReportTable
* @param array $arrayData * @param array $arrayData
* @param bool $flagAlterTable * @param bool $flagAlterTable
* *
* @see pmTablesProxy->save()
* @see ProcessMaker\BusinessModel\ReportTable->createStructureOfTables()
* @see Table->validateTableBeforeUpdate()
* @link https://wiki.processmaker.com/3.1/Report_Tables
*
* @return object * @return object
*/ */
public function saveStructureOfTable($arrayData, $flagAlterTable = true) public function saveStructureOfTable($arrayData, $flagAlterTable = true)
@@ -561,6 +566,7 @@ class ReportTable
//Delete Report Table //Delete Report Table
$resultDeleteReportTable = $pmTablesProxy->delete($obj); $resultDeleteReportTable = $pmTablesProxy->delete($obj);
} }
$this->updateConfigurationCaseList($additionalTableUid, $columns);
} catch (Exception $e) { } catch (Exception $e) {
$buildResult = ob_get_contents(); $buildResult = ob_get_contents();
@@ -579,7 +585,6 @@ class ReportTable
$result->trace = $e->getTraceAsString(); $result->trace = $e->getTraceAsString();
} }
$this->updateCaseListFieldsConfiguration($columns);
//Return //Return
return $result; return $result;
} }
@@ -588,8 +593,12 @@ class ReportTable
* Update the Custom Case List fields configuration. * Update the Custom Case List fields configuration.
* *
* @param array $columns * @param array $columns
*
* @see ProcessMaker\BusinessModel\ReportTable->saveStructureOfTable()
* @link https://wiki.processmaker.com/3.1/Report_Tables
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
public function updateCaseListFieldsConfiguration($columns) public function updateConfigurationCaseList($addTabUid, $columns)
{ {
$actions = [ $actions = [
"todo", "draft", "sent", "unassigned", "paused", "completed", "cancelled" "todo", "draft", "sent", "unassigned", "paused", "completed", "cancelled"
@@ -597,21 +606,84 @@ class ReportTable
$conf = new Configurations(); $conf = new Configurations();
foreach ($actions as $action) { foreach ($actions as $action) {
$confCasesList = $conf->loadObject("casesList", $action, "", "", ""); $confCasesList = $conf->loadObject("casesList", $action, "", "", "");
if (is_array($confCasesList) && !empty($confCasesList)) { $sw = is_array($confCasesList) && !empty($confCasesList) && !empty($confCasesList['PMTable']) && $confCasesList['PMTable'] === $addTabUid;
$this->removeNonExistentElementsCustomCaseList($confCasesList['first']['data'], $columns); if ($sw) {
$this->removeNonExistentElementsCustomCaseList($confCasesList['second']['data'], $columns); $this->addFieldsToCustomCaseList($confCasesList['first']['data'], $confCasesList['second']['data'], $columns);
$this->removeFieldsFromCustomCaseList($confCasesList['first']['data'], $columns);
$this->removeFieldsFromCustomCaseList($confCasesList['second']['data'], $columns);
$conf->saveObject($confCasesList, "casesList", $action); $conf->saveObject($confCasesList, "casesList", $action);
} }
} }
} }
/** /**
* Remove non existent elements in Custom Case List. * Add fields to Custom Case List.
* @param array $data1
* @param array $data2
* @param array $columns
*
* @see ProcessMaker\BusinessModel\ReportTable->saveStructureOfTable()
* @link https://wiki.processmaker.com/3.1/Report_Tables
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/
public function addFieldsToCustomCaseList(&$data1, $data2, $columns)
{
$all = [];
$type = 'PM Table';
$this->loadFieldTypeValues($data1, $all, $type);
$this->loadFieldTypeValues($data2, $all, $type);
foreach ($all as $value) {
foreach ($columns as $index => $column) {
if ($value['name'] === $column->field_name) {
unset($columns[$index]);
break;
}
}
}
$defaults = ["APP_UID", "APP_NUMBER", "APP_STATUS"];
foreach ($defaults as $value) {
foreach ($columns as $index => $column) {
if ($value === $column->field_name) {
unset($columns[$index]);
break;
}
}
}
foreach ($columns as $value) {
$data1[] = [
"name" => $column->field_name,
"fieldType" => $type
];
}
}
/**
* Load field type values.
*
* @param array $fields
* @param array $all
* @param string $type
*/
private function loadFieldTypeValues($fields, array &$all, $type)
{
foreach ($fields as $value) {
if ($value['fieldType'] === $type) {
$all[] = $value;
}
}
}
/**
* Remove fields from Custom Cases List.
* *
* @param array $data * @param array $data
* @param array $columns * @param array $columns
*
* @see ProcessMaker\BusinessModel\ReportTable->saveStructureOfTable()
* @link https://wiki.processmaker.com/3.1/Report_Tables
* @link https://wiki.processmaker.com/3.2/Cases_List_Builder#Installation_and_Configuration
*/ */
public function removeNonExistentElementsCustomCaseList(&$data, $columns) public function removeFieldsFromCustomCaseList(&$data, $columns)
{ {
$n = count($data); $n = count($data);
for ($key = 0; $key < $n; $key++) { for ($key = 0; $key < $n; $key++) {

View File

@@ -164,9 +164,11 @@ Ext.onReady(function () {
fields: [ fields: [
'ADD_TAB_UID', 'ADD_TAB_NAME' 'ADD_TAB_UID', 'ADD_TAB_NAME'
], ],
listeners : {load: function() { listeners: {
load: function () {
tabs.setActiveTab(tabIndex); tabs.setActiveTab(tabIndex);
}} }
}
}); });
// create the Data Store to list PMTables in the dropdown // create the Data Store to list PMTables in the dropdown
@@ -179,6 +181,9 @@ Ext.onReady(function () {
triggerAction: 'all', triggerAction: 'all',
store: PmTableStore, store: PmTableStore,
listeners: { listeners: {
focus: function(){
PmTableStore.load();
},
'select': function () { 'select': function () {
var tableUid = this.value; var tableUid = this.value;
Ext.Ajax.request({ Ext.Ajax.request({
@@ -479,6 +484,20 @@ Ext.onReady(function () {
height : screen.height-245, height : screen.height-245,
layout : 'hbox', layout : 'hbox',
layoutConfig : {align : 'stretch'}, layoutConfig : {align : 'stretch'},
listeners: {
render: function (target) {
var el;
if (target.container && target.container.dom) {
el = target.container.dom;
el.style.cssText = 'overflow:hidden;position:absolute;top:28px;bottom:0px;left:0px;right:0px;';
target.setHeight(el.clientHeight);
Ext.EventManager.onWindowResize(function () {
mainPanel.setHeight(el.clientHeight);
mainPanel.doLayout();
});
}
}
},
tbar : new Ext.Toolbar({ tbar : new Ext.Toolbar({
items: [ items: [
_("ID_PM_TABLE"), _("ID_PM_TABLE"),