Skip to content

Commit

Permalink
Added Measurement.js
Browse files Browse the repository at this point in the history
Some layout changes
  • Loading branch information
zalsader committed Sep 12, 2015
1 parent ab29328 commit e6c9bbf
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function index($questionId)
public function submit(Request $request, $questionId)
{
if ($request->ajax()) {
$question = Question::find($questionId);
$question = Question::find($questionId); // TODO
if (empty($question)) {
retrun \Response::json(['error' => 'true', 'message' => 'Question Not found']);
}
Expand Down
60 changes: 60 additions & 0 deletions public/js/measurement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

function createMeasurement(canv){
var ctx = canv.getContext("2d");
canv.onclick = click;
var xpoints = [];
var ypoints = [];
function click(e){
ctx.clearRect(0,0,400,400);
var rect = canv.getBoundingClientRect();
xpoints.push((e.clientX - rect.left));
ypoints.push((e.clientY - rect.top));
switch(xpoints.length){
case 3:
drawAngle(xpoints[0], ypoints[0], xpoints[1], ypoints[1], xpoints[2], ypoints[2]);
drawLine(xpoints[1], ypoints[1], xpoints[2], ypoints[2]);
drawPoint(xpoints[2], ypoints[2]);
case 2:
drawLine(xpoints[0], ypoints[0], xpoints[1], ypoints[1]);
drawPoint(xpoints[1], ypoints[1]);
case 1:
drawPoint(xpoints[0], ypoints[0]);
break;
default:
xpoints = [];
ypoints = [];
}
}

function drawLine(startX, startY, toX, toY){
ctx.strokeStyle = '#00f';
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(toX,toY);
ctx.stroke();
ctx.fillStyle = '#00f';
ctx.fillText(""+Math.floor(Math.sqrt(Math.pow(startX - toX, 2) + Math.pow(startY - toY,2))), (startX + toX)/2+5, (startY + toY)/2+5);

}

function drawPoint(xp, yp){
ctx.fillStyle = '#f00';
ctx.beginPath();
ctx.arc(xp, yp, 3, 0, 2*Math.PI);
ctx.fill();
ctx.fillText("("+Math.floor(xp-200)+","+Math.floor(-yp+200)+")", xp+5, yp-5);
}

function drawAngle(x0, y0, x1, y1, x2, y2){
var stangle = Math.atan2(x1-x0, y1-y0);
var endangle = Math.atan2(x1-x2, y1 - y2);
var angle = Math.floor((Math.abs(stangle - endangle)*180/Math.PI));
angle = angle>180?360-angle:angle;
// ctx.strokeStyle = '#f08';
// ctx.beginPath();
// ctx.arc(x1, y1, 10, -stangle, -endangle, true);
// ctx.stroke();
ctx.fillStyle = '#f08';
ctx.fillText(""+angle+"\xB0", x1+5, y1+10);
}
}
1 change: 1 addition & 0 deletions resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<script type="text/javascript" src="{{asset('js/jquery.min.js')}}"></script>
<script type="text/javascript" src="{{asset('js/jquery-ui.min.js')}}"></script>
<script type="text/javascript" src="{{asset('js/bootstrap.min.js')}}"></script>
<script type="text/javascript" src="{{asset('js/measurement.js')}}"></script>
<script type="text/javascript">
$.ajaxSetup({
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<input name = "password" type="password" class="form-control" aria-describedby="basic-addon1">
</div>
<br>
<button type="submit" class="col-xs-4 col-lg-offset-4 btn btn-info">Sign in</button>
<button type="submit" class="col-xs-4 col-xs-offset-4 btn btn-info">Sign in</button>
</form>
<br><br><br>
<p class="col-xs-4 col-lg-offset-4">Don't have account? then
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
<input name="password_confirmation" type="password" class="form-control" aria-describedby="basic-addon1">
</div>
<br>
<button type="submit" class="col-xs-4 col-lg-offset-4 btn btn-info">Sign Up</button>
<button type="submit" class="col-xs-4 col-xs-offset-4 btn btn-info">Sign Up</button>
</form>
@stop
6 changes: 3 additions & 3 deletions resources/views/embrace.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
</head>
<body>
<center>
<img src="{{asset('images/TLAP.jpg')}}" width="350px">
<a href="{{url('/')}}"><img src="{{url('images/TLAP.jpg')}}" width="350px"></a>

@yield('content')

<br>
<br>
</center>
<hr>
<a href="https://www.facebook.com/ieeenajah"><img src="{{asset('images/SBLogo.png')}}" width="150px" class="col-lg-offset-4"></a>
<a href="https://www.facebook.com/ieeenajah"><img src="{{asset('images/cs.jpg')}}" width="150px" class="col-lg-offset-1"></a>
<a href="https://www.facebook.com/ieeenajah"><img src="{{url('images/SBLogo.png')}}" width="150px" class="col-lg-offset-4"></a>
<a href="https://www.facebook.com/ieeenajah"><img src="{{url('images/cs.jpg')}}" width="150px" class="col-lg-offset-1"></a>
</body>
</html>
2 changes: 2 additions & 0 deletions resources/views/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</thead>
<tbody>
@foreach($level->questions as $question)
@if($question->active)
<tr>
<td><a href="{{url('question', [$question->id])}}">{{$question->name}}</a></td>
<td>{{round($level->mark,1)}}</td>
Expand All @@ -31,6 +32,7 @@
<td> Never </td>
@endif
</tr>
@endif
@endforeach
</tbody>
</table>
Expand Down
5 changes: 5 additions & 0 deletions resources/views/questions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<p>{{ $question->description }}</p>
</div>
<div class="col-md-6">
<div width="400" height="400" style="position: relative;">
<img src="{{asset('images/questions/'.$question->image)}}" alt="">
<canvas id="measure" width="400" height="400"
style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>
</div>

</div>
Expand Down Expand Up @@ -94,6 +98,7 @@ class="{{empty($question->hint_image)? 'hidden': ''}}">
container:'body',
trigger:'manual'
});
createMeasurement($('#measure')[0]);
});
$('#submit').click(function(){
Expand Down

0 comments on commit e6c9bbf

Please sign in to comment.