Cachet is now a Laravel 5 app
This commit is contained in:
69
app/Http/Controllers/Admin/ApiController.php
Normal file
69
app/Http/Controllers/Admin/ApiController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Updates a component with the entered info.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postUpdateComponent(Component $component)
|
||||
{
|
||||
if (!$component->update(Binput::except(['_token']))) {
|
||||
throw new Exception(trans('dashboard.components.edit.failure'));
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a components ordering.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function postUpdateComponentOrder()
|
||||
{
|
||||
$componentData = Binput::all();
|
||||
unset($componentData['component'][0]); // Remove random 0 index.
|
||||
|
||||
foreach ($componentData['component'] as $componentId => $order) {
|
||||
$component = Component::find($componentId);
|
||||
$component->update(['order' => $order]);
|
||||
}
|
||||
|
||||
return $componentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a template by slug.
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\IncidentTemplate
|
||||
*/
|
||||
public function getIncidentTemplate()
|
||||
{
|
||||
$templateSlug = Binput::get('slug');
|
||||
|
||||
$template = IncidentTemplate::where('slug', $templateSlug)->first();
|
||||
|
||||
if ($template) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
|
||||
}
|
||||
}
|
||||
373
app/Http/Controllers/Admin/ComponentController.php
Normal file
373
app/Http/Controllers/Admin/ComponentController.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ComponentController extends Controller
|
||||
{
|
||||
protected $subMenu = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'components' => [
|
||||
'title' => trans('dashboard.components.components'),
|
||||
'url' => route('dashboard.components'),
|
||||
'icon' => 'ion-outlet',
|
||||
'active' => false,
|
||||
],
|
||||
'groups' => [
|
||||
'title' => trans_choice('dashboard.components.groups.groups', 2),
|
||||
'url' => route('dashboard.components.groups'),
|
||||
'icon' => 'ion-folder',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share([
|
||||
'subMenu' => $this->subMenu,
|
||||
'subTitle' => trans_choice('dashboard.components.components', 2),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the components view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponents()
|
||||
{
|
||||
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$this->subMenu['components']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'),
|
||||
'components' => $components,
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the component groups view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponentGroups()
|
||||
{
|
||||
$this->subMenu['groups']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.groups.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
|
||||
'groups' => ComponentGroup::all(),
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponent(Component $component)
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
$pageTitle = sprintf(
|
||||
'"%s" - %s - %s',
|
||||
$component->name,
|
||||
trans('dashboard.components.edit.title'),
|
||||
trans('dashboard.dashboard')
|
||||
);
|
||||
|
||||
return View::make('dashboard.components.edit')->with([
|
||||
'pageTitle' => $pageTitle,
|
||||
'component' => $component,
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentAction(Component $component)
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component->update($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.edit.failure')
|
||||
))
|
||||
->with('errors', $component->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponent()
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
return View::make('dashboard.components.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createComponentAction()
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
// We deal with tags separately.
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component = Component::create($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.add.failure')
|
||||
))
|
||||
->with('errors', $component->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentAction(Component $component)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component',
|
||||
]);
|
||||
|
||||
$component->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component Group',
|
||||
]);
|
||||
|
||||
$group->components->map(function ($component) {
|
||||
$component->update([
|
||||
'group_id' => 0,
|
||||
]);
|
||||
});
|
||||
|
||||
$group->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component group view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponentGroup()
|
||||
{
|
||||
return View::make('dashboard.components.groups.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component group view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponentGroup(ComponentGroup $group)
|
||||
{
|
||||
return View::make('dashboard.components.groups.edit')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'group' => $group,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAddComponentGroup()
|
||||
{
|
||||
$group = ComponentGroup::create(Binput::get('group'));
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.groups.add.failure')
|
||||
))
|
||||
->with('errors', $group->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
$groupData = Binput::get('group');
|
||||
$group->update($groupData);
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.groups.edit.failure')
|
||||
))
|
||||
->with('errors', $group->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
36
app/Http/Controllers/Admin/DashboardController.php
Normal file
36
app/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the dashboard view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showDashboard()
|
||||
{
|
||||
$components = Component::all();
|
||||
|
||||
return View::make('dashboard.index')->with([
|
||||
'components' => $components,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notifications view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showNotifications()
|
||||
{
|
||||
return View::make('dashboard.notifications.index')->with([
|
||||
'pageTitle' => trans('dashboard.notifications.notifications').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
317
app/Http/Controllers/Admin/IncidentController.php
Normal file
317
app/Http/Controllers/Admin/IncidentController.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashIncidentController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => true,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incidents view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIncidents()
|
||||
{
|
||||
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.incidents.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'),
|
||||
'incidents' => $incidents,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncident()
|
||||
{
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incident templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTemplates()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentAction()
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$componentStatus = array_pull($incidentData, 'component_status');
|
||||
|
||||
$incident = Incident::create($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.incidents.add.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
// Update the component.
|
||||
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
|
||||
Component::find($incidentData['component_id'])->update([
|
||||
'status' => $componentStatus,
|
||||
]);
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident template view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncidentTemplate()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident template view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'template' => $template,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident Template',
|
||||
]);
|
||||
|
||||
$template->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident template.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentTemplateAction()
|
||||
{
|
||||
$_template = Binput::get('template');
|
||||
$template = IncidentTemplate::create($_template);
|
||||
|
||||
if (! $template->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.add.failure')
|
||||
))
|
||||
->with('errors', $template->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteIncidentAction(Incident $incident)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident',
|
||||
]);
|
||||
|
||||
$incident->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditIncidentAction(Incident $incident)
|
||||
{
|
||||
return View::make('dashboard.incidents.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'incident' => $incident,
|
||||
'components' => Component::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editIncidentAction(Incident $incident)
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$incident->update($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.edit.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident Template',
|
||||
]);
|
||||
|
||||
$template->update(Binput::get('template'));
|
||||
|
||||
return Redirect::back()->with('updatedTemplate', $template);
|
||||
}
|
||||
}
|
||||
203
app/Http/Controllers/Admin/MetricController.php
Normal file
203
app/Http/Controllers/Admin/MetricController.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class MetricController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
$metrics = Metric::orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
|
||||
'metrics' => $metrics,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetric()
|
||||
{
|
||||
return View::make('dashboard.metrics.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metric points.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetricPoints()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricAction()
|
||||
{
|
||||
$metricData = Binput::get('metric');
|
||||
$metric = Metric::create($metricData);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.metrics.add.failure')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric point view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetricPoint()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric point.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricPointAction()
|
||||
{
|
||||
$_point = Binput::get('point');
|
||||
$point = MetricPoint::create($_point);
|
||||
|
||||
if (! $point->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.failure')
|
||||
))
|
||||
->with('errors', $point->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteMetricAction(Metric $metric)
|
||||
{
|
||||
$metric->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit metric view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditMetricAction(Metric $metric)
|
||||
{
|
||||
return View::make('dashboard.metrics.edit')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'metric' => $metric,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editMetricAction(Metric $metric)
|
||||
{
|
||||
$_metric = Binput::get('metric');
|
||||
$metric->update($_metric);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong>',
|
||||
trans('dashboard.notifications.awesome')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/metrics')->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
233
app/Http/Controllers/Admin/ScheduleController.php
Normal file
233
app/Http/Controllers/Admin/ScheduleController.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class ScheduleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashScheduleController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: Remove this from DashIncidentController, so it's shared?
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => false,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all scheduled maintenance.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$schedule = Incident::scheduled()->orderBy('created_at')->get();
|
||||
|
||||
return View::make('dashboard.schedule.index')->withSchedule($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add schedule maintenance form.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddSchedule()
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.add')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scheduled maintenance "incident".
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function addScheduleAction()
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$incident = Incident::create($scheduleData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('success', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.add.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit schedule maintenance form.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditSchedule(Incident $schedule)
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.edit')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
'schedule' => $schedule,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editScheduleAction(Incident $schedule)
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$schedule->update($scheduleData);
|
||||
|
||||
if (! $schedule->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.failure')
|
||||
))
|
||||
->with('errors', $schedule->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/schedule')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given schedule.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteScheduleAction(Incident $schedule)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Schedule',
|
||||
]);
|
||||
|
||||
$schedule->delete();
|
||||
|
||||
return Redirect::back()->with('warning', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.delete.failure')
|
||||
));
|
||||
}
|
||||
}
|
||||
180
app/Http/Controllers/Admin/SettingsController.php
Normal file
180
app/Http/Controllers/Admin/SettingsController.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use CachetHQ\Cachet\Controllers\AbstractController;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SettingsController extends AbstractController
|
||||
{
|
||||
protected $subMenu = [];
|
||||
protected $subTitle = 'Settings';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'setup' => [
|
||||
'title' => trans('dashboard.settings.app-setup.app-setup'),
|
||||
'url' => '/dashboard/settings/setup',
|
||||
'icon' => 'ion-gear-b',
|
||||
'active' => false,
|
||||
],
|
||||
'security' => [
|
||||
'title' => trans('dashboard.settings.security.security'),
|
||||
'url' => '/dashboard/settings/security',
|
||||
'icon' => 'ion-lock-combination',
|
||||
'active' => false,
|
||||
],
|
||||
'theme' => [
|
||||
'title' => trans('dashboard.settings.theme.theme'),
|
||||
'url' => '/dashboard/settings/theme',
|
||||
'icon' => 'ion-paintbrush',
|
||||
'active' => false,
|
||||
],
|
||||
'stylesheet' => [
|
||||
'title' => trans('dashboard.settings.stylesheet.stylesheet'),
|
||||
'url' => '/dashboard/settings/stylesheet',
|
||||
'icon' => 'ion-paintbucket',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subTitle', $this->subTitle);
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings setup view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSetupView()
|
||||
{
|
||||
$this->subMenu['setup']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.app-setup')->with([
|
||||
'pageTitle' => 'Application Setup - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings theme view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showThemeView()
|
||||
{
|
||||
$this->subMenu['theme']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.theme')->with([
|
||||
'pageTitle' => 'Theme - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings security view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSecurityView()
|
||||
{
|
||||
$this->subMenu['security']['active'] = true;
|
||||
|
||||
$unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get();
|
||||
|
||||
return View::make('dashboard.settings.security')->with([
|
||||
'pageTitle' => 'Security - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
'unsecureUsers' => $unsecureUsers,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings stylesheet view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showStylesheetView()
|
||||
{
|
||||
$this->subMenu['stylesheet']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.stylesheet')->with([
|
||||
'pageTitle' => 'Stylesheet - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status page settings.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postSettings()
|
||||
{
|
||||
if (Binput::get('remove_banner') === '1') {
|
||||
$setting = Setting::where('name', 'app_banner');
|
||||
$setting->delete();
|
||||
}
|
||||
|
||||
if (Binput::hasFile('app_banner')) {
|
||||
$file = Binput::file('app_banner');
|
||||
|
||||
// Image Validation.
|
||||
// Image size in bytes.
|
||||
$maxSize = $file->getMaxFilesize();
|
||||
|
||||
if ($file->getSize() > $maxSize) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
|
||||
'size' => $maxSize,
|
||||
]));
|
||||
}
|
||||
|
||||
if (!$file->isValid() || $file->getError()) {
|
||||
return Redirect::back()->withErrors($file->getErrorMessage());
|
||||
}
|
||||
|
||||
if (strpos($file->getMimeType(), 'image/') !== 0) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.images-only'));
|
||||
}
|
||||
|
||||
// Store the banner.
|
||||
Setting::firstOrCreate([
|
||||
'name' => 'app_banner',
|
||||
])->update([
|
||||
'value' => base64_encode(file_get_contents($file->getRealPath())),
|
||||
]);
|
||||
|
||||
// Store the banner type
|
||||
Setting::firstOrCreate([
|
||||
'name' => 'app_banner_type',
|
||||
])->update([
|
||||
'value' => $file->getMimeType(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
|
||||
Setting::firstOrCreate([
|
||||
'name' => $settingName,
|
||||
])->update([
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
|
||||
}
|
||||
|
||||
Lang::setLocale(Binput::get('app_locale'));
|
||||
|
||||
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
|
||||
}
|
||||
}
|
||||
138
app/Http/Controllers/Admin/TeamController.php
Normal file
138
app/Http/Controllers/Admin/TeamController.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class TeamController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the team members view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTeamView()
|
||||
{
|
||||
$team = User::all();
|
||||
|
||||
return View::make('dashboard.team.index')->with([
|
||||
'pageTitle' => trans('dashboard.team.team').' - '.trans('dashboard.dashboard'),
|
||||
'teamMembers' => $team,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit team member view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTeamMemberView(User $user)
|
||||
{
|
||||
return View::make('dashboard.team.edit')->with([
|
||||
'pageTitle' => trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add team member view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddTeamMemberView()
|
||||
{
|
||||
return View::make('dashboard.team.add')->with([
|
||||
'pageTitle' => trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new team member.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAddUser()
|
||||
{
|
||||
$user = User::create(Binput::all());
|
||||
|
||||
if (! $user->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.add.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a user.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUpdateUser(User $user)
|
||||
{
|
||||
$items = Binput::all();
|
||||
|
||||
$passwordChange = array_get($items, 'password');
|
||||
|
||||
if (trim($passwordChange) === '') {
|
||||
unset($items['password']);
|
||||
}
|
||||
|
||||
$user->update($items);
|
||||
|
||||
if (! $user->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.edit.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
98
app/Http/Controllers/Admin/UserController.php
Normal file
98
app/Http/Controllers/Admin/UserController.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the user view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showUser()
|
||||
{
|
||||
return View::make('dashboard.user.index')->with([
|
||||
'pageTitle' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUser()
|
||||
{
|
||||
$items = Binput::all();
|
||||
|
||||
$passwordChange = array_get($items, 'password');
|
||||
$enable2FA = (bool) array_pull($items, 'google2fa');
|
||||
|
||||
// Let's enable/disable auth
|
||||
if ($enable2FA && ! Auth::user()->hasTwoFactor) {
|
||||
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => true,
|
||||
]);
|
||||
} elseif (! $enable2FA) {
|
||||
$items['google_2fa_secret'] = '';
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if (trim($passwordChange) === '') {
|
||||
unset($items['password']);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$user->update($items);
|
||||
|
||||
if (! $user->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.edit.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerates the users API key.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function regenerateApiKey(User $user)
|
||||
{
|
||||
segment_track('User Management', [
|
||||
'event' => 'regenrated_api_token',
|
||||
]);
|
||||
|
||||
$user->api_key = User::generateApiKey();
|
||||
$user->save();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user