Cachet/src/Http/Controllers/DashComponentController.php

240 lines
6.9 KiB
PHP
Raw Normal View History

<?php
namespace CachetHQ\Cachet\Http\Controllers;
2015-01-01 15:45:04 +00:00
use CachetHQ\Cachet\Models\Component;
2015-01-04 20:56:10 +00:00
use CachetHQ\Cachet\Models\ComponentGroup;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
2015-01-01 16:18:24 +00:00
use Illuminate\Routing\Controller;
2015-01-01 15:45:04 +00:00
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
2014-12-20 21:20:17 +00:00
class DashComponentController extends Controller
{
2015-01-04 20:56:10 +00:00
protected $subMenu = [];
public function __construct()
{
$this->subMenu = [
'components' => [
'title' => trans_choice('dashboard.components.components', 2),
2015-01-05 12:01:51 +00:00
'url' => route('dashboard.components'),
2015-01-04 20:56:10 +00:00
'icon' => 'ion-ios-keypad',
'active' => false,
],
'groups' => [
'title' => trans_choice('dashboard.components.groups.groups', 2),
2015-01-05 12:01:51 +00:00
'url' => route('dashboard.components.groups'),
2015-01-04 20:56:10 +00:00
'icon' => 'ion-folder',
'active' => false,
],
];
2015-01-05 12:03:56 +00:00
View::share('subMenu', $this->subMenu);
2015-01-05 12:03:56 +00:00
View::share('subTitle', trans_choice('dashboard.components.components', 2));
2015-01-04 20:56:10 +00:00
}
2014-12-20 21:20:17 +00:00
/**
* Shows the components view.
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\View\View
*/
public function showComponents()
{
$components = Component::orderBy('order')->orderBy('created_at')->get();
2015-01-04 20:56:10 +00:00
$this->subMenu['components']['active'] = true;
2015-01-01 10:39:22 +00:00
return View::make('dashboard.components.index')->with([
'pageTitle' => trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'),
2014-12-20 21:20:17 +00:00
'components' => $components,
2015-01-04 20:56:10 +00:00
'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'),
2015-01-04 20:56:10 +00:00
'groups' => ComponentGroup::all(),
'subMenu' => $this->subMenu,
2014-12-20 21:20:17 +00:00
]);
}
2014-12-20 21:20:17 +00:00
/**
* Shows the edit component view.
2014-12-29 23:07:46 +00:00
*
* @param \CachetHQ\Cachet\Models\Component $component
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\View\View
*/
public function showEditComponent(Component $component)
{
2015-01-04 20:56:10 +00:00
$groups = ComponentGroup::all();
2015-01-14 16:04:15 +00:00
$pageTitle = sprintf(
'"%s" - %s - %s',
$component->name,
trans('dashboard.components.edit.title'),
trans('dashboard.dashboard')
);
2015-01-01 10:39:22 +00:00
return View::make('dashboard.components.edit')->with([
2015-01-14 16:04:15 +00:00
'pageTitle' => $pageTitle,
2014-12-20 21:20:17 +00:00
'component' => $component,
2015-01-04 20:56:10 +00:00
'groups' => $groups,
2014-12-20 21:20:17 +00:00
]);
}
2014-12-20 20:40:48 +00:00
2014-12-20 21:20:17 +00:00
/**
* Updates a component.
2014-12-29 23:07:46 +00:00
*
* @param \CachetHQ\Cachet\Models\Component $component
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\Http\RedirectResponse
*/
public function updateComponentAction(Component $component)
{
2015-01-02 12:05:50 +00:00
$_component = Binput::get('component');
2014-12-20 21:20:17 +00:00
$component->update($_component);
2014-12-20 20:40:48 +00:00
if (! $component->isValid()) {
return Redirect::back()->withInput(Binput::all())
2015-01-14 16:04:15 +00:00
->with('title', sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.whoops'),
trans('dashboard.components.edit.failure')
))
->with('errors', $component->getErrors());
}
2015-01-14 16:04:15 +00:00
$successMsg = sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.awesome'),
trans('dashboard.components.edit.success')
);
return Redirect::back()->with('success', $successMsg);
2014-12-20 21:20:17 +00:00
}
2014-12-20 20:40:48 +00:00
2014-12-20 21:20:17 +00:00
/**
* Shows the add component view.
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\View\View
*/
public function showAddComponent()
{
2015-01-04 20:56:10 +00:00
$groups = ComponentGroup::all();
2015-01-01 10:39:22 +00:00
return View::make('dashboard.components.add')->with([
'pageTitle' => trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'),
2015-01-04 20:56:10 +00:00
'groups' => $groups,
2014-12-20 21:20:17 +00:00
]);
}
2014-12-20 20:40:48 +00:00
2014-12-20 21:20:17 +00:00
/**
* Creates a new component.
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\Http\RedirectResponse
*/
public function createComponentAction()
{
2015-01-02 12:05:50 +00:00
$_component = Binput::get('component');
2014-12-20 21:20:17 +00:00
$component = Component::create($_component);
if (! $component->isValid()) {
return Redirect::back()->withInput(Binput::all())
2015-01-14 16:04:15 +00:00
->with('title', sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.whoops'),
trans('dashboard.components.add.failure')
))
->with('errors', $component->getErrors());
}
2015-01-14 16:04:15 +00:00
$successMsg = sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.awesome'),
trans('dashboard.components.add.success')
);
return Redirect::back()->with('success', $successMsg);
2014-12-20 21:20:17 +00:00
}
2014-12-20 21:20:17 +00:00
/**
* Deletes a given component.
2014-12-29 23:07:46 +00:00
*
* @param \CachetHQ\Cachet\Models\Component $component
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteComponentAction(Component $component)
{
$component->delete();
2014-12-20 21:20:17 +00:00
return Redirect::back();
}
2015-01-04 20:56:10 +00:00
/**
* Deletes a given component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteComponentGroupAction(ComponentGroup $group)
{
$group->delete();
return Redirect::back();
}
2015-01-04 20:56:10 +00:00
/**
* 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'),
2015-01-04 20:56:10 +00:00
]);
}
2015-01-05 14:26:42 +00:00
/**
* Creates a new component.
*
* @return \Illuminate\Http\RedirectResponse
*/
2015-01-04 20:56:10 +00:00
public function postAddComponentGroup()
{
2015-01-05 22:18:22 +00:00
$group = ComponentGroup::create(Binput::get('group'));
2015-01-04 20:56:10 +00:00
if (! $group->isValid()) {
return Redirect::back()->withInput(Binput::all())
2015-01-14 16:04:15 +00:00
->with('title', sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.whoops'),
trans('dashboard.components.groups.add.failure')
))
->with('errors', $group->getErrors());
}
2015-01-14 16:04:15 +00:00
$successMsg = sprintf(
"<strong>%s</strong> %s",
trans('dashboard.notifications.awesome'),
trans('dashboard.components.groups.add.success')
);
return Redirect::back()->with('success', $successMsg);
2015-01-04 20:56:10 +00:00
}
}