diff --git a/app/assets/sass/partials/_base.scss b/app/assets/sass/partials/_base.scss index 959b3076..c910f91d 100644 --- a/app/assets/sass/partials/_base.scss +++ b/app/assets/sass/partials/_base.scss @@ -51,4 +51,10 @@ body.dashboard { margin-right: 0; } } + + .alerts { + .alert h5 { + margin-top: 5px; + } + } } diff --git a/app/views/dashboard/components/add.blade.php b/app/views/dashboard/components/add.blade.php index 8c2f009c..8cc935a0 100644 --- a/app/views/dashboard/components/add.blade.php +++ b/app/views/dashboard/components/add.blade.php @@ -13,16 +13,7 @@
- @if($component = Session::get('component')) -
- @if($component->isValid()) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure').' '.$component->getErrors()) }} - @endif -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/components/edit.blade.php b/app/views/dashboard/components/edit.blade.php index cc5e5cef..0d3005a1 100644 --- a/app/views/dashboard/components/edit.blade.php +++ b/app/views/dashboard/components/edit.blade.php @@ -13,16 +13,7 @@
- @if($savedComponent = Session::get('savedComponent')) -
- @if($savedComponent->isValid()) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure').' '.$component->getErrors()) }} - @endif -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/components/groups/add.blade.php b/app/views/dashboard/components/groups/add.blade.php index 6d489a1b..903ffd7c 100644 --- a/app/views/dashboard/components/groups/add.blade.php +++ b/app/views/dashboard/components/groups/add.blade.php @@ -13,16 +13,7 @@
- @if($group = Session::get('group')) -
- @if($group->isValid()) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure').' '.$group->getErrors()) }} - @endif -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/incidents/add.blade.php b/app/views/dashboard/incidents/add.blade.php index ad1f60e8..a710d230 100644 --- a/app/views/dashboard/incidents/add.blade.php +++ b/app/views/dashboard/incidents/add.blade.php @@ -13,16 +13,7 @@
- @if($incident = Session::get('incident')) -
- @if($incident->isValid()) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure').' '.$incident->getErrors()) }} - @endif -
- @endif - + @include('partials.dashboard.errors') {{ Form::open(['name' => 'IncidentForm', 'class' => 'form-vertical', 'role' => 'form']) }}
diff --git a/app/views/dashboard/incidents/edit.blade.php b/app/views/dashboard/incidents/edit.blade.php index 86157815..6efa1019 100644 --- a/app/views/dashboard/incidents/edit.blade.php +++ b/app/views/dashboard/incidents/edit.blade.php @@ -13,6 +13,7 @@
+ @include('partials.dashboard.errors') {{ Form::open(['name' => 'IncidentForm', 'class' => 'form-vertical', 'role' => 'form']) }}
diff --git a/app/views/dashboard/incidents/index.blade.php b/app/views/dashboard/incidents/index.blade.php index 09de5beb..b1c7c63d 100644 --- a/app/views/dashboard/incidents/index.blade.php +++ b/app/views/dashboard/incidents/index.blade.php @@ -16,6 +16,7 @@
+ @include('partials.dashboard.errors')

{{ trans_choice('dashboard.incidents.logged', $incidents->count(), ['count' => $incidents->count()]) }}

diff --git a/app/views/dashboard/incidents/templates/add.blade.php b/app/views/dashboard/incidents/templates/add.blade.php index 35bcc698..45115a2b 100644 --- a/app/views/dashboard/incidents/templates/add.blade.php +++ b/app/views/dashboard/incidents/templates/add.blade.php @@ -13,16 +13,7 @@
- @if($template = Session::get('template')) -
- @if($template->isValid()) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.add.failure').' '.$template->getErrors()) }} - @endif -
- @endif - + @include('partials.dashboard.errors') {{ Form::open(['name' => 'IncidentTemplateForm', 'class' => 'form-vertical', 'role' => 'form']) }}
diff --git a/app/views/dashboard/settings/app-setup.blade.php b/app/views/dashboard/settings/app-setup.blade.php index 0fbace84..9590794a 100644 --- a/app/views/dashboard/settings/app-setup.blade.php +++ b/app/views/dashboard/settings/app-setup.blade.php @@ -10,13 +10,7 @@

{{ trans('dashboard.settings.app-setup.app-setup') }}

- - @if(($saved = Session::get('saved'))) -
{{ trans('dashboard.settings.edit.success') }}
- @elseif(Session::has('error_message')) -
{{ Session::get('error_message') }}
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/settings/security.blade.php b/app/views/dashboard/settings/security.blade.php index 05d01eba..9d295bec 100644 --- a/app/views/dashboard/settings/security.blade.php +++ b/app/views/dashboard/settings/security.blade.php @@ -10,13 +10,7 @@

{{ trans('dashboard.settings.security.security') }}

