Skip to content

Commit 1a0256e

Browse files
author
Jon Janelle
committed
arrow links between problem views
1 parent cd96701 commit 1a0256e

7 files changed

Lines changed: 72 additions & 54 deletions

File tree

app/Http/Controllers/ProblemController.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ private static function loadProblemData($category, $sortCat="id",$order="asc"){
5656
Session::put($category, $data);
5757
}
5858

59-
60-
6159
/*
6260
* View a problem from a given $category with id $pid
61+
* if $feedback is true, then showing problem after an answer submit.
6362
*/
64-
public function show($category, $pid){
63+
public function show($category, $pid, $feedback=false, $correct=false, $userResponse=null){
6564
if (!Session::has($category)) { //load problem data if needed
6665
$this->loadProblemData($category);
6766
}
@@ -71,19 +70,31 @@ public function show($category, $pid){
7170

7271
//Retrieve data from session (rather than querying db again.)
7372
$pData = Session::get($category);
74-
foreach ($pData as $p) { //linear search for id (ids not necessarily ordered)
73+
for ($i=0; $i<$pData->count(); $i++) {
74+
$p=$pData[$i];
75+
//linear search for id (ids not necessarily ordered)
7576
if ($p->id==$pid){
77+
$prev = 'None';
78+
$next = 'None';
79+
if ($i>0) { $prev=$pData[$i-1]->id; }
80+
if ($i<$pData->count()-1) { $next=$pData[$i+1]->id; }
81+
$solved = [];
82+
if (!Auth::guest()) { $solved = Session::get('solved');}
83+
7684
return view('problem')->with(['problem'=>$p,
7785
'category'=>$category,
7886
'feedback'=>false,
79-
'next'=>'None',
80-
'prev'=>'None',
81-
'comments'=>$comments]);
87+
'next'=>$next,
88+
'prev'=>$prev,
89+
'comments'=>$comments,
90+
'feedback'=>$feedback,
91+
'correct'=>$correct,
92+
'userAns'=>$userResponse,
93+
'solved'=>$solved]);
8294
}
8395
}
8496

8597
//If requested problem not found, then go to listing page for category.
86-
//TO DO: return error message indicating requested problem not found.
8798
return view('problemlist')->with(['problems'=>$pData,
8899
'category'=>$category]);
89100
}
@@ -101,7 +112,7 @@ public function checkResponse(Request $request, $category, $pid) {
101112
$pData = Session::get($category);
102113
$correct = false;
103114
$userResponse = $request->input("answer-input");
104-
$comments = Auth::guest()?null:$this->getCommentsByProblem($pid);
115+
105116
foreach ($pData as $p) {
106117
if ($p->id==$pid){
107118
if ($p->answer==floatval($userResponse)){
@@ -110,13 +121,8 @@ public function checkResponse(Request $request, $category, $pid) {
110121
$this->updateUserData($p);
111122
}
112123
}
113-
return view('problem')->with(['problem'=> $p,
114-
'feedback'=>true,
115-
'correct'=>$correct,
116-
'userAns'=>$userResponse,
117-
'next'=>'None',
118-
'prev'=>'None',
119-
'comments'=>$comments]);
124+
return $this->show($category, $pid, true, $correct, $userResponse);
125+
120126
}
121127
}
122128
return view('problemlist')->with(['problems'=>$pData,

public/css/home.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
.home-container{
22
margin: 3%;
33
}
4+
5+
.home-panel .panel-heading{
6+
font-weight: bold;
7+
}
8+
9+
#leaderboard {
10+
width: 90%;
11+
height: 80vh;
12+
margin: 0 auto;
13+
border-radius: 5px;
14+
text-align: center;
15+
16+
}
17+
18+
#leaderboard .panel-heading {
19+
font-size: 1.2em;
20+
letter-spacing: 3px;
21+
font-weight: bold;
22+
}

public/css/leaderboard.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/css/problems.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
.spacer-sm {
5555
margin: 5px;
5656
}
57+
58+
5759
#left-link{
5860
float: left;
5961
}
@@ -63,12 +65,13 @@
6365
}
6466

6567
.arrow-link {
68+
font-size: 1.4em;
6669
transition: color .5s ease;
67-
color: #aac;
70+
color: #777;
6871
}
6972
.arrow-link:hover {
7073
transition: color .5s ease;
71-
color: #fff;
74+
color: #333;
7275
}
7376

7477
#problem-title {

