Skip to content

Commit

Permalink
Revert "[FIX] table column actions icon (atk4#960)"
Browse files Browse the repository at this point in the history
This reverts commit f4d5a13.
  • Loading branch information
georgehristov authored Feb 19, 2020
1 parent 2edfaf5 commit 0865223
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 52 deletions.
5 changes: 2 additions & 3 deletions public/agileui.less
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ footer.atk-footer {

// table dropdown menu
.atk-table-dropdown {
margin-top: -8px;
float: left;
margin-top: -10px;
i {
opacity: 0.3;
vertical-align: bottom;
Expand All @@ -98,7 +97,7 @@ footer.atk-footer {
}

.atk-table-column-header {
white-space: break-spaces;
padding-bottom: 4px;
&:after {
//display: none;
font-style: normal;
Expand Down
111 changes: 62 additions & 49 deletions src/TableColumn/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use atk4\ui\jsExpression;
use atk4\ui\Popup;
use atk4\data\Field;
use atk4\data\Model;

/**
* Implements Column helper for table.
Expand Down Expand Up @@ -79,11 +80,11 @@ public function __construct($defaults = [])
*
* @return mixed
*/
public function addPopup($popup = null, $icon = 'table-filter-off')
public function addPopup($popup = null, $icon = 'table-filter-off icon')
{
$id = $this->name.'_ac';

$popup = $this->table->owner->add($popup ?: 'Popup')->setHoverable();
$popup = $this->table->owner->add($popup ? $popup : 'Popup')->setHoverable();

$this->setHeaderPopup($icon, $id);

Expand Down Expand Up @@ -114,7 +115,7 @@ public function setHeaderPopup($class, $id)

$this->headerActionTag = ['div', ['class'=>'atk-table-dropdown'],
[
['i', ['id' => $id, 'class' => $class.' icon'], ''],
['i', ['id' => $id, 'class' => $class.' icon']],
],
];
}
Expand All @@ -126,9 +127,10 @@ public function setHeaderPopup($class, $id)
*/
public function setHeaderPopupIcon($icon)
{
$id = $this->name.'_ac';
$this->headerActionTag = ['div', ['class'=>'atk-table-dropdown'],
[
['i', ['id' => $this->name.'_ac', 'class' => $icon.' icon'], ''],
['i', ['id' => $id, 'class' => $icon.' icon']],
],
];
}
Expand All @@ -145,12 +147,16 @@ public function setHeaderPopupIcon($icon)
*/
public function addDropdown($items, $fx, $icon = 'caret square down', $menuId = null)
{
$menuItems = [];
$menuITems = [];
foreach ($items as $key => $item) {
$menuItems[] = ['name' => is_int($key) ? $item : $key, 'value' => $item];
if (is_int($key)) {
$menuITems[] = ['name' => $item, 'value' => $item];
} else {
$menuITems[] = ['name' => $key, 'value' => $item];
}
}

$cb = $this->setHeaderDropdown($menuItems, $icon, $menuId);
$cb = $this->setHeaderDropdown($menuITems, $icon, $menuId);

$cb->onSelectItem(function ($menu, $item) use ($fx) {
return call_user_func($fx, $item, $menu);
Expand Down Expand Up @@ -178,7 +184,7 @@ public function setHeaderDropdown($items, $icon = 'caret square down', $menuId =
[
[
'div', ['id' => $id, 'class'=>'ui top left pointing dropdown', 'data-menu-id' => $menuId],
[['i', ['class' => $icon.' icon'], '']],
[['i', ['class' => $icon.' icon']]],
],
],
];
Expand Down Expand Up @@ -251,11 +257,13 @@ public function setAttr($attr, $value, $position = 'body')
public function getTagAttributes($position, $attr = [])
{
// "all" applies on all positions
// $position is for specific position classes
foreach (['all', $position] as $key) {
if (isset($this->attr[$key])) {
$attr = array_merge_recursive($attr, $this->attr[$key]);
}
if (isset($this->attr['all'])) {
$attr = array_merge_recursive($attr, $this->attr['all']);
}

// specific position classes
if (isset($this->attr[$position])) {
$attr = array_merge_recursive($attr, $this->attr[$position]);
}

return $attr;
Expand Down Expand Up @@ -286,69 +294,74 @@ public function getTag($position, $value, $attr = [])
* Provided with a field definition (from a model) will return a header
* cell, fully formatted to be included in a Table. (<th>).
*
* @param Field $field
* @param mixed $value
* @param Field $f
*
* @return string
*/
public function getHeaderCellHTML(Field $field = null, $value = null)
public function getHeaderCellHTML(Field $f = null, $value = null)
{
$attr = [];
if (!$this->table) {
throw new \atk4\ui\Exception(['How $table could not be set??', 'field' => $field, 'value' => $value]);
throw new \atk4\ui\Exception(['How $table could not be set??', 'f' => $f, 'value' => $value]);
}

if ($tag = $this->table->hook('getColumnHeaderCell', [$this, $field, $value])) {
if ($tag = $this->table->hook('getColumnHeaderCell', [$this, $f, $value])) {
return $tag[0];
}

if ($field === null) {
if ($f === null) {
return $this->getTag('head', $this->caption ?: '', $this->table->sortable ? ['class' => ['disabled']] : []);
}

// if $this->caption is empty, header caption will be overriden by linked field definition
$caption = $this->caption ?: $field->getCaption();

$attr = [
'data-column' => $this->columnData
];

$class = 'atk-table-column-header';

if ($this->hasHeaderAction) {
$attr['id'] = $this->name.'_th';

//add the action tag to the caption
$caption = [$this->headerActionTag, $caption];
}
$captionHtmlTag = ['div', ['class' => 'atk-table-column-header'], empty($this->caption) ? $f->getCaption() : $this->caption];

// If table is being sorted by THIS column, set the proper class
$attr['data-column'] = $this->columnData;
if ($this->table->sortable) {
$attr['data-sort'] = $field->short_name;
if ($this->table->sort_by === $field->short_name) {
$class .= ' sorted '.$this->table->sort_order;
$attr['data-sort'] = $f->short_name;
if ($this->table->sort_by === $f->short_name) {
$captionHtmlTag[1]['class'] = $captionHtmlTag[1]['class'].' '.'sorted '.$this->table->sort_order;

if ($this->table->sort_order === 'ascending') {
$attr['data-sort'] = '-'.$field->short_name;
$attr['data-sort'] = '-'.$f->short_name;
} elseif ($this->table->sort_order === 'descending') {
$attr['data-sort'] = '';
}
}
}

return $this->getTag('head', [['div', compact('class'), $caption]], $attr);
if ($this->hasHeaderAction) {
$attr = array_merge($attr, ['id' => $this->name.'_th']);
$tag = $this->getTag(
'head',
[$captionHtmlTag,
$this->headerActionTag,
],
$attr
);
} else {
$tag = $this->getTag(
'head',
[$captionHtmlTag],
$attr
);
}

return $tag;
}

/**
* Return HTML for a total value of a specific field.
*
* @param Field $field
* @param mixed $value
* @param Field $f
* @param mixed $value
*
* @return string
*/
public function getTotalsCellHTML(Field $field, $value)
public function getTotalsCellHTML(Field $f, $value)
{
return $this->getTag('foot', $this->app->ui_persistence->typecastSaveField($field, $value));
return $this->getTag('foot', $this->app->ui_persistence->typecastSaveField($f, $value));
}

/**
Expand All @@ -363,13 +376,13 @@ public function getTotalsCellHTML(Field $field, $value)
* This method will be executed only once per table rendering, if you need to format data manually,
* you should use $this->table->addHook('formatRow');
*
* @param Field $field
* @param Field $f
*
* @return string
*/
public function getDataCellHTML(Field $field = null, $extra_tags = [])
public function getDataCellHTML(Field $f = null, $extra_tags = [])
{
return $this->getTag('body', [$this->getDataCellTemplate($field)], $extra_tags);
return $this->getTag('body', [$this->getDataCellTemplate($f)], $extra_tags);
}

/**
Expand All @@ -383,14 +396,14 @@ public function getDataCellHTML(Field $field = null, $extra_tags = [])
* applied to the same column. The first one to be applied is executed first, then
* a subsequent ones are executed.
*
* @param Field $field
* @param Field $f
*
* @return string
*/
public function getDataCellTemplate(Field $field = null)
public function getDataCellTemplate(Field $f = null)
{
if ($field) {
return '{$'.$field->short_name.'}';
if ($f) {
return '{$'.$f->short_name.'}';
} else {
return '{_$'.$this->short_name.'}';
}
Expand Down

0 comments on commit 0865223

Please sign in to comment.