From b60a9148ac96f53beec54fe6952abef9ff11f12d Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:52:45 +0100 Subject: [PATCH 01/19] Updates course factory --- database/factories/CourseFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/CourseFactory.php b/database/factories/CourseFactory.php index c121372..361f310 100644 --- a/database/factories/CourseFactory.php +++ b/database/factories/CourseFactory.php @@ -9,7 +9,7 @@ return [ 'name' => $faker->company, 'association_id' => $faker->numberbetween(1,100), - 'code' => $faker->word . ' ' . $faker->century, + 'code' => $faker->regexify('[A-Za-z0-9]{10}'), 'points' => $faker->numberbetween(1,30), 'url' => $faker->url, 'description' => $faker->text From dd9b44ba908e0df15c5267ac462bcacddaaa6a77 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:52:58 +0100 Subject: [PATCH 02/19] Update .env.example --- .env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.example b/.env.example index bc05bf9..5d37aaf 100644 --- a/.env.example +++ b/.env.example @@ -44,3 +44,5 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +FILESYSTEM_DRIVER=local From 658dc52223f458398a9d6abe206a163ddcdf8391 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:53:03 +0100 Subject: [PATCH 03/19] Delete .gitignore --- storage/app/public/.gitignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 storage/app/public/.gitignore diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/storage/app/public/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore From 311f419e8d93c82e3d91ca3323365e4b86004d5b Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:53:57 +0100 Subject: [PATCH 04/19] Course code must be unique --- database/migrations/2019_09_12_110140_create_courses_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2019_09_12_110140_create_courses_table.php b/database/migrations/2019_09_12_110140_create_courses_table.php index 7fdc4f1..037b079 100644 --- a/database/migrations/2019_09_12_110140_create_courses_table.php +++ b/database/migrations/2019_09_12_110140_create_courses_table.php @@ -17,7 +17,7 @@ public function up() $table->bigIncrements('id'); $table->integer('association_id'); $table->string('name'); - $table->string('code'); + $table->string('code')->unique(); $table->longText( 'description' )->nullable(); $table->decimal( 'points', 8, 1 ); $table->string( 'url' )->nullable(); From b8fe659736f40d5f42cce258d44b412cc5120633 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:54:24 +0100 Subject: [PATCH 05/19] Adds columns to exam table #12 --- database/migrations/2019_09_12_110121_create_exams_table.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/migrations/2019_09_12_110121_create_exams_table.php b/database/migrations/2019_09_12_110121_create_exams_table.php index 7112f24..126f0cf 100644 --- a/database/migrations/2019_09_12_110121_create_exams_table.php +++ b/database/migrations/2019_09_12_110121_create_exams_table.php @@ -18,7 +18,9 @@ public function up() $table->integer('course_id'); $table->string('file_name'); $table->string('name'); - $table->bigInteger('views')->nullable(); + $table->string( 'path' ); + $table->bigInteger('views')->default( 0 ); + $table->bigInteger('downloads')->default( 0 ); $table->decimal('rating')->nullable(); $table->string('grade')->nullable(); $table->decimal('points')->nullable(); From b81d4cf95ff271baeb08fa86243c594e916c7c51 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:54:30 +0100 Subject: [PATCH 06/19] Update ExamsTableSeeder.php --- database/seeds/ExamsTableSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeds/ExamsTableSeeder.php b/database/seeds/ExamsTableSeeder.php index 707bf8a..87aaa5c 100644 --- a/database/seeds/ExamsTableSeeder.php +++ b/database/seeds/ExamsTableSeeder.php @@ -12,6 +12,6 @@ class ExamsTableSeeder extends Seeder */ public function run() { - $exams = factory( Exam::class, 100 )->create(); + // $exams = factory( Exam::class, 100 )->create(); } } From d8128093452ebd025b21561d8ea9b57c01b93113 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 13:55:05 +0100 Subject: [PATCH 07/19] Users can now upload, view and download exams #12 #32 --- app/Exam.php | 9 ++ app/Http/Controllers/ExamController.php | 130 ++++++++++++++++++++++++ config/filesystems.php | 3 +- resources/views/exams/create.blade.php | 85 ++++++++++++++++ resources/views/exams/index.blade.php | 21 ++++ routes/web.php | 2 + 6 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ExamController.php create mode 100644 resources/views/exams/create.blade.php create mode 100644 resources/views/exams/index.blade.php diff --git a/app/Exam.php b/app/Exam.php index 93b106f..079747b 100644 --- a/app/Exam.php +++ b/app/Exam.php @@ -8,6 +8,15 @@ class Exam extends Model { protected $table = 'exams'; + protected $fillable = [ + 'course_id', + 'file_name', + 'name', + 'grade', + 'points', + 'path' + ]; + public function course(){ return $this->belongsTo('App\Course'); } diff --git a/app/Http/Controllers/ExamController.php b/app/Http/Controllers/ExamController.php new file mode 100644 index 0000000..2fbae4b --- /dev/null +++ b/app/Http/Controllers/ExamController.php @@ -0,0 +1,130 @@ +with( 'exams', $exams ); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + $universities = University::all(); + + return view( 'exams.create' )->with( 'universities', $universities ); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $request->validate( [ + 'name' => 'required|string', + 'grade' => 'required|string', + 'points' => 'required|integer', + 'exam' => 'required|mimetypes:application/pdf', + ] ); + + $course = Course::findOrFail( $request->course_id ); + + $path = Storage::putFile( + 'exams/' . str_replace( ' ', '-', $course->code ), new File($request->exam) + ); + + Exam::create( [ + 'name' => $request->name, + 'grade' => $request->grade, + 'points' => $request->points, + 'file_name' => $request->exam->getClientOriginalName(), + 'course_id' => $request->course_id, + 'path' => $path + ] ); + + return redirect()->route( 'exams.index' )->with( 'success', 'Ny tenta uppladdad! Yay.' ); + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + $exam = Exam::findOrFail( $id ); + + $exam->views += 1; + $exam->save(); + + return redirect( Storage::url( $exam->path ) ); + } + + public function download( $id ) + { + $exam = Exam::findOrFail( $id ); + $exam->downloads += 1; + $exam->save(); + + return Storage::download( $exam->path ); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + abort( 404 ); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + abort( 403 ); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + abort( 403 ); + } +} diff --git a/config/filesystems.php b/config/filesystems.php index 77fa5de..0f915a4 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -45,7 +45,8 @@ 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), + 'root' => storage_path('app/public'), + 'visibility' => 'public', ], 'public' => [ diff --git a/resources/views/exams/create.blade.php b/resources/views/exams/create.blade.php new file mode 100644 index 0000000..ea53c91 --- /dev/null +++ b/resources/views/exams/create.blade.php @@ -0,0 +1,85 @@ +@extends('layouts.app') +@section( 'title', 'Lägg till ny tenta' ) +@section('content') + +
+
+
+

Ladda upp tenta

+
+ @csrf +
+ + + @error( 'name' ) + + {{ $message }} + + @enderror +
+
+ + + @error( 'grade' ) + + {{ $message }} + + @enderror +
+
+ + + @error( 'points' ) + + {{ $message }} + + @enderror +
+
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+ Avbryt +
+
+
+
+
+
+ +@endsection diff --git a/resources/views/exams/index.blade.php b/resources/views/exams/index.blade.php new file mode 100644 index 0000000..d3888b1 --- /dev/null +++ b/resources/views/exams/index.blade.php @@ -0,0 +1,21 @@ +@extends('layouts.app') +@section( 'title', 'Tentor' ) +@section('content') + +
+ +
+ +@endsection diff --git a/routes/web.php b/routes/web.php index af8e7ee..c6b5ce5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -86,3 +86,5 @@ 'users' => 'UserController', 'supers' => 'SuperController', ] ); + +Route::get( 'exams/{exam}/download', 'ExamController@download' )->name( 'exams.download' ); From c031f77142d8bb06c39022f08e92db8f7affc247 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 18:11:44 +0100 Subject: [PATCH 08/19] Improves UI #32 #12 --- public/css/app.css | 8 +++++ resources/sass/layout/common.scss | 10 +++++++ resources/views/exams/index.blade.php | 42 ++++++++++++++++++--------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/public/css/app.css b/public/css/app.css index 8582f82..5826872 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -14211,6 +14211,14 @@ a.is-primary:hover { border-right-color: var(--color-scheme-text-color-diff); } +.list { + background-color: var(--color-scheme-background-diff); +} + +.list-item:not(a) { + color: var(--color-scheme-text-color); +} + .section { padding: 5rem 1.5rem; } diff --git a/resources/sass/layout/common.scss b/resources/sass/layout/common.scss index 1a82512..3e30025 100644 --- a/resources/sass/layout/common.scss +++ b/resources/sass/layout/common.scss @@ -46,6 +46,16 @@ a { } } +.list { + background-color: var(--color-scheme-background-diff); + + &-item { + &:not(a) { + color: var( --color-scheme-text-color ); + } + } +} + // Section .section { padding: 5rem 1.5rem; diff --git a/resources/views/exams/index.blade.php b/resources/views/exams/index.blade.php index d3888b1..ed10b70 100644 --- a/resources/views/exams/index.blade.php +++ b/resources/views/exams/index.blade.php @@ -2,20 +2,34 @@ @section( 'title', 'Tentor' ) @section('content') -
- +
+
+
+

