FEATURE #1451: add logging to all actions in widget management
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\AssignWidget;
|
||||
use App\Events\RemoveWidgetFromArea;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetArea;
|
||||
use App\Models\WidgetInWidgetArea;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class AssociateWidget extends Controller
|
||||
{
|
||||
@@ -26,6 +29,10 @@ class AssociateWidget extends Controller
|
||||
|
||||
public function makeAssociation($widgetId, $widgetAreaId)
|
||||
{
|
||||
// check if given values are valid
|
||||
$widget = Widget::findOrFail($widgetId);
|
||||
$widgetArea = WidgetArea::findOrFail($widgetAreaId);
|
||||
|
||||
try {
|
||||
WidgetInWidgetArea::create(['widget_id' => $widgetId, 'widget_area_id' => $widgetAreaId]);
|
||||
} catch (QueryException $e) {
|
||||
@@ -34,6 +41,8 @@ class AssociateWidget extends Controller
|
||||
->with('error', trans('admin/widgets.associationExists'));
|
||||
}
|
||||
|
||||
Event::fire(new AssignWidget($widget, $widgetArea));
|
||||
|
||||
return redirect()
|
||||
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
|
||||
->with('success', trans('admin/widgets.successfullyAssociated'));
|
||||
@@ -41,6 +50,10 @@ class AssociateWidget extends Controller
|
||||
|
||||
public function deleteAssociation($widgetId, $widgetAreaId)
|
||||
{
|
||||
// check if given values are valid
|
||||
$widget = Widget::findOrFail($widgetId);
|
||||
$widgetArea = WidgetArea::findOrFail($widgetAreaId);
|
||||
|
||||
$widgetInArea = WidgetInWidgetArea::where('widget_id', $widgetId)
|
||||
->where('widget_area_id', $widgetAreaId);
|
||||
|
||||
@@ -52,6 +65,8 @@ class AssociateWidget extends Controller
|
||||
|
||||
$widgetInArea->delete();
|
||||
|
||||
Event::fire(new RemoveWidgetFromArea($widget, $widgetArea));
|
||||
|
||||
return redirect()
|
||||
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
|
||||
->with('success', trans('admin/widgets.successfullyDeassociated'));
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Widgets\Exceptions\MissingParameterException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class CreateNewWidget extends Controller
|
||||
{
|
||||
@@ -65,6 +66,9 @@ class CreateNewWidget extends Controller
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with newly created widget
|
||||
Event::fire(new \App\Events\CreateNewWidget($widget));
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
->route('widgets.new', ['type' => $type])
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\NewWidgetAreaRequest;
|
||||
use App\Models\WidgetArea;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class CreateNewWidgetArea extends Controller
|
||||
{
|
||||
@@ -32,8 +33,10 @@ class CreateNewWidgetArea extends Controller
|
||||
'description' => $request->description
|
||||
];
|
||||
|
||||
WidgetArea::create($parameters);
|
||||
$area = WidgetArea::create($parameters);
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\CreateNewWidgetArea($area));
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Requests\EditWidgetRequest;
|
||||
use App\Models\Widget;
|
||||
use App\Widgets\Exceptions\MissingParameterException;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EditWidget extends Controller
|
||||
{
|
||||
@@ -49,6 +50,9 @@ class EditWidget extends Controller
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with editing widget
|
||||
Event::fire(new \App\Events\EditWidget($widget));
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
->route('widgets.overview')
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Requests;
|
||||
use App\Http\Requests\EditWidgetAreaRequest;
|
||||
use App\Models\WidgetArea;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EditWidgetArea extends Controller
|
||||
{
|
||||
@@ -30,6 +31,9 @@ class EditWidgetArea extends Controller
|
||||
|
||||
$area->save();
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\EditWidgetArea($area));
|
||||
|
||||
return redirect()
|
||||
->route('widgetareas.edit', ['id' => $id])
|
||||
->with('success', trans('admin/widgetAreas.editSuccessfull'));
|
||||
@@ -54,6 +58,9 @@ class EditWidgetArea extends Controller
|
||||
// delete area
|
||||
$area->delete();
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\DeleteWidgetArea($area));
|
||||
|
||||
// redirect and inform user
|
||||
return redirect()
|
||||
->route('widgetareas.overview')
|
||||
|
||||
Reference in New Issue
Block a user