Skip to content

Commit 3bf9706

Browse files
committed
Added Quick Comment Feature
1 parent 117cf10 commit 3bf9706

File tree

9 files changed

+230
-1
lines changed

9 files changed

+230
-1
lines changed

app/Comment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Comment extends Model
8+
{
9+
protected $fillable = [
10+
'user_id', 'comment', 'percent'
11+
];
12+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Comment;
6+
use App\User;
7+
use Illuminate\Http\Request;
8+
9+
class CommentController extends Controller
10+
{
11+
/**
12+
* Display a listing of the resource.
13+
*
14+
* @return \Illuminate\Http\Response
15+
*/
16+
public function index()
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Show the form for creating a new resource.
23+
*
24+
* @return \Illuminate\Http\Response
25+
*/
26+
public function create()
27+
{
28+
//
29+
}
30+
31+
/**
32+
* Store a newly created resource in storage.
33+
*
34+
* @param \Illuminate\Http\Request $request
35+
* @return \Illuminate\Http\Response
36+
*/
37+
public function store(Request $request)
38+
{
39+
$comment = new Comment();
40+
$comment->comment = $request->comment;
41+
$comment->percent = $request->percent;
42+
$comment->user_id = auth()->user()->id;
43+
$comment->save();
44+
return redirect()->back();
45+
}
46+
/**
47+
* Display the specified resource.
48+
*
49+
* @param \App\Comment $comment
50+
* @return \Illuminate\Http\Response
51+
*/
52+
public function show(Comment $comment)
53+
{
54+
//
55+
}
56+
57+
/**
58+
* Show the form for editing the specified resource.
59+
*
60+
* @param \App\Comment $comment
61+
* @return \Illuminate\Http\Response
62+
*/
63+
public function edit(Comment $comment)
64+
{
65+
//
66+
}
67+
68+
/**
69+
* Update the specified resource in storage.
70+
*
71+
* @param \Illuminate\Http\Request $request
72+
* @param \App\Comment $comment
73+
* @return \Illuminate\Http\Response
74+
*/
75+
public function update(Request $request, Comment $comment)
76+
{
77+
//
78+
}
79+
80+
/**
81+
* Remove the specified resource from storage.
82+
*
83+
* @param \App\Comment $comment
84+
* @return \Illuminate\Http\Response
85+
*/
86+
public function destroy(Comment $comment)
87+
{
88+
//
89+
}
90+
}

app/Http/Controllers/HomeController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct()
2424
public function index()
2525
{
2626
$user = auth()->user();
27+
2728
return view('home')->with('user',$user);
2829
}
2930
}

app/Http/Controllers/SubmissionsController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public function update(Request $request, $id)
8989
if(auth()->user()->user_level < 2) return redirect('home');
9090
$submission = \App\Submission::find($id);
9191
if(!$this->checkEditAccess($submission->announcement->course)) return redirect('home');
92+
93+
if($request->quickComment!=0){
94+
$comment = \App\Comment::find($request->quickComment);
95+
$announcement = \App\Announcement::find($submission->announcement->id);
96+
$submission->grade = ($comment->percent*$announcement->max_grade)/100;
97+
$submission->comment =$comment->comment;
98+
$submission->save();
99+
return redirect('/announcements'.'/'.$submission->announcement->id)->with('status', 'Submission for '.$submission->user->roll_no.' graded succesfully!');
100+
}
92101
$submission->grade = $request->input('grade');
93102
$submission->comment = $request->input('comment');
94103
$submission->save();

app/User.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public function announcements()
5050
{
5151
return $this->hasMany('App\Announcement');
5252
}
53+
public function comments()
54+
{
55+
return $this->hasMany('App\Comment');
56+
}
5357
public function submissions()
5458
{
5559
return $this->hasMany('App\Submission');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateCommentsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('comments', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('comment');
19+
$table->integer('user_id');
20+
$table->integer('percent');
21+
$table->timestamps();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::dropIfExists('comments');
33+
}
34+
}

resources/views/home.blade.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,71 @@
482482

483483

484484
</div>
485+
@if($user->user_level==2)
486+
<div class="col-xl-4">
487+
<div class="card">
488+
<div class="card-header border-0">
489+
<div class="row align-items-center">
490+
<div class="col">
491+
<h3 class="mb-0">Grading Scheme</h3>
492+
</div>
493+
<div class="col text-right">
494+
<a href="#!" class="btn btn-sm btn-primary">See all</a>
495+
</div>
496+
</div>
497+
</div>
498+
<div class="table-responsive">
499+
<!-- Projects table -->
500+
<table class="table align-items-center table-flush">
501+
<thead class="thead-light">
502+
<tr>
503+
<th scope="col">Comment</th>
504+
<th scope="col">Percent</th>
505+
<th scope="col">Delete</th>
506+
</tr>
507+
</thead>
508+
<tbody>
509+
@foreach ($user->comments()->get() as $item)
510+
<tr>
511+
<th scope="row">
512+
{{$item->comment}}
513+
</th>
514+
<td>
515+
<div class="d-flex align-items-center">
516+
<span class="mr-2">{{$item->percent}}%</span>
517+
<div>
518+
<div class="progress">
519+
<div class="progress-bar bg-gradient-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: {{$item->percent}}%;"></div>
520+
</div>
521+
</div>
522+
</div>
523+
</td>
524+
<td>
525+
Delete
526+
</td>
527+
</tr>
528+
@endforeach
529+
<tr>
530+
<form method="POST" action="/comments">
531+
@csrf
532+
<th scope="row">
533+
<input class="form-control" name="comment" placeholder="Comment" type="text">
534+
</th>
535+
<td>
536+
<input class="form-control" name="percent" placeholder="Percent" type="number">
537+
</td>
538+
<td>
539+
<button type="submit" class="btn btn-sm btn-primary">Add </button>
540+
</td>
541+
542+
</tr>
543+
</tbody>
544+
</table>
545+
</div>
546+
</div>
547+
</div>
548+
</div>
549+
@endif
485550
<div class="col-xl-4">
486551
<!-- Checklist -->
487552
<div class="card">
@@ -555,6 +620,7 @@
555620
</div>
556621
</div>
557622
</div>
623+
558624
<!-- Footer -->
559625
<footer class="footer pt-0">
560626
<div class="row align-items-center justify-content-lg-between">

resources/views/submissions/edit.blade.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
@enderror
4949
</div>
5050
</div>
51+
52+
<div class="form-group row">
53+
<label for="quickComment" class="col-md-2 col-form-label text-md-right">{{ __('Quick Comment') }}</label>
54+
55+
<div class="col-md-8">
56+
<select name="quickComment" class="form-control">
57+
<option value="0" selected > None </option>
58+
@foreach (auth()->user()->comments as $item)
59+
<option value="{{$item->id}}"> {{$item->comment}} - {{$item->percent}}% </option>
60+
@endforeach
61+
</select>
62+
</div>
63+
</div>
5164
<input type="hidden" name="_method" value="put">
5265

5366
{{-- <div class="dropzone dropzone-single form-group row" data-toggle="dropzone" data-dropzone-url="http://">

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Route::resource('admins', 'AdminsController');
2929
Route::resource('announcements', 'AnnouncementsController');
3030
Route::resource('submissions', 'SubmissionsController');
31-
31+
Route::resource('comments', 'CommentController');
3232

3333

3434
//Attedance routes - Note Security aspects are not added.

0 commit comments

Comments
 (0)