|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Components\Layout; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\View\Component; |
|
6
|
|
|
|
|
7
|
|
|
class NavbarNotificationLink extends Component |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The id attribute for the underlying <li> wrapper. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
public $id; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The notification icon (a Font Awesome icon). |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
public $icon; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The notification icon color (an AdminLTE color). |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $iconColor; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The label for the notification badge. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $badgeLabel; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The background color for the notification badge (an AdminLTE color). |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
public $badgeColor; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* An array with the update configuration. The valid properties are: |
|
46
|
|
|
* url => string/array representing the url to fetch for new data. |
|
47
|
|
|
* route => string/array representing the route to fetch for new data. |
|
48
|
|
|
* period => integer representing the updating period time (in seconds). |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
public $updateCfg; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Create a new component instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
2 |
|
public function __construct( |
|
60
|
|
|
$id, $icon, $iconColor = null, $badgeLabel = null, $badgeColor = null, |
|
61
|
|
|
$updateCfg = [] |
|
62
|
|
|
) { |
|
63
|
2 |
|
$this->id = $id; |
|
64
|
2 |
|
$this->icon = $icon; |
|
65
|
2 |
|
$this->iconColor = $iconColor; |
|
66
|
2 |
|
$this->badgeLabel = $badgeLabel; |
|
67
|
2 |
|
$this->badgeColor = $badgeColor; |
|
68
|
2 |
|
$this->updateCfg = is_array($updateCfg) ? $updateCfg : []; |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Make the class attribute for the notification icon. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function makeIconClass() |
|
77
|
|
|
{ |
|
78
|
1 |
|
$classes = [$this->icon]; |
|
79
|
|
|
|
|
80
|
1 |
|
if (! empty($this->iconColor)) { |
|
81
|
1 |
|
$classes[] = "text-{$this->iconColor}"; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
return implode(' ', $classes); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Make the class attribute for the notification badge. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function makeBadgeClass() |
|
93
|
|
|
{ |
|
94
|
1 |
|
$classes = ['badge navbar-badge text-bold text-xs badge-pill']; |
|
95
|
|
|
|
|
96
|
1 |
|
if (! empty($this->badgeColor)) { |
|
97
|
1 |
|
$classes[] = "badge-{$this->badgeColor}"; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
1 |
|
return implode(' ', $classes); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Make the period time for updating the notification badge. |
|
105
|
|
|
* |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function makeUpdatePeriod() |
|
109
|
|
|
{ |
|
110
|
1 |
|
if (! isset($this->updateCfg['period'])) { |
|
111
|
|
|
|
|
112
|
1 |
|
return 0; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
return (intval($this->updateCfg['period']) ?? 0) * 1000; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Make the url to use for fetch new notification data. |
|
120
|
|
|
* |
|
121
|
|
|
* @return string|null |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function makeUpdateUrl() |
|
124
|
|
|
{ |
|
125
|
|
|
// Check if url property is available. |
|
126
|
|
|
|
|
127
|
1 |
|
if (! empty($this->updateCfg['url'])) { |
|
128
|
1 |
|
$uParams = $this->updateCfg['url']; |
|
129
|
|
|
|
|
130
|
1 |
|
return is_array($uParams) ? url(...$uParams) : url($uParams); |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
// Check if route property is available. |
|
134
|
|
|
|
|
135
|
1 |
|
if (! empty($this->updateCfg['route'])) { |
|
136
|
1 |
|
$rParams = $this->updateCfg['route']; |
|
137
|
|
|
|
|
138
|
1 |
|
return is_array($rParams) ? route(...$rParams) : route($rParams); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
// Return null when no url was configured. |
|
142
|
|
|
|
|
143
|
1 |
|
return null; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get the view / contents that represent the component. |
|
148
|
|
|
* |
|
149
|
|
|
* @return \Illuminate\View\View|string |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function render() |
|
152
|
|
|
{ |
|
153
|
1 |
|
return view('adminlte::components.layout.navbar-notification-link'); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|