Skip to content

Commit

Permalink
feat: submission and index
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Oct 10, 2023
1 parent 6d19180 commit fb97ab0
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 20 deletions.
33 changes: 27 additions & 6 deletions app/Http/Controllers/FeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,52 @@
namespace App\Http\Controllers;

use App\Models\Feedback;
use App\Models\Position;
use App\Models\User;
use Illuminate\Http\Request;

class FeedbackController extends Controller
{


/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
$positions = Position::all();
$controllers = User::all();

return view('feedback.create', compact('positions', 'controllers'));
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
$data = $request->validate([
'position' => 'nullable|exists:positions,callsign',
'controller' => 'nullable|exists:users,id',
'feedback' => 'required',
]);

$position = isset($data['position']) ? Position::where('callsign', $data['position'])->get()->first() : null;
$controller = isset($data['controller']) ? User::find($data['controller']) : null;
$feedback = $data['feedback'];

$submitter = auth()->user();

$feedback = Feedback::create([
'feedback' => $feedback,
'submitter_user_id' => $submitter->id,
'reference_user_id' => isset($controller) ? $controller->id : null,
'reference_position_id' => isset($position) ? $position->id : null,
]);

return redirect()->route('dashboard')->with('success', 'Feedback submitted!');

}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace App\Http\Controllers;

use App\Models\Area;
use App\Models\Feedback;
use App\Models\Group;
use App\Models\ManagementReport;
use App\Models\Rating;
use App\Models\Training;
use App\Models\TrainingActivity;
use App\Models\User;
use App\Models\Feedback;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -125,12 +125,13 @@ public function mentors()

/**
* Index received feedback
*
*
* @return \Illuminate\View\View
*/

public function feedback(){
public function feedback()
{
$feedback = Feedback::all();

return view('reports.feedback', compact('feedback'));
}

Expand Down
10 changes: 6 additions & 4 deletions app/Models/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class Feedback extends Model

protected $guarded = [];

public function submitter(){
public function submitter()
{
return $this->belongsTo(User::class, 'submitter_user_id');
}

public function referenceUser(){
public function referenceUser()
{
return $this->belongsTo(User::class, 'reference_user_id');
}

public function referencePosition(){
public function referencePosition()
{
return $this->belongsTo(Position::class, 'reference_position_id');
}

}
6 changes: 4 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ public function getNameAttribute()
return $this->first_name . ' ' . $this->last_name;
}

public function submittedFeedback(){
public function submittedFeedback()
{
return $this->hasMany(Feedback::class, 'submitter_user_id');
}

public function receivedFeedback(){
public function receivedFeedback()
{
return $this->hasMany(Feedback::class, 'reference_user_id');
}

Expand Down
4 changes: 4 additions & 0 deletions database/migrations/2023_10_08_144001_add_feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function up()
$table->unsignedBigInteger('reference_position_id')->nullable();
$table->boolean('forwarded')->default(false);
$table->timestamps();

$table->foreign('submitter_user_id')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE');
$table->foreign('reference_user_id')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE');
$table->foreign('reference_position_id')->references('id')->on('positions')->onUpdate('CASCADE')->onDelete('SET NULL');
});

Schema::table('settings', function (Blueprint $table) {
Expand Down
106 changes: 106 additions & 0 deletions resources/views/feedback/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@extends('layouts.app')

@section('title', 'Feedback')
@section('content')

<div class="row">
<div class="col-xl-6 col-lg-12 col-md-12 mb-12">
<div class="card shadow mb-4">
<div class="card-header bg-primary py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 fw-bold text-white">
Submit Feedback
</h6>
</div>
<div class="card-body">
<form action="{!! action('FeedbackController@store') !!}" method="POST">
@csrf

<div class="row mb-4">
<div class="col-md-4">
<label class="form-label">VATSIM ID</label>
<input class="form-control" type="text" value="{{ Auth::user()->id }}" disabled>
</div>

<div class="col-md-4">
<label class="form-label">Your name</label>
<input class="form-control" type="text" value="{{ Auth::user()->name }}" disabled>
</div>

<div class="col-md-4">
<label class="form-label">Your email</label>
<input class="form-control" type="text" value="{{ Auth::user()->email }}" disabled>
</div>
</div>

<div class="row mb-3">
<div class="col-md-6">
<label class="form-label" for="controllers">Controller</label>
<input
id="controllers"
class="form-control"
type="text"
name="controller"
list="controllersList"
multiple="multiple"
value="{{ old('controller') }}"
>

<datalist id="controllersList">
@foreach($controllers as $controller)
@browser('isFirefox')
<option>{{ $controller->id }}</option>
@else
<option value="{{ $controller->id }}">{{ $controller->name }}</option>
@endbrowser
@endforeach
</datalist>
@error('controller')
<span class="text-danger">{{ $errors->first('controller') }}</span>
@enderror
</div>
<div class="col-md-6">
<label class="form-label" for="positions">Controller's position</label>
<input
id="positions"
class="form-control"
type="text"
name="position"
list="positionsList"
multiple="multiple"
value="{{ old('position') }}"
>

<datalist id="positionsList">
@foreach($positions as $position)
@browser('isFirefox')
<option>{{ $position->callsign }}</option>
@else
<option value="{{ $position->callsign }}">{{ $position->name }}</option>
@endbrowser
@endforeach
</datalist>
@error('position')
<span class="text-danger">{{ $errors->first('position') }}</span>
@enderror
</div>
</div>

<div class="row mb-3">
<div class="col-md-12">
<label class="form-label">Your feedback</label>
<textarea class="form-control" name="feedback" rows="5">{{ old('feedback') }}</textarea>
@error('feedback')
<span class="text-danger">{{ $errors->first('feedback') }}</span>
@enderror
</div>
</div>

<button type="submit" class="btn btn-success">Submit Feedback</button>

</form>
</div>
</div>
</div>
</div>

@endsection
2 changes: 2 additions & 0 deletions resources/views/layouts/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
@can('viewAccessReport', \App\Models\ManagementReport::class)
<a class="collapse-item" href="{{ route('reports.access') }}">Access</a>
@endcan

<a class="collapse-item" href="{{ route('reports.feedback') }}">Feedback</a>

</div>
</div>
Expand Down
18 changes: 14 additions & 4 deletions resources/views/reports/feedback.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@
<tbody>
@foreach($feedback as $f)
<tr>
<td><a href="{{ route('user.show', $f->submitter->name) }}">{{ $f->submitter_user_id }}</a></td>
<td>{{ $f->reference_user_id }}</td>
<td><a href="{{ route('user.show', $f->submitter->name) }}">{{ $f->submitter->name }} ({{ $f->submitter_user_id }})</a></td>
<td>
{{ $f->reference_position_id }}
@isset($f->referenceUser)
<a href="{{ route('user.show', $f->referenceUser) }}">{{ $f->referenceUser->name }} ({{ $f->referenceUser->id }})</a>
@else
N/A
@endisset
</td>
<td>
{{ $f->feedback }}
@isset($f->referencePosition)
{{ $f->referencePosition->callsign }}
@else
N/A
@endisset
</td>
<td>
{!! nl2br($f->feedback) !!}
</td>
</tr>
@endforeach
Expand Down

0 comments on commit fb97ab0

Please sign in to comment.