Tentor

+
+ @if( $exams->isEmpty() ) +

Inga tentor att visa. Lägg till en!

+
+ @else +
+ @foreach( $exams as $exam ) +

+ + {{ $exam->name }} + + - + + Ladda ner + +

+ @endforeach +
+ @endif + + Lägg till tenta + +
+
@endsection From f4cc51f94ec849274a2e2ff28bd8f240ba2188b7 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 18:12:52 +0100 Subject: [PATCH 09/19] Fixes UI bug on university show --- resources/views/universities/show.blade.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/views/universities/show.blade.php b/resources/views/universities/show.blade.php index dedc600..88e9170 100644 --- a/resources/views/universities/show.blade.php +++ b/resources/views/universities/show.blade.php @@ -20,9 +20,11 @@ @endforeach
- @if( Auth::user()->role === 'super' || Auth::user()->role >= 'admin' && Auth::user()->association->univerity == $university ) - Lägg till förening - @endif + @auth + @if( Auth::user()->role === 'super' || Auth::user()->role >= 'admin' && Auth::user()->association->univerity == $university ) + Lägg till förening + @endif + @endauth @else

Inga föreningar har lagts till på det här universitetet, vill du lägga till en ny?

@auth From 7d6ad8c9a426bbacf9c014b1e87b2fa0fdd7b162 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 18:13:25 +0100 Subject: [PATCH 10/19] Displays exams in fancy list on courses #32 --- resources/views/courses/show.blade.php | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/resources/views/courses/show.blade.php b/resources/views/courses/show.blade.php index ae03df1..a3a62f6 100644 --- a/resources/views/courses/show.blade.php +++ b/resources/views/courses/show.blade.php @@ -9,29 +9,27 @@

