Permalink
Browse files

removed stats handler and lavacharts, ui can render external template…

…s, custom handler now are lazy loaded
  • Loading branch information...
michelerota committed Jul 5, 2016
1 parent 7b68d8f commit eb5becf8c0deb8b7a34c77a70ef8fc50715c7a4c
View
@@ -14,7 +14,6 @@
"php": ">=5.5.9",
"fightbulc/moment": "^1.13",
"smarty/smarty": "^3.1",
"vlucas/phpdotenv": "^2.2",
"khill/lavacharts": "^3.0"
"vlucas/phpdotenv": "^2.2"
}
}
@@ -2491,40 +2491,6 @@ public function addToSearchformFields(&$fields, $node, &$record, $fieldprefix =
return $this;
}
public function addToStatsformFields(&$fields, $node, &$record, $fieldprefix = '')
{
$field = [];
$defaults = $record;
$opts = $this->getStatOptions();
$extended = $opts['extended'];
//$this->m_isStatsMode = true;
// set "widget" value:
$funcname = $this->m_name.'_search';
if (method_exists($node, $funcname)) {
$field['widget'] = $node->$funcname($defaults, $extended, $fieldprefix);
} else {
$field['widget'] = $this->stats($defaults, $extended, $fieldprefix); // second param indicates extended search.
}
$field['id'] = $this->getSearchFieldName($fieldprefix);
$field['rowid'] = 'ar_'.($field['id'] != '' ? $field['id'] : Tools::getUniqueId('anonymousattribrows')); // The id of the containing row
// pre-emptive set "full" value:
$field['full'] = $field['widget']; // lateron, we might add more to full
// set "searchmode" value:
$field['searchmode'] = $opts['showSearchMode'] ? $this->searchMode($extended, $fieldprefix) : '';
// set "label" value:
$field['label'] = $this->label();
// add $field to fields array
$fields[] = $field;
return $this;
}
/**
* Retrieve the fieldname of the attribute in an atksearch form.
*
View
@@ -266,17 +266,24 @@ public function moduleDir($moduleName)
* @param string $nodeUri the uri of the node
* @param string $action the node action
*
* @return ActionHandler functionname or object (is_subclass_of ActionHandler) or
* NULL if no handler exists for the specified action
* @return ActionHandler full class or object instance (subclass of ActionHandler) or NULL if no handler exists for the specified action
*/
public function atkGetNodeHandler($nodeUri, $action)
{
if (isset($this->g_nodeHandlers[$nodeUri][$action])) {
$handler = $this->g_nodeHandlers[$nodeUri][$action];
if(!is_object($handler)){
$handler = new $handler();
$this->g_nodeHandlers[$nodeUri][$action] = $handler;
}
} elseif (isset($this->g_nodeHandlers['*'][$action])) {
$handler = $this->g_nodeHandlers['*'][$action];
if(!is_object($handler)){
$handler = new $handler();
$this->g_nodeHandlers['*'][$action] = $handler;
}
} else {
$handler = null;
return null;
}
return $handler;
View
@@ -1795,8 +1795,6 @@ public function getFormButtons($mode, $record = array())
// (don't change the order of button)
$result[] = $this->getButton('search', true);
$result[] = $this->getButton('cancel');
} elseif ($mode == 'stats') {
$result[] = $this->getButton('search', true);
}
return $result;
@@ -2444,8 +2442,6 @@ public function getTemplate($action, $record = null, $tab = '')
return 'smartsearchform.tpl';
case 'admin':
return 'recordlist.tpl';
case 'stats':
return 'statsform.tpl';
}
}
@@ -1,131 +0,0 @@
<?php
namespace Sintattica\Atk\Handlers;
use Sintattica\Atk\Core\Config;
use Sintattica\Atk\Session\SessionManager;
use Sintattica\Atk\Core\Tools;
class StatsHandler extends SearchHandler
{
public function action_stats()
{
if (!empty($this->m_partial)) {
$this->partial($this->m_partial);
return;
}
$page = $this->getPage();
$page->register_script(Config::getGlobal('assets_url').'javascript/formsubmit.js');
$page->addContent($this->m_node->renderActionPage('stats', $this->invoke('statsPage')));
}
public function statsPage($record = null)
{
$result = $this->getStatsPage($record);
if ($result !== false) {
return $result;
}
return;
}
public function getStatsPage($record = null)
{
if ($record == null) {
$record = $this->getNode()->updateRecord('', null, null, true);
}
$page = $this->getPage();
$page->register_script(Config::getGlobal('assets_url').'javascript/tools.js');
$res = [];
$res[] = $this->invoke('statsFormPage', $record);
$res[] = $this->invoke('statsGraphPage', $record);
return $res;
}
public function statsFormPage($record = null)
{
$node = $this->getNode();
$ui = $this->getUi();
$params = [];
$params['formstart'] = $this->getFormStart();
$params['content'] = $this->invoke('statsForm', $record);
$params['buttons'] = $node->getFormButtons('stats');
$params['formend'] = '</form>';
return $ui->renderBox([
'title' => $node->actionTitle('stats'),
'content' => $ui->renderAction('stats', $params),
]);
}
public function getFormStart()
{
$sm = SessionManager::getInstance();
$formstart = '<form name="entryform" action="'.Config::getGlobal('dispatcher').'" method="get">';
$formstart .= $sm->formState(SessionManager::SESSION_REPLACE);
$formstart .= '<input type="hidden" name="atkaction" value="stats">';
$formstart .= '<input type="hidden" name="atknodeuri" value="'.$this->getNode()->atkNodeUri().'">';
return $formstart;
}
public function statsGraphPage($record)
{
$ui = $this->getUi();
$vars = array(
'title' => 'Stats',
'content' => $this->invoke('renderStatsGraphPage', $record),
);
return $ui->renderBox($vars);
}
public function statsForm($record)
{
$params = [];
$params['fields'] = [];
$ui = $this->getUi();
$node = $this->getNode();
/** @var EditHandler $edithandler */
$edithandler = $node->getHandler('edit');
$form = $edithandler->editForm('stats', $record, [], '', $node->getEditFieldPrefix(), $node->getTemplate('stats', $record), true);
return $form;
}
public function renderStatsGraphPage($record)
{
return print_r($record, 1);
}
/**
* Handler for partial actions on an stats page.
*
* @param string $partial full partial name
*
* @return string
*/
public function partial_attribute($partial)
{
list($type, $attribute, $partial) = explode('.', $partial);
$attr = $this->m_node->getAttribute($attribute);
if ($attr == null) {
Tools::atkerror("Unknown / invalid attribute '$attribute' for node '".$this->m_node->atkNodeUri()."'");
return '';
}
return $attr->partial($partial, 'add');
}
}
Oops, something went wrong.

0 comments on commit eb5becf

Please sign in to comment.