Skip to content

Commit

Permalink
Assessments Controller and views
Browse files Browse the repository at this point in the history
  • Loading branch information
zalsader committed Sep 16, 2015
1 parent e7481ec commit bfb5305
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
55 changes: 55 additions & 0 deletions app/Http/Controllers/AssessmentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Assessment;
use App\Question;
use App\Submission;

class AssessmentController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index($questionId, $submissionId)
{
$question = Question::findOrFail($questionId);
$this->authorize('grade', $question);
$submission = Submission::findOrFail($submissionId);
$assessments = $submission->assessments;
return view('assessments.index')->with(compact(['question', 'submission', 'assessments']));
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function assess(Request $request, $questionId, $submissionId)
{
if ($request->ajax()) {
$question = Question::find($questionId); // TODO
$this->authorize('grade', $question);
if (empty($question)) {
retrun \Response::json(['error' => 'true', 'message' => 'Question Not found']);
}
$submission = Submission::findOrFail($id);
$assessment = new Assessment($request->all());
$assessment->submission_id = $submission->id;
$assessment->grader_id = $request->user()->id;
$assessment->updateFinalGrade();
$submission->updateScore();
$submission->user->updateTotalScore();
return \Response::json(['success' => 'true']);
} else {
return redirect()->home();
}
}
}
4 changes: 4 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
$r->get('submissions/', ['as' => 'index', 'uses' => 'SubmissionController@index']);
$r->get('submissions/{id}', ['as' => 'show', 'uses' => 'SubmissionController@show']);
});
Route::group(['as' => 'Assessment::', 'prefix' => 'question/{questionId}/submissions/{submissionId}'], function($r){
$r->post('assess', ['as' => 'assess', 'uses' => 'AssessmentController@assess']);
$r->get('assessments/', ['as' => 'index', 'uses' => 'AssessmentController@index']);
});
$router->get('question/{questionId}/hint', 'QuestionController@hint');
$router->resource('question','QuestionController');
});
48 changes: 48 additions & 0 deletions resources/views/assessments/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@extends('app')

@section('content')
<div class="container">
<div class="row">
<div class="col-md-2">
<a class="btn btn-default" href="{{route('Submission::show', ['questionId' => $question->id, 'id' => $submission->id])}}">&#8592; Back to submission</a>
</div>
</div>
<div class="row">
<div class="col-md-10" >
<div class="">
<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>
@if(!empty($assessments))
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th width="30%">Grader</th>
<th width="20%">Grade</th>
<th width="20%">Score</th>
<th width="30%">Assessed at</th>
</tr>
</thead>
<tbody>
@foreach($assessments as $assessment)
<tr>
<td>{{$assessment->grader->name}}</td>
<td>{{round($assessment->grade,5)*100.0}}%</td>
<td>{{round($assessment->final_grade,3)}}</td>
<td>{{\Carbon\Carbon::parse($assessment->created_at)->toDayDateTimeString()}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
No Assessments
@endif
<hr>
</div>
</div>
</div>
</div>
@stop
25 changes: 24 additions & 1 deletion resources/views/submissions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@
</div>
</div>
</div>
<!-- TODO diff & assess -->
<div class="row">
<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>
</form>
</div>
</div>
<!-- TODO diff -->
</div>

<iframe class="game" src="{{url('/game/apps/turtle/index.html')}}" width="95%" height="655" sandbox="allow-same-origin allow-scripts"></iframe>
Expand All @@ -57,5 +66,19 @@
var BlocklyApps = this.contentWindow.BlocklyApps;
BlocklyApps.loadBlocks(defaultXml);
})
$('#assessmentForm').submit(function(event){
event.preventDefault();
$.ajax({
data: {
grade: $(this).find('input#grade').val()*100.0
},
type: 'POST',
url: "{{route(Assessment::assess, ['questionId' => $question->id, 'submissionId' => $submission->id])}}",
success: function(response) {
$('#successfulSubmission').removeClass('hidden');
window.scrollTo(0, 0);
}
});
})
</script>
@stop

0 comments on commit bfb5305

Please sign in to comment.