diff --git a/app/Http/Controllers/ActionplanController.php b/app/Http/Controllers/ActionplanController.php index 7c04293..7318581 100644 --- a/app/Http/Controllers/ActionplanController.php +++ b/app/Http/Controllers/ActionplanController.php @@ -489,4 +489,29 @@ public function export() ); } + public function delete() { + // For administrators and users only + abort_if( + Auth::User()->role !== 1 && Auth::User()->rol !== 2, + Response::HTTP_FORBIDDEN, + '403 Forbidden' + ); + + // Get the action plan + $id = (int)request('id'); + $action = Action::find($id); + + // Action not found + abort_if($action === null, Response::HTTP_NOT_FOUND, '404 Not Found'); + + // delete links + DB::table('action_measure')->where('action_id', $action->id)->delete(); + + // delete + $action->delete(); + + // Return + return redirect('/actions'); + } + } diff --git a/app/Http/Controllers/ControlController.php b/app/Http/Controllers/ControlController.php index 9f68604..1d80107 100644 --- a/app/Http/Controllers/ControlController.php +++ b/app/Http/Controllers/ControlController.php @@ -7,6 +7,8 @@ use App\Models\Document; use App\Models\Domain; use App\Models\User; +use App\Models\Action; + use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -1242,13 +1244,13 @@ public function make(Request $request) } /** - * Do a Control + * Make a Control * - * @param \App\Domain $domain + * @param Request $request * * @return \Illuminate\Http\Response */ - public function doMake() + public function doMake(Request $request) { // Only for admin, user and auditee abort_if( @@ -1295,10 +1297,39 @@ public function doMake() $control->note = request('note'); $control->score = request('score'); $control->realisation_date = request('realisation_date'); + // only admin and user can update the plan_date and action_plan if (Auth::User()->role === 1 || Auth::User()->role === 2) { $control->plan_date = request('plan_date'); $control->action_plan = request('action_plan'); + + // Create an action plan ? + if ($request->has('add_action_plan')) { + $action = new Action(); + $action->name = $control->name; + $action->scope = $control->scope; + $action->status = 0; + $action->cause = $control->observations; + $action->remediation = $control->action_plan; + $action->due_date = request('next_date'); + $action->control_id = $control->id; + $action->save(); + + // Sync measures + $measures = DB::table('control_measure') + ->select('measure_id') + ->where('control_id',$control->id) + ->pluck('measure_id')->toArray(); + $action->measures()->sync($measures); + + // Sync owners + $owners = DB::table('control_user') + ->select('user_id') + ->where('control_id',$control->id) + ->pluck('user_id')->toArray(); + $action->owners()->sync($owners); + + } } else { $control->realisation_date = date('Y-m-d', strtotime('today')); } diff --git a/resources/views/actions/show.blade.php b/resources/views/actions/show.blade.php index 40e7608..2258896 100644 --- a/resources/views/actions/show.blade.php +++ b/resources/views/actions/show.blade.php @@ -172,19 +172,26 @@ {{ trans('common.save') }}   - +   {{ trans("common.close") }}   @endif - - -   - {{ trans("common.edit") }} + + +   + {{ trans('common.edit') }}   + +     diff --git a/resources/views/controls/make.blade.php b/resources/views/controls/make.blade.php index c2be1f0..7a7b44a 100644 --- a/resources/views/controls/make.blade.php +++ b/resources/views/controls/make.blade.php @@ -1,6 +1,16 @@ @extends("layout") - +@section("style") + + @endsection @section("content") +
@@ -162,6 +172,14 @@
@if ((Auth::User()->role === 1)||(Auth::User()->role === 2)) +
+
+
+
+ + Create an action plan +
+
{{ trans('cruds.control.fields.action_plan') }} @@ -334,20 +352,33 @@ items.forEach((item) => { console.log(item.kind); if (item.kind === 'file') { - // adds the file to your dropzone instance myDropzone.addFile(item.getAsFile()) } }) } @if ((Auth::User()->role === 1)||(Auth::User()->role === 2)) - const mde1 = new EasyMDE({ + const easyMDE = new EasyMDE({ element: document.getElementById('mde1'), minHeight: "200px", maxHeight: "200px", status: false, spellChecker: false, }); + + // Rendre l'éditeur en lecture seule par défaut + easyMDE.codemirror.setOption("readOnly", true); + easyMDE.codemirror.getWrapperElement().classList.add('disabled-editor'); + + document.getElementById('toggleTextarea').addEventListener('change', function() { + if (this.checked) { + easyMDE.codemirror.setOption("readOnly", false); + easyMDE.codemirror.getWrapperElement().classList.remove('disabled-editor'); + } else { + easyMDE.codemirror.setOption("readOnly", true); + easyMDE.codemirror.getWrapperElement().classList.add('disabled-editor'); + } + }); @endif diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index d549758..e0c3c7c 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -11,6 +11,7 @@ + @yield('style') diff --git a/routes/web.php b/routes/web.php index bd4a7d1..fd182a7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -108,6 +108,7 @@ Route::post('/action/update', 'ActionplanController@update'); Route::post('/action/save', 'ActionplanController@save'); Route::post('/action/close', 'ActionplanController@doClose'); + Route::post('/action/delete', 'ActionplanController@delete'); /* Reports */ Route::get('/reports', 'ReportController@show');