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 23, 2023
1 parent 4025c8c commit 0204a46
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 57 deletions.
6 changes: 2 additions & 4 deletions app/Http/Controllers/ActionplanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function index()
}

/**
* Save a Action plan
* Save an action plan
*
* @param \App\Domain $domain
*
Expand Down Expand Up @@ -89,9 +89,7 @@ public function show(int $id)
'c2.id as next_id'
)
->leftJoin('controls as c2', function ($join) {
$join->on('c1.id', '<>', 'c2.id');
$join->on('c1.measure_id', '=', 'c2.measure_id');
$join->whereNull('c2.realisation_date');
$join->on('c1.next_id', '=', 'c2.id');
})
->where('c1.id', '=', $id)
->first();
Expand Down
82 changes: 40 additions & 42 deletions app/Http/Controllers/MeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public function index(Request $request)
'measures.domain_id',
'measures.clause',
'measures.name',
'controls.id as control_id',
'controls.scope',
'controls.plan_date',
DB::raw('count(controls.id) as control_count'),
'domains.title',
]
)
->leftjoin('domains', 'measures.domain_id', '=', 'domains.id')
->join('controls', function (JoinClause $join) {
$join->on('measures.id', '=', 'controls.measure_id')
->whereNull('controls.realisation_date');
}, null, null, 'left outer');
}, null, null, 'left outer')
->groupBy('measures.id');
;

if ($domain !== null) {
$measures->where('measures.domain_id', $domain);
Expand Down Expand Up @@ -315,45 +315,43 @@ public function activate(Request $request)
->where('realisation_date', null)
->first();

if ($control === null) {
// create a new control
$control = new Control();
$control->measure_id = $measure->id;
$control->domain_id = $measure->domain_id;
$control->name = $measure->name;
$control->scope = $request->scope;
$control->attributes = $measure->attributes;
$control->clause = $measure->clause;
$control->objective = $measure->objective;
$control->input = $measure->input;
$control->model = $measure->model;
$control->indicator = $measure->indicator;
$control->action_plan = $measure->action_plan;
$control->periodicity = $request->get('periodicity');
$control->plan_date = $request->get('plan_date');
// Save it
$control->save();

// Sync onwers
$control->owners()->sync($request->input('owners', []));

// Update link
$prev_control = Control::where('measure_id', '=', $measure->id)
->where('next_id', null)
->whereNotNull('realisation_date')
->orderBy('id', 'desc')
->first();
if ($prev_control !== null) {
$prev_control->next_id = $control->id;
$prev_control->update();
if ($control !== null) {
// control already exixts
return back()
->withErrors(['msg' => 'A control already exists for that scope'])
->withInput();
}
} else {
// just update the date
$control = Control::find($control->id);
$control->periodicity = $request->get('periodicity');
$control->owners()->sync($request->input('owners', []));
$control->plan_date = $request->get('plan_date');
$control->save();

// create a new control
$control = new Control();
$control->measure_id = $measure->id;
$control->domain_id = $measure->domain_id;
$control->name = $measure->name;
$control->scope = $request->scope;
$control->attributes = $measure->attributes;
$control->clause = $measure->clause;
$control->objective = $measure->objective;
$control->input = $measure->input;
$control->model = $measure->model;
$control->indicator = $measure->indicator;
$control->action_plan = $measure->action_plan;
$control->periodicity = $request->get('periodicity');
$control->plan_date = $request->get('plan_date');
// Save it
$control->save();

// Sync onwers
$control->owners()->sync($request->input('owners', []));

// Update link
$prev_control = Control::where('measure_id', '=', $measure->id)
->where('scope','=',$measure->scope)
->where('next_id', null)
->whereNotNull('realisation_date')
->first();
if ($prev_control !== null) {
$prev_control->next_id = $control->id;
$prev_control->update();
}

// return to the list of measures
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/2023_08_22_095642_add_scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::table("controls", function(Blueprint $table) {
$table->string("scope", 32);
$table->string("scope", 32)->nullable();
});
}

Expand Down
14 changes: 4 additions & 10 deletions resources/views/measures/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
<tr>
<th class="sortable-column sort-asc" width="10%">{{ trans('cruds.measure.fields.domain') }}</th>
<th class="sortable-column sort-asc" width="10%">{{ trans('cruds.measure.fields.clause') }}</th>
<th class="sortable-column sort-asc" width="70%">{{ trans('cruds.measure.fields.name') }}</th>
<th class="sortable-column sort-asc" width="70%">{{ trans('cruds.control.fields.scope') }}</th>
<th width="10% class="sortable-column sort-asc" width="70%">{{ trans('cruds.control.fields.plan_date') }}</th>
<th></th>
<th class="sortable-column sort-asc" width="60%">{{ trans('cruds.measure.fields.name') }}</th>
<th class="sortable-column sort-asc" data-cls-column="text-center" width="10%"># {{ trans('cruds.control.title') }}</th>
<th width="10%"></th>
</tr>
</thead>
<tbody>
Expand All @@ -75,12 +74,7 @@
</a>
</td>
<td>{{ $measure->name }}</td>
<td>{{ $measure->scope }}</td>
<td>
@if ($measure->plan_date!==null)
<a href="/control/plan/{{ $measure->control_id }}">{{ $measure->plan_date }}</a>
@endif
</td>
<td>{{ $measure->control_count }}</td>
<td>
<form action="/measure/plan/{{ $measure->id }}">
<button class="button info">
Expand Down
13 changes: 13 additions & 0 deletions resources/views/measures/plan.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
@section("content")
<div class="p-3">
<div data-role="panel" data-title-caption="{{ trans('cruds.measure.plan') }}" data-collapsible="true" data-title-icon="<span class='mif-chart-line'></span>">

@if (count($errors))
<div class="grid">
<div class="cell-3 bg-red fg-white">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
@endif

<form method="POST" action="/measure/activate/{{ $measure->id }}">
@csrf
<div class="grid">
Expand Down

0 comments on commit 0204a46

Please sign in to comment.