Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #87 from RedRoundRobin/feature/backendFixes
Browse files Browse the repository at this point in the history
Feature/backend fixes
  • Loading branch information
BroHPotato committed May 9, 2020
2 parents 5b463b0 + 5af856f commit c9c34ce
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/DeviceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function index()
*/
public function show($deviceId)
{
$device = $this->deviceProvider->find($deviceId) ?? [];
$sensors = $this->sensorProvider->findAllFromDevice($device->deviceId) ?? [];
$gateway = $this->gatewayProvider->findAllFromDevice($device->deviceId)[0] ?? [];
$device = $this->deviceProvider->find($deviceId);
$sensors = $this->sensorProvider->findAllFromDevice($device->deviceId);
$gateway = $this->gatewayProvider->findAllFromDevice($device->deviceId)[0];
return view('devices.show', compact(['device', 'sensors', 'gateway']));
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/GatewayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function edit($gateway)
public function store()
{
$data = request()->validate([
'name' => 'required|string'
'name' => 'required|string|regex:/(gw_)([A-Za-z0-9_-]+){1,27}/'
]);
return $this->gatewayProvider->store(json_encode($data)) ?
redirect(route('gateways.index'))->withErrors(['GoodCreate' => 'Gateway creato con successo']) :
Expand All @@ -90,7 +90,7 @@ public function store()
public function update($gatewayId)
{
$data = request()->validate([
'name' => 'required|string'
'name' => 'required|string|regex:/(gw_)([A-Za-z0-9_-]+){1,27}/'
]);
return $this->gatewayProvider->update($gatewayId, json_encode($data)) ?
redirect(route('gateways.index'))->withErrors(['GoodUpdate' => 'Gateway aggiornato con successo']) :
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public function destroy($userId)
public function restore($userId)
{
$user = $this->provider->retrieveById($userId);
return $this->provider->update($user->getAuthIdentifier(), '{"deleted":false}') ?
$data['deleted'] = false;
return $this->provider->update($user->getAuthIdentifier(), $data) ?
redirect(route('users.index'))->withErrors(['GoodRestore' => 'Utente ripristinato con successo']) :
redirect(route('users.index'))->withErrors(['NotRestore' => 'Utente non ripristinato']);
}
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/BasicProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ protected function isExpired(RequestException $e)
session()->invalidate();
session()->flush();
return redirect(route('login'));
} elseif ($e->getCode() != 401 || $e->getCode() == 0) {
($e->getCode()) ? abort($e->getCode()) : abort(409);
}
}

Expand Down
41 changes: 21 additions & 20 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,33 @@
@method('PUT')
</form>
@endcan
@endif
@if($user->deleted)
<!-- TODO - non previsto dal AdR, ma se c'è anche nelle API manteniamolo e lo aggiungiamo a mano -->
<a class="btn btn-success btn-icon-split" href="{{ route('users.restore', ['userId' => $user->userId ]) }}"
onclick="event.preventDefault(); document.getElementById('restore-form-{{$user->userId}}').submit();">
@if($user->deleted )
<a class="btn btn-success btn-icon-split" href="{{ route('users.restore', ['userId' => $user->userId ]) }}"
onclick="event.preventDefault(); document.getElementById('restore-form-{{$user->userId}}').submit();">
<span class="icon text-white-50">
<span class="fas fa-user-check"></span>
</span>
<span class="text">Ripristina</span>
</a>
<form id="restore-form-{{$user->userId}}" action="{{ route('users.restore', ['userId' => $user->userId ]) }}" method="POST" style="display: none;">
@csrf
@method('PUT')
</form>
@else
<a class="btn btn-danger btn-icon-split" href="{{ route('users.destroy', ['userId' => $user->userId ]) }}"
onclick="event.preventDefault(); document.getElementById('delete-form-{{$user->userId}}').submit();">
<span class="text">Ripristina</span>
</a>
<form id="restore-form-{{$user->userId}}" action="{{ route('users.restore', ['userId' => $user->userId ]) }}" method="POST" style="display: none;">
@csrf
@method('PUT')
</form>
@else
<a class="btn btn-danger btn-icon-split" href="{{ route('users.destroy', ['userId' => $user->userId ]) }}"
onclick="event.preventDefault(); document.getElementById('delete-form-{{$user->userId}}').submit();">
<span class="icon text-white-50">
<span class="fas fa-user-times"></span>
</span>
<span class="text">Disattiva utente</span>
</a>
<form id="delete-form-{{$user->userId}}" action="{{ route('users.destroy', ['userId' => $user->userId ]) }}" method="POST" style="display: none;">
@csrf
@method('DELETE')
</form>
<span class="text">Disattiva utente</span>
</a>
<form id="delete-form-{{$user->userId}}" action="{{ route('users.destroy', ['userId' => $user->userId ]) }}" method="POST" style="display: none;">
@csrf
@method('DELETE')
</form>
@endif
@else
Non ci sono opzioni disponibili
@endif
</div>
</div>
Expand Down

0 comments on commit c9c34ce

Please sign in to comment.