1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Show; |
4
|
|
|
|
5
|
|
|
use Encore\Admin\Show; |
6
|
|
|
use Illuminate\Contracts\Support\Renderable; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
|
9
|
|
|
class Panel implements Renderable |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The view to be rendered. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $view = 'admin::show.panel'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The fields that this panel holds. |
20
|
|
|
* |
21
|
|
|
* @var Collection |
22
|
|
|
*/ |
23
|
|
|
protected $fields; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Variables in the view. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $data; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Parent show instance. |
34
|
|
|
* |
35
|
|
|
* @var Show |
36
|
|
|
*/ |
37
|
|
|
protected $parent; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Panel constructor. |
41
|
|
|
*/ |
42
|
|
|
public function __construct(Show $show) |
43
|
|
|
{ |
44
|
|
|
$this->parent = $show; |
45
|
|
|
|
46
|
|
|
$this->initData(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initialize view data. |
51
|
|
|
*/ |
52
|
|
|
protected function initData() |
53
|
|
|
{ |
54
|
|
|
$this->data = [ |
55
|
|
|
'fields' => new Collection(), |
56
|
|
|
'tools' => new Tools($this), |
57
|
|
|
'style' => 'info', |
58
|
|
|
'title' => trans('admin.detail'), |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set parent container. |
64
|
|
|
* |
65
|
|
|
* @param Show $show |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setParent(Show $show) |
70
|
|
|
{ |
71
|
|
|
$this->parent = $show; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get parent container. |
78
|
|
|
* |
79
|
|
|
* @return Show |
80
|
|
|
*/ |
81
|
|
|
public function getParent() |
82
|
|
|
{ |
83
|
|
|
return $this->parent; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Set style for this panel. |
88
|
|
|
* |
89
|
|
|
* @param string $style |
90
|
|
|
* |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
|
|
public function style($style = 'info') |
94
|
|
|
{ |
95
|
|
|
$this->data['style'] = $style; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set title for this panel. |
102
|
|
|
* |
103
|
|
|
* @param string $title |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
|
|
public function title($title) |
108
|
|
|
{ |
109
|
|
|
$this->data['title'] = $title; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set view for this panel to render. |
116
|
|
|
* |
117
|
|
|
* @param string $view |
118
|
|
|
* |
119
|
|
|
* @return $this |
120
|
|
|
*/ |
121
|
|
|
public function view($view) |
122
|
|
|
{ |
123
|
|
|
$this->view = $view; |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Build panel tools. |
130
|
|
|
* |
131
|
|
|
* @param $callable |
132
|
|
|
*/ |
133
|
|
|
public function tools($callable) |
134
|
|
|
{ |
135
|
|
|
call_user_func($callable, $this->data['tools']); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Fill fields to panel. |
140
|
|
|
* |
141
|
|
|
* @param []Field $fields |
|
|
|
|
142
|
|
|
* |
143
|
|
|
* @return $this |
144
|
|
|
*/ |
145
|
|
|
public function fill($fields) |
146
|
|
|
{ |
147
|
|
|
$this->data['fields'] = $fields; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Render this panel. |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function render() |
158
|
|
|
{ |
159
|
|
|
return view($this->view, $this->data)->render(); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.