Skip to content

Commit

Permalink
Small update and fix Editable setReadonly
Browse files Browse the repository at this point in the history
  • Loading branch information
daaner committed May 29, 2021
1 parent dfd2797 commit c53a08a
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 76 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<p align="center"><h2>[Unreleased] (Only in SleepingOwl <code class="language-php">8+</code> branch)</h2></p>


## 2021-05-30
* [Fix] Fixed setReadonly callback in editable columns and add policy on editable columns

## 2021-02-06
* [Fix] Fixed editable columns (checkbox, datetime, number, select, text & textarea) saving on relations.

Expand Down Expand Up @@ -168,7 +173,7 @@ AdminColumn::checkbox()
->setVisibled(function($item){
return $item->id < 3;
});

//or
AdminColumn::link('title', 'Title')->setVisibled(false);
```
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Build Status](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin.svg?branch=development)](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin)
[![StyleCI](https://styleci.io/repos/52141393/shield?branch=development)](https://styleci.io/repos/52141393)
[![Laravel Support](https://img.shields.io/badge/Laravel-5.5--8.2-brightgreen.svg)]()
[![Laravel Support](https://img.shields.io/badge/Laravel-5.5--8.44-brightgreen.svg)]()
[![PHP Support](https://img.shields.io/badge/PHP-7.1.3+-brightgreen.svg)]()

[![Official Site](https://img.shields.io/badge/official-site-blue.svg)](https://sleepingowladmin.ru)
Expand All @@ -23,7 +23,7 @@ __Lumen is NOT supported(((__

## Documentation new ver.8

Powered by Laravel 5.5 - 8+. (latest tested version 8.2.0)
Powered by Laravel 5.5 - 8+. (latest tested version 8.44.0)

* [Russian](http://sleepingowladmin.ru/#/ru/) (90% process)
* [English](http://sleepingowladmin.ru/#/en/) (30% process)
Expand Down
1 change: 1 addition & 0 deletions resources/views/default/column/editable/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div {!! $attributes !!}>

@if ($visibled)
@if($isEditable)
<a href="#"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/default/column/filter.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if ( ! is_null($value))
<a href="{{ $url }}" class="btn btn-xs btn btn-default pull-right" data-toggle="tooltip" title="{{ $title }}">
<a href="{{ $url }}" class="btn btn-xs btn-default pull-right" data-toggle="tooltip" title="{{ $title }}">
<i class="{{ $icon }}"></i>
</a>
@endif
4 changes: 2 additions & 2 deletions resources/views/default/display/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="card card-default {!! $card_class !!}">
<div class="card-heading card-header">
@if ($creatable)
<a href="{{ url($createUrl) }}" class="btn btn-primary btn-create">
<a href="{{ url($createUrl) }}" class="btn btn-primary btn-create mb-3">
<i class="fas fa-plus"></i> {{ $newEntryButtonText }}
</a>
@endif
Expand All @@ -25,7 +25,7 @@
@yield('card.buttons')
@yield('panel.buttons')
</div>

@yield('card.heading')
@yield('panel.heading')
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/Contracts/Display/ColumnEditableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ interface ColumnEditableInterface extends ColumnInterface
* @return void
*/
public function save(Request $request);

/**
* @param Closure|bool $readonlyEditable
* @return void
*/
public function setReadonly($readonlyEditable);
}
22 changes: 12 additions & 10 deletions src/Contracts/Display/DisplayColumnFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

/**
* @method Column\Action action($name, $title = null)
* @method Column\Checkbox checkbox($label = null)
* @method Column\Boolean boolean($name, $title = null, $small = null)
* @method Column\Checkbox checkbox($label = null, $small = null)
* @method Column\Control control($label = null)
* @method Column\Count count($name, $label = null)
* @method Column\Custom custom($label = null, \Closure $callback = null)
* @method Column\DateTime datetime($name, $label = null)
* @method Column\Custom custom($label = null, \Closure $callback = null, $small = null)
* @method Column\DateTime datetime($name, $label = null, $small = null)
* @method Column\Filter filter($name, $label = null)
* @method Column\Image image($name, $label = null)
* @method Column\Lists lists($name, $label = null)
* @method Column\Image image($name, $label = null, $small = null)
* @method Column\Gravatar gravatar($name, $label = null, $small = null)
* @method Column\Lists lists($name, $label = null, $small = null)
* @method Column\Order order()
* @method Column\Text text($name, $label = null)
* @method Column\Link link($name, $label = null)
* @method Column\RelatedLink relatedLink($name, $label = null)
* @method Column\Email email($name, $label = null)
* @method Column\Text text($name, $label = null, $small = null)
* @method Column\Link link($name, $label = null, $small = null)
* @method Column\RelatedLink relatedLink($name, $label = null, $small = null)
* @method Column\Email email($name, $label = null, $small = null)
* @method Column\TreeControl treeControl()
* @method Column\Url url($name, $label = null)
* @method Column\Url url($name, $label = null, $small = null)
*/
interface DisplayColumnFactoryInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @method Text text()
* @method Date date()
* @method Select select()
* @method Select select($options = null, $title = null)
* @method Range range()
*/
interface DisplayColumnFilterFactoryInterface
Expand Down
6 changes: 5 additions & 1 deletion src/Display/Column/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class Custom extends NamedColumn
* Custom constructor.
*
* @param null|string $label
* @param null|string $small
* @param Closure $callback
*/
public function __construct($label = null, Closure $callback = null)
public function __construct($label = null, Closure $callback = null, $small = null)
{
parent::__construct($label);
if (! is_null($label)) {
Expand All @@ -43,6 +44,9 @@ public function __construct($label = null, Closure $callback = null)
if (! is_null($callback)) {
$this->setCallback($callback);
}
if (! is_null($small)) {
$this->setSmall($small);
}
}

/**
Expand Down
38 changes: 35 additions & 3 deletions src/Display/Column/Editable/EditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace SleepingOwl\Admin\Display\Column\Editable;

use Closure;
use SleepingOwl\Admin\Display\Column\NamedColumn;
use SleepingOwl\Admin\Traits\EditableReadonlyTrait;

class EditableColumn extends NamedColumn
{
use EditableReadonlyTrait;
/**
* @var bool
*/
protected $readonlyEditable = false;

/**
* @var string
Expand Down Expand Up @@ -145,15 +148,44 @@ public function setEditableMode($mode)
return $this;
}

/**
* @return bool|callable
*/
public function isReadonly()
{
if ($this->getModelConfiguration()->isEditable($this->getModel())) {
if (is_callable($this->readonlyEditable)) {
return (bool) call_user_func($this->readonlyEditable, $this->getModel());
}
} else {
return false;
}

return (bool) $this->readonlyEditable;
}

/**
* @param Closure|bool $readonlyEditable
*
* @return $this
*/
public function setReadonly($readonlyEditable)
{
$this->readonlyEditable = $readonlyEditable;

return $this;
}

/**
* @return array
*/
public function toArray()
{

return parent::toArray() + [
'id' => $this->getModel()->getKey(),
'value' => $this->getModelValue(),
'isEditable' => $this->getReadonly(),
'isEditable' => $this->isReadonly(),
'url' => $this->getUrl(),
'title' => $this->getTitle(),
'mode' => $this->getEditableMode(),
Expand Down
4 changes: 2 additions & 2 deletions src/Display/Column/Filter/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Select extends BaseColumnFilter

/**
* Select constructor.
* @param null $options
* @param null $title
* @param null|array|Model $options
* @param null|string $title
* @throws \SleepingOwl\Admin\Exceptions\Form\Element\SelectException
*/
public function __construct($options = null, $title = null)
Expand Down
6 changes: 3 additions & 3 deletions src/Display/Column/NamedColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ abstract class NamedColumn extends TableColumn implements NamedColumnInterface
/**
* NamedColumn constructor.
* @param $name
* @param $label string
* @param $small string
* @param $label string|null
* @param $small string|Closure|null
*/
public function __construct($name, $label = null, $small = null)
public function __construct($name, string $label = null, $small = null)
{
parent::__construct($label);
$this->setName($name);
Expand Down
2 changes: 1 addition & 1 deletion src/Display/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function setRepositoryClass($repositoryClass)
}

/**
* @param array|string[] ...$relations
* @param array|string|string[] ...$relations
*
* @return $this
*/
Expand Down
5 changes: 4 additions & 1 deletion src/Facades/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace SleepingOwl\Admin\Facades;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\Facade;
use SleepingOwl\Admin\Section;

/**
* @see \SleepingOwl\Admin\Admin
* @method static \SleepingOwl\Admin\Section getModel(string|object $class)
* @method static Section getModel(string|object $class)
* @method static Section view(string|Renderable $content, null|string $title)
*/
class Admin extends Facade
{
Expand Down
6 changes: 6 additions & 0 deletions src/Facades/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Collection;

/**
* Class Navigation
* @package SleepingOwl\Admin\Facades
* @method static \SleepingOwl\Admin\Navigation setFromArray(array $navigation)
*/
class Navigation extends Facade
{
/**
Expand Down
27 changes: 14 additions & 13 deletions src/Facades/TableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static \SleepingOwl\Admin\Display\Column\Action action($name, $title = null)
* @method static \SleepingOwl\Admin\Display\Column\Checkbox checkbox($label = null)
* @method static \SleepingOwl\Admin\Display\Column\Action action($name, $title = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Boolean boolean($name, $title = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Checkbox checkbox($label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Control control($label = null)
* @method static \SleepingOwl\Admin\Display\Column\Count count($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Custom custom($label = null, \Closure $callback = null)
* @method static \SleepingOwl\Admin\Display\Column\DateTime datetime($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Count count($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Custom custom($label = null, \Closure $callback = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\DateTime datetime($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Filter filter($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Image image($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Gravatar gravatar($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Lists lists($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Image image($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Gravatar gravatar($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Lists lists($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Order order()
* @method static \SleepingOwl\Admin\Display\Column\Text text($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Link link($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\RelatedLink relatedLink($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Email email($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Text text($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Link link($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\RelatedLink relatedLink($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\Email email($name, $label = null, $small = null)
* @method static \SleepingOwl\Admin\Display\Column\TreeControl treeControl()
* @method static \SleepingOwl\Admin\Display\Column\Url url($name, $label = null)
* @method static \SleepingOwl\Admin\Display\Column\Url url($name, $label = null, $small = null)
*/
class TableColumn extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/TableColumnFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @method static \SleepingOwl\Admin\Display\Column\Filter\Text text()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Date date()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Select select()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Select select($options = null, $title = null)
* @method static \SleepingOwl\Admin\Display\Column\Filter\Range range()
* @method static \SleepingOwl\Admin\Display\Column\Filter\DateRange daterange()
*/
Expand Down
31 changes: 0 additions & 31 deletions src/Traits/EditableReadonlyTrait.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/Traits/SelectOptionsFromModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SleepingOwl\Admin\Traits;

use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -37,7 +38,7 @@ trait SelectOptionsFromModel
protected $fetchColumns = [];

/**
* @var \Closure|object callable
* @var Closure|object callable
*/
protected $loadOptionsQueryPreparer;

Expand Down Expand Up @@ -100,7 +101,7 @@ public function getDisplay()
}

/**
* @param string|\Closure $display
* @param string|Closure $display
*
* @return $this
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/SmallDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SleepingOwl\Admin\Traits;

use Closure;

trait SmallDisplay
{
/**
Expand Down Expand Up @@ -29,7 +31,7 @@ public function getSmall()
}

/**
* @param string $small
* @param string|Closure $small
*
* @return $this
*/
Expand Down

0 comments on commit c53a08a

Please sign in to comment.