From 8703d5279f713beb4c90ab4799af7af7213233c5 Mon Sep 17 00:00:00 2001 From: Didier Date: Thu, 24 Aug 2023 10:52:46 +0200 Subject: [PATCH] impove report with scope --- app/Http/Controllers/ControlController.php | 52 ++++++++++++++-------- resources/lang/en/common.php | 2 + resources/lang/fr/common.php | 2 + resources/views/controls/plan.blade.php | 2 +- resources/views/radar/controls.blade.php | 47 ++++++++++++++----- resources/views/radar/domains.blade.php | 1 - routes/web.php | 3 -- 7 files changed, 75 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/ControlController.php b/app/Http/Controllers/ControlController.php index ac872ab2..b0812735 100644 --- a/app/Http/Controllers/ControlController.php +++ b/app/Http/Controllers/ControlController.php @@ -377,8 +377,6 @@ public function domains(Request $request) // get all scopes $scopes = DB::table('controls') ->select('scope') - ->whereNotNull('scope') - ->where('scope', '<>', '') ->whereNull('realisation_date') ->distinct() ->orderBy('scope') @@ -444,6 +442,22 @@ public function measures(Request $request) // Get all domains $domains = Domain::All(); + // get all scopes + $scopes = DB::table('controls') + ->select('scope') + ->whereNull('realisation_date') + ->distinct() + ->orderBy('scope') + ->get() + ->pluck('scope') + ->toArray(); + + $cur_scope = $request->get("scope"); + if ($cur_scope !== null) + $request->session()->put('scope', $cur_scope); + else + $request->session()->forget('scope'); + $cur_date = $request->get('cur_date'); if ($cur_date === null) { $cur_date = today()->format('Y-m-d'); @@ -457,28 +471,32 @@ public function measures(Request $request) ->select( DB::raw( ' - max(c1.id) AS control_id, - max(c1.name) AS name, - c1.clause AS clause, - c1.measure_id AS measure_id, - max(c1.domain_id) AS domain_id, - max(c1.plan_date) AS plan_date, - max(c1.realisation_date) AS realisation_date, - max(c1.score) AS score, - max(c2.plan_date) AS next_date, - max(c2.id) AS next_id' + c1.id AS control_id, + c1.name, + c1.clause, + c1.scope, + c1.measure_id, + c1.domain_id, + c1.plan_date, + c1.realisation_date, + c1.score AS score, + c2.plan_date AS next_date, + c2.id AS next_id' ) ) ->leftjoin('controls as c2', 'c1.next_id', '=', 'c2.id') - ->where('c2.realisation_date', '=', null) - ->where('c1.next_id', '<>', null) + ->where('c2.realisation_date', '=', null); + if ($cur_scope !=null) + $controls = $controls->where('c1.scope','=',$cur_scope); + $controls = $controls ->where('c1.realisation_date', '<=', $cur_date) - ->groupBy('c1.measure_id', 'c1.clause') - ->orderBy('c1.clause') + ->orderBy('clause') + ->orderBy('scope') ->get(); // return return view('radar.controls') + ->with('scopes', $scopes) ->with('controls', $controls) ->with('cur_date', $cur_date) ->with('domains', $domains); @@ -551,8 +569,6 @@ public function plan(int $id) $scopes = DB::table('controls') ->select('scope') - ->whereNotNull('scope') - ->where('scope', '<>', '') ->whereNull('realisation_date') ->distinct() ->orderBy('scope') diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php index b8e84da1..a3c077dc 100644 --- a/resources/lang/en/common.php +++ b/resources/lang/en/common.php @@ -32,6 +32,8 @@ 'success' => 'Success', 'unknown' => 'Unknown', + 'date' => 'Date', + 'never' => 'Never', 'day' => 'Daily', 'week' => 'Weekly', diff --git a/resources/lang/fr/common.php b/resources/lang/fr/common.php index e14c8041..29fdbd8c 100644 --- a/resources/lang/fr/common.php +++ b/resources/lang/fr/common.php @@ -31,6 +31,8 @@ 'success' => 'Réussi', 'unknown' => 'Inconnu', + 'date' => 'Date', + 'never' => 'Jamais', 'day' => 'Journalièrement', 'week' => 'Hebdomadairement', diff --git a/resources/views/controls/plan.blade.php b/resources/views/controls/plan.blade.php index 3049a398..88044c63 100644 --- a/resources/views/controls/plan.blade.php +++ b/resources/views/controls/plan.blade.php @@ -45,7 +45,7 @@
+ value="{{ $control->scope }}" data-autocomplete="{{ implode(",",$scopes) }}"/>
diff --git a/resources/views/radar/controls.blade.php b/resources/views/radar/controls.blade.php index 749d8b7e..35ea7192 100644 --- a/resources/views/radar/controls.blade.php +++ b/resources/views/radar/controls.blade.php @@ -8,15 +8,25 @@
- @foreach($domains as $domain) -
-
- {{ $domain->title }} - {{ $domain->description }} -
- - @if ($loop->first) -
-
+ +
+
+
+
+ {{ trans("cruds.control.fields.scope") }} + +
+
+ {{ trans("common.date") }} - +
- @endif + + + @foreach($domains as $domain) +
+
+ {{ $domain->title }} - {{ $domain->description }} +
@@ -41,6 +57,7 @@ {{ trans("cruds.control.fields.note") }}
#
{{ trans("cruds.control.fields.name") }} + {{ trans("cruds.control.fields.scope") }} {{ trans("cruds.control.fields.realisation_date") }} {{ trans("cruds.control.fields.next") }} @@ -63,6 +80,7 @@ {{ $control->clause }} {{ $control->name }} + {{ $control->scope }} {{ $control->realisation_date }} {{ $control->next_date }} @@ -185,6 +203,13 @@ }); @endforeach + window.addEventListener('load', function(){ + var select = document.getElementById('scope'); + select.addEventListener('change', function(){ + window.location = '/control/radar/measures?scope=' + this.value; + }, false); + }); + @endsection diff --git a/resources/views/radar/domains.blade.php b/resources/views/radar/domains.blade.php index 43bdcbfb..0da0df47 100644 --- a/resources/views/radar/domains.blade.php +++ b/resources/views/radar/domains.blade.php @@ -13,7 +13,6 @@
{{ trans("cruds.control.fields.scope") }}