Skip to content

Commit

Permalink
Fixed Assessment form
Browse files Browse the repository at this point in the history
  • Loading branch information
zalsader committed Sep 16, 2015
1 parent bfb5305 commit e7b4672
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
7 changes: 5 additions & 2 deletions app/Http/Controllers/AssessmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public function assess(Request $request, $questionId, $submissionId)
{
if ($request->ajax()) {
$question = Question::find($questionId); // TODO
$this->authorize('grade', $question);

if ($request->user()->cannot('grade', $question)) {
retrun \Response::json(['error' => 'true', 'message' => 'Question Not found']);
}
if (empty($question)) {
retrun \Response::json(['error' => 'true', 'message' => 'Question Not found']);
}
$submission = Submission::findOrFail($id);
$submission = Submission::findOrFail($submissionId);
$assessment = new Assessment($request->all());
$assessment->submission_id = $submission->id;
$assessment->grader_id = $request->user()->id;
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Controllers\Controller;
use App\Submission;
use App\Question ;
use App\Assessment;

class SubmissionController extends Controller
{
Expand Down Expand Up @@ -61,7 +62,9 @@ public function show($questionId, $id)
{
$question = Question::findOrFail($questionId);
$this->authorize('grade', $question);
$submission = Submission::findOrFail($id);
return view('submissions.show')->with(compact(['question', 'submission']));
$submission = $question->submissions()->findOrFail($id);
$prevId = $question->submissions()->where('created_at', '<', $submission->created_at)->max('id');
$nextId = $question->submissions()->where('created_at', '>', $submission->created_at)->min('id');
return view('submissions.show')->with(compact(['question', 'submission', 'nextId', 'prevId']));
}
}
4 changes: 2 additions & 2 deletions resources/views/assessments/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1>Assessments for Submission.</h1>
<h3>submitted by user {{$submission->user->name}}, {{$submission->user->email}}</h3>
<h3>Question #{{$question->id}}: {{ $question->name }}</h3>
<p>Final Submission Grade {{$submission->score}}</p>
<p>Final Submission Grade {{round($submission->score, 5)}}</p>
@if(!empty($assessments))
<div class="table-responsive">
<table class="table table-hover">
Expand All @@ -30,7 +30,7 @@
<tr>
<td>{{$assessment->grader->name}}</td>
<td>{{round($assessment->grade,5)*100.0}}%</td>
<td>{{round($assessment->final_grade,3)}}</td>
<td>{{round($assessment->final_grade,5)}}</td>
<td>{{\Carbon\Carbon::parse($assessment->created_at)->toDayDateTimeString()}}</td>
</tr>
@endforeach
Expand Down
8 changes: 5 additions & 3 deletions resources/views/submissions/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10" >
<div class="col-md-12" >
<div class="">
<h1>Submissions for Question #{{$question->id}}: {{ $question->name }}</h1>
<div class="table-responsive">
Expand All @@ -12,9 +12,10 @@
<tr>
<th width="20%">User</th>
<th width="20%">Email</th>
<th width="20%">Score</th>
<th width="10%">Score</th>
<th width="30%">Last Assessed</th>
<th width="10%">View<th>
<th width="10%">View</th>
<th width="10%">Assessments</th>
</tr>
</thead>
<tbody>
Expand All @@ -31,6 +32,7 @@
<td> Never </td>
@endif
<td><a class="btn btn-danger" href="{{route('Submission::show', ['questionId' => $question->id, 'id' => $submission->id])}}">View Submission<a></td>
<td><a class="btn btn-danger" href="{{route('Assessment::index', ['questionId' => $question->id, 'submissionId' => $submission->id])}}">View Assessments<a></td>
</tr>
@endforeach
</tbody>
Expand Down
25 changes: 21 additions & 4 deletions resources/views/submissions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
<div class="col-md-2">
<a class="btn btn-default" href="{{route('Submission::index', ['questionId' => $question->id])}}">&#8592; Back to submissions</a>
</div>
<div class="col-md-3 pull-right btn-group">
@if(!empty($prevId))
<a class="btn btn-default" href="{{route('Submission::show', ['questionId' => $question->id, 'id' => $prevId])}}">&#8592; Previous</a>
@endif
@if(!empty($nextId))
<a class="btn btn-default" href="{{route('Submission::show', ['questionId' => $question->id, 'id' => $nextId])}}">Next &#8594;</a>
@endif
</div>

</div>
<div class="row">
<div class="col-md-6" >
Expand Down Expand Up @@ -42,8 +51,9 @@
<div class="col-md-6">
<form id="assessmentForm" method="post" action="">
<label for="grade">Grade:</label>
<input type="range" name="grade" id="grade" value="50" min="0" max="100">
<button type="submit">Submit</button>
<input type="range" name="grade" id="grade" class="grade" value="50" min="0" max="100">
<input type="text" class="grade form-control col-md-2" value="50">
<button type="submit" class="btn btn-danger">Submit</button>
</form>
</div>
</div>
Expand All @@ -61,6 +71,13 @@
$('.measure').each(function(){
createMeasurement(this);
});
$('.grade').change(function(){
var value = $(this).val();
value = value > 100 ? 100 : (value<0? 0: value);
$('.grade').each(function(){
$(this).val(value);
});
});
});
$('.game').on('load', function(){
var BlocklyApps = this.contentWindow.BlocklyApps;
Expand All @@ -70,10 +87,10 @@
event.preventDefault();
$.ajax({
data: {
grade: $(this).find('input#grade').val()*100.0
grade: $(this).find('input#grade').val()/100.0
},
type: 'POST',
url: "{{route(Assessment::assess, ['questionId' => $question->id, 'submissionId' => $submission->id])}}",
url: "{{route('Assessment::assess', ['questionId' => $question->id, 'submissionId' => $submission->id])}}",
success: function(response) {
$('#successfulSubmission').removeClass('hidden');
window.scrollTo(0, 0);
Expand Down

0 comments on commit e7b4672

Please sign in to comment.