1
|
|
|
<?php namespace Anomaly\DashboardModule\Http\Controller\Admin; |
2
|
|
|
|
3
|
|
|
use Anomaly\DashboardModule\Dashboard\Contract\DashboardInterface; |
4
|
|
|
use Anomaly\DashboardModule\Dashboard\Contract\DashboardRepositoryInterface; |
5
|
|
|
use Anomaly\DashboardModule\Dashboard\Form\DashboardFormBuilder; |
6
|
|
|
use Anomaly\DashboardModule\Dashboard\Table\DashboardTableBuilder; |
7
|
|
|
use Anomaly\Streams\Platform\Http\Controller\AdminController; |
8
|
|
|
use Anomaly\UsersModule\User\Contract\UserInterface; |
9
|
|
|
use Illuminate\Contracts\Auth\Guard; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DashboardsController |
13
|
|
|
* |
14
|
|
|
* @link http://pyrocms.com/ |
15
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
16
|
|
|
* @author Ryan Thompson <[email protected]> |
17
|
|
|
* @package Anomaly\DashboardModule\Http\Controller\Admin |
18
|
|
|
*/ |
19
|
|
|
class DashboardsController extends AdminController |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Display a management index of existing entries. |
24
|
|
|
* |
25
|
|
|
* @param DashboardRepositoryInterface $dashboards |
26
|
|
|
* @return \Illuminate\Contracts\View\View|mixed |
27
|
|
|
*/ |
28
|
|
|
public function index(DashboardRepositoryInterface $dashboards) |
29
|
|
|
{ |
30
|
|
|
$dashboards = $dashboards->allowed(); |
31
|
|
|
|
32
|
|
|
/* @var DashboardInterface $dashboard */ |
33
|
|
|
if (!$dashboard = $dashboards->first()) { |
34
|
|
|
return $this->redirect->to('admin/dashboard/manage'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return $this->redirect->to('admin/dashboard/view/' . $dashboard->getSlug()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Display a management index of existing entries. |
42
|
|
|
* |
43
|
|
|
* @param DashboardTableBuilder $table |
44
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
45
|
|
|
*/ |
46
|
|
|
public function manage(DashboardTableBuilder $table) |
47
|
|
|
{ |
48
|
|
|
return $table->render(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Create a new entry. |
53
|
|
|
* |
54
|
|
|
* @param DashboardFormBuilder $form |
55
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
56
|
|
|
*/ |
57
|
|
|
public function create(DashboardFormBuilder $form) |
58
|
|
|
{ |
59
|
|
|
return $form->render(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Edit an existing entry. |
64
|
|
|
* |
65
|
|
|
* @param DashboardFormBuilder $form |
66
|
|
|
* @param $id |
67
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
68
|
|
|
*/ |
69
|
|
|
public function edit(DashboardFormBuilder $form, $id) |
70
|
|
|
{ |
71
|
|
|
return $form->render($id); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* View a dashboard. |
76
|
|
|
* |
77
|
|
|
* @param DashboardRepositoryInterface $dashboards |
78
|
|
|
* @param Guard $guard |
79
|
|
|
* @param $dashboard |
80
|
|
|
* @return \Illuminate\Contracts\View\View|mixed |
81
|
|
|
*/ |
82
|
|
|
public function view(DashboardRepositoryInterface $dashboards, Guard $guard, $dashboard) |
83
|
|
|
{ |
84
|
|
|
$dashboards = $dashboards->allowed(); |
85
|
|
|
|
86
|
|
|
/* @var DashboardInterface $dashboard */ |
87
|
|
|
if (!$dashboard = $dashboards->find($dashboard)) { |
88
|
|
|
abort(404); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$dashboard->setActive(true); |
92
|
|
|
|
93
|
|
|
/* @var UserInterface $user */ |
94
|
|
|
$user = $guard->user(); |
95
|
|
|
$roles = $dashboard->getAllowedRoles(); |
96
|
|
|
|
97
|
|
|
if (!$roles->isEmpty() && !$user->hasAnyRole($roles)) { |
98
|
|
|
abort(403); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $this->view->make( |
102
|
|
|
'module::admin/dashboards/dashboard', |
103
|
|
|
[ |
104
|
|
|
'dashboard' => $dashboard, |
105
|
|
|
'dashboards' => $dashboards |
106
|
|
|
] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|