Skip to content

Commit

Permalink
add control managementon edit user screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Jun 25, 2023
1 parent 00561ea commit b709ba6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
10 changes: 8 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\User;
use App\Control;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -104,7 +105,8 @@ public function edit(User $user)
'403 Forbidden'
);

return view('users.edit', compact('user'));
$controls = Control::select("id","clause")->whereNull("realisation_date")->get();
return view('users.edit', compact('user', 'controls'));
}

/**
Expand Down Expand Up @@ -148,10 +150,14 @@ public function update(Request $request, User $user)
if (request('password1') !== null) {
$user->password = bcrypt(request('password1'));
}

// TODO : should not update controls already made
$user->controls()->sync($request->input('controls', []));

$user->update();

if (Auth::User()->role === 1) {
return redirect('/users');
return redirect('/users/' . $user->id);
}
return redirect('/');
}
Expand Down
2 changes: 1 addition & 1 deletion docs/measures.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ L’écran contient :

* La périodicité du contrôles et

* Les responsable de la réalisation du contrôles.
* Les responsables de la réalisation du contrôles.

[<img src="/deming/images/plan.png" width="600">](/deming/images/plan.png)

Expand Down
22 changes: 21 additions & 1 deletion resources/views/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,33 @@
<div class="cell-1">
<label class="label" for="description">{{ trans('cruds.user.fields.password') }}</label>
</div>
<div class="cell-3">
<div class="cell-5">
<input type="password" name="password1"/>
<input type="password" name="password2"/>
</div>
</div>
</div>

<div class="row">
<div class="cell-2">
<strong>{{ trans('cruds.user.fields.controls') }}</strong>
</div>
</div>

<div class="row">
<div class="cell-8">

<select data-role="select" name="controls[]" id="controls" multiple>
@foreach($controls as $control)
<option value="{{ $control->id }}" {{ (in_array($control->id, old('controls', [])) || ($user->controls->contains($control->id))) ? 'selected' : '' }}>{{ $control->clause }}</option>
@endforeach
</select>

</div>
</div>



<div class="row">
<div class="cell-1">
</div>
Expand Down
38 changes: 31 additions & 7 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,39 @@
</div>
<div class="row">
<div class="cell-8">
<table class="table">
<table class="table striped row-hover cell-border"
data-role="table"
data-rows="25"
data-show-activity="true"
data-rownum="false"
data-check="false"
data-check-style="1"
onDraw="alert('change')"
>
<thead>
<tr>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.domain") }}</th>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.measure") }}</th>
<th width="50%">{{ trans("cruds.control.fields.name") }}</th>
<th class="sortable-column sort-asc" width="5%">{{ trans("cruds.control.fields.planned") }}</th>
</tr>
</thead>
<tbody>
@foreach($user->controls as $control)
@if($control->realisation_date==null)
<tr>
<td>
<a href="/measures/{{ $control->measure_id }}">{{ $control->clause }}</a> &nbsp; - &nbsp; {{ $control->name }}
</td>
<td>
<a id="{{ $control->domain->title }}" href="/domains/{{ $control->domain_id}}">
{{ $control->domain->title }}
</a>
</td>
<td>
<a id="{{ $control->clause }}" href="/measures/{{ $control->measure_id }}">
{{ $control->clause }}
</a>
</td>
<td>
{{ $control->name }}
</td>
<td>
<a id="{{ $control->plan_date }}" href="/control/show/{{$control->id}}">
<b>
Expand All @@ -88,8 +114,6 @@
</a>
</td>
</tr>
@endif
</tr>
@endforeach
</table>
</div>
Expand Down

0 comments on commit b709ba6

Please sign in to comment.