akaunting 3.0 (the last dance)
This commit is contained in:
116
app/View/Components/Table/Actions.php
Normal file
116
app/View/Components/Table/Actions.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
|
||||
class Actions extends Component
|
||||
{
|
||||
public $model;
|
||||
|
||||
/** @var array */
|
||||
public $actions;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
$model = false,
|
||||
array $actions = []
|
||||
) {
|
||||
$this->model = $model;
|
||||
$this->actions = $this->getActions($actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.actions');
|
||||
}
|
||||
|
||||
protected function getActions($actions)
|
||||
{
|
||||
if (! empty($actions)) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$actions = [];
|
||||
|
||||
if ($this->model && !empty($this->model->line_actions)) {
|
||||
$actions = $this->model->line_actions;
|
||||
}
|
||||
|
||||
foreach ($actions as $key => $action) {
|
||||
$attributes = [];
|
||||
|
||||
if (! empty($action['attributes'])) {
|
||||
$attributes = $action['attributes'];
|
||||
}
|
||||
|
||||
$actions[$key]['attributes'] = $this->getAttributes($attributes);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an HTML attribute string from an array.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAttributes($attributes)
|
||||
{
|
||||
$html = [];
|
||||
|
||||
foreach ((array) $attributes as $key => $value) {
|
||||
$element = $this->attributeElement($key, $value);
|
||||
|
||||
if (! is_null($element)) {
|
||||
$html[] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
return count($html) > 0 ? ' ' . implode(' ', $html) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a single attribute element.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function attributeElement($key, $value)
|
||||
{
|
||||
// For numeric keys we will assume that the value is a boolean attribute
|
||||
// where the presence of the attribute represents a true value and the
|
||||
// absence represents a false value.
|
||||
// This will convert HTML attributes such as "required" to a correct
|
||||
// form instead of using incorrect numerics.
|
||||
if (is_numeric($key)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Treat boolean attributes as HTML properties
|
||||
if (is_bool($value) && $key !== 'value') {
|
||||
return $value ? $key : '';
|
||||
}
|
||||
|
||||
if (is_array($value) && $key === 'class') {
|
||||
return 'class=' . implode(' ', $value);
|
||||
}
|
||||
|
||||
if (! is_null($value)) {
|
||||
return $key . '=' . e($value, false);
|
||||
}
|
||||
}
|
||||
}
|
18
app/View/Components/Table/Tbody.php
Normal file
18
app/View/Components/Table/Tbody.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
|
||||
class Tbody extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.tbody');
|
||||
}
|
||||
}
|
71
app/View/Components/Table/Td.php
Normal file
71
app/View/Components/Table/Td.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
|
||||
class Td extends Component
|
||||
{
|
||||
public $class;
|
||||
|
||||
public $override;
|
||||
|
||||
public $kind;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
string $class = '', string $override = '', string $kind = ''
|
||||
) {
|
||||
$this->override = $this->getOverride($override);
|
||||
|
||||
$this->kind = $kind;
|
||||
$this->class = $this->getClass($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.td');
|
||||
}
|
||||
|
||||
protected function getOverride($override)
|
||||
{
|
||||
return explode(',', $override);
|
||||
}
|
||||
|
||||
protected function getClass($class)
|
||||
{
|
||||
if (in_array('class', $this->override)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
$default = 'py-4 whitespace-nowrap text-sm font-normal text-black truncate';
|
||||
|
||||
switch ($this->kind) {
|
||||
case 'amount':
|
||||
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left ' . $default;
|
||||
break;
|
||||
case 'right':
|
||||
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left ' . $default;
|
||||
break;
|
||||
case 'action':
|
||||
$default = 'p-0';
|
||||
break;
|
||||
case 'cursor-none':
|
||||
$default = $class . ' cursor-default ' . $default;
|
||||
break;
|
||||
default:
|
||||
$default = $class . ' ltr:pr-6 rtl:pl-6 ltr:text-left rtl:text-right cursor-pointer ' . $default;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
65
app/View/Components/Table/Th.php
Normal file
65
app/View/Components/Table/Th.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
|
||||
class Th extends Component
|
||||
{
|
||||
public $class;
|
||||
|
||||
public $override;
|
||||
|
||||
public $kind;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
string $class = '', string $override = '', string $kind = ''
|
||||
) {
|
||||
$this->override = $this->getOverride($override);
|
||||
|
||||
$this->kind = $kind;
|
||||
$this->class = $this->getClass($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.th');
|
||||
}
|
||||
|
||||
protected function getOverride($override)
|
||||
{
|
||||
return explode(',', $override);
|
||||
}
|
||||
|
||||
protected function getClass($class)
|
||||
{
|
||||
if (in_array('class', $this->override)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
$default = 'py-3 text-xs font-medium text-black tracking-wider';
|
||||
|
||||
switch ($this->kind) {
|
||||
case 'amount':
|
||||
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left ' . $default;
|
||||
break;
|
||||
case 'right':
|
||||
$default = $class . ' ltr:pl-6 rtl:pr-6 ltr:text-right rtl:text-left' . $default;
|
||||
break;
|
||||
default:
|
||||
$default = $class . ' ltr:pr-6 rtl:pl-6 ltr:text-left rtl:text-right ' . $default;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
18
app/View/Components/Table/Thead.php
Normal file
18
app/View/Components/Table/Thead.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
|
||||
class Thead extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.thead');
|
||||
}
|
||||
}
|
50
app/View/Components/Table/Tr.php
Normal file
50
app/View/Components/Table/Tr.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Table;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
use Illuminate\Support\Arr;
|
||||
use ReflectionProperty;
|
||||
|
||||
class Tr extends Component
|
||||
{
|
||||
/** @var string */
|
||||
public $class;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($class = '') {
|
||||
$this->class = $this->getClass($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.table.tr');
|
||||
}
|
||||
|
||||
protected function getClass($class)
|
||||
{
|
||||
if (! empty($class)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
$self = new ReflectionProperty($this::class, 'methodCache');
|
||||
$self->setAccessible(true);
|
||||
|
||||
$values = $self->getValue();
|
||||
|
||||
if (array_key_exists('App\View\Components\Table\Tbody', $values)) {
|
||||
return 'relative flex items-center px-1 group border-b hover:bg-gray-100';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user