Skip to content

Commit

Permalink
Merge pull request #220 from dbarzin/dev
Browse files Browse the repository at this point in the history
Work on actions
  • Loading branch information
dbarzin authored Nov 10, 2024
2 parents fb376af + 835985b commit 50c15a4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 11 deletions.
25 changes: 25 additions & 0 deletions app/Http/Controllers/ActionplanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
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
17 changes: 12 additions & 5 deletions resources/views/actions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,26 @@
{{ trans('common.save') }}
</button>
&nbsp;
<a class="button primary" href="/action/close/{{ $action->id }}">
<a class="button info" href="/action/close/{{ $action->id }}">
<span class="mif-done"></span>
&nbsp;
{{ trans("common.close") }}
</a>
&nbsp;
@endif
<a class="button alert" href="/action/edit/{{ $action->id }}">
<span class="mif-wrench"></span>
&nbsp;
{{ trans("common.edit") }}
<a class="button primary" href="/action/edit/{{ $action->id }}">
<span class="mif-wrench"></span>
&nbsp;
{{ trans('common.edit') }}
</a>
&nbsp;
<button class="button alert" type="submit" onclick='this.form.action="/action/delete"'
onSubmit="if(!confirm('{{ trans('common.confirm') }}')){return false;}">
<span class="mif-fire"></span>
&nbsp;
{{ trans('common.delete') }}
</button>
&nbsp;
<a class="button dafault" href="/actions">
<span class="mif-cancel"></span>
&nbsp;
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
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 50c15a4

Please sign in to comment.