Skip to content

Commit

Permalink
work on scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Aug 22, 2023
1 parent ccc475e commit 7a77abe
Show file tree
Hide file tree
Showing 27 changed files with 342 additions and 110 deletions.
21 changes: 12 additions & 9 deletions app/Exports/ControlsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function headings(): array
return [
trans('cruds.control.fields.clause'),
trans('cruds.control.fields.name'),
trans('cruds.control.fields.scope'),
trans('cruds.control.fields.objective'),
trans('cruds.control.fields.attributes'),
trans('cruds.control.fields.model'),
Expand Down Expand Up @@ -48,15 +49,16 @@ public function columnWidths(): array
return [
'A' => 10, // Clause
'B' => 30, // Nom
'C' => 50, // Objectif
'D' => 50, // Attibuts
'E' => 50, // Modele
'F' => 50, // Indicateur
'G' => 15, // Date
'H' => 50, // Observation
'I' => 15, // Score
'J' => 15, // Note
'K' => 50, // Plan d'action
'C' => 20, // Scope
'D' => 50, // Objectif
'E' => 50, // Attibuts
'F' => 50, // Modele
'G' => 50, // Indicateur
'H' => 15, // Date
'I' => 50, // Observation
'J' => 15, // Score
'K' => 15, // Note
'L' => 50, // Plan d'action
];
}

Expand All @@ -69,6 +71,7 @@ public function map($control): array
[
$control->clause,
$control->name,
$control->scope,
$control->objective,
$control->input,
$control->model,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/ActionplanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function index()
c2.action_plan,
c2.score,
c2.name,
c2.scope,
c2.plan_date,
c3.id as next_id,
c3.plan_date as next_date
Expand Down Expand Up @@ -87,6 +88,7 @@ public function show(int $id)
'c1.measure_id',
'c1.clause',
'c1.name',
'c1.scope',
'c1.objective',
'c1.observations',
'c1.action_plan',
Expand Down
108 changes: 95 additions & 13 deletions app/Http/Controllers/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ControlController extends Controller
*/
public function index(Request $request)
{
// get all doains
// get all domains
$domains = Domain::All();

// get all attributes
Expand All @@ -51,6 +51,18 @@ public function index(Request $request)
}
}

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereNull('realisation_date')
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// Domain filter
$domain = $request->get('domain');
if ($domain !== null) {
Expand All @@ -64,6 +76,19 @@ public function index(Request $request)
$domain = $request->session()->get('domain');
}

// Scope filter
$scope = $request->get('scope');
if ($scope !== null) {
if ($scope === 'none') {
$request->session()->forget('scope');
$scope = null;
} else {
$request->session()->put('scope', $scope);
}
} else {
$scope = $request->session()->get('scope');
}

// Attribute filter
$attribute = $request->get('attribute');
if ($attribute !== null) {
Expand Down Expand Up @@ -115,6 +140,11 @@ public function index(Request $request)
$controls = $controls->where('c1.domain_id', '=', $domain);
}

// Filter on scope
if ($scope !== null) {
$controls = $controls->where('c1.scope', '=', $scope);
}

// Filter on period
if (($period !== null) && ($period !== 99)) {
$controls = $controls
Expand Down Expand Up @@ -144,6 +174,7 @@ public function index(Request $request)
'c1.id',
'c1.measure_id',
'c1.name',
'c1.scope',
'c1.clause',
'c1.domain_id',
'c1.plan_date',
Expand All @@ -160,6 +191,7 @@ public function index(Request $request)
return view('controls.index')
->with('controls', $controls)
->with('attributes', $attributes)
->with('scopes', $scopes)
->with('domains', $domains);
}

Expand Down Expand Up @@ -249,6 +281,18 @@ public function edit(int $id)

$documents = DB::table('documents')->where('control_id', $id)->get();

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereNull('realisation_date')
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// get all attributes
$values = [];
$attributes = DB::table('attributes')
Expand All @@ -264,6 +308,7 @@ public function edit(int $id)
return view('controls.edit')
->with('control', $control)
->with('documents', $documents)
->with('scopes', $scopes)
->with('attributes', $values);
}

Expand Down Expand Up @@ -318,21 +363,40 @@ public function history()
->with('controls', $controls);
}