- - @if($saved = Session::get('saved')) -
{{ trans('dashboard.settings.edit.success') }}
- @elseif(Session::has('saved')) -
{{ trans('dashboard.settings.edit.failure') }}
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/settings/stylesheet.blade.php b/app/views/dashboard/settings/stylesheet.blade.php index 0fcb45e6..96c25ccc 100644 --- a/app/views/dashboard/settings/stylesheet.blade.php +++ b/app/views/dashboard/settings/stylesheet.blade.php @@ -10,13 +10,7 @@

{{ trans('dashboard.settings.stylesheet.stylesheet') }}

- - @if($saved = Session::get('saved')) -
{{ trans('dashboard.settings.edit.success') }}
- @elseif(Session::has('saved')) -
{{ trans('dashboard.settings.edit.failure') }}
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/settings/theme.blade.php b/app/views/dashboard/settings/theme.blade.php index 6877e459..aafa01e0 100644 --- a/app/views/dashboard/settings/theme.blade.php +++ b/app/views/dashboard/settings/theme.blade.php @@ -10,13 +10,7 @@

{{ trans('dashboard.settings.theme.theme') }}

- - @if($saved = Session::get('saved')) -
{{ trans('dashboard.settings.edit.success') }}
- @elseif(Session::has('saved')) -
{{ trans('dashboard.settings.edit.failure') }}
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/team/add.blade.php b/app/views/dashboard/team/add.blade.php index 73dbf9d9..341ae757 100644 --- a/app/views/dashboard/team/add.blade.php +++ b/app/views/dashboard/team/add.blade.php @@ -12,16 +12,7 @@
- @if($created = Session::get('created')) -
- {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.team.add.success')) }} -
- @elseif($errors = Session::get('errors')) -
- {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.team.add.failure')) }} -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/team/edit.blade.php b/app/views/dashboard/team/edit.blade.php index 06380958..44258682 100644 --- a/app/views/dashboard/team/edit.blade.php +++ b/app/views/dashboard/team/edit.blade.php @@ -12,16 +12,7 @@
- @if($updated = Session::get('updated')) -
- @if($updated) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')) }} - @endif -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/dashboard/user/index.blade.php b/app/views/dashboard/user/index.blade.php index c9c7026f..981edb32 100644 --- a/app/views/dashboard/user/index.blade.php +++ b/app/views/dashboard/user/index.blade.php @@ -12,16 +12,7 @@
- @if($updated = Session::get('updated')) -
- @if($updated) - {{ sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')) }} - @else - {{ sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')) }} - @endif -
- @endif - + @include('partials.dashboard.errors')
diff --git a/app/views/partials/dashboard/_error.blade.php b/app/views/partials/dashboard/_error.blade.php new file mode 100644 index 00000000..7bdd1bd7 --- /dev/null +++ b/app/views/partials/dashboard/_error.blade.php @@ -0,0 +1,15 @@ +
+ +
diff --git a/app/views/partials/dashboard/errors.blade.php b/app/views/partials/dashboard/errors.blade.php new file mode 100644 index 00000000..df785361 --- /dev/null +++ b/app/views/partials/dashboard/errors.blade.php @@ -0,0 +1,15 @@ +@if ($errors->any()) + @include('partials.dashboard._error', ['level' => 'danger', 'title' => Session::get('title'), 'message' => $errors->all(':message')]) +@endif + +@if ($message = Session::get('success')) + @include('partials.dashboard._error', ['level' => 'success', 'title' => Session::get('title'), 'message' => $message]) +@endif + +@if ($message = Session::get('warning')) + @include('partials.dashboard._error', ['level' => 'warning', 'title' => Session::get('title'), 'message' => $message]) +@endif + +@if ($message = Session::get('info')) + @include('partials.dashboard._error', ['level' => 'info', 'title' => Session::get('title'), 'message' => $message]) +@endif diff --git a/src/Http/Controllers/DashComponentController.php b/src/Http/Controllers/DashComponentController.php index 9e322932..14a7e93a 100644 --- a/src/Http/Controllers/DashComponentController.php +++ b/src/Http/Controllers/DashComponentController.php @@ -99,7 +99,13 @@ class DashComponentController extends Controller $_component = Binput::get('component'); $component->update($_component); - return Redirect::back()->with('savedComponent', $component); + if (! $component->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure'))) + ->with('errors', $component->getErrors()); + } + + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success'))); } /** @@ -127,7 +133,13 @@ class DashComponentController extends Controller $_component = Binput::get('component'); $component = Component::create($_component); - return Redirect::back()->with('component', $component); + if (! $component->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure'))) + ->with('errors', $component->getErrors()); + } + + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success'))); } /** @@ -179,6 +191,12 @@ class DashComponentController extends Controller { $group = ComponentGroup::create(Binput::get('group')); - return Redirect::back()->withGroup($group); + if (! $group->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure'))) + ->with('errors', $group->getErrors()); + } + + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success'))); } } diff --git a/src/Http/Controllers/DashIncidentController.php b/src/Http/Controllers/DashIncidentController.php index f3889022..cd38b5a7 100644 --- a/src/Http/Controllers/DashIncidentController.php +++ b/src/Http/Controllers/DashIncidentController.php @@ -38,6 +38,24 @@ class DashIncidentController extends Controller ]); } + /** + * Creates a new incident. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function createIncidentAction() + { + $incident = Incident::create(Binput::get('incident')); + + if (! $incident->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure'))) + ->with('errors', $incident->getErrors()); + } + + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success'))); + } + /** * Shows the add incident template view. * @@ -60,19 +78,13 @@ class DashIncidentController extends Controller $_template = Binput::get('template'); $template = IncidentTemplate::create($_template); - return Redirect::back()->with('template', $template); - } + if (! $template->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.failure'))) + ->with('errors', $template->getErrors()); + } - /** - * Creates a new incident. - * - * @return \Illuminate\Http\RedirectResponse - */ - public function createIncidentAction() - { - $incident = Incident::create(Binput::get('incident')); - - return Redirect::back()->withInput(Binput::all())->with('incident', $incident); + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success'))); } /** @@ -116,6 +128,12 @@ class DashIncidentController extends Controller $_incident = Binput::get('incident'); $incident->update($_incident); - return Redirect::to('dashboard/incidents'); + if (! $incident->isValid()) { + return Redirect::back()->withInput(Binput::all()) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.edit.failure'))) + ->with('errors', $incident->getErrors()); + } + + return Redirect::to('dashboard/incidents')->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success'))); } } diff --git a/src/Http/Controllers/DashSettingsController.php b/src/Http/Controllers/DashSettingsController.php index 4809a34c..c17afe6f 100644 --- a/src/Http/Controllers/DashSettingsController.php +++ b/src/Http/Controllers/DashSettingsController.php @@ -46,6 +46,7 @@ class DashSettingsController extends Controller ]; View::share('subTitle', $this->subTitle); + View::share('subMenu', $this->subMenu); } @@ -167,15 +168,15 @@ class DashSettingsController extends Controller $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { - return Redirect::back()->withErrorMessage("You need to upload an image that is less than $maxSize."); + return Redirect::back()->withErrors("You need to upload an image that is less than $maxSize."); } if (!$file->isValid() || $file->getError()) { - return Redirect::back()->withErrorMessage($file->getErrorMessage()); + return Redirect::back()->withErrors($file->getErrorMessage()); } if (strpos($file->getMimeType(), 'image/') !== 0) { - return Redirect::back()->withErrorMessage('Only images may be uploaded.'); + return Redirect::back()->withErrors('Only images may be uploaded.'); } // Store the banner. @@ -202,9 +203,9 @@ class DashSettingsController extends Controller ]); } } catch (Exception $e) { - return Redirect::back()->withSaved(false); + return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure')); } - return Redirect::back()->withSaved(true); + return Redirect::back()->with('success', trans('dashboard.settings.edit.success')); } } diff --git a/src/Http/Controllers/DashUserController.php b/src/Http/Controllers/DashUserController.php index 59c49826..1b69209d 100644 --- a/src/Http/Controllers/DashUserController.php +++ b/src/Http/Controllers/DashUserController.php @@ -47,9 +47,16 @@ class DashUserController extends Controller unset($items['password']); } - $updated = Auth::user()->update($items); + $user = Auth::user(); + $user->update($items); - return Redirect::back()->with('updated', $updated); + if (! $user->isValid()) { + return Redirect::back()->withInput(Binput::except('password')) + ->with('title', sprintf("%s %s", trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure'))) + ->with('errors', $user->getErrors()); + } + + return Redirect::back()->with('success', sprintf("%s %s", trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success'))); } /** diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index 78b2a9d0..d566c708 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -3,10 +3,7 @@ namespace CachetHQ\Cachet\Http\Controllers; use CachetHQ\Cachet\Models\Component; -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 DashboardController extends Controller @@ -26,80 +23,6 @@ class DashboardController 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()) { - return Redirect::back()->with('created', $user->isValid()); - } else { - return Redirect::back() - ->withInput(Binput::except('password')) - ->with('errors', $user->getErrors()); - } - } - - /** - * Updates a user. - * - * @param \CachetHQ\Cachet\Models\User $user - * - * @return \Illuminate\View\View - */ - public function postUpdateUser(User $user) - { - $items = Binput::all(); - - $updated = $user->update($items); - - return Redirect::back()->with('updated', $updated); - } - /** * Shows the metrics view. *