Skip to content

Commit 63014ab

Browse files
committed
add - everything - begin - user- progress - display
1 parent a303afd commit 63014ab

File tree

10 files changed

+248
-16
lines changed

10 files changed

+248
-16
lines changed

Diff for: app/Lesson.php

+20
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,38 @@
66

77
class Lesson extends Model
88
{
9+
/**
10+
* Fields for mass assignment
11+
*
12+
* @var array
13+
*/
914
protected $guarded = [];
1015

16+
/**
17+
* A lesson belongs to a series
18+
*
19+
* @return void
20+
*/
1121
public function series() {
1222
return $this->belongsTo(Series::class);
1323
}
1424

25+
/**
26+
* Get next lesson after $this
27+
*
28+
* @return \Bahdcasts\Lesson
29+
*/
1530
public function getNextLesson() {
1631
return $this->series->lessons()->where('episode_number', '>', $this->episode_number)
1732
->orderBy('episode_number', 'asc')
1833
->first();
1934
}
2035

36+
/**
37+
* Get previous lesson for $this
38+
*
39+
* @return \Bahdcasts\Lesson
40+
*/
2141
public function getPrevLesson() {
2242
return $this->series->lessons()->where('episode_number', '<', $this->episode_number)
2343
->orderBy('episode_number', 'desc')

Diff for: app/Series.php

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function getImagePathAttribute() {
4949
return asset('storage/' . $this->image_url);
5050
}
5151

52+
/**
53+
* Get a list of lessons for series in watching order
54+
*
55+
* @return void
56+
*/
5257
public function getOrderedLessons() {
5358
return $this->lessons()->orderBy('episode_number', 'asc')->get();
5459
}

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"predis/predis": "^1.1"
1414
},
1515
"require-dev": {
16+
"barryvdh/laravel-debugbar": "^3.1",
1617
"filp/whoops": "~2.0",
1718
"fzaninotto/faker": "~1.4",
1819
"mockery/mockery": "0.9.*",

Diff for: composer.lock

+130-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"vue": "^2.1.10"
2020
},
2121
"dependencies": {
22+
"@vimeo/player": "^2.2.0",
2223
"sweetalert": "^2.0.5"
2324
}
2425
}

Diff for: public/js/app.js

+40-6
Large diffs are not rendered by default.

Diff for: resources/assets/js/components/Player.vue

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55
</template>
66

77
<script>
8+
import Swal from 'sweetalert'
89
import Player from '@vimeo/player'
910
export default {
10-
props: ['default_lesson'],
11+
props: ['default_lesson', 'next_lesson_url'],
1112
data() {
1213
return {
1314
lesson: JSON.parse(this.default_lesson)
1415
}
1516
},
17+
methods: {
18+
displayVideoEndedAlert() {
19+
if(this.next_lesson_url) {
20+
Swal('Yaaay ! You completed this lesson !')
21+
.then(() => {
22+
window.location = this.next_lesson_url
23+
})
24+
} else {
25+
Swal('Yaaay ! You completed this series !')
26+
}
27+
28+
}
29+
},
1630
mounted() {
1731
const player = new Player('handstick')
1832
19-
player.on('play', () => {
20-
console.log('our video is playing !')
33+
player.on('ended', () => {
34+
this.displayVideoEndedAlert()
2135
})
2236
}
2337
}

Diff for: resources/views/watch.blade.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@
2020
@section('content')
2121
<div class="section bg-grey">
2222
<div class="container">
23-
23+
@php
24+
$nextLesson = $lesson->getNextLesson();
25+
$prevLesson = $lesson->getPrevLesson();
26+
@endphp
2427
<div class="row gap-y text-center">
2528
<div class="col-12">
26-
<vue-player default_lesson="{{ $lesson }}"></vue-player>
27-
@if($lesson->getPrevLesson())
28-
<a href="{{ route('series.watch', ['series' => $series->slug, 'lesson' => $lesson->getPrevLesson()->id ]) }}" class="btn btn-info btn-lg pull-left">Prev Lesson</a>
29+
<vue-player default_lesson="{{ $lesson }}"
30+
@if($nextLesson)
31+
next_lesson_url="{{ route('series.watch', ['series' => $series->slug, 'lesson' => $nextLesson->id ]) }}"
32+
@endif
33+
></vue-player>
34+
@if($prevLesson)
35+
<a href="{{ route('series.watch', ['series' => $series->slug, 'lesson' => $prevLesson->id ]) }}" class="btn btn-info btn-lg pull-left">Prev Lesson</a>
2936
@endif
30-
@if($lesson->getNextLesson())
31-
<a href="{{ route('series.watch', ['series' => $series->slug, 'lesson' => $lesson->getNextLesson()->id ]) }}" class="btn btn-info btn-lg pull-right">Next Lesson</a>
37+
@if($nextLesson)
38+
<a href="{{ route('series.watch', ['series' => $series->slug, 'lesson' => $nextLesson->id ]) }}" class="btn btn-info btn-lg pull-right">Next Lesson</a>
3239
@endif
3340

3441
</div>

Diff for: storage/debugbar/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)