{{ $course->description }}

{{ $course->url }}
- @if( $exams->isNotEmpty() ) -

Tentor:

- -
- @if( Auth::user()->role === 'super' || Auth::user()->role === 'admin' && Auth::user()->association->university->id == $course->association->university->id || Auth::user()->role === 'moderator' && Auth::user()->association->id == $course->association_id ) - Lägg till tenta - @endif - @else -

Inga tentor har lagts till på den här kursen, vill du lägga till en?

- @auth - @if( Auth::user()->role === 'super' || Auth::user()->role === 'admin' && Auth::user()->association->university->id == $course->association->university->id || Auth::user()->role === 'moderator' && Auth::user()->association->id == $course->association_id ) - Lägg till tenta - @endif - @endauth + @endif + + Lägg till tenta + @auth @if( Auth::user()->role === 'super' || Auth::user()->role === 'admin' && Auth::user()->association->university->id == $course->association->university->id || Auth::user()->role === 'moderator' && Auth::user()->association->id == $course->association_id )
From 0b1ab2523a4e1887949f08621eacdaf69901c932 Mon Sep 17 00:00:00 2001 From: Felix Wetell Date: Mon, 2 Dec 2019 18:41:45 +0100 Subject: [PATCH 11/19] Update navbar.blade.php --- resources/views/partials/layouts/navbar.blade.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/views/partials/layouts/navbar.blade.php b/resources/views/partials/layouts/navbar.blade.php index 7645d9a..1b0aedb 100644 --- a/resources/views/partials/layouts/navbar.blade.php +++ b/resources/views/partials/layouts/navbar.blade.php @@ -37,6 +37,9 @@ Kurser + + Tentor +