BUG 0000 Added new option "create dashboard" in wizard for the plugins

- New requirement in the creation of plugins, creating dashlets
- The new option was added in the wizard for creating dashlets
- Fixed the files needed for this new option
This commit is contained in:
Victor Saisa Lopez
2012-03-27 09:45:10 -04:00
parent 80a298f5ca
commit cd456e6bde
6 changed files with 339 additions and 114 deletions

View File

@@ -273,8 +273,9 @@ function convertPhpName($f) {
}
function copyPluginFile($tplName, $fName, $class) {
$pluginOutDirectory = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $class . PATH_SEP . $class . PATH_SEP;
$pluginOutDirectory = PATH_OUTTRUNK . "plugins" . PATH_SEP . $class . PATH_SEP;
$pluginFilename = $pluginOutDirectory . $fName;
$fileTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl';
$content = file_get_contents($fileTpl);
$iSize = file_put_contents($pluginFilename, $content);
@@ -282,8 +283,7 @@ function copyPluginFile($tplName, $fName, $class) {
}
function savePluginFile($fName, $tplName, $class, $tableName, $fields = null) {
$pluginOutDirectory = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $class . PATH_SEP;
$pluginOutDirectory = PATH_OUTTRUNK . "plugins" . PATH_SEP . $class . PATH_SEP;
$pluginFilename = $pluginOutDirectory . $fName;
$pluginTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl';
@@ -677,6 +677,7 @@ function run_new_plugin($task, $args) {
}
}
//External step
$externalStep = strtolower(prompt('Create external step for Processmaker [y/N]'));
if( $externalStep == 'y' ) {
$fields['externalStep'][] = array (
@@ -690,13 +691,34 @@ function run_new_plugin($task, $args) {
savePluginFile($pluginName . PATH_SEP . "step" . $pluginName . "ApplicationAjax.php", "pluginStepApplicationAjax.php", $pluginName, $pluginName);
}
//$dashboard = strtolower(prompt('Create an element for the Processmaker Dashboard [y/N]'));
//if( $dashboard == 'y' ) {
// $fields['dashboard'][] = array (
// 'className' => $pluginName
// );
// savePluginFile($pluginName . PATH_SEP . 'drawChart.php', 'pluginDrawChart.php', $pluginName, $pluginName, $fields);
//}
//Dashboards
$dashboard = strtolower(prompt("Create an element for the Processmaker Dashboards [y/N]"));
if ($dashboard == "y") {
$fields["dashboard"][] = array(
"className" => $pluginName
);
$fields["dashboardAttribute"] = "private \$dashletsUids;";
$fields["dashboardAttributeValue"] = "
\$this->dashletsUids = array(
array(\"DAS_UID\" => \"". G::GenerateUniqueId() ."\",
\"DAS_CLASS\" => \"dashlet" . $pluginName . "\",
\"DAS_TITLE\" => \"Dashlet $pluginName\",
\"DAS_DESCRIPTION\" => \"Dashlet $pluginName\",
\"DAS_VERSION\" => \"1.0\",
\"DAS_CREATE_DATE\" => date(\"Y-m-d\"),
\"DAS_UPDATE_DATE\" => date(\"Y-m-d\"))
);
";
$fields["dashboardSetup"] = "\$this->registerDashlets();";
$fields["dashboardEnable"] = "\$this->dashletInsert();";
$fields["dashboardDisable"] = "\$this->dashletDelete();";
G::verifyPath($pluginHome . PATH_SEP . "views", true);
savePluginFile($pluginName . PATH_SEP . "classes" . PATH_SEP . "class.dashlet". $pluginName . ".php", "pluginDashletClass.php", $pluginName, $pluginName);
copyPluginFile("pluginDashlet.html", $pluginName . PATH_SEP . "views" . PATH_SEP . "dashlet". $pluginName . ".html", $pluginName);
}
//$report = strtolower(prompt('Create a Report for Processmaker [y/N]'));
//if( $report == 'y' ) {

View File

@@ -24,80 +24,6 @@
{
}
<!-- START BLOCK : dashboard -->
//here we are defining the available charts, the dashboard setup will call this function to know the charts
function getAvailableCharts() {
return array(
'{className}Chart',
);
}
function getChart($chartName) {
$prePath = '/sys' . SYS_SYS . '/' . SYS_LANG . '/blank/';
$obj = new StdClass();
switch ($chartName) {
case '{className}Chart':
$obj->title = '{className} Chart - Per Forum';
break;
}
$obj->height = 220;
$obj->open->image = $prePath . '{className}/drawChart?chart=' . $chartName . "&u=";
return $obj;
}
/* definition of all charts */
/* that definition comes in two parts :
/* 1. the getXX() function to get the data from the databases
/* 2. the XX() function to draw the graph
*/
/** chart {className} ***/
function get{className}Chart() {
$dataSet = array();
$past1months = mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
$con = Propel::getConnection('workflow');
$sql = "select CON_VALUE, COUNT(*) AS CANT from APPLICATION LEFT JOIN CONTENT ON ( CON_CATEGORY = 'PRO_TITLE' AND CON_ID = PRO_UID AND CON_LANG = 'en' ) GROUP BY CON_VALUE" ;
$stmt = $con->createStatement();
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
$rs->next();
$row = $rs->getRow();
while (is_array($row)) {
if (strlen(trim($row['CON_VALUE'])) > 0) {
$label[] = $row['CON_VALUE'];
$data[] = $row['CANT'];
}
$rs->next();
$row = $rs->getRow();
}
$dataSet['data'] = $data;
$dataSet['label'] = $label;
$max = 1;
foreach ($dataSet['data'] as $k => $val ) if ($val > $max) $max = $val;
$aux = intval($max / 6) * 6 + 6;
$dataSet['max'] = $aux;
return $dataSet;
}
function {className}Chart() {
G::LoadThirdParty("libchart/classes", "libchart" );
$chart = new VerticalBarChart(430, 220);
$dataSet = $this->get{className}Chart();
$dataPostSet = new XYDataSet();
$dataTopicSet = new XYDataSet();
foreach ($dataSet['label'] as $key => $label) {
$dataPostSet->addPoint(new Point($label, $dataSet['data'][$key])) ;
}
$chart->setDataSet($dataPostSet);
$chart->setTitle( " Posts by Week " );
$chart->render();
}
<!-- END BLOCK : dashboard -->
<!-- START BLOCK : report -->
//here we are defining the available charts, the dashboard setup will call this function to know the charts

View File

@@ -0,0 +1,81 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
{literal}
<style type="text/css">
body {
margin: 0;
padding: 0;
background: #FFFFFF;
color: #000000;
font: 85% arial, verdana, helvetica, sans-serif;
}
.dataGrid {
border: 1px solid #48627A;
padding: 0;
width: 99%;
height: 100%;
background: #FFFFFF;
text-align: left;
}
.dataGridTitle{
border: 1px solid #0D1115;
padding-top: 1px;
padding-right: 3px;
padding-bottom: 1px;
padding-left: 3px;
background: #48627A;
color: #FFFFFF;
text-align: center;
font: bold 0.8em verdana, arial, helvetica, sans-serif;
}
.dataGridElement{
padding-top: 1px;
padding-right: 3px;
padding-bottom:1px;
padding-left: 3px;
background: #E8EAEA;
color: #000000;
font: 0.8em verdana, arial, helvetica, sans-serif;
}
</style>
{/literal}
</head>
<body>
<div class="dataGrid">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<th class="dataGridTitle">User name</th>
<th class="dataGridTitle">Full name</th>
<th class="dataGridTitle">Status</th>
</tr>
{foreach from=$user item=item}
<tr>
<td class="dataGridElement">{$item.userName}</td>
<td class="dataGridElement">{$item.fullName}</td>
<td class="dataGridElement">{$item.status}</td>
</tr>
{/foreach}
</table>
</div>
<div style="margin-top: 0.25em;"><strong>Note: </strong>{$note}</div>
</html>

View File

@@ -0,0 +1,145 @@
<?php
require_once ("classes/interfaces/dashletInterface.php");
class dashlet{className} implements DashletInterface
{
private $role;
private $note;
public static function getAdditionalFields($className)
{
$additionalFields = array();
///////
$cnn = Propel::getConnection("rbac");
$stmt = $cnn->createStatement();
$arrayRole = array();
$sql = "SELECT ROL_CODE
FROM ROLES
WHERE ROL_SYSTEM = '00000000000000000000000000000002' AND ROL_STATUS = 1
ORDER BY ROL_CODE ASC";
$rsSQL = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
while ($rsSQL->next()) {
$row = $rsSQL->getRow();
$arrayRole[] = array($row["ROL_CODE"], $row["ROL_CODE"]);
}
///////
$storeRole = new stdclass();
$storeRole->xtype = "arraystore";
$storeRole->idIndex = 0;
$storeRole->fields = array("value", "text");
$storeRole->data = $arrayRole;
///////
$cboRole = new stdclass();
$cboRole->xtype = "combo";
$cboRole->name = "DAS_ROLE";
$cboRole->valueField = "value";
$cboRole->displayField = "text";
$cboRole->value = $arrayRole[0][0];
$cboRole->store = $storeRole;
$cboRole->triggerAction = "all";
$cboRole->mode = "local";
$cboRole->editable = false;
$cboRole->width = 320;
$cboRole->fieldLabel = "Role";
$additionalFields[] = $cboRole;
///////
$txtNote = new stdclass();
$txtNote->xtype = "textfield";
$txtNote->name = "DAS_NOTE";
$txtNote->fieldLabel = "Note";
$txtNote->width = 320;
$txtNote->value = null;
$additionalFields[] = $txtNote;
///////
return ($additionalFields);
}
public static function getXTemplate($className)
{
return "<iframe src=\"{" . "page" . "}?DAS_INS_UID={" . "id" . "}\" width=\"{" . "width" . "}\" height=\"207\" frameborder=\"0\"></iframe>";
}
public function setup($config)
{
$this->role = $config["DAS_ROLE"];
$this->note = $config["DAS_NOTE"];
}
public function render($width = 300)
{
$cnn = Propel::getConnection("workflow");
$stmt = $cnn->createStatement();
$arrayUser = array();
$sql = "SELECT USR.USR_USERNAME, USR.USR_FIRSTNAME, USR.USR_LASTNAME, USR.USR_STATUS
FROM USERS AS USR
WHERE USR.USR_ROLE = '" . $this->role . "'
ORDER BY USR.USR_USERNAME ASC";
$rsSQL = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
while ($rsSQL->next()) {
$row = $rsSQL->getRow();
$arrayUser[] = array("userName" => $row["USR_USERNAME"], "fullName" => $row["USR_FIRSTNAME"] . " " . $row["USR_LASTNAME"], "status" => $row["USR_STATUS"]);
}
///////
$dashletView = new dashlet{className}View($arrayUser, $this->note);
$dashletView->templatePrint();
}
}
class dashlet{className}View extends Smarty
{
private $smarty;
private $user;
private $note;
public function __construct($u, $n)
{
$this->user = $u;
$this->note = $n;
$this->smarty = new Smarty();
$this->smarty->compile_dir = PATH_SMARTY_C;
$this->smarty->cache_dir = PATH_SMARTY_CACHE;
$this->smarty->config_dir = PATH_THIRDPARTY . "smarty/configs";
$this->smarty->caching = false;
$this->smarty->templateFile = PATH_PLUGINS . "{className}" . PATH_SEP . "views" . PATH_SEP . "dashlet{className}.html";
}
public function templateRender()
{
$this->smarty->assign("user", $this->user);
$this->smarty->assign("note", $this->note);
return ($this->smarty->fetch($this->smarty->templateFile));
}
public function templatePrint()
{
echo $this->templateRender();
exit(0);
}
}
?>

View File

@@ -3,7 +3,10 @@ G::LoadClass("plugin");
class {className}Plugin extends PMPlugin
{
function {className}Plugin($sNamespace, $sFilename = null) {
{dashboardAttribute}
public function {className}Plugin($sNamespace, $sFilename = null)
{
$res = parent::PMPlugin($sNamespace, $sFilename);
$this->sFriendlyName = "{className} Plugin";
$this->sDescription = "Autogenerated plugin for class {className}";
@@ -13,10 +16,14 @@ class {className}Plugin extends PMPlugin
//$this->iPMVersion = 2425;
$this->aWorkspaces = null;
//$this->aWorkspaces = array("os");
{dashboardAttributeValue}
return $res;
}
function setup() {
public function setup()
{
<!-- START BLOCK : changeLogo -->
$this->setCompanyLogo("/plugin/{className}/{className}.png");
<!-- END BLOCK : changeLogo -->
@@ -32,9 +39,6 @@ class {className}Plugin extends PMPlugin
<!-- START BLOCK : externalStep -->
$this->registerStep("{GUID}", "step{className}Application", "{className} external step");
<!-- END BLOCK : externalStep -->
<!-- START BLOCK : dashboard -->
$this->registerDashboard();
<!-- END BLOCK : dashboard -->
<!-- START BLOCK : report -->
$this->registerReport();
<!-- END BLOCK : report -->
@@ -44,9 +48,12 @@ class {className}Plugin extends PMPlugin
<!-- START BLOCK : redirectLogin -->
$this->redirectLogin("PROCESSMAKER_{className}", "users/users_List");
<!-- END BLOCK : redirectLogin -->
{dashboardSetup}
}
function install() {
public function install()
{
<!-- START BLOCK : createPermission -->
$RBAC = RBAC::getSingleton() ;
$RBAC->initRBAC();
@@ -62,6 +69,47 @@ class {className}Plugin extends PMPlugin
$RBAC->createPermision("PM_{className}");
<!-- END BLOCK : createPermission -->
}
public function enable()
{
{dashboardEnable}
}
public function disable()
{
{dashboardDisable}
}
<!-- START BLOCK : dashboard -->
public function dashletInsert()
{
require_once ("classes/model/Dashlet.php");
$connection = Propel::getConnection(DashletPeer::DATABASE_NAME);
foreach ($this->dashletsUids as $dashletData) {
$dashlet = new Dashlet();
if (is_null($dashlet->load($dashletData["DAS_UID"]))) {
$dashlet->fromArray($dashletData, BasePeer::TYPE_FIELDNAME);
$connection->begin();
$dashlet->save();
$connection->commit();
}
}
}
public function dashletDelete()
{
require_once ("classes/model/Dashlet.php");
foreach ($this->dashletsUids as $dashletData) {
$criteria = new Criteria("workflow");
$criteria->add(DashletPeer::DAS_UID, $dashletData["DAS_UID"]);
DashletPeer::doDelete($criteria);
}
}
<!-- END BLOCK : dashboard -->
}
$oPluginRegistry = &PMPluginRegistry::getSingleton();

View File

@@ -19,8 +19,9 @@ class PMDashlet extends DashletInstance implements DashletInterface {
$pluginsDashlets = $oPluginRegistry->getDashlets();
foreach ($pluginsDashlets as $pluginDashlet) {
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_PLUGINS . $pluginDashlet . PATH_SEP);
require_once 'classes/class.' . $className . '.php';
}
require_once ("classes" . PATH_SEP . "class." . $className . ".php");
}
G::LoadClass($className);
eval("\$additionalFields = $className::getAdditionalFields(\$className);");
@@ -43,8 +44,9 @@ class PMDashlet extends DashletInstance implements DashletInterface {
$pluginsDashlets = $oPluginRegistry->getDashlets();
foreach ($pluginsDashlets as $pluginDashlet) {
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_PLUGINS . $pluginDashlet . PATH_SEP);
require_once 'classes/class.' . $className . '.php';
}
require_once ("classes" . PATH_SEP . "class." . $className . ".php");
}
$this->dashletObject = new $className();
$this->dashletObject->setup($this->dashletInstance);
@@ -303,8 +305,9 @@ class PMDashlet extends DashletInstance implements DashletInterface {
$pluginsDashlets = $oPluginRegistry->getDashlets();
foreach ($pluginsDashlets as $pluginDashlet) {
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_PLUGINS . $pluginDashlet . PATH_SEP);
require_once 'classes/class.' . $className . '.php';
}
require_once ("classes" . PATH_SEP . "class." . $className . ".php");
}
G::LoadClass($className);
eval("\$additionalFields = $className::getXTemplate(\$className);");