Skip to content

Commit

Permalink
add optional action plan
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Nov 10, 2024
1 parent 33a6e48 commit e14c7e3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
37 changes: 34 additions & 3 deletions app/Http/Controllers/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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'));
}
Expand Down
37 changes: 34 additions & 3 deletions resources/views/controls/make.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
@extends("layout")

@section("style")
<style>
.disabled-editor {
background-color: #f0f0f0; /* Couleur de fond pour l'état désactivé */
}
.CodeMirror {
height: auto;
}
</style>
@endsection
@section("content")

<div class="p-3">
<div data-role="panel" data-title-caption="{{ trans('cruds.control.make') }}" data-collapsible="true" data-title-icon="<span class='mif-chart-line'></span>">

Expand Down Expand Up @@ -162,6 +172,14 @@
</div>
</div>
@if ((Auth::User()->role === 1)||(Auth::User()->role === 2))
<div class="row">
<div class="cell-1">
</div>
<div class="cell-3">
<input type="checkbox" name="add_action_plan" data-role="checkbox" id="toggleTextarea"/>
Create an action plan
</div>
</div>
<div class="row">
<div class="cell-1">
<strong>{{ trans('cruds.control.fields.action_plan') }}</strong>
Expand Down Expand Up @@ -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
</script>

Expand Down
1 change: 1 addition & 0 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<script src="/js/all.js"></script>
<script src="/js/easymde.min.js"></script>
@yield('style')

</head>

Expand Down

0 comments on commit e14c7e3

Please sign in to comment.