Skip to content

Commit

Permalink
upgrade presentation/framework to v0.16.1, page generation time added…
Browse files Browse the repository at this point in the history
… to webapp
  • Loading branch information
Nayjest committed Dec 9, 2015
1 parent f371710 commit 82b8841
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 39 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
],
"require": {
"php": ">=5.5.0",
"presentation/framework": "dev-dev",
"nayjest/tree-init": "^1"
"presentation/framework": "0.16.1",
"nayjest/tree": "^2"

},
"require-dev": {
"phpunit/phpunit": "4.6.*",
Expand Down
25 changes: 19 additions & 6 deletions src/Component/CsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@

use League\Url\Query;
use League\Url\Url;
use Nayjest\TreeInit\InitializableTrait;
use Nayjest\TreeInit\InitializableInterface;
use Presentation\Framework\Base\ComponentInterface;
use Presentation\Framework\Base\CompoundPartInterface;
use Presentation\Framework\Base\CompoundPartTrait;
use Presentation\Framework\Base\ViewAggregate;
use Presentation\Framework\Component\CompoundComponent;
use Presentation\Framework\Component\Html\Tag;
use Presentation\Framework\Component\Text;
use Presentation\Framework\Data\DataProviderInterface;
use Presentation\Framework\Data\Operation\PaginateOperation;
use Presentation\Framework\Initialization\InitializableInterface;
use Presentation\Framework\Initialization\InitializableTrait;
use Presentation\Framework\Input\InputOption;
use Presentation\Grids\Grid;

class CsvExport extends ViewAggregate implements InitializableInterface
class CsvExport extends ViewAggregate implements InitializableInterface, CompoundPartInterface
{
use InitializableTrait;
use InitializableTrait {
InitializableTrait::initialize as private initializeInternal;
}
use CompoundPartTrait;

private $fileName = 'data.csv';
private $csvDelimiter = ';';
private $exitFunction;

/**
* @var InputOption
*/
Expand All @@ -33,6 +40,11 @@ public function __construct(InputOption $inputOption = null, ComponentInterface
parent::__construct($controlView);
}

public function resolveParentName(CompoundComponent $root)
{
return 'control_container';
}

/**
* @param InputOption $inputOption
* @return CsvExport
Expand Down Expand Up @@ -110,11 +122,12 @@ public function getFileName()
}

/**
* @param Grid $grid
* @param Grid|ComponentInterface $grid
* @return bool
*/
protected function initializeInternal($grid)
public function initialize(ComponentInterface $grid)
{
$this->initializeInternal($grid);
$grid->onRender(function() {
if ($this->inputOption->hasValue())
$this->renderCsv();
Expand Down
14 changes: 9 additions & 5 deletions src/Component/PageTotalsRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use Closure;
use LogicException;
use Nayjest\TreeInit\InitializableTrait;
use Nayjest\TreeInit\InitializableInterface;
use Presentation\Framework\Base\AbstractComponent;
use Presentation\Framework\Base\ComponentInterface;
use Presentation\Framework\Initialization\InitializableInterface;
use Presentation\Framework\Initialization\InitializableTrait;
use Presentation\Grids\Grid;

/**
* Class PageTotalsRow
*/
class PageTotalsRow extends AbstractComponent implements InitializableInterface
{
use InitializableTrait;
use InitializableTrait {
InitializableTrait::initialize as private initializeInternal;
}

const OPERATION_SUM = 'sum';
const OPERATION_AVG = 'avg';
Expand Down Expand Up @@ -174,11 +177,12 @@ public function setValuePrefixes(array $valuePrefixes)
}

/**
* @param Grid $grid
* @param ComponentInterface|Grid $grid
* @return bool
*/
protected function initializeInternal($grid)
public function initialize(ComponentInterface $grid)
{
$this->initializeInternal($grid);
// attach event handler to TR inside grid.onRender to guarantee that TR will not be changed.
$grid->onRender(function (Grid $grid) {
$grid->getTableRow()->onRender($this->dataCollectingCallback);
Expand Down
9 changes: 6 additions & 3 deletions src/Control/ColumnSortingControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ public function getOperation()
}

/**
* @return ComponentInterface|DataAcceptorInterface
* Returns view component.
*
* @param bool $useDefault optional, false by default; pass true to use default view
* @return ComponentInterface|DataAcceptorInterface|null
*/
public function getView()
public function getView($useDefault = false)
{
return parent::getView();
return parent::getView($useDefault);
}

/**
Expand Down
22 changes: 2 additions & 20 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

namespace Presentation\Grids;

use Nayjest\TreeInit\InitializerInterface;
use Nayjest\TreeInit\InitializerTrait;
use Presentation\Framework\Base\ComponentInterface;
use Presentation\Framework\Base\RepeaterInterface;
use Presentation\Framework\Component\Html\Tag;
use Presentation\Framework\Component\ManagedList\ManagedList;
use Presentation\Framework\Data\DataProviderInterface;
use Presentation\Framework\Initialization\InitializerTrait;
use Presentation\Framework\Input\InputSource;
use Presentation\Grids\Component\SolidRow;
use Traversable;

/**
* Grid component.
*/
class Grid extends ManagedList implements InitializerInterface
class Grid extends ManagedList
{
use GridPartsAccessTrait;
use InitializerTrait;
Expand Down Expand Up @@ -101,23 +100,6 @@ protected function makeDefaultComponents()
return $components;
}

/**
* @return ComponentInterface|null
*/
public function getTableRow()
{
return $this->getRecordView();
}

/**
* @param ComponentInterface|null $component
* @return $this
*/
public function setTableRow(ComponentInterface $component = null)
{
return $this->setRecordView($component);
}

/**
* Returns current grid row, used internally for grid rendering.
*
Expand Down
22 changes: 22 additions & 0 deletions src/GridPartsAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ abstract public function getComponent($componentName);
*/
abstract public function setComponent($name, ComponentInterface $component = null);

abstract public function setRecordView(ComponentInterface $component);

abstract public function getRecordView();

public function getTable()
{
return $this->getComponent('table');
Expand Down Expand Up @@ -77,4 +81,22 @@ public function setTableFooter(ComponentInterface $table)
{
return $this->setComponent('table_footer', $table);
}


/**
* @return ComponentInterface|null
*/
public function getTableRow()
{
return $this->getRecordView();
}

/**
* @param ComponentInterface|null $component
* @return $this
*/
public function setTableRow(ComponentInterface $component = null)
{
return $this->setRecordView($component);
}
}
27 changes: 25 additions & 2 deletions tests/webapp/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use DateTime;
use Presentation\Framework\Component\ManagedList\Control\FilterControl;
use Presentation\Framework\Component\ManagedList\Control\PageSizeSelectControl;
use Presentation\Framework\Component\ManagedList\Control\PaginationControl;
use Presentation\Framework\Component\Text;
use Presentation\Framework\Input\InputOption;
Expand Down Expand Up @@ -116,8 +117,8 @@ public function demo3()
$grid->removeComponent('control_row');
$row->getCell('action')->addChild($submitButton);

$nameFilter->getView()->setLabel('');
$roleFilter->getView()->setLabel('');
$nameFilter->getView(true)->setLabel('');
$roleFilter->getView(true)->setLabel('');

return $this->page($grid->render(), 'Filters placed under column headers');
}
Expand Down Expand Up @@ -318,4 +319,26 @@ public function demo9()
);
return $this->page($grid->render(), 'CSV Export & Filter');
}

public function demo10()
{
$provider = $this->getDataProvider();
$input = new InputSource($_GET);
$grid = new Grid($provider,
[
new Column('id'),
new Column('name'),
new Column('role'),
],
[
new FilterControl('role', FilterOperation::OPERATOR_EQ, $input->option('role')),
new PageSizeSelectControl($input->option('ps', 4), [2,4,10,100]),
new CsvExport($input->option('csv')),
new PaginationControl($input->option('page', 1), 5, $provider),

]
);
//$grid->addChild(new PaginationControl($input->option('page', 1), 5, $provider));
return $this->page($grid->render(), 'PageSizeSelectControl');
}
}
1 change: 1 addition & 0 deletions tests/webapp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

$controller = new Controller;
$method = str_replace('/', '', $_SERVER['SCRIPT_NAME'])?:'index';
$_SERVER['start_time'] = microtime(true);
echo $controller->{$method}();
6 changes: 5 additions & 1 deletion tests/webapp/resources/views/layout.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<html>
<body>
<?= $this->renderMenu() ?>
</body>
<h1>Test App <?= $title?": <small>$title</small>":'' ?></h1>
<hr>
<?= $content ?>
Expand Down Expand Up @@ -43,4 +42,9 @@
border: 1px solid gray;
}
</style>
<?php
$diff = round((microtime(true) - $_SERVER['start_time']), 4);
echo '<br>Generation Time: ' . $diff;
?>
</body>
</html>

0 comments on commit 82b8841

Please sign in to comment.