Skip to content

Commit c53a08a

Browse files
committed
Small update and fix Editable setReadonly
1 parent dfd2797 commit c53a08a

20 files changed

+108
-76
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<p align="center"><h2>[Unreleased] (Only in SleepingOwl <code class="language-php">8+</code> branch)</h2></p>
2+
3+
4+
## 2021-05-30
5+
* [Fix] Fixed setReadonly callback in editable columns and add policy on editable columns
6+
27
## 2021-02-06
38
* [Fix] Fixed editable columns (checkbox, datetime, number, select, text & textarea) saving on relations.
49

@@ -168,7 +173,7 @@ AdminColumn::checkbox()
168173
->setVisibled(function($item){
169174
return $item->id < 3;
170175
});
171-
176+
172177
//or
173178
AdminColumn::link('title', 'Title')->setVisibled(false);
174179
```

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

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

2424
## Documentation new ver.8
2525

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

2828
* [Russian](http://sleepingowladmin.ru/#/ru/) (90% process)
2929
* [English](http://sleepingowladmin.ru/#/en/) (30% process)

resources/views/default/column/editable/checkbox.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div {!! $attributes !!}>
2+
23
@if ($visibled)
34
@if($isEditable)
45
<a href="#"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@if ( ! is_null($value))
2-
<a href="{{ $url }}" class="btn btn-xs btn btn-default pull-right" data-toggle="tooltip" title="{{ $title }}">
2+
<a href="{{ $url }}" class="btn btn-xs btn-default pull-right" data-toggle="tooltip" title="{{ $title }}">
33
<i class="{{ $icon }}"></i>
44
</a>
55
@endif

resources/views/default/display/table.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="card card-default {!! $card_class !!}">
1414
<div class="card-heading card-header">
1515
@if ($creatable)
16-
<a href="{{ url($createUrl) }}" class="btn btn-primary btn-create">
16+
<a href="{{ url($createUrl) }}" class="btn btn-primary btn-create mb-3">
1717
<i class="fas fa-plus"></i> {{ $newEntryButtonText }}
1818
</a>
1919
@endif
@@ -25,7 +25,7 @@
2525
@yield('card.buttons')
2626
@yield('panel.buttons')
2727
</div>
28-
28+
2929
@yield('card.heading')
3030
@yield('panel.heading')
3131
</div>

src/Contracts/Display/ColumnEditableInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ interface ColumnEditableInterface extends ColumnInterface
1212
* @return void
1313
*/
1414
public function save(Request $request);
15+
16+
/**
17+
* @param Closure|bool $readonlyEditable
18+
* @return void
19+
*/
20+
public function setReadonly($readonlyEditable);
1521
}

src/Contracts/Display/DisplayColumnFactoryInterface.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@
66

77
/**
88
* @method Column\Action action($name, $title = null)
9-
* @method Column\Checkbox checkbox($label = null)
9+
* @method Column\Boolean boolean($name, $title = null, $small = null)
10+
* @method Column\Checkbox checkbox($label = null, $small = null)
1011
* @method Column\Control control($label = null)
1112
* @method Column\Count count($name, $label = null)
12-
* @method Column\Custom custom($label = null, \Closure $callback = null)
13-
* @method Column\DateTime datetime($name, $label = null)
13+
* @method Column\Custom custom($label = null, \Closure $callback = null, $small = null)
14+
* @method Column\DateTime datetime($name, $label = null, $small = null)
1415
* @method Column\Filter filter($name, $label = null)
15-
* @method Column\Image image($name, $label = null)
16-
* @method Column\Lists lists($name, $label = null)
16+
* @method Column\Image image($name, $label = null, $small = null)
17+
* @method Column\Gravatar gravatar($name, $label = null, $small = null)
18+
* @method Column\Lists lists($name, $label = null, $small = null)
1719
* @method Column\Order order()
18-
* @method Column\Text text($name, $label = null)
19-
* @method Column\Link link($name, $label = null)
20-
* @method Column\RelatedLink relatedLink($name, $label = null)
21-
* @method Column\Email email($name, $label = null)
20+
* @method Column\Text text($name, $label = null, $small = null)
21+
* @method Column\Link link($name, $label = null, $small = null)
22+
* @method Column\RelatedLink relatedLink($name, $label = null, $small = null)
23+
* @method Column\Email email($name, $label = null, $small = null)
2224
* @method Column\TreeControl treeControl()
23-
* @method Column\Url url($name, $label = null)
25+
* @method Column\Url url($name, $label = null, $small = null)
2426
*/
2527
interface DisplayColumnFactoryInterface
2628
{

src/Contracts/Display/DisplayColumnFilterFactoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @method Text text()
1212
* @method Date date()
13-
* @method Select select()
13+
* @method Select select($options = null, $title = null)
1414
* @method Range range()
1515
*/
1616
interface DisplayColumnFilterFactoryInterface

src/Display/Column/Custom.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ class Custom extends NamedColumn
3232
* Custom constructor.
3333
*
3434
* @param null|string $label
35+
* @param null|string $small
3536
* @param Closure $callback
3637
*/
37-
public function __construct($label = null, Closure $callback = null)
38+
public function __construct($label = null, Closure $callback = null, $small = null)
3839
{
3940
parent::__construct($label);
4041
if (! is_null($label)) {
@@ -43,6 +44,9 @@ public function __construct($label = null, Closure $callback = null)
4344
if (! is_null($callback)) {
4445
$this->setCallback($callback);
4546
}
47+
if (! is_null($small)) {
48+
$this->setSmall($small);
49+
}
4650
}
4751

4852
/**

src/Display/Column/Editable/EditableColumn.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
namespace SleepingOwl\Admin\Display\Column\Editable;
44

5+
use Closure;
56
use SleepingOwl\Admin\Display\Column\NamedColumn;
6-
use SleepingOwl\Admin\Traits\EditableReadonlyTrait;
77

88
class EditableColumn extends NamedColumn
99
{
10-
use EditableReadonlyTrait;
10+
/**
11+
* @var bool
12+
*/
13+
protected $readonlyEditable = false;
1114

1215
/**
1316
* @var string
@@ -145,15 +148,44 @@ public function setEditableMode($mode)
145148
return $this;
146149
}
147150

151+
/**
152+
* @return bool|callable
153+
*/
154+
public function isReadonly()
155+
{
156+
if ($this->getModelConfiguration()->isEditable($this->getModel())) {
157+
if (is_callable($this->readonlyEditable)) {
158+
return (bool) call_user_func($this->readonlyEditable, $this->getModel());
159+
}
160+
} else {
161+
return false;
162+
}
163+
164+
return (bool) $this->readonlyEditable;
165+
}
166+
167+
/**
168+
* @param Closure|bool $readonlyEditable
169+
*
170+
* @return $this
171+
*/
172+
public function setReadonly($readonlyEditable)
173+
{
174+
$this->readonlyEditable = $readonlyEditable;
175+
176+
return $this;
177+
}
178+
148179
/**
149180
* @return array
150181
*/
151182
public function toArray()
152183
{
184+
153185
return parent::toArray() + [
154186
'id' => $this->getModel()->getKey(),
155187
'value' => $this->getModelValue(),
156-
'isEditable' => $this->getReadonly(),
188+
'isEditable' => $this->isReadonly(),
157189
'url' => $this->getUrl(),
158190
'title' => $this->getTitle(),
159191
'mode' => $this->getEditableMode(),

src/Display/Column/Filter/Select.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class Select extends BaseColumnFilter
4646

4747
/**
4848
* Select constructor.
49-
* @param null $options
50-
* @param null $title
49+
* @param null|array|Model $options
50+
* @param null|string $title
5151
* @throws \SleepingOwl\Admin\Exceptions\Form\Element\SelectException
5252
*/
5353
public function __construct($options = null, $title = null)

src/Display/Column/NamedColumn.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ abstract class NamedColumn extends TableColumn implements NamedColumnInterface
3636
/**
3737
* NamedColumn constructor.
3838
* @param $name
39-
* @param $label string
40-
* @param $small string
39+
* @param $label string|null
40+
* @param $small string|Closure|null
4141
*/
42-
public function __construct($name, $label = null, $small = null)
42+
public function __construct($name, string $label = null, $small = null)
4343
{
4444
parent::__construct($label);
4545
$this->setName($name);

src/Display/Display.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function setRepositoryClass($repositoryClass)
148148
}
149149

150150
/**
151-
* @param array|string[] ...$relations
151+
* @param array|string|string[] ...$relations
152152
*
153153
* @return $this
154154
*/

src/Facades/Admin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace SleepingOwl\Admin\Facades;
44

5+
use Illuminate\Contracts\Support\Renderable;
56
use Illuminate\Support\Facades\Facade;
7+
use SleepingOwl\Admin\Section;
68

79
/**
810
* @see \SleepingOwl\Admin\Admin
9-
* @method static \SleepingOwl\Admin\Section getModel(string|object $class)
11+
* @method static Section getModel(string|object $class)
12+
* @method static Section view(string|Renderable $content, null|string $title)
1013
*/
1114
class Admin extends Facade
1215
{

src/Facades/Navigation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
namespace SleepingOwl\Admin\Facades;
44

55
use Illuminate\Support\Facades\Facade;
6+
use Illuminate\Support\Collection;
67

8+
/**
9+
* Class Navigation
10+
* @package SleepingOwl\Admin\Facades
11+
* @method static \SleepingOwl\Admin\Navigation setFromArray(array $navigation)
12+
*/
713
class Navigation extends Facade
814
{
915
/**

src/Facades/TableColumn.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* @method static \SleepingOwl\Admin\Display\Column\Action action($name, $title = null)
9-
* @method static \SleepingOwl\Admin\Display\Column\Checkbox checkbox($label = null)
8+
* @method static \SleepingOwl\Admin\Display\Column\Action action($name, $title = null, $small = null)
9+
* @method static \SleepingOwl\Admin\Display\Column\Boolean boolean($name, $title = null, $small = null)
10+
* @method static \SleepingOwl\Admin\Display\Column\Checkbox checkbox($label = null, $small = null)
1011
* @method static \SleepingOwl\Admin\Display\Column\Control control($label = null)
11-
* @method static \SleepingOwl\Admin\Display\Column\Count count($name, $label = null)
12-
* @method static \SleepingOwl\Admin\Display\Column\Custom custom($label = null, \Closure $callback = null)
13-
* @method static \SleepingOwl\Admin\Display\Column\DateTime datetime($name, $label = null)
12+
* @method static \SleepingOwl\Admin\Display\Column\Count count($name, $label = null, $small = null)
13+
* @method static \SleepingOwl\Admin\Display\Column\Custom custom($label = null, \Closure $callback = null, $small = null)
14+
* @method static \SleepingOwl\Admin\Display\Column\DateTime datetime($name, $label = null, $small = null)
1415
* @method static \SleepingOwl\Admin\Display\Column\Filter filter($name, $label = null)
15-
* @method static \SleepingOwl\Admin\Display\Column\Image image($name, $label = null)
16-
* @method static \SleepingOwl\Admin\Display\Column\Gravatar gravatar($name, $label = null)
17-
* @method static \SleepingOwl\Admin\Display\Column\Lists lists($name, $label = null)
16+
* @method static \SleepingOwl\Admin\Display\Column\Image image($name, $label = null, $small = null)
17+
* @method static \SleepingOwl\Admin\Display\Column\Gravatar gravatar($name, $label = null, $small = null)
18+
* @method static \SleepingOwl\Admin\Display\Column\Lists lists($name, $label = null, $small = null)
1819
* @method static \SleepingOwl\Admin\Display\Column\Order order()
19-
* @method static \SleepingOwl\Admin\Display\Column\Text text($name, $label = null)
20-
* @method static \SleepingOwl\Admin\Display\Column\Link link($name, $label = null)
21-
* @method static \SleepingOwl\Admin\Display\Column\RelatedLink relatedLink($name, $label = null)
22-
* @method static \SleepingOwl\Admin\Display\Column\Email email($name, $label = null)
20+
* @method static \SleepingOwl\Admin\Display\Column\Text text($name, $label = null, $small = null)
21+
* @method static \SleepingOwl\Admin\Display\Column\Link link($name, $label = null, $small = null)
22+
* @method static \SleepingOwl\Admin\Display\Column\RelatedLink relatedLink($name, $label = null, $small = null)
23+
* @method static \SleepingOwl\Admin\Display\Column\Email email($name, $label = null, $small = null)
2324
* @method static \SleepingOwl\Admin\Display\Column\TreeControl treeControl()
24-
* @method static \SleepingOwl\Admin\Display\Column\Url url($name, $label = null)
25+
* @method static \SleepingOwl\Admin\Display\Column\Url url($name, $label = null, $small = null)
2526
*/
2627
class TableColumn extends Facade
2728
{

src/Facades/TableColumnFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @method static \SleepingOwl\Admin\Display\Column\Filter\Text text()
99
* @method static \SleepingOwl\Admin\Display\Column\Filter\Date date()
10-
* @method static \SleepingOwl\Admin\Display\Column\Filter\Select select()
10+
* @method static \SleepingOwl\Admin\Display\Column\Filter\Select select($options = null, $title = null)
1111
* @method static \SleepingOwl\Admin\Display\Column\Filter\Range range()
1212
* @method static \SleepingOwl\Admin\Display\Column\Filter\DateRange daterange()
1313
*/

src/Traits/EditableReadonlyTrait.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Traits/SelectOptionsFromModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SleepingOwl\Admin\Traits;
44

5+
use Closure;
56
use Illuminate\Database\Eloquent\Model;
67
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
78
use Illuminate\Support\Arr;
@@ -37,7 +38,7 @@ trait SelectOptionsFromModel
3738
protected $fetchColumns = [];
3839

3940
/**
40-
* @var \Closure|object callable
41+
* @var Closure|object callable
4142
*/
4243
protected $loadOptionsQueryPreparer;
4344

@@ -100,7 +101,7 @@ public function getDisplay()
100101
}
101102

102103
/**
103-
* @param string|\Closure $display
104+
* @param string|Closure $display
104105
*
105106
* @return $this
106107
*/

src/Traits/SmallDisplay.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace SleepingOwl\Admin\Traits;
44

5+
use Closure;
6+
57
trait SmallDisplay
68
{
79
/**
@@ -29,7 +31,7 @@ public function getSmall()
2931
}
3032

3133
/**
32-
* @param string $small
34+
* @param string|Closure $small
3335
*
3436
* @return $this
3537
*/

0 commit comments

Comments
 (0)