Skip to content

Commit

Permalink
Исправление ошибок.
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Feb 19, 2016
1 parent 91d933c commit bb2b744
Show file tree
Hide file tree
Showing 28 changed files with 178 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/ColumnFilters/BaseColumnFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function toArray()
*/
public function render()
{
return app('sleeping_owl.template')->view('columnfilter.'.$this->getView(), $this->getParams());
return app('sleeping_owl.template')->view('columnfilter.'.$this->getView(), $this->getParams())->render();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ColumnFilters/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getFrom()
*/
public function setFrom(ColumnFilterInterface $from)
{
$this->from = (int) $from;
$this->from = $from;

return $this;
}
Expand All @@ -70,7 +70,7 @@ public function getTo()
*/
public function setTo(ColumnFilterInterface $to)
{
$this->to = (int) $to;
$this->to = $to;

return $this;
}
Expand Down
17 changes: 13 additions & 4 deletions src/ColumnFilters/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ public function getModel()
}

/**
* @param Model $model
* @param Model|string $model
*
* @return $this
* @throws \Exception
*/
public function setModel(Model $model)
public function setModel($model)
{
if (is_string($model) and class_exists($model)) {
$model = new $model;
}

if (! ($model instanceof Model)) {
throw new \Exception('Model must be an instance of Illuminate\Database\Eloquent\Model');
}

$this->model = $model;

return $this;
Expand Down Expand Up @@ -155,7 +164,7 @@ public function getParams()
{
return parent::getParams() + [
'options' => $this->getOptions(),
'placeholder' => $this->getPlaceholder(),
'placeholder' => $this->getPlaceholder()
];
}

Expand Down Expand Up @@ -208,7 +217,7 @@ protected function loadOptions()
{
$repository = new BaseRepository($this->getModel());
$key = $repository->getModel()->getKeyName();
$options = $repository->query()->get()->lists($this->getDisplay(), $key);
$options = $repository->getQuery()->get()->lists($this->getDisplay(), $key);

if ($options instanceof Collection) {
$options = $options->all();
Expand Down
8 changes: 4 additions & 4 deletions src/Columns/Column/BaseColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setView($view)
/**
* @return ColumnInterface
*/
public function getAppend()
public function getAppends()
{
return $this->append;
}
Expand All @@ -122,7 +122,7 @@ public function getAppend()
*
* @return $this
*/
public function setAppend(ColumnInterface $append)
public function append(ColumnInterface $append)
{
$this->append = $append;

Expand All @@ -145,9 +145,9 @@ public function getModel()
public function setModel(Model $model)
{
$this->model = $model;
$append = $this->getAppend();
$append = $this->getAppends();

if (! is_null($append) && ($append instanceof ColumnInterface)) {
if (! is_null($append)) {
$append->setModel($model);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Columns/Column/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function toArray()
{
return parent::toArray() + [
'value' => count($this->getModelValue()),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
3 changes: 2 additions & 1 deletion src/Columns/Column/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace KodiCMS\SleepingOwlAdmin\Columns\Column;

use Closure;
use Illuminate\Database\Eloquent\Model;

class Custom extends BaseColumn
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public function toArray()
{
return parent::toArray() + [
'value' => $this->getValue($this->getModel()),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
2 changes: 1 addition & 1 deletion src/Columns/Column/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function toArray()
return parent::toArray() + [
'value' => $value,
'originalValue' => $originalValue,
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
2 changes: 1 addition & 1 deletion src/Columns/Column/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function toArray()
{
return parent::toArray() + [
'value' => $this->getModelValue(),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
10 changes: 5 additions & 5 deletions src/Columns/Column/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct($name)
public function getRelatedModel()
{
if (is_null($this->relatedModel)) {
$this->setModel(get_class($this->getModel()));
$this->setRelatedModel($this->getModel());
}

return $this->relatedModel;
Expand Down Expand Up @@ -72,9 +72,9 @@ public function setField($field)
*/
public function getUrl()
{
$value = $this->getValue($this->getModel(), $this->getField());
$value = $this->getModelValue($this->getModel(), $this->getField());

return app('sleeping_owl')->getModel($this->relatedModel)->getDisplayUrl([$this->getName() => $value]);
return app('sleeping_owl')->getModel($this->getRelatedModel())->getDisplayUrl([$this->getName() => $value]);
}

/**
Expand All @@ -83,7 +83,7 @@ public function getUrl()
*/
protected function isSelf()
{
return get_class($this->getModel()) == $this->getRelatedModel();
return get_class($this->getModel()) == get_class($this->getRelatedModel());
}

/**
Expand All @@ -95,7 +95,7 @@ public function toArray()
'icon' => $this->isSelf() ? 'fa-filter' : 'fa-arrow-circle-o-right',
'title' => $this->isSelf() ? trans('sleepingowl::core.table.filter') : trans('sleepingowl::core.table.filter-goto'),
'url' => $this->getUrl(),
'value' => $this->getValue($this->getModel(), $this->getField()),
'value' => $this->getModelValue($this->getModel(), $this->getField()),
];
}
}
2 changes: 1 addition & 1 deletion src/Columns/Column/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toArray()

return parent::toArray() + [
'value' => $value,
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
2 changes: 1 addition & 1 deletion src/Columns/Column/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function toArray()
return parent::toArray() + [
'value' => $this->getModelValue(),
'link' => $this->getModelConfiguration()->getEditUrl($this->getModel()->getKey()),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
'linkAttributes' => $this->getLinkAttributes()
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Columns/Column/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function toArray()
{
return parent::toArray() + [
'values' => $this->getModelValue(),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
4 changes: 2 additions & 2 deletions src/Columns/Column/NamedColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ protected function getValueFromObject($instance, $name)
$part = array_shift($parts);

if ($instance instanceof Collection) {
$instance = $instance->lists($part);
$instance = $instance->pluck($part);
} else {
$instance = $instance->{$part};
$instance = $instance->getAttribute($part);
}

if (! empty($parts) && ! is_null($instance)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Columns/Column/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function toArray()
{
return parent::toArray() + [
'value' => $this->getModelValue(),
'append' => $this->getAppend(),
'append' => $this->getAppends(),
];
}
}
73 changes: 47 additions & 26 deletions src/Display/DisplayDatatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class DisplayDatatables extends DisplayTable
{
const FILTER_POSITION_TOP = 0;
const FILTER_POSITION_BOTTOM = 2;
const FILTER_POSITION_BOTH = 2;

/**
* View to render.
* @var string
Expand All @@ -25,7 +29,12 @@ class DisplayDatatables extends DisplayTable
/**
* @var array
*/
protected $attributes = [];
protected $datatableAttributes = [];

/**
* @var int
*/
protected $filterPosition = self::FILTER_POSITION_BOTH;

/**
* Initialize display.
Expand All @@ -38,6 +47,42 @@ public function initialize()
$columnFilter->initialize();
}
}

$this->setAttribute('data-order', json_encode($this->getOrder()));
$this->setAttribute('data-attributes', json_encode($this->getDatatableAttributes(), JSON_FORCE_OBJECT));
}

/**
* TODO: сделать чтобы работал
* @return array
*/
public function getDatatableAttributes()
{
return $this->datatableAttributes;
}

/**
* @param array $datatableAttributes
*/
public function setDatatableAttributes(array $datatableAttributes)
{
$this->datatableAttributes = $datatableAttributes;
}

/**
* @return int
*/
public function getFilterPosition()
{
return $this->filterPosition;
}

/**
* @param int $filterPosition
*/
public function setFilterPosition($filterPosition)
{
$this->filterPosition = $filterPosition;
}

/**
Expand Down Expand Up @@ -88,30 +133,6 @@ public function setColumnFilters($columnFilters)
return $this;
}

/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* @param array|string $attributes
*
* @return $this
*/
public function setAttributes($attributes)
{
if (! is_array($attributes)) {
$attributes = func_get_args();
}

$this->attributes = $attributes;

return $this;
}

/**
* Get view render parameters.
* @return array
Expand All @@ -121,7 +142,7 @@ public function getParams()
$params = parent::getParams();
$params['order'] = $this->getOrder();
$params['columnFilters'] = $this->getColumnFilters();
$params['attributes'] = $this->getAttributes();
$params['filterPosition'] = $this->getFilterPosition();

return $params;
}
Expand Down
Loading

0 comments on commit bb2b744

Please sign in to comment.