¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -2,6 +2,7 @@
namespace Modules\Admin\Ui;
use Closure;
use Illuminate\Support\ViewErrorBag;
class Tab
@@ -11,21 +12,21 @@ class Tab
*
* @var bool
*/
private $active = false;
public $active = false;
/**
* Name of the tab.
*
* @var string
*/
private $name;
public $name;
/**
* Label of the tab.
*
* @var string
*/
private $label;
public $label;
/**
* Weight of the tab.
@@ -44,10 +45,25 @@ class Tab
/**
* View of the tab.
*
* @var string|\Closure
* @var string|Closure
*/
private $view;
/**
* Prepend to the View of the tab.
*
* @var string|Closure
*/
private $prependView;
/**
* Append to the view of the tab.
*
* @var string|Closure
*/
private $appendView;
/**
* Data for the tab view.
*
@@ -58,15 +74,17 @@ class Tab
/**
* Error message bag.
*
* @var \Illuminate\Support\ViewErrorBag
* @var ViewErrorBag
*/
private $errors;
/**
* Create a new Tab instance.
*
* @param string $name
* @param string $label
*
* @return void
*/
public function __construct($name, $label)
@@ -76,6 +94,7 @@ class Tab
$this->errors = request()->session()->get('errors') ?: new ViewErrorBag;
}
/**
* Set tab as active.
*
@@ -88,10 +107,12 @@ class Tab
return $this;
}
/**
* Set weight of tab.
*
* @param int $weight
*
* @return self
*/
public function weight($weight)
@@ -101,6 +122,7 @@ class Tab
return $this;
}
/**
* Get weight of the tab.
*
@@ -111,10 +133,12 @@ class Tab
return $this->weight;
}
/**
* Get nav of the tab.
*
* @param array $data
*
* @return string
*/
public function getNav()
@@ -124,30 +148,12 @@ class Tab
</li>";
}
/**
* Return active class if tab is active.
*
* @return string
*/
private function activeClass()
{
return $this->active ? 'active' : '';
}
/**
* Return error class if tab fields has any error.
*
* @return string
*/
private function errorClass()
{
return $this->errors->hasAny($this->fields) ? 'has-error' : '';
}
/**
* Set fields of the tab.
*
* @param array|string $fields
*
* @return self
*/
public function fields($fields)
@@ -157,6 +163,7 @@ class Tab
return $this;
}
/**
* Get fields of the tab.
*
@@ -167,31 +174,61 @@ class Tab
return $this->fields;
}
/**
* Set view of the tab.
*
* @param \Closure|string $view
* @param Closure|string $view
* @param array $data
*
* @return self
*/
public function view($view, $data = [])
public function view($view, $data = [], $prependView = null, $appendView = null)
{
$this->view = $view;
$this->data = $data;
$this->prependView = $prependView;
$this->appendView = $appendView;
return $this;
}
/**
* Get view of the tab.
*
* @param array $data
*
* @return string
*/
public function getView($data = [])
{
$html = "<div class='tab-pane fade in {$this->activeClass()}' id='{$this->name}'>";
$html .= "<h3 class='tab-content-title'>{$this->label}</h3>";
return $this->getPrependView($data) . $this->getMainView($data) . $this->getAppendView($data);
}
public function getPrependView($data = [])
{
$html = '';
if (!is_null($this->prependView)) {
if (is_callable($this->prependView)) {
$html .= call_user_func($this->prependView, $this->name, $this->label, $this->activeClass());
} else {
$html .= $this->prependView;
}
} else {
$html .= "<div class='tab-pane fade in {$this->activeClass()}' id='{$this->name}'>";
$html .= "<h4 class='tab-content-title'>{$this->label}</h4>";
}
return $html;
}
public function getMainView($data = [])
{
$html = '';
if (is_callable($this->view)) {
$html .= call_user_func($this->view, array_merge($this->data, $data));
@@ -199,6 +236,46 @@ class Tab
$html .= view($this->view)->with(array_merge($this->data, $data))->render();
}
return $html .= '</div>';
return $html;
}
public function getAppendView($data = [])
{
$html = '';
if (!is_null($this->appendView)) {
if (is_callable($this->appendView)) {
$html .= call_user_func($this->appendView, $this->name, $this->label, $this->activeClass());
} else {
$html .= $this->appendView;
}
} else {
$html .= '</div>';
}
return $html;
}
/**
* Return active class if tab is active.
*
* @return string
*/
private function activeClass()
{
return $this->active ? 'active' : '';
}
/**
* Return error class if tab fields has any error.
*
* @return string
*/
private function errorClass()
{
return $this->errors->hasAny($this->fields) ? 'has-error' : '';
}
}