Namespaced models and refactored filters
This commit is contained in:
76
src/Http/Controllers/Api/ComponentController.php
Normal file
76
src/Http/Controllers/Api/ComponentController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class ComponentController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
/**
|
||||
* The component repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Component\ComponentRepository
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Create a new component controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Component\ComponentRepository $component
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentRepository $component)
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return $this->component->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
{
|
||||
return $this->component->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a component with incidents.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponentIncidents($id)
|
||||
{
|
||||
return $this->component->with($id, ['incidents']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new component.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postComponents()
|
||||
{
|
||||
return $this->component->create($this->auth->user()->id, Input::all());
|
||||
}
|
||||
}
|
||||
76
src/Http/Controllers/Api/IncidentController.php
Normal file
76
src/Http/Controllers/Api/IncidentController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
/**
|
||||
* The incident repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Incident\IncidentRepository
|
||||
*/
|
||||
protected $incident;
|
||||
|
||||
/**
|
||||
* Create a new incident controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Incident\IncidentRepository $incident
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(IncidentRepository $incident)
|
||||
{
|
||||
$this->incident = $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents()
|
||||
{
|
||||
return $this->incident->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
{
|
||||
return $this->incident->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new incident.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function postIncidents()
|
||||
{
|
||||
return $this->incident->create($this->auth->user()->id, Input::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
{
|
||||
return $this->incident->update($id, Input::all());
|
||||
}
|
||||
}
|
||||
75
src/Http/Controllers/Api/MetricController.php
Normal file
75
src/Http/Controllers/Api/MetricController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class MetricController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
/**
|
||||
* The metric repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Metric\MetricRepository
|
||||
*/
|
||||
protected $metric;
|
||||
|
||||
/**
|
||||
* Create a new metric controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Metric\MetricRepository $metric
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricRepository $metric)
|
||||
{
|
||||
$this->metric = $metric;
|
||||
}
|
||||
/**
|
||||
* Get all metrics.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics()
|
||||
{
|
||||
return $this->metric->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function getMetric($id)
|
||||
{
|
||||
return $this->metric->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function postMetrics()
|
||||
{
|
||||
return $this->metric->create(Input::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function putMetric($id)
|
||||
{
|
||||
return $this->metric->update($id, Input::all());
|
||||
}
|
||||
}
|
||||
63
src/Http/Controllers/Api/MetricPointController.php
Normal file
63
src/Http/Controllers/Api/MetricPointController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use Dingo\Api\Routing\ControllerTrait;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class MetricPointController extends Controller
|
||||
{
|
||||
use ControllerTrait;
|
||||
|
||||
/**
|
||||
* The metric point repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository
|
||||
*/
|
||||
protected $metricPoint;
|
||||
|
||||
/**
|
||||
* Create a new metric point controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository $metricPoint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricPointRepository $metricPoint)
|
||||
{
|
||||
$this->metricPoint = $metricPoint;
|
||||
}
|
||||
/**
|
||||
* Get all metric points.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetricPoints()
|
||||
{
|
||||
return $this->metricPoint->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function getMetricPoint($id)
|
||||
{
|
||||
return $this->metricPoint->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function postMetricPoints()
|
||||
{
|
||||
return $this->metricPoint->create(Input::all());
|
||||
}
|
||||
}
|
||||
57
src/Http/Controllers/AuthController.php
Normal file
57
src/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
/**
|
||||
* Logs users into their account.
|
||||
*/
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showLogin()
|
||||
{
|
||||
return View::make('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user in.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postLogin()
|
||||
{
|
||||
if (Auth::attempt(Input::only(['email', 'password']))) {
|
||||
return Redirect::intended('dashboard');
|
||||
}
|
||||
|
||||
Throttle::hit(Request::instance(), 10, 10);
|
||||
|
||||
return Redirect::back()
|
||||
->withInput(Input::except('password'))
|
||||
->with('error', 'Invalid email or password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user out, deleting their session etc.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
47
src/Http/Controllers/DashAPIController.php
Normal file
47
src/Http/Controllers/DashAPIController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Exception;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class DashAPIController 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(Input::except(['_token']))) {
|
||||
throw new Exception('Failed to update the component.');
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a components ordering.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function postUpdateComponentOrder()
|
||||
{
|
||||
$componentData = Input::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;
|
||||
}
|
||||
}
|
||||
96
src/Http/Controllers/DashComponentController.php
Normal file
96
src/Http/Controllers/DashComponentController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashComponentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the components view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponents()
|
||||
{
|
||||
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
return View::make('dashboard.components.index')->with([
|
||||
'pageTitle' => 'Components - Dashboard',
|
||||
'components' => $components,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponent(Component $component)
|
||||
{
|
||||
return View::make('dashboard.components.edit')->with([
|
||||
'pageTitle' => 'Editing "'.$component->name.'" Component - Dashboard',
|
||||
'component' => $component,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentAction(Component $component)
|
||||
{
|
||||
$_component = Input::get('component');
|
||||
$component->update($_component);
|
||||
|
||||
return Redirect::back()->with('savedComponent', $component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponent()
|
||||
{
|
||||
return View::make('dashboard.components.add')->with([
|
||||
'pageTitle' => 'Add Component - Dashboard',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createComponentAction()
|
||||
{
|
||||
$_component = Input::get('component');
|
||||
$component = Component::create($_component);
|
||||
|
||||
return Redirect::back()->with('component', $component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentAction(Component $component)
|
||||
{
|
||||
$component->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
92
src/Http/Controllers/DashIncidentController.php
Normal file
92
src/Http/Controllers/DashIncidentController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashIncidentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the incidents view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIncidents()
|
||||
{
|
||||
$incidents = Incident::orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.incidents.index')->with([
|
||||
'pageTitle' => 'Incidents - Dashboard',
|
||||
'incidents' => $incidents,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncident()
|
||||
{
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => 'Add Incident - Dashboard',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident template view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncidentTemplate()
|
||||
{
|
||||
return View::make('dashboard.incidents.incident-template')->with([
|
||||
'pageTitle' => 'Add Incident Template - Dashboard',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident template.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentTemplateAction()
|
||||
{
|
||||
$_template = Input::get('template');
|
||||
$template = IncidentTemplate::create($_template);
|
||||
|
||||
return Redirect::back()->with('template', $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentAction()
|
||||
{
|
||||
$_incident = Input::get('incident');
|
||||
$incident = Incident::create($_incident);
|
||||
|
||||
return Redirect::back()->with('incident', $incident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteIncidentAction(Incident $incident)
|
||||
{
|
||||
$incident->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
170
src/Http/Controllers/DashSettingsController.php
Normal file
170
src/Http/Controllers/DashSettingsController.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashSettingsController extends Controller
|
||||
{
|
||||
protected $subMenu = [];
|
||||
protected $subTitle = 'Settings';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'setup' => [
|
||||
'title' => 'Application Setup',
|
||||
'url' => '/dashboard/settings/setup',
|
||||
'icon' => 'ion-gear-b',
|
||||
'active' => false,
|
||||
],
|
||||
'security' => [
|
||||
'title' => 'Security',
|
||||
'url' => '/dashboard/settings/security',
|
||||
'icon' => 'ion-lock-combination',
|
||||
'active' => false,
|
||||
],
|
||||
'theme' => [
|
||||
'title' => 'Theme',
|
||||
'url' => '/dashboard/settings/theme',
|
||||
'icon' => 'ion-paintbrush',
|
||||
'active' => false,
|
||||
],
|
||||
'stylesheet' => [
|
||||
'title' => '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;
|
||||
|
||||
return View::make('dashboard.settings.security')->with([
|
||||
'pageTitle' => 'Security - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (Input::get('remove_banner') == "1") {
|
||||
$setting = Setting::where('name', 'app_banner');
|
||||
$setting->delete();
|
||||
}
|
||||
|
||||
if (Input::hasFile('app_banner')) {
|
||||
$file = Input::file('app_banner');
|
||||
|
||||
// Image Validation.
|
||||
// Image size in bytes.
|
||||
$maxSize = $file->getMaxFilesize();
|
||||
|
||||
if ($file->getSize() > $maxSize) {
|
||||
return Redirect::back()->withErrorMessage("You need to upload an image that is less than $maxSize.");
|
||||
}
|
||||
|
||||
if (!$file->isValid() || $file->getError()) {
|
||||
return Redirect::back()->withErrorMessage($file->getErrorMessage());
|
||||
}
|
||||
|
||||
if (strpos($file->getMimeType(), 'image/') !== 0) {
|
||||
return Redirect::back()->withErrorMessage('Only images may be uploaded.');
|
||||
}
|
||||
|
||||
// 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 (Input::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
|
||||
Setting::firstOrCreate([
|
||||
'name' => $settingName,
|
||||
])->update([
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::back()->withSaved(false);
|
||||
}
|
||||
|
||||
return Redirect::back()->withSaved(true);
|
||||
}
|
||||
}
|
||||
38
src/Http/Controllers/DashUserController.php
Normal file
38
src/Http/Controllers/DashUserController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the user view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showUser()
|
||||
{
|
||||
return View::make('dashboard.user.index')->with([
|
||||
'pageTitle' => 'User - Dashboard',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUser()
|
||||
{
|
||||
$items = Input::all();
|
||||
|
||||
$updated = Auth::user()->update($items);
|
||||
|
||||
return Redirect::back()->with('updated', $updated);
|
||||
}
|
||||
}
|
||||
49
src/Http/Controllers/DashboardController.php
Normal file
49
src/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
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()
|
||||
{
|
||||
// TODO: Find steps needed to complete setup.
|
||||
$components = Component::all();
|
||||
|
||||
return View::make('dashboard.index')->with([
|
||||
'components' => $components,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => 'Metrics - Dashboard',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notifications view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showNotifications()
|
||||
{
|
||||
return View::make('dashboard.notifications.index')->with([
|
||||
'pageTitle' => 'Notifications - Dashboard',
|
||||
]);
|
||||
}
|
||||
}
|
||||
42
src/Http/Controllers/HomeController.php
Normal file
42
src/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Returns the rendered Blade templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$allIncidents = [];
|
||||
|
||||
foreach (range(0, 7) as $i) {
|
||||
$date = Carbon::now()->subDays($i);
|
||||
$incidents = Incident::whereBetween('created_at', [
|
||||
$date->format('Y-m-d').' 00:00:00',
|
||||
$date->format('Y-m-d').' 23:59:59',
|
||||
])->orderBy('created_at', 'desc')->get();
|
||||
$allIncidents[] = ['date' => $date->format('jS F Y'), 'incidents' => $incidents];
|
||||
}
|
||||
|
||||
return View::make('index', [
|
||||
'components' => $components,
|
||||
'allIncidents' => $allIncidents,
|
||||
'pageTitle' => Setting::get('app_name'),
|
||||
'aboutApp' => Markdown::render(Setting::get('app_about')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
46
src/Http/Controllers/RssController.php
Normal file
46
src/Http/Controllers/RssController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Thujohn\Rss\RssFacade;
|
||||
|
||||
class RssController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generates an RSS feed of all incidents.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
{
|
||||
$feed = RssFacade::feed('2.0', 'UTF-8');
|
||||
$feed->channel([
|
||||
'title' => Setting::get('app_name'),
|
||||
'description' => 'Status Feed',
|
||||
'link' => Setting::get('app_domain'),
|
||||
]);
|
||||
|
||||
Incident::get()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->item([
|
||||
'title' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'component' => $componentName,
|
||||
'status' => $incident->humanStatus,
|
||||
'created_at' => $incident->created_at,
|
||||
'updated_at' => $incident->updated_at,
|
||||
]);
|
||||
});
|
||||
|
||||
return Response::make($feed, 200, ['Content-Type' => 'text/xml']);
|
||||
}
|
||||
}
|
||||
85
src/Http/Controllers/SetupController.php
Normal file
85
src/Http/Controllers/SetupController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SetupController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new setup controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->beforeFilter('csrf', ['only' => ['postCachet']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setup page.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => 'Setup',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the actual app setup.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postIndex()
|
||||
{
|
||||
$postData = Input::get();
|
||||
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'required',
|
||||
'settings.show_support' => 'boolean',
|
||||
'user.username' => 'alpha_dash|required',
|
||||
'user.email' => 'email|required',
|
||||
'user.password' => 'required'
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Pull the user details out.
|
||||
$userDetails = array_pull($postData, 'user');
|
||||
|
||||
// TODO: Do we want to just use Model::unguard() here?
|
||||
$user = User::create([
|
||||
'username' => $userDetails['username'],
|
||||
'email' => $userDetails['email'],
|
||||
'password' => $userDetails['password'],
|
||||
'level' => 1,
|
||||
]);
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
$settings = array_get($postData, 'settings');
|
||||
|
||||
foreach ($settings as $settingName => $settingValue) {
|
||||
$setting = new Setting();
|
||||
$setting->name = $settingName;
|
||||
$setting->value = $settingValue;
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
return Redirect::to('dashboard');
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
return Redirect::back()->withInput()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user