resources/views/home.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<!--begin account summary section-->
1919
<div class="row">
2020
<div class="col col-md-12">
21-
<div class="panel panel-info shadow-transition" id="leaderboard">
21+
<div class="panel panel-info shadow-transition home-panel">
2222
<!-- Default panel contents -->
2323
<div class="panel-heading">Account Overview</div>
2424
<table class="table table-hover table-striped">
@@ -47,7 +47,7 @@
4747
<!--begin problem history section-->
4848
<div class="row">
4949
<div class="col col-md-12">
50-
<div class="panel panel-info shadow-transition" id="leaderboard">
50+
<div class="panel panel-info shadow-transition home-panel">
5151
<!-- Default panel contents -->
5252
<div class="panel-heading">Problem History</div>
5353
<table class="table table-hover table-striped">
@@ -80,7 +80,7 @@
8080
<!--begin comment history section-->
8181
<div class="row">
8282
<div class="col col-md-12">
83-
<div class="panel panel-info shadow-transition" id="leaderboard">
83+
<div class="panel panel-info shadow-transition home-panel">
8484
<!-- Default panel contents -->
8585
<div class="panel-heading">Comment History</div>
8686
<table class="table table-hover table-striped">

resources/views/leaderboard.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@extends('master.master')
22
@push('head')
3-
<link rel="stylesheet" href= "/css/leaderboard.css">
3+
<link rel="stylesheet" href= "/css/home.css">
44
@endpush
55

66
@section('content')

resources/views/problem.blade.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,38 @@
99
@section('content')
1010

1111
<div class="header" id="problem-title">
12-
@if ($prev !='None')
13-
<div id="left-link">
14-
<a href="/problems/{{$problem->category}}/{{$prev}}">
15-
<span class="glyphicon glyphicon-circle-arrow-left arrow-link"></span>
16-
</a>
17-
</div>
18-
@endif
12+
1913

2014
{{$problem->category}} - {{$problem->name}}
21-
@if ($next!='None')
22-
<div id="right-link">
23-
<a href="/problems/{{$problem->category}}/{{$next}}">
24-
<span class="glyphicon glyphicon-circle-arrow-right arrow-link"></span>
25-
</a>
26-
</div>
27-
@endif
15+
2816

2917
<div class="sub-header">
3018
<div class="alert alert-info" id='sub-head-alert'>
19+
@if ($prev !='None')
20+
<div id="left-link">
21+
<a href="/problems/{{$problem->category}}/problem/{{$prev}}">
22+
<span class="glyphicon glyphicon-circle-arrow-left arrow-link"></span>
23+
</a>
24+
</div>
25+
@endif
3126
Difficulty: {{$problem->difficulty}}
27+
@if ($next!='None')
28+
<div id="right-link">
29+
<a href="/problems/{{$problem->category}}/problem/{{$next}}">
30+
<span class="glyphicon glyphicon-circle-arrow-right arrow-link"></span>
31+
</a>
32+
</div>
33+
@endif
3234
</div>
3335
XP: {{$problem->xp}}
36+
@if (in_array($problem->id,$solved))
37+
<span class="glyphicon glyphicon-ok green-check"></span>
38+
@endif
3439
</div>
3540
</div> <!-- end header -->
3641
<div class="pad-20"><!-- begin problem display -->
3742
<div class="img-box light-shadowbox">
38-
<img src={{$problem->image}} alt="problem image">
43+
<img src="{{$problem->image}}" alt="problem image">
3944
</div>
4045

4146
@if ($feedback)
@@ -65,7 +70,7 @@
6570
</h3>
6671
<div class="input-group">
6772
<span class="input-group-addon" id="submit-addon1"><span class="glyphicon glyphicon-pencil"></span></span>
68-
<input type="text" class="form-control" id="answer-input" name="answer-input" aria-describedby="submit-addon1">
73+
<input type="text" class="form-control" id="answer-input" name="answer-input" aria-describedby="submit-addon1" required="true">
6974
</div>
7075
<div class="spacer-sm">
7176
<input class="btn btn-primary" type="submit" value="Submit">
@@ -92,7 +97,7 @@
9297
<form method="POST" id="comment-form" action="/problems/{{$problem->category}}/problem/{{$problem->id}}/comment">
9398
{{ csrf_field() }}
9499
<div class="form-group">
95-
<textarea rows="3" class="form-control" id="comment-input" name="comment-input" placeholder="posts containing profanity, insults, or answers may be removed at the discretion of the moderator"></textarea>
100+
<textarea rows="3" class="form-control" id="comment-input" name="comment-input" placeholder="Posts containing profanity, insults, or answers may be removed at the discretion of the moderator." required></textarea>
96101
<input class="btn btn-primary" id="comment-submit" type="submit" value="Post">
97102
</div>
98103

0 commit comments

Comments
 (0)