Save and load the additional fields for the dashlets

This commit is contained in:
Julio Cesar Laura
2011-11-10 16:39:14 -04:00
parent 4cc0f6c137
commit f0f3a69af1
7 changed files with 152 additions and 125 deletions

View File

@@ -5,41 +5,11 @@ require_once 'interfaces/dashletInterface.php';
class dashletOpenVSCompleted implements DashletInterface {
function setup($config) {
/*
Array
(
[DAS_UID] => 00000000000000000000000000000001
[DAS_CLASS] => dashletOpenVSCompleted
[DAS_TITLE] => Open Cases VS Complete Cases
[DAS_DESCRIPTION] => Open Cases VS Complete Cases
[DAS_VERSION] => 1.0
[DAS_CREATE_DATE] => 2011-10-28 00:00:00
[DAS_UPDATE_DATE] => 2011-10-28 00:00:00
[DAS_STATUS] => 1
[DAS_INS_UID] => 00000000000000000000000000000001
[DAS_INS_TYPE] => OPEN_CASES
[DAS_INS_CONTEXT_TIME] => MONTH
[DAS_INS_START_DATE] =>
[DAS_INS_END_DATE] =>
[DAS_INS_OWNER_TYPE] => DEPARTMENT
[DAS_INS_OWNER_UID] => 2502663244e6f5e1e3c2254024148892
[DAS_INS_PROCESSES] =>
[DAS_INS_TASKS] =>
[DAS_INS_ADDITIONAL_PROPERTIES] =>
[DAS_INS_CREATE_DATE] => 2011-10-28 00:00:00
[DAS_INS_UPDATE_DATE] => 2011-10-28 00:00:00
[DAS_INS_STATUS] => 1
)
*/
//$this->w = $config['w'];
//loadData
$thisYear = date('Y');
$lastYear = $thisYear -1;
$thisMonth = date('M');
$lastMonth = date('M', strtotime( "31 days ago") );
//print "$thisMonth $lastMonth"; die;
$todayIni = date('Y-m-d H:i:s', strtotime( "today 00:00:00"));
$todayEnd = date('Y-m-d H:i:s', strtotime( "today 23:59:59"));
$yesterdayIni = date('Y-m-d H:i:s', strtotime( "yesterday 00:00:00"));
@@ -60,7 +30,7 @@ Array
$previousYearIni = date('Y-m-d H:i:s', strtotime( "jan $lastYear 00:00:00"));
$previousYearEnd = date('Y-m-d H:i:s', strtotime( "Dec 31 $lastYear 23:59:59"));
switch ( $config['DAS_INS_CONTEXT_TIME'] ) {
switch ( $config['DAS_INS_CONTEXT_TIME'] ) {
case 'TODAY' : $dateIni = $todayIni; $dateEnd = $todayEnd; break;
case 'YESTERDAY' : $dateIni = $yesterdayIni; $dateEnd = $yesterdayEnd; break;
case 'THIS_WEEK' : $dateIni = $thisWeekIni; $dateEnd = $thisWeekEnd; break;
@@ -91,7 +61,7 @@ Array
$rs->next();
$row = $rs->getRow();
$casesCompleted = $row['CANT'];
if ( $casesCompleted + $casesTodo != 0 ) {
if ( $casesCompleted + $casesTodo != 0 ) {
$this->value = $casesCompleted / ($casesCompleted + $casesTodo)*100;
}
else {
@@ -99,7 +69,7 @@ Array
}
$this->open = $casesCompleted;
$this->completed = $casesCompleted + $casesTodo;
switch ( $config['DAS_INS_CONTEXT_TIME'] ) {
switch ( $config['DAS_INS_CONTEXT_TIME'] ) {
case 'TODAY' : $this->centerLabel = 'Today'; break;
case 'YESTERDAY' : $this->centerLabel = 'Yesterday'; break;
case 'THIS_WEEK' : $this->centerLabel = 'This week'; break;
@@ -115,18 +85,52 @@ Array
return true;
}
function getAdditionalFields() {
$additionalFields = array();
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_RED_FROM';
$greenFrom->fieldLabel = 'Red Starts In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_RED_TO';
$greenFrom->fieldLabel = 'Red Ends In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_YELLOW_FROM';
$greenFrom->fieldLabel = 'Yellow Starts In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_YELLOW_TO';
$greenFrom->fieldLabel = 'Yellow Ends In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_GREEN_FROM';
$greenFrom->fieldLabel = 'Green Starts In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
$greenFrom = new stdclass();
$greenFrom->xtype = 'textfield';
$greenFrom->name = 'DAS_GREEN_TO';
$greenFrom->fieldLabel = 'Green Ends In';
$greenFrom->width = 50;
$additionalFields[] = $greenFrom;
return $additionalFields;
}
function render ($width = 300) {
G::LoadClass('pmGauge');
$g = new pmGauge();
$g->w = $width;
$g->value = $this->value;
$g->maxValue = 100;
$g->greenFrom = 90;
$g->greenTo = 100;
$g->yellowFrom = 70;
$g->yellowTo = 90;
$g->redFrom = 100;
$g->redTo = 100;
$g->greenFrom = 50;
$g->greenTo = 100;
@@ -136,8 +140,8 @@ Array
$g->redTo = 30;
$g->centerLabel = $this->centerLabel;
$g->open = $this->open;
$g->completed = $this->completed;
$g->open = $this->open;
$g->completed = $this->completed;
$g->render();
}

View File

@@ -7,16 +7,17 @@ require_once 'model/DashletInstance.php';
class PMDashlet extends DashletInstance implements DashletInterface {
// Own properties
private $dashletInstance;
private $dashletObject;
// Interface functions
public function setup($dasInsUid) {
try {
$dashletInstance = $this->getDashletInstance($dasInsUid);
G::LoadClass($dashletInstance['DAS_CLASS']);
$this->dashletObject = new $dashletInstance['DAS_CLASS']();
$this->dashletObject->setup($dashletInstance);
$this->dashletInstance = $this->loadDashletInstance($dasInsUid);
G::LoadClass($this->dashletInstance['DAS_CLASS']);
$this->dashletObject = new $this->dashletInstance['DAS_CLASS']();
$this->dashletObject->setup($this->dashletInstance);
}
catch (Exception $error) {
throw $error;
@@ -35,6 +36,27 @@ class PMDashlet extends DashletInstance implements DashletInterface {
}
}
public function getAdditionalFields() {
try {
//Change this in the next release
G::LoadClass('dashletOpenVSCompleted');
return dashletOpenVSCompleted::getAdditionalFields();
}
catch (Exception $error) {
throw $error;
}
}
// Getter and Setters
public function getDashletInstance() {
return $this->dashletInstance;
}
public function getDashletObject() {
return $this->dashletObject;
}
// Own functions
public function getDashletsInstances($start = null, $limit = null) {
@@ -99,9 +121,10 @@ class PMDashlet extends DashletInstance implements DashletInterface {
}
}
public function getDashletInstance($dasInsUid) {
public function loadDashletInstance($dasInsUid) {
try {
$dashletInstance = $this->load($dasInsUid);
//Load data from the serialized field
$dashlet = new Dashlet();
$dashletFields = $dashlet->load($dashletInstance['DAS_UID']);
return array_merge($dashletFields, $dashletInstance);

View File

@@ -4,5 +4,6 @@ interface DashletInterface {
public function setup($dasInsUid);
public function render();
public function getAdditionalFields();
}

View File

@@ -16,6 +16,10 @@ require_once 'classes/model/om/BaseDashletInstance.php';
*/
class DashletInstance extends BaseDashletInstance {
private $validFields = array('DAS_INS_UID', 'DAS_UID', 'DAS_INS_TYPE', 'DAS_INS_CONTEXT_TIME', 'DAS_INS_START_DATE', 'DAS_INS_END_DATE', 'DAS_INS_OWNER_TYPE',
'DAS_INS_OWNER_UID', 'DAS_INS_PROCESSES', 'DAS_INS_TASKS', ' DAS_INS_CREATE_DATE', 'DAS_INS_UPDATE_DATE', 'DAS_INS_STATUS',
'pmos_generik', 'ys-admin-tabpanel', 'PHPSESSID');
public function load($dasInsUid) {
try {
$dashletInstance = DashletInstancePeer::retrieveByPK($dasInsUid);
@@ -31,6 +35,19 @@ class DashletInstance extends BaseDashletInstance {
}
public function createOrUpdate($data) {
$additionalFields = array();
foreach ($data as $field => $value) {
if (!in_array($field, $this->validFields)) {
$additionalFields[$field] = $value;
unset($data[$field]);
}
}
if (!empty($additionalFields)) {
$data['DAS_INS_ADDITIONAL_PROPERTIES'] = serialize($additionalFields);
}
else {
$data['DAS_INS_ADDITIONAL_PROPERTIES'] = '';
}
$connection = Propel::getConnection(DashletInstancePeer::DATABASE_NAME);
try {
if (!isset($data['DAS_INS_UID'])) {

View File

@@ -12,7 +12,7 @@ include_once 'classes/model/DashletInstancePeer.php';
/**
* Base class that represents a row from the 'DASHLET_INSTANCE' table.
*
*
*
*
* @package workflow.classes.model.om
*/
@@ -141,7 +141,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_uid] column value.
*
*
* @return string
*/
public function getDasInsUid()
@@ -152,7 +152,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_uid] column value.
*
*
* @return string
*/
public function getDasUid()
@@ -163,7 +163,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_type] column value.
*
*
* @return string
*/
public function getDasInsType()
@@ -174,7 +174,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_context_time] column value.
*
*
* @return string
*/
public function getDasInsContextTime()
@@ -185,7 +185,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [optionally formatted] [das_ins_start_date] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the integer unix timestamp will be returned.
* @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
@@ -216,7 +216,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [optionally formatted] [das_ins_end_date] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the integer unix timestamp will be returned.
* @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
@@ -247,7 +247,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_owner_type] column value.
*
*
* @return string
*/
public function getDasInsOwnerType()
@@ -258,7 +258,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_owner_uid] column value.
*
*
* @return string
*/
public function getDasInsOwnerUid()
@@ -269,7 +269,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_processes] column value.
*
*
* @return string
*/
public function getDasInsProcesses()
@@ -280,7 +280,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_tasks] column value.
*
*
* @return string
*/
public function getDasInsTasks()
@@ -291,7 +291,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_additional_properties] column value.
*
*
* @return string
*/
public function getDasInsAdditionalProperties()
@@ -302,7 +302,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [optionally formatted] [das_ins_create_date] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the integer unix timestamp will be returned.
* @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
@@ -333,7 +333,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [optionally formatted] [das_ins_update_date] column value.
*
*
* @param string $format The date/time format string (either date()-style or strftime()-style).
* If format is NULL, then the integer unix timestamp will be returned.
* @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).
@@ -364,7 +364,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Get the [das_ins_status] column value.
*
*
* @return int
*/
public function getDasInsStatus()
@@ -375,7 +375,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_uid] column.
*
*
* @param string $v new value
* @return void
*/
@@ -385,7 +385,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_uid !== $v || $v === '') {
@@ -397,7 +397,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_uid] column.
*
*
* @param string $v new value
* @return void
*/
@@ -407,7 +407,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_uid !== $v || $v === '') {
@@ -419,7 +419,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_type] column.
*
*
* @param string $v new value
* @return void
*/
@@ -429,7 +429,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_type !== $v || $v === '') {
@@ -441,7 +441,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_context_time] column.
*
*
* @param string $v new value
* @return void
*/
@@ -451,7 +451,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_context_time !== $v || $v === '') {
@@ -463,7 +463,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_start_date] column.
*
*
* @param int $v new value
* @return void
*/
@@ -487,7 +487,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_end_date] column.
*
*
* @param int $v new value
* @return void
*/
@@ -511,7 +511,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_owner_type] column.
*
*
* @param string $v new value
* @return void
*/
@@ -521,7 +521,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_owner_type !== $v || $v === '') {
@@ -533,7 +533,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_owner_uid] column.
*
*
* @param string $v new value
* @return void
*/
@@ -543,7 +543,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_owner_uid !== $v || $v === '') {
@@ -555,7 +555,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_processes] column.
*
*
* @param string $v new value
* @return void
*/
@@ -565,7 +565,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_processes !== $v) {
@@ -577,7 +577,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_tasks] column.
*
*
* @param string $v new value
* @return void
*/
@@ -587,7 +587,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_tasks !== $v) {
@@ -599,7 +599,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_additional_properties] column.
*
*
* @param string $v new value
* @return void
*/
@@ -609,7 +609,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
$v = (string) $v;
}
if ($this->das_ins_additional_properties !== $v) {
@@ -621,7 +621,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_create_date] column.
*
*
* @param int $v new value
* @return void
*/
@@ -645,7 +645,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_update_date] column.
*
*
* @param int $v new value
* @return void
*/
@@ -669,7 +669,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
/**
* Set the value of [das_ins_status] column.
*
*
* @param int $v new value
* @return void
*/
@@ -928,7 +928,7 @@ abstract class BaseDashletInstance extends BaseObject implements Persistent {
*/
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
{
$pos = DashletInstancePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
$pos = DashletInstancePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);var_dump($name,$pos);die();
return $this->getByPosition($pos);
}

View File

@@ -109,10 +109,13 @@ class Dashboard extends Controller {
$data->DAS_INS_UID = '';
}
if ($data->DAS_INS_UID != '') {
$this->setJSVar('dashletInstance', $this->pmDashlet->getDashletInstance($data->DAS_INS_UID));
$this->pmDashlet->setup($data->DAS_INS_UID);
$this->setJSVar('dashletInstance', $this->pmDashlet->getDashletInstance());
$this->setJSVar('additionaFields', $this->pmDashlet->getAdditionalFields());
}
else {
$this->setJSVar('dashletInstance', new stdclass());
$this->setJSVar('additionaFields', $this->pmDashlet->getAdditionalFields());
}
G::RenderPage('publish', 'extJs');
return null;

View File

@@ -9,18 +9,7 @@ dashletInstance.form = {
Ext.Ajax.request({
url: "saveDashletInstance",
method: "POST",
params:{"DAS_INS_UID": hiddenDasInsUID.getValue(),
"DAS_UID": cboDasUID.getValue(),
"DAS_INS_TYPE": cboDasInsType.getValue(),
"DAS_INS_CONTEXT_TIME": cboDasInsContextTime.getValue(),
//"DAS_INS_START_DATE": txtDasInsStartDate.getValue().format(txtDasInsStartDate.format),
//"DAS_INS_END_DATE": txtDasInsEndDate.getValue().format(txtDasInsEndDate.format),
"DAS_INS_OWNER_TYPE": cboDasInsOwnerType.getValue(),
"DAS_INS_OWNER_UID": cboDasInsOwnerUID.getValue()
//,
//"DAS_INS_PROCESSES": cboProcess.getValue(),
//"DAS_INS_TASKS": cboTask.getValue()
},
params: dashletInstanceFrm.getForm().getFieldValues(),
success:function (result, request) {
myMask.hide();
@@ -42,18 +31,6 @@ dashletInstance.form = {
});
}
dashletInstanceFrmLoad = function () {
if (dashletInstance.DAS_INS_UID) {
hiddenDasInsUID.setValue(dashletInstance.DAS_INS_UID)
cboDasUID.setValue(dashletInstance.DAS_UID);
cboDasInsType.setValue(dashletInstance.DAS_INS_TYPE);
cboDasInsContextTime.setValue(dashletInstance.DAS_INS_CONTEXT_TIME);
cboDasInsOwnerType.setValue(dashletInstance.DAS_INS_OWNER_TYPE);
//cboDasInsOwnerUID.setValue(dashletInstance.DAS_INS_OWNER_UID);
}
}
//------------------------------------------------------------------------------------------------------------------
var storeDasUID = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
@@ -321,6 +298,19 @@ dashletInstance.form = {
fieldLabel: "Task"
});
var formFields = [hiddenDasInsUID,
cboDasUID,
cboDasInsType,
cboDasInsContextTime,
//txtDasInsStartDate,
//txtDasInsEndDate,
cboDasInsOwnerType,
cboDasInsOwnerUID
//cboProcess,
//cboTask
];
formFields = formFields.concat(additionaFields);
//------------------------------------------------------------------------------------------------------------------
var dashletInstanceFrm = new Ext.form.FormPanel({
id: "dashletInstanceFrm",
@@ -336,18 +326,7 @@ dashletInstance.form = {
title: "New Dashboard Instance",
items: [hiddenDasInsUID,
cboDasUID,
cboDasInsType,
cboDasInsContextTime,
//txtDasInsStartDate,
//txtDasInsEndDate,
cboDasInsOwnerType,
cboDasInsOwnerUID
//,
//cboProcess,
//cboTask
],
items: formFields,
buttonAlign: "right",
buttons: [new Ext.Action({
@@ -381,7 +360,7 @@ dashletInstance.form = {
});
//------------------------------------------------------------------------------------------------------------------
dashletInstanceFrmLoad();
dashletInstanceFrm.getForm().setValues(dashletInstance);
//------------------------------------------------------------------------------------------------------------------
var pnlMain = new Ext.Panel({