mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 13:38:20 +01:00
[Standards] Updated Codebase to reflect new coding standards. See CONTRIBUTING.md for standards.
This commit is contained in:
parent
f662352f66
commit
107a4c2a6e
@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
$dbURL = parse_url(getenv('CLEARDB_DATABASE_URL'));
|
||||
$dbName = substr($dbURL["path"], 1);
|
||||
$dbURL = parse_url(getenv('CLEARDB_DATABASE_URL'));
|
||||
$dbName = substr($dbURL["path"], 1);
|
||||
|
||||
return array(
|
||||
'default' => 'cleardb',
|
||||
'connections' => array(
|
||||
'cleardb' => array(
|
||||
'driver' => 'mysql',
|
||||
'host' => $dbURL['host'],
|
||||
'database' => $dbName,
|
||||
'username' => $dbURL['user'],
|
||||
'password' => $dbURL['pass'],
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
),
|
||||
)
|
||||
);
|
||||
return array(
|
||||
'default' => 'cleardb',
|
||||
'connections' => array(
|
||||
'cleardb' => array(
|
||||
'driver' => 'mysql',
|
||||
'host' => $dbURL['host'],
|
||||
'database' => $dbName,
|
||||
'username' => $dbURL['user'],
|
||||
'password' => $dbURL['pass'],
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Logs users into their account
|
||||
*/
|
||||
class AuthController extends Controller {
|
||||
public function showLogin() {
|
||||
return View::make('auth.login');
|
||||
}
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
|
||||
public function postLogin() {
|
||||
if (Auth::attempt(Input::only(['email', 'password']))) {
|
||||
return Redirect::intended('dashboard');
|
||||
} else {
|
||||
return Redirect::back()->withInput(Input::except('password'))->with('error', 'Invalid email or password');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Logs users into their account
|
||||
*/
|
||||
class AuthController extends Controller {
|
||||
public function showLogin() {
|
||||
return View::make('auth.login');
|
||||
}
|
||||
|
||||
public function logoutAction() {
|
||||
Auth::logout();
|
||||
public function postLogin() {
|
||||
if (Auth::attempt(Input::only(['email', 'password']))) {
|
||||
return Redirect::intended('dashboard');
|
||||
} else {
|
||||
return Redirect::back()->withInput(Input::except('password'))->with('error', 'Invalid email or password');
|
||||
}
|
||||
}
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
public function logoutAction() {
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AKA the Management Panel.
|
||||
*/
|
||||
class DashboardController extends Controller {
|
||||
public function showDashboard() {
|
||||
return View::make('dashboard.index');
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
|
||||
/**
|
||||
* AKA the Management Panel.
|
||||
*/
|
||||
class DashboardController extends Controller {
|
||||
public function showDashboard() {
|
||||
return View::make('dashboard.index');
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
class HomeController extends Controller {
|
||||
/**
|
||||
* Returns the rendered Blade templates.
|
||||
* @return View
|
||||
*/
|
||||
public function showIndex() {
|
||||
return View::make('index', ['components' => Component::all()]);
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
|
||||
class HomeController extends Controller {
|
||||
/**
|
||||
* Returns the rendered Blade templates.
|
||||
* @return View
|
||||
*/
|
||||
public function showIndex() {
|
||||
return View::make('index', ['components' => Component::all()]);
|
||||
}
|
||||
}
|
@ -1,27 +1,29 @@
|
||||
<?php
|
||||
|
||||
class RSSController extends Controller {
|
||||
public function feedAction() {
|
||||
$feed = RSS::feed('2.0', 'UTF-8');
|
||||
$feed->channel([
|
||||
'title' => Setting::get('app_name'),
|
||||
'description' => 'Status Feed',
|
||||
'link' => Setting::get('app_domain'),
|
||||
]);
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
|
||||
Incident::get()->map(function($incident) use ($feed) {
|
||||
$feed->item([
|
||||
'title' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'component' => $incident->parent->name,
|
||||
'status' => $incident->humanStatus,
|
||||
'created_at' => $incident->created_at,
|
||||
'updated_at' => $incident->updated_at
|
||||
]);
|
||||
});
|
||||
class RSSController extends Controller {
|
||||
public function feedAction() {
|
||||
$feed = RSS::feed('2.0', 'UTF-8');
|
||||
$feed->channel([
|
||||
'title' => Setting::get('app_name'),
|
||||
'description' => 'Status Feed',
|
||||
'link' => Setting::get('app_domain'),
|
||||
]);
|
||||
|
||||
return Response::make($feed, 200, [
|
||||
'Content-Type' => 'text/xml'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Incident::get()->map(function($incident) use ($feed) {
|
||||
$feed->item([
|
||||
'title' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'component' => $incident->parent->name,
|
||||
'status' => $incident->humanStatus,
|
||||
'created_at' => $incident->created_at,
|
||||
'updated_at' => $incident->updated_at
|
||||
]);
|
||||
});
|
||||
|
||||
return Response::make($feed, 200, [
|
||||
'Content-Type' => 'text/xml'
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,48 +1,50 @@
|
||||
<?php
|
||||
|
||||
class SetupController extends Controller {
|
||||
public function showSetup() {
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => 'Setup'
|
||||
]);
|
||||
}
|
||||
namespace CachetHQ\Cachet\Controllers;
|
||||
|
||||
public function setupCachet() {
|
||||
$postData = Input::get();
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'url|required',
|
||||
'settings.show_support' => 'boolean',
|
||||
'user.name'=> 'alpha_dash|required',
|
||||
'user.email' => 'email|required',
|
||||
'user.password' => 'required'
|
||||
]);
|
||||
class SetupController extends Controller {
|
||||
public function showSetup() {
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => 'Setup'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($v->passes()) {
|
||||
// Pull the user details out.
|
||||
$userDetails = array_get($postData, 'user');
|
||||
unset($postData['user']);
|
||||
public function setupCachet() {
|
||||
$postData = Input::get();
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'url|required',
|
||||
'settings.show_support' => 'boolean',
|
||||
'user.name' => 'alpha_dash|required',
|
||||
'user.email' => 'email|required',
|
||||
'user.password' => 'required'
|
||||
]);
|
||||
|
||||
$user = new User;
|
||||
$user->username = $userDetails['name'];
|
||||
$user->email = $userDetails['email'];
|
||||
$user->password = Hash::make($userDetails['password']);
|
||||
$user->save();
|
||||
if ($v->passes()) {
|
||||
// Pull the user details out.
|
||||
$userDetails = array_get($postData, 'user');
|
||||
unset($postData['user']);
|
||||
|
||||
Auth::login($user);
|
||||
$user = new User;
|
||||
$user->username = $userDetails['name'];
|
||||
$user->email = $userDetails['email'];
|
||||
$user->password = Hash::make($userDetails['password']);
|
||||
$user->save();
|
||||
|
||||
// Create the settings, boi.
|
||||
foreach (array_get($postData, 'settings') as $settingName => $settingValue) {
|
||||
$setting = new Setting;
|
||||
$setting->name = $settingName;
|
||||
$setting->value = $settingValue;
|
||||
$setting->save();
|
||||
}
|
||||
Auth::login($user);
|
||||
|
||||
return Redirect::to('/');
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
return Redirect::back()->withInput()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the settings, boi.
|
||||
foreach (array_get($postData, 'settings') as $settingName => $settingValue) {
|
||||
$setting = new Setting;
|
||||
$setting->name = $settingName;
|
||||
$setting->value = $settingValue;
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
return Redirect::to('/');
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
return Redirect::back()->withInput()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
108
app/filters.php
108
app/filters.php
@ -1,64 +1,64 @@
|
||||
<?php
|
||||
|
||||
Route::filter('no_setup', 'NoSetupFilter');
|
||||
Route::filter('cors', 'CORSFilter');
|
||||
Route::filter('no_setup', 'NoSetupFilter');
|
||||
Route::filter('cors', 'CORSFilter');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following filters are used to verify that the user of the current
|
||||
| session is logged into this application. The "basic" filter easily
|
||||
| integrates HTTP Basic authentication for quick, simple checking.
|
||||
|
|
||||
*/
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following filters are used to verify that the user of the current
|
||||
| session is logged into this application. The "basic" filter easily
|
||||
| integrates HTTP Basic authentication for quick, simple checking.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter('auth', function() {
|
||||
if (Auth::guest()) {
|
||||
if (Request::ajax()) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
} else {
|
||||
return Redirect::guest('auth/login');
|
||||
}
|
||||
}
|
||||
});
|
||||
Route::filter('auth', function() {
|
||||
if (Auth::guest()) {
|
||||
if (Request::ajax()) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
} else {
|
||||
return Redirect::guest('auth/login');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Route::filter('auth.basic', function() {
|
||||
return Auth::basic();
|
||||
});
|
||||
Route::filter('auth.basic', function() {
|
||||
return Auth::basic();
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Guest Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The "guest" filter is the counterpart of the authentication filters as
|
||||
| it simply checks that the current user is not logged in. A redirect
|
||||
| response will be issued if they are, which you may freely change.
|
||||
|
|
||||
*/
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Guest Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The "guest" filter is the counterpart of the authentication filters as
|
||||
| it simply checks that the current user is not logged in. A redirect
|
||||
| response will be issued if they are, which you may freely change.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter('guest', function() {
|
||||
if (Auth::check()) {
|
||||
return Redirect::to('/');
|
||||
}
|
||||
});
|
||||
Route::filter('guest', function() {
|
||||
if (Auth::check()) {
|
||||
return Redirect::to('/');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CSRF Protection Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The CSRF filter is responsible for protecting your application against
|
||||
| cross-site request forgery attacks. If this special token in a user
|
||||
| session does not match the one given in this request, we'll bail.
|
||||
|
|
||||
*/
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CSRF Protection Filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The CSRF filter is responsible for protecting your application against
|
||||
| cross-site request forgery attacks. If this special token in a user
|
||||
| session does not match the one given in this request, we'll bail.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::filter('csrf', function() {
|
||||
if (Session::token() !== Input::get('_token')) {
|
||||
throw new Illuminate\Session\TokenMismatchException;
|
||||
}
|
||||
});
|
||||
Route::filter('csrf', function() {
|
||||
if (Session::token() !== Input::get('_token')) {
|
||||
throw new Illuminate\Session\TokenMismatchException;
|
||||
}
|
||||
});
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
class CORSFilter {
|
||||
public function filter($route, $request, $response) {
|
||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Filters;
|
||||
|
||||
class CORSFilter {
|
||||
public function filter($route, $request, $response) {
|
||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
class NoSetupFilter {
|
||||
public function filter($route, $request, $settingName) {
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if ($setting->value) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Filters;
|
||||
|
||||
class NoSetupFilter {
|
||||
public function filter($route, $request, $settingName) {
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if ($setting->value) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'status' => array(
|
||||
1 => 'Operational',
|
||||
2 => 'Performance Issues',
|
||||
3 => 'Partial Outage',
|
||||
4 => 'Major Outage'
|
||||
)
|
||||
);
|
||||
return array(
|
||||
'status' => array(
|
||||
1 => 'Operational',
|
||||
2 => 'Performance Issues',
|
||||
3 => 'Partial Outage',
|
||||
4 => 'Major Outage'
|
||||
)
|
||||
);
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'status' => array(
|
||||
1 => 'Investigating',
|
||||
2 => 'Identified',
|
||||
3 => 'Watching',
|
||||
4 => 'Fixed'
|
||||
)
|
||||
);
|
||||
return array(
|
||||
'status' => array(
|
||||
1 => 'Investigating',
|
||||
2 => 'Identified',
|
||||
3 => 'Watching',
|
||||
4 => 'Fixed'
|
||||
)
|
||||
);
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'good' => 'All systems are functional.',
|
||||
'bad' => 'Some systems are experiencing issues.',
|
||||
);
|
||||
return array(
|
||||
'good' => 'All systems are functional.',
|
||||
'bad' => 'Some systems are experiencing issues.',
|
||||
);
|
@ -1,40 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class Component extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer'
|
||||
];
|
||||
class Component extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
|
||||
protected $fillable = ['name', 'description', 'status'];
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
* @return Illuminate\Database\Eloquent\Relations
|
||||
*/
|
||||
public function incidents() {
|
||||
return $this->hasMany('Incident', 'component', 'id');
|
||||
}
|
||||
protected $fillable = ['name', 'description', 'status'];
|
||||
|
||||
/**
|
||||
* Looks up the human readable version of the status.
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute() {
|
||||
return Lang::get('component.status.' . $this->status);
|
||||
}
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
* @return Illuminate\Database\Eloquent\Relations
|
||||
*/
|
||||
public function incidents() {
|
||||
return $this->hasMany('Incident', 'component', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return ComponentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new ComponentTransformer();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Looks up the human readable version of the status.
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute() {
|
||||
return Lang::get('component.status.' . $this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return ComponentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new ComponentTransformer();
|
||||
}
|
||||
}
|
@ -1,59 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'component' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'message' => 'required',
|
||||
];
|
||||
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
|
||||
protected $fillable = ['component', 'name', 'status', 'message'];
|
||||
protected $rules = [
|
||||
'user_id' => 'required|integer',
|
||||
'component' => 'required|integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'message' => 'required',
|
||||
];
|
||||
|
||||
protected $appends = ['humanStatus'];
|
||||
protected $fillable = ['component', 'name', 'status', 'message'];
|
||||
|
||||
/**
|
||||
* An incident belongs to a component.
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function parent() {
|
||||
return $this->belongsTo('Component', 'component', 'id');
|
||||
}
|
||||
protected $appends = ['humanStatus'];
|
||||
|
||||
/**
|
||||
* Returns a human readable version of the status.
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute() {
|
||||
$statuses = Lang::get('incident.status');
|
||||
return $statuses[$this->status];
|
||||
}
|
||||
/**
|
||||
* An incident belongs to a component.
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function parent() {
|
||||
return $this->belongsTo('Component', 'component', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the icon to use for each status.
|
||||
* @return string
|
||||
*/
|
||||
public function getIconAttribute() {
|
||||
switch ($this->status) {
|
||||
case 1: return 'glyphicon-flag';
|
||||
case 2: return 'glyphicon-warning-sign';
|
||||
case 3: return 'glyphicon-eye-open';
|
||||
case 4: return 'glyphicon-ok';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a human readable version of the status.
|
||||
* @return string
|
||||
*/
|
||||
public function getHumanStatusAttribute() {
|
||||
$statuses = Lang::get('incident.status');
|
||||
return $statuses[$this->status];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return IncidentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new IncidentTransformer();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Finds the icon to use for each status.
|
||||
* @return string
|
||||
*/
|
||||
public function getIconAttribute() {
|
||||
switch ($this->status) {
|
||||
case 1: return 'glyphicon-flag';
|
||||
case 2: return 'glyphicon-warning-sign';
|
||||
case 3: return 'glyphicon-eye-open';
|
||||
case 4: return 'glyphicon-ok';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return IncidentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new IncidentTransformer();
|
||||
}
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class IncidentTemplate extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'name' => 'alpha|required',
|
||||
'slug' => 'alpha_dash|required',
|
||||
'template' => 'required'
|
||||
];
|
||||
class IncidentTemplate extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
|
||||
public static function boot() {
|
||||
parent::boot();
|
||||
protected $rules = [
|
||||
'name' => 'alpha|required',
|
||||
'slug' => 'alpha_dash|required',
|
||||
'template' => 'required'
|
||||
];
|
||||
|
||||
self::on('saving', function($template) {
|
||||
$template->slug = Str::slug($template->name);
|
||||
});
|
||||
}
|
||||
}
|
||||
public static function boot() {
|
||||
parent::boot();
|
||||
|
||||
self::on('saving', function($template) {
|
||||
$template->slug = Str::slug($template->name);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,32 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
];
|
||||
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
||||
use ValidatingTrait;
|
||||
|
||||
protected $fillable = ['name', 'suffix', 'description', 'display_chart'];
|
||||
protected $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Determines whether a chart should be shown.
|
||||
* @return bool
|
||||
*/
|
||||
public function getShouldDisplayAttribute() {
|
||||
return $this->display_chart === 1;
|
||||
}
|
||||
protected $fillable = ['name', 'suffix', 'description', 'display_chart'];
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return ComponentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new MetricTransformer();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines whether a chart should be shown.
|
||||
* @return bool
|
||||
*/
|
||||
public function getShouldDisplayAttribute() {
|
||||
return $this->display_chart === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return ComponentTransformer
|
||||
*/
|
||||
public function getTransformer() {
|
||||
return new MetricTransformer();
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
class MetricPoint extends Eloquent {
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
}
|
||||
class MetricPoint extends Eloquent {
|
||||
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class Service extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'type' => 'alpha_dash|required',
|
||||
'active' => 'required|in:0,1',
|
||||
'properties' => ''
|
||||
];
|
||||
class Service extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
|
||||
public function getPropertiesAttribute($properties) {
|
||||
return json_decode($properties);
|
||||
}
|
||||
protected $rules = [
|
||||
'type' => 'alpha_dash|required',
|
||||
'active' => 'required|in:0,1',
|
||||
'properties' => ''
|
||||
];
|
||||
|
||||
public function setPropertiesAttribute($properties) {
|
||||
$this->attributes['properties'] = json_encode($properties);
|
||||
}
|
||||
}
|
||||
public function getPropertiesAttribute($properties) {
|
||||
return json_decode($properties);
|
||||
}
|
||||
|
||||
public function setPropertiesAttribute($properties) {
|
||||
$this->attributes['properties'] = json_encode($properties);
|
||||
}
|
||||
}
|
@ -1,42 +1,44 @@
|
||||
<?php
|
||||
|
||||
class Setting extends Eloquent {
|
||||
/**
|
||||
* Returns a setting from the database.
|
||||
* @param string $settingName
|
||||
* @param bool $checkEnv
|
||||
* @return string
|
||||
*/
|
||||
public static function get($settingName, $checkEnv = true) {
|
||||
// Default setting value.
|
||||
$setting = null;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
// First try finding the setting in the database.
|
||||
try {
|
||||
$setting = self::whereName($settingName)->first()->value;
|
||||
} catch (\ErrorException $e) {
|
||||
// If we don't have a setting, check the env (fallback for original version)
|
||||
if ($checkEnv) {
|
||||
if (!($setting = getenv(strtoupper($settingName)))) {
|
||||
return $setting;
|
||||
}
|
||||
} else {
|
||||
return $setting;
|
||||
}
|
||||
}
|
||||
class Setting extends Eloquent {
|
||||
/**
|
||||
* Returns a setting from the database.
|
||||
* @param string $settingName
|
||||
* @param bool $checkEnv
|
||||
* @return string
|
||||
*/
|
||||
public static function get($settingName, $checkEnv = true) {
|
||||
// Default setting value.
|
||||
$setting = null;
|
||||
|
||||
return $setting;
|
||||
}
|
||||
// First try finding the setting in the database.
|
||||
try {
|
||||
$setting = self::whereName($settingName)->first()->value;
|
||||
} catch (\ErrorException $e) {
|
||||
// If we don't have a setting, check the env (fallback for original version)
|
||||
if ($checkEnv) {
|
||||
if (!($setting = getenv(strtoupper($settingName)))) {
|
||||
return $setting;
|
||||
}
|
||||
} else {
|
||||
return $setting;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an Exception
|
||||
* @param string $setting
|
||||
* @throws Exception
|
||||
* @return void
|
||||
*/
|
||||
public static function unknownSettingException($setting) {
|
||||
throw new \Exception(
|
||||
sprintf('Unknown setting %s', $setting)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an Exception
|
||||
* @param string $setting
|
||||
* @throws Exception
|
||||
* @return void
|
||||
*/
|
||||
public static function unknownSettingException($setting) {
|
||||
throw new \Exception(
|
||||
sprintf('Unknown setting %s', $setting)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class Subscriber extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
use SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'email' => 'required|email'
|
||||
];
|
||||
class Subscriber extends Eloquent {
|
||||
use ValidatingTrait;
|
||||
use SoftDeletingTrait;
|
||||
|
||||
protected $fillable = ['email'];
|
||||
}
|
||||
protected $rules = [
|
||||
'email' => 'required|email'
|
||||
];
|
||||
|
||||
protected $fillable = ['email'];
|
||||
}
|
@ -1,26 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Auth\UserTrait;
|
||||
use Illuminate\Auth\UserInterface;
|
||||
use Illuminate\Auth\Reminders\RemindableTrait;
|
||||
use Illuminate\Auth\Reminders\RemindableInterface;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class User extends Eloquent implements UserInterface, RemindableInterface {
|
||||
use Illuminate\Auth\UserTrait;
|
||||
use Illuminate\Auth\UserInterface;
|
||||
use Illuminate\Auth\Reminders\RemindableTrait;
|
||||
use Illuminate\Auth\Reminders\RemindableInterface;
|
||||
|
||||
use UserTrait, RemindableTrait;
|
||||
class User extends Eloquent implements UserInterface, RemindableInterface {
|
||||
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
use UserTrait, RemindableTrait;
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
|
||||
}
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
}
|
@ -1,117 +1,119 @@
|
||||
<?php
|
||||
|
||||
class WebHook extends Eloquent {
|
||||
// Request Methods.
|
||||
const HEAD = 0;
|
||||
const GET = 1;
|
||||
const POST = 2;
|
||||
const PATCH = 3;
|
||||
const PUT = 4;
|
||||
const DELETE = 5;
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
/**
|
||||
* Returns all responses for a WebHook.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function response() {
|
||||
return $this->hasMany('WebHookContent', 'hook_id', 'id');
|
||||
}
|
||||
class WebHook extends Eloquent {
|
||||
// Request Methods.
|
||||
const HEAD = 0;
|
||||
const GET = 1;
|
||||
const POST = 2;
|
||||
const PATCH = 3;
|
||||
const PUT = 4;
|
||||
const DELETE = 5;
|
||||
|
||||
/**
|
||||
* Returns all active hooks.
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeActive($query) {
|
||||
return $query->where('active', 1);
|
||||
}
|
||||
/**
|
||||
* Returns all responses for a WebHook.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function response() {
|
||||
return $this->hasMany('WebHookContent', 'hook_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups a Ping event that is fired upon a web hook.
|
||||
*
|
||||
* @return array result of the ping
|
||||
*/
|
||||
public function ping() {
|
||||
return $this->fire('ping', 'Coming live to you from Cachet.');
|
||||
}
|
||||
/**
|
||||
* Returns all active hooks.
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeActive($query) {
|
||||
return $query->where('active', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires the actual web hook event.
|
||||
*
|
||||
* @param string $eventType the event to send X-Cachet-Event
|
||||
* @param mixed $data Data to send to the Web Hook
|
||||
* @return object
|
||||
*/
|
||||
public function fire($eventType, $data = null) {
|
||||
$startTime = microtime(true);
|
||||
/**
|
||||
* Setups a Ping event that is fired upon a web hook.
|
||||
*
|
||||
* @return array result of the ping
|
||||
*/
|
||||
public function ping() {
|
||||
return $this->fire('ping', 'Coming live to you from Cachet.');
|
||||
}
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$request = $client->createRequest($this->requestMethod, $this->endpoint, [
|
||||
'headers' => [
|
||||
'X-Cachet-Event' => $eventType,
|
||||
],
|
||||
'body' => $data
|
||||
]);
|
||||
/**
|
||||
* Fires the actual web hook event.
|
||||
*
|
||||
* @param string $eventType the event to send X-Cachet-Event
|
||||
* @param mixed $data Data to send to the Web Hook
|
||||
* @return object
|
||||
*/
|
||||
public function fire($eventType, $data = null) {
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
$response = $client->send($request);
|
||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||
// Do nothing with the exception, we want it.
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$request = $client->createRequest($this->requestMethod, $this->endpoint, [
|
||||
'headers' => [
|
||||
'X-Cachet-Event' => $eventType,
|
||||
],
|
||||
'body' => $data
|
||||
]);
|
||||
|
||||
$timeTaken = microtime(TRUE) - $startTime;
|
||||
try {
|
||||
$response = $client->send($request);
|
||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||
// Do nothing with the exception, we want it.
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
|
||||
// Store the request
|
||||
$hookResponse = new WebHookResponse;
|
||||
$hookResponse->web_hook_id = $this->id;
|
||||
$hookResponse->response_code = $response->getStatusCode();
|
||||
$hookResponse->sent_headers = json_encode($request->getHeaders());
|
||||
$hookResponse->sent_body = json_encode($data);
|
||||
$hookResponse->recv_headers = json_encode($response->getHeaders());
|
||||
$hookResponse->recv_body = json_encode($response->getBody());
|
||||
$hookResponse->time_taken = $timeTaken;
|
||||
$hookResponse->save();
|
||||
$timeTaken = microtime(TRUE) - $startTime;
|
||||
|
||||
return $hookResponse;
|
||||
}
|
||||
// Store the request
|
||||
$hookResponse = new WebHookResponse;
|
||||
$hookResponse->web_hook_id = $this->id;
|
||||
$hookResponse->response_code = $response->getStatusCode();
|
||||
$hookResponse->sent_headers = json_encode($request->getHeaders());
|
||||
$hookResponse->sent_body = json_encode($data);
|
||||
$hookResponse->recv_headers = json_encode($response->getHeaders());
|
||||
$hookResponse->recv_body = json_encode($response->getBody());
|
||||
$hookResponse->time_taken = $timeTaken;
|
||||
$hookResponse->save();
|
||||
|
||||
/**
|
||||
* Returns a human readable request type name.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string HEAD, GET, POST, DELETE, PATCH, PUT etc
|
||||
*/
|
||||
public function getRequestMethodAttribute() {
|
||||
$requestMethod = NULL;
|
||||
return $hookResponse;
|
||||
}
|
||||
|
||||
switch ($this->request_type) {
|
||||
case self::HEAD:
|
||||
$requestMethod = 'HEAD';
|
||||
break;
|
||||
case self::GET:
|
||||
$requestMethod = 'GET';
|
||||
break;
|
||||
case self::POST:
|
||||
$requestMethod = 'POST';
|
||||
break;
|
||||
case self::PATCH:
|
||||
$requestMethod = 'PATCH';
|
||||
break;
|
||||
case self::PUT:
|
||||
$requestMethod = 'PUT';
|
||||
break;
|
||||
case self::DELETE:
|
||||
$requestMethod = 'DELETE';
|
||||
break;
|
||||
/**
|
||||
* Returns a human readable request type name.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string HEAD, GET, POST, DELETE, PATCH, PUT etc
|
||||
*/
|
||||
public function getRequestMethodAttribute() {
|
||||
$requestMethod = NULL;
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown request type value: ' . $this->request_type);
|
||||
break;
|
||||
}
|
||||
switch ($this->request_type) {
|
||||
case self::HEAD:
|
||||
$requestMethod = 'HEAD';
|
||||
break;
|
||||
case self::GET:
|
||||
$requestMethod = 'GET';
|
||||
break;
|
||||
case self::POST:
|
||||
$requestMethod = 'POST';
|
||||
break;
|
||||
case self::PATCH:
|
||||
$requestMethod = 'PATCH';
|
||||
break;
|
||||
case self::PUT:
|
||||
$requestMethod = 'PUT';
|
||||
break;
|
||||
case self::DELETE:
|
||||
$requestMethod = 'DELETE';
|
||||
break;
|
||||
|
||||
return $requestMethod;
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new Exception('Unknown request type value: ' . $this->request_type);
|
||||
break;
|
||||
}
|
||||
|
||||
return $requestMethod;
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
class WebHookResponse extends Eloquent {
|
||||
public function hook() {
|
||||
return $this->belongsTo('WebHook', 'id', 'hook_id');
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
class WebHookResponse extends Eloquent {
|
||||
public function hook() {
|
||||
return $this->belongsTo('WebHook', 'id', 'hook_id');
|
||||
}
|
||||
}
|
@ -1,24 +1,24 @@
|
||||
<?php
|
||||
|
||||
Route::model('component', 'Component');
|
||||
Route::model('incident', 'Incident');
|
||||
Route::model('incident_template', 'IncidentTemplate');
|
||||
Route::model('setting', 'Setting');
|
||||
Route::model('webhook', 'WebHook');
|
||||
Route::model('user', 'User');
|
||||
Route::model('component', 'Component');
|
||||
Route::model('incident', 'Incident');
|
||||
Route::model('incident_template', 'IncidentTemplate');
|
||||
Route::model('setting', 'Setting');
|
||||
Route::model('webhook', 'WebHook');
|
||||
Route::model('user', 'User');
|
||||
|
||||
routesInDirectory();
|
||||
routesInDirectory();
|
||||
|
||||
function routesInDirectory($app = '') {
|
||||
$routeDir = app_path('routes/' . $app . ($app !== '' ? '/' : null));
|
||||
$iterator = new RecursiveDirectoryIterator($routeDir);
|
||||
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
function routesInDirectory($app = '') {
|
||||
$routeDir = app_path('routes/' . $app . ($app !== '' ? '/' : null));
|
||||
$iterator = new RecursiveDirectoryIterator($routeDir);
|
||||
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
||||
foreach ($iterator as $route) {
|
||||
$isDotFile = strpos($route->getFilename(), '.') === 0;
|
||||
foreach ($iterator as $route) {
|
||||
$isDotFile = strpos($route->getFilename(), '.') === 0;
|
||||
|
||||
if (!$isDotFile && !$route->isDir()) {
|
||||
require $routeDir . $route->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$isDotFile && !$route->isDir()) {
|
||||
require $routeDir . $route->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
<?php
|
||||
|
||||
Route::api(['version' => 'v1', 'prefix' => 'api', 'namespace' => 'CachetHQ\Cachet\Controllers\Api'], function() {
|
||||
Route::api(['version' => 'v1', 'prefix' => 'api', 'namespace' => 'CachetHQ\Cachet\Controllers\Api'], function() {
|
||||
|
||||
Route::get('components', 'ComponentController@getComponents');
|
||||
Route::get('components/{id}', 'ComponentController@getComponent');
|
||||
Route::get('components/{id}/incidents', 'ComponentController@getComponentIncidents');
|
||||
Route::get('incidents', 'IncidentController@getIncidents');
|
||||
Route::get('incidents/{id}', 'IncidentController@getIncident');
|
||||
Route::get('metrics', 'MetricController@getMetrics');
|
||||
Route::get('metrics/{id}', 'MetricController@getMetric');
|
||||
Route::get('components', 'ComponentController@getComponents');
|
||||
Route::get('components/{id}', 'ComponentController@getComponent');
|
||||
Route::get('components/{id}/incidents', 'ComponentController@getComponentIncidents');
|
||||
Route::get('incidents', 'IncidentController@getIncidents');
|
||||
Route::get('incidents/{id}', 'IncidentController@getIncident');
|
||||
Route::get('metrics', 'MetricController@getMetrics');
|
||||
Route::get('metrics/{id}', 'MetricController@getMetric');
|
||||
|
||||
Route::group(['protected' => true], function() {
|
||||
Route::post('components', 'ComponentController@postComponents');
|
||||
Route::post('incidents', 'IncidentController@postIncidents');
|
||||
Route::post('metrics', 'MetricController@postMetrics');
|
||||
Route::group(['protected' => true], function() {
|
||||
Route::post('components', 'ComponentController@postComponents');
|
||||
Route::post('incidents', 'IncidentController@postIncidents');
|
||||
Route::post('metrics', 'MetricController@postMetrics');
|
||||
|
||||
Route::put('components/{id}', 'ComponentController@putComponent');
|
||||
Route::put('incidents/{id}', 'IncidentController@putIncident');
|
||||
Route::put('metrics/{id}', 'MetricController@putMetric');
|
||||
});
|
||||
Route::put('components/{id}', 'ComponentController@putComponent');
|
||||
Route::put('incidents/{id}', 'IncidentController@putIncident');
|
||||
Route::put('metrics/{id}', 'MetricController@putMetric');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
@ -1,24 +1,24 @@
|
||||
<?php
|
||||
|
||||
Route::get('/', 'HomeController@showIndex');
|
||||
Route::get('/incident/{incident}', 'HomeController@showIncident');
|
||||
Route::get('/', 'HomeController@showIndex');
|
||||
Route::get('/incident/{incident}', 'HomeController@showIncident');
|
||||
|
||||
Route::group(['before' => 'no_setup:app_name'], function() {
|
||||
Route::get('/setup', 'SetupController@showSetup');
|
||||
Route::group(['before' => 'csrf'], function() {
|
||||
Route::post('/setup', 'SetupController@setupCachet');
|
||||
});
|
||||
});
|
||||
Route::group(['before' => 'no_setup:app_name'], function() {
|
||||
Route::get('/setup', 'SetupController@showSetup');
|
||||
Route::group(['before' => 'csrf'], function() {
|
||||
Route::post('/setup', 'SetupController@setupCachet');
|
||||
});
|
||||
});
|
||||
|
||||
Route::get('/auth/login', 'AuthController@showLogin')->before('guest');
|
||||
Route::post('/auth/login', 'AuthController@postLogin')->before('guest|csrf');
|
||||
Route::get('/auth/login', 'AuthController@showLogin')->before('guest');
|
||||
Route::post('/auth/login', 'AuthController@postLogin')->before('guest|csrf');
|
||||
|
||||
Route::group(['before' => 'auth'], function() {
|
||||
// Dashboard/Management Panel etc.
|
||||
Route::get('/dashboard', 'DashboardController@showDashboard');
|
||||
Route::group(['before' => 'auth'], function() {
|
||||
// Dashboard/Management Panel etc.
|
||||
Route::get('/dashboard', 'DashboardController@showDashboard');
|
||||
|
||||
// Authorization stuff.
|
||||
Route::get('/auth/logout', 'AuthController@logoutAction');
|
||||
});
|
||||
// Authorization stuff.
|
||||
Route::get('/auth/logout', 'AuthController@logoutAction');
|
||||
});
|
||||
|
||||
Route::get('/rss', 'RSSController@feedAction');
|
||||
Route::get('/rss', 'RSSController@feedAction');
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Tests;
|
||||
|
||||
class ExampleTest extends TestCase {
|
||||
|
||||
/**
|
||||
@ -13,5 +15,4 @@ class ExampleTest extends TestCase {
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Tests;
|
||||
|
||||
class TestCase extends Illuminate\Foundation\Testing\TestCase {
|
||||
|
||||
/**
|
||||
@ -15,5 +17,4 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase {
|
||||
|
||||
return require __DIR__.'/../../bootstrap/start.php';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
|
||||
class ComponentTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Component $component) {
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'status_id' => (int) $component->status,
|
||||
'status' => $component->humanStatus,
|
||||
'incident_count' => $component->incidents()->count(),
|
||||
'created_at' => $component->created_at->timestamp,
|
||||
'updated_at' => $component->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
namespace CachetHQ\Cachet\Transformers;
|
||||
|
||||
class ComponentTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Component $component) {
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'status_id' => (int) $component->status,
|
||||
'status' => $component->humanStatus,
|
||||
'incident_count' => $component->incidents()->count(),
|
||||
'created_at' => $component->created_at->timestamp,
|
||||
'updated_at' => $component->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
@ -1,24 +1,24 @@
|
||||
<?php
|
||||
|
||||
View::composer('index', function($view) {
|
||||
$date = date('Y-m-d');
|
||||
View::composer('index', function($view) {
|
||||
$date = date('Y-m-d');
|
||||
|
||||
$incidents = Incident::whereRaw('DATE(created_at) = "' . $date . '"')
|
||||
->groupBy('status')
|
||||
->orderBy('status', 'desc');
|
||||
$incidents = Incident::whereRaw('DATE(created_at) = "' . $date . '"')
|
||||
->groupBy('status')
|
||||
->orderBy('status', 'desc');
|
||||
|
||||
$incidentCount = $incidents->count();
|
||||
$incidentCount = $incidents->count();
|
||||
|
||||
if ($incidentCount <= 1 || ($incidentCount > 1 && (int) $incidents->first()->status === 4)) {
|
||||
$status = 'success';
|
||||
$message = Lang::get('overview.good');
|
||||
} else {
|
||||
$status = 'danger';
|
||||
$message = Lang::get('overview.bad');
|
||||
}
|
||||
if ($incidentCount <= 1 || ($incidentCount > 1 && (int) $incidents->first()->status === 4)) {
|
||||
$status = 'success';
|
||||
$message = Lang::get('overview.good');
|
||||
} else {
|
||||
$status = 'danger';
|
||||
$message = Lang::get('overview.bad');
|
||||
}
|
||||
|
||||
$view->with([
|
||||
'systemStatus' => $status,
|
||||
'systemMessage' => $message
|
||||
]);
|
||||
});
|
||||
$view->with([
|
||||
'systemStatus' => $status,
|
||||
'systemMessage' => $message
|
||||
]);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user