Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8db03e1
commit b65f128
Showing
7 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/app/app-components/training-app/course/course.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.container { | ||
max-width: 100%; | ||
} | ||
|
||
.video-container { | ||
position: relative; | ||
padding-bottom: 56.25%; | ||
height: 0; | ||
overflow: hidden; | ||
} | ||
|
||
.video-container iframe { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.lecture-navigation { | ||
display: flex; | ||
justify-content: space-between; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.lecture-action { | ||
display: flex; | ||
justify-content: center; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/app/app-components/training-app/course/course.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="container" *ngIf="course && lectures"> | ||
<h5>{{ course.title }}</h5> | ||
<h6>Lección {{ currentLectureIndex + 1 }} de {{ lectures.length }}</h6> | ||
<div class="video-container"> | ||
<iframe | ||
[src]="getVideoUrl(lectures[currentLectureIndex]?.youtube_code)" | ||
frameborder="0" | ||
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" | ||
allowfullscreen | ||
></iframe> | ||
</div> | ||
<div class="lecture-navigation"> | ||
<button class="btn" (click)="goToPreviousLecture()" [disabled]="currentLectureIndex === 0">←</button> | ||
<button class="btn" (click)="goToNextLecture()" [disabled]="currentLectureIndex === lectures.length - 1">→</button> | ||
</div> | ||
<div class="lecture-action"> | ||
<label> | ||
<input type="checkbox" (change)="markAsDone(lectures[currentLectureIndex])" [disabled]="lectures[currentLectureIndex]?.status === 1" /> | ||
<span>Visto</span> | ||
</label> | ||
</div> | ||
<div *ngIf="isCourseCompleted()"> | ||
<a class="btn" href="https://studies.solidjobs.org/course/{{courseUuid}}/certificate">Obtén tu certificado</a> | ||
</div> | ||
</div> | ||
<app-loading *ngIf="this.loading"></app-loading> |
25 changes: 25 additions & 0 deletions
25
src/app/app-components/training-app/course/course.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CourseComponent } from './course.component'; | ||
|
||
describe('CourseComponent', () => { | ||
let component: CourseComponent; | ||
let fixture: ComponentFixture<CourseComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ CourseComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CourseComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
76 changes: 76 additions & 0 deletions
76
src/app/app-components/training-app/course/course.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {ActivatedRoute} from '@angular/router'; | ||
import {HttpClient} from '@angular/common/http'; | ||
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser'; | ||
|
||
@Component({ | ||
selector: 'app-course', | ||
templateUrl: './course.component.html', | ||
styleUrls: ['./course.component.css'] | ||
}) | ||
export class CourseComponent implements OnInit { | ||
courseUuid: string; | ||
course: any; | ||
lectures: any[]; | ||
currentLectureIndex: number = 0; | ||
loading = true; | ||
|
||
constructor(private route: ActivatedRoute, private http: HttpClient, private sanitizer: DomSanitizer) { | ||
} | ||
|
||
ngOnInit() { | ||
this.courseUuid = this.route.snapshot.paramMap.get('uuid'); | ||
|
||
this.getCourse(); | ||
this.getLectures(); | ||
} | ||
|
||
getCourse() { | ||
const token = localStorage.getItem('session'); | ||
const headers = {token: token}; | ||
this.http.get('https://studies.solidjobs.org/course', {headers}).subscribe((courses: any[]) => { | ||
this.course = courses.find(course => course.uuid === this.courseUuid); | ||
}); | ||
} | ||
|
||
getLectures() { | ||
const token = localStorage.getItem('session'); | ||
const headers = {token: token}; | ||
this.http.get(`https://studies.solidjobs.org/course/${this.courseUuid}`, {headers}).subscribe((lectures: any[]) => { | ||
this.lectures = lectures; | ||
this.loading = false; | ||
}); | ||
} | ||
|
||
markAsDone(lecture) { | ||
const token = localStorage.getItem('session'); | ||
const headers = {token: token}; | ||
const body = {status: 1}; | ||
this.http | ||
.put(`https://studies.solidjobs.org/course/${this.courseUuid}/lecture/${lecture.uuid}`, body, {headers}) | ||
.subscribe(() => { | ||
lecture.status = 1; | ||
this.goToNextLecture(); | ||
}); | ||
} | ||
|
||
goToNextLecture() { | ||
if (this.currentLectureIndex < this.lectures.length - 1) { | ||
this.currentLectureIndex++; | ||
} | ||
} | ||
|
||
goToPreviousLecture() { | ||
if (this.currentLectureIndex > 0) { | ||
this.currentLectureIndex--; | ||
} | ||
} | ||
|
||
isCourseCompleted() { | ||
return this.lectures.every(lecture => lecture.status === 1); | ||
} | ||
|
||
getVideoUrl(youtubeCode: string): SafeResourceUrl { | ||
return this.sanitizer.bypassSecurityTrustResourceUrl(`https://www.youtube.com/embed/${youtubeCode}?autoplay=1`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters