Skip to content

Commit

Permalink
Replacement of getName with lookupPath #2 (#787)
Browse files Browse the repository at this point in the history
* Add files via upload

* Add files via upload

* Update DataGrid.php

* Add files via upload

* Add files via upload

* Update DataGrid.php

* Update GroupActionCollection.php

* Update GroupActionCollection.php

* Update DataGrid.php

* Fixed auto-merge in template

* format

* private property + getter

* lookup moved to monitor callback

* using getter instead of direct property access

* spacing

* spaces -> tabs
  • Loading branch information
peldax authored and paveljanda committed May 27, 2019
1 parent 4db7a2f commit 9186f6b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
37 changes: 30 additions & 7 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ class DataGrid extends Control
*/
private $customPaginatorTemplate = null;

/**
* @var string
*/
private $componentFullName;


public function __construct(?IContainer $parent = null, ?string $name = null)
{
Expand Down Expand Up @@ -469,8 +474,9 @@ function (Presenter $presenter): void {

$this->gridSession = $sessionSection;
}
}
);

$this->componentFullName = $this->lookupPath();
});
}


Expand Down Expand Up @@ -1549,10 +1555,10 @@ public function filterSucceeded(Form $form): void
if ($edit['submit']->isSubmittedBy() && $edit->getErrors() === []) {
$this->inlineEdit->onSubmit($id, $values['inline_edit']);
$this->getPresenterInstance()->payload->_datagrid_inline_edited = $id;
$this->getPresenterInstance()->payload->_datagrid_name = $this->getName();
$this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName();
} else {
$this->getPresenterInstance()->payload->_datagrid_inline_edit_cancel = $id;
$this->getPresenterInstance()->payload->_datagrid_name = $this->getName();
$this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName();
}

if ($edit['submit']->isSubmittedBy() && $this->inlineEdit->onCustomRedraw !== []) {
Expand Down Expand Up @@ -2273,7 +2279,7 @@ public function reload(array $snippets = []): void
}

$this->getPresenterInstance()->payload->_datagrid_url = $this->refreshURL;
$this->getPresenterInstance()->payload->_datagrid_name = $this->getName();
$this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName();

$this->onRedraw();
} else {
Expand All @@ -2288,7 +2294,7 @@ public function reloadTheWholeGrid(): void
$this->redrawControl('grid');

$this->getPresenterInstance()->payload->_datagrid_url = $this->refreshURL;
$this->getPresenterInstance()->payload->_datagrid_name = $this->getName();
$this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName();

$this->onRedraw();
} else {
Expand Down Expand Up @@ -2897,7 +2903,7 @@ public function handleInlineEdit($id): void

if ($presenter->isAjax()) {
$presenter->payload->_datagrid_inline_editing = true;
$presenter->payload->_datagrid_name = $this->getName();
$presenter->payload->_datagrid_name = $this->getFullName();
}

$this->redrawItem((int) $id, $primaryWhereColumn);
Expand Down Expand Up @@ -2990,6 +2996,23 @@ public function getColumnsSummary(): ?ColumnsSummary
* INTERNAL *
********************************************************************************/

/**
* Gets component's full name in component tree
* @return string
* @throws DataGridHasToBeAttachedToPresenterComponentException
*/
public function getFullName() : string
{
if ($this->componentFullName === null) {
throw new DataGridHasToBeAttachedToPresenterComponentException(
'Datagrid needs to be attached to presenter in order to get its full name.'
);
}

return $this->componentFullName;
}


/**
* Tell grid filters to by submitted automatically
*/
Expand Down
6 changes: 3 additions & 3 deletions src/GroupAction/GroupActionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public function addToFormContainer(Container $container): void

$groupActionSelect->addCondition(Form::FILLED)
->toggle(
strtolower((string) $this->datagrid->getName()) . 'group_action_submit'
strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit'
);

$container->addSubmit('submit', 'ublaboo_datagrid.execute')
->setValidationScope([$container])
->setAttribute(
'id',
strtolower((string) $this->datagrid->getName()) . 'group_action_submit'
strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit'
);

$form->onSubmit[] = [$this, 'submitted'];
Expand Down Expand Up @@ -146,7 +146,7 @@ public function submitted(Form $form): void
*/
$http_ids = $form->getHttpData(
Form::DATA_LINE | Form::DATA_KEYS,
strtolower((string) $this->datagrid->getName()) . '_group_action_item[]'
strtolower((string) $this->datagrid->getFullName()) . '_group_action_item[]'
);

$ids = array_keys($http_ids);
Expand Down
16 changes: 8 additions & 8 deletions src/templates/datagrid.latte
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @param InlineEdit|null $inlineAdd Inline add data
*}

<div class="datagrid datagrid-{$control->getName()}" data-refresh-state="{link refreshState!}">
<div class="datagrid datagrid-{$control->getFullName()}" data-refresh-state="{link refreshState!}">
<div n:snippet="grid">
{snippetArea gridSnippets}
{form filter, class => 'ajax'}
{if $control->hasOuterFilterRendering()}
{block outer-filters}
<div class="row text-right datagrid-collapse-filters-button-row" n:if="$control->hasCollapsibleOuterFilters()">
<div class="col-sm-12">
<button class="btn btn-xs btn-primary" type="button" data-toggle="collapse" data-target="#datagrid-{$control->getName()}-row-filters">
<button class="btn btn-xs btn-primary" type="button" data-toggle="collapse" data-target="#datagrid-{$control->getFullName()}-row-filters">
<i n:block="icon-filter" class="{$iconPrefix}filter"></i> {='ublaboo_datagrid.show_filter'|translate}
</button>
</div>
Expand All @@ -35,11 +35,11 @@
{else}
{var $filter_row_class = 'row-filters'}
{/if}
<div class="{$filter_row_class}" id="datagrid-{$control->getName()}-row-filters">
<div class="{$filter_row_class}" id="datagrid-{$control->getFullName()}-row-filters">
<div class="row">
{var $i = 0}
{var $filter_columns_class = 'col-sm-' . (12 / $control->getOuterFilterColumnsCount())}
<div class="datagrid-row-outer-filters-group {$filter_columns_class}" n:foreach="$filters as $f">
<div class="{$filter_columns_class}" n:foreach="$filters as $f">
{**
* Each fitler is rendered separately in its own template
*}
Expand All @@ -51,8 +51,8 @@
{else}
{ifset #$filter_type_block}
{include #$filter_type_block, filter => $f, input => $form['filter'][$f->getKey()], outer => TRUE}
{else}
{include $f->getTemplate(), filter => $f, input => $form['filter'][$f->getKey()], outer => TRUE}
{else}
{include $f->getTemplate(), filter => $f, input => $form['filter'][$f->getKey()], outer => TRUE}
{/ifset}
{/ifset}
{var $i = $i+1}
Expand Down Expand Up @@ -135,7 +135,7 @@
</tr>
<tr n:block="header-column-row">
<th n:snippet="thead-group-action" n:if="$hasGroupActions" n:attr="'rowspan=2' => !empty($filters) && !$control->hasOuterFilterRendering()" class="col-checkbox">
<input n:if="$hasGroupActionOnRows" n:class="$control->shouldUseHappyComponents() ? 'happy gray-border' , primary" name="{$control->getName()|lower}-toggle-all" type="checkbox" data-check="{$control->getName()}" data-check-all="{$control->getName()}">
<input n:if="$hasGroupActionOnRows" n:class="$control->shouldUseHappyComponents() ? 'happy gray-border' , primary" name="{$control->getFullName()|lower}-toggle-all" type="checkbox" data-check="{$control->getFullName()}" data-check-all="{$control->getFullName()}">
</th>
{foreach $columns as $key => $column}
{var $th = $column->getElementForRender('th', $key)}
Expand Down Expand Up @@ -276,7 +276,7 @@
<tr data-id="{$row->getId()}" n:snippet="item-{$row->getId()}" n:attr="$row->getControl()->attrs">
<td n:if="$hasGroupActions" class="col-checkbox">
{if $row->hasGroupAction()}
<input n:class="$control->shouldUseHappyComponents() ? 'happy gray-border' , primary" type="checkbox" data-check="{$control->getName()}" data-check-all-{$control->getName()|noescape} name="{$control->getName()|lower}_group_action_item[{$row->getId()}]">
<input n:class="$control->shouldUseHappyComponents() ? 'happy gray-border' , primary" type="checkbox" data-check="{$control->getFullName()}" data-check-all-{$control->getFullName()|noescape} name="{$control->getFullName()|lower}_group_action_item[{$row->getId()}]">
{/if}
</td>
{foreach $columns as $key => $column}
Expand Down

0 comments on commit 9186f6b

Please sign in to comment.