public function domains()
public function domains(Request $request)
{
// get all domains
$domains = DB::table('domains')->get();

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereNull('realisation_date')
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// Scope filter
$scope = $request->get('scope');
if ($scope !== null) {
$request->session()->put('scope', $scope);
} else {
$request->session()->forget('scope');
}

// count control never made
$controls_never_made = DB::select(
'
select domain_id
from controls c1
where realisation_date is null and
not exists (
select *
from controls c2
where realisation_date is not null and c1.measure_id=c2.measure_id);'
'select domain_id
from controls c1
where realisation_date is null and
not exists (
select *
from controls c2
where realisation_date is not null and c1.measure_id=c2.measure_id);'
);

// Last controls made by measures
Expand All @@ -351,8 +415,9 @@ public function domains()
from
controls
where
realisation_date is not null
group by measure_id
realisation_date is not null ' .
($scope !== null ? "and scope=\"{$scope}\"" : '') .
'group by measure_id
) as c1,
controls c2,
domains
Expand All @@ -363,6 +428,7 @@ public function domains()
// return
return view('/radar/domains')
->with('domains', $domains)
->with('scopes', $scopes)
->with('active_controls', $active_controls)
->with('controls_never_made', $controls_never_made);
}
Expand Down Expand Up @@ -477,12 +543,25 @@ public function plan(int $id)

$users = User::orderBy('name')->get();

$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereNull('realisation_date')
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

return view('controls.plan', compact('control'))
->with('years', $years)
->with('day', date('d', strtotime($control->plan_date)))
->with('month', date('m', strtotime($control->plan_date)))
->with('year', date('Y', strtotime($control->plan_date)))
->with('users', $users);
->with('scopes', $scopes)
->with('users', $users)
;
}

/**
Expand All @@ -509,6 +588,7 @@ public function doPlan(Request $request)
return null;
}

$control->scope = $request->scope;
$control->plan_date = $request->plan_date;
$control->periodicity = $request->periodicity;
$control->owners()->sync($request->input('owners', []));
Expand Down Expand Up @@ -637,6 +717,7 @@ public function save(Request $request)
}

$control->name = request('name');
$control->scope = request('scope');
$control->objective = request('objective');
$control->attributes = request('attributes') !== null ? implode(' ', request('attributes')) : null;
$control->input = request('input');
Expand Down Expand Up @@ -701,6 +782,7 @@ public function template()
// Replace names
$templateProcessor->setValue('ref', $control->clause);
$templateProcessor->setValue('name', $control->name);
$templateProcessor->setValue('scope', $control->scope);
$templateProcessor->setValue('attributes', $control->attributes);

$templateProcessor->setValue(
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function index(Request $request)
c1.id,
c1.measure_id,
c1.name,
c1.scope,
c1.clause,
c1.domain_id,
c1.plan_date,
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/MeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,23 @@ public function destroy(Measure $measure)
public function plan(Request $request)
{
$measure = Measure::find($request->id);

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereNull('realisation_date')
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// Get all users
$users = User::orderBy('name')->get();

return view('measures.plan', compact('measure', 'users'));
return view('measures.plan', compact('measure', 'scopes', 'users'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function update(Request $request, User $user)
*
* @return \Illuminate\Http\Response
*/
public function destroy(USer $user)
public function destroy(User $user)
{
abort_if(Auth::User()->role !== 1, Response::HTTP_FORBIDDEN, '403 Forbidden');
$user->delete();
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/2023_08_22_095642_add_scope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table("controls", function(Blueprint $table) {
$table->string("scope", 32);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table("controls", function(Blueprint $table) {
$table->dropColumn("scope");
});
}
};
6 changes: 3 additions & 3 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ plugins:
translate_nav:
fr:
section title: "Section"
subsection: "Souse-section"
subsection: "Sous-section"
page title: "Titre"
en:
section title: "Section"
Expand All @@ -42,9 +42,9 @@ nav:
- Introduction: index.fr.md
- Homepage : home.md
- Page principale : home.fr.md
- Measures : measures.md
- Controls : measures.md
- Mesures : measures.fr.md
- Controls : controls.md
- Measures : controls.md
- Contrôles : controls.fr.md
- Planning : plan.md
- Planning : plan.fr.md
Expand Down
Loading

0 comments on commit 7a77abe

Please sign in to comment.