Quellcode durchsuchen

Removed subscriptions for demotype and implemented local storage

master
kj1352 vor 5 Jahren
Ursprung
Commit
624cd97358
8 geänderte Dateien mit 60 neuen und 73 gelöschten Zeilen
  1. +5
    -1
      src/app/app.component.ts
  2. +0
    -8
      src/app/services/demo.service.ts
  3. +5
    -14
      src/app/tabs/courses/course-details/course-details.component.ts
  4. +9
    -13
      src/app/tabs/courses/courses.component.ts
  5. +8
    -16
      src/app/tabs/home/home.component.ts
  6. +6
    -3
      src/app/tabs/more/more.component.html
  7. +18
    -4
      src/app/tabs/more/more.component.ts
  8. +9
    -14
      src/app/welcome/welcome.component.ts

+ 5
- 1
src/app/app.component.ts Datei anzeigen

@@ -7,5 +7,9 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
if (!localStorage.demoType) {
localStorage.demoType = 'Teacher';
}
}
}

+ 0
- 8
src/app/services/demo.service.ts Datei anzeigen

@@ -1,14 +1,10 @@
import { Injectable } from '@angular/core';
import { Observable, Observer } from 'rxjs';
import * as moment from 'moment';

@Injectable({
providedIn: 'root'
})
export class DemoService {
demoType: Observable<string>;
demoTypeObserver: Observer<string>;

courseData = [{
classLevel: '10',
courses: [{
@@ -328,9 +324,5 @@ export class DemoService {
}];

constructor() {
this.demoType = Observable.create((observer: Observer<string>) => {
this.demoTypeObserver = observer;
this.demoTypeObserver.next('Teacher');
});
}
}

+ 5
- 14
src/app/tabs/courses/course-details/course-details.component.ts Datei anzeigen

@@ -19,7 +19,6 @@ export class CourseDetailsComponent implements OnInit {
selectedTopic: number;
classLevel: string;

demoTypeSubscriber: Subscription;
demoType: string;

chapterList = [];
@@ -38,19 +37,11 @@ export class CourseDetailsComponent implements OnInit {
courseId = params['courseId'];
});

this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => {
this.demoType = type;

let courseData = this.demoService.courseData;

let course = courseData.find((courseClass) => courseClass.classLevel === classLevel).courses.find((course) => course.id === courseId);

this.heading = course.name;

this.chapterList = course.chapterList;

console.log(this.chapterList);
});
this.demoType = localStorage.demoType;
let courseData = this.demoService.courseData;
let course = courseData.find((courseClass) => courseClass.classLevel === classLevel).courses.find((course) => course.id === courseId);
this.heading = course.name;
this.chapterList = course.chapterList;
}

ngOnDestroy() {


+ 9
- 13
src/app/tabs/courses/courses.component.ts Datei anzeigen

@@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { DemoService } from '../../services/demo.service';
import { Subscription } from 'rxjs';
import { Router } from '@angular/router';

@Component({
@@ -9,7 +8,6 @@ import { Router } from '@angular/router';
styleUrls: ['./courses.component.scss']
})
export class CoursesComponent implements OnInit {
demoTypeSubscriber: Subscription;
demoType: string;
classCourseList = [];

@@ -19,17 +17,15 @@ export class CoursesComponent implements OnInit {
) { }

ngOnInit(): void {
this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => {
this.demoType = type;
if (type === 'Student') {
this.classCourseList = this.demoService.courseData;
this.classCourseList = this.classCourseList.filter((courseClass) => {
return courseClass.level === '10';
})
} else {
this.classCourseList = this.demoService.courseData;
}
});
this.demoType = localStorage.demoType;
if (this.demoType === 'Student') {
this.classCourseList = this.demoService.courseData;
this.classCourseList = this.classCourseList.filter((courseClass) => {
return courseClass.classLevel === '10';
});
} else {
this.classCourseList = this.demoService.courseData;
}
}

goToCourse(classLevel: string, courseId: string) {


+ 8
- 16
src/app/tabs/home/home.component.ts Datei anzeigen

@@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ScrollEvent } from 'ngx-scroll-event';
import { DemoService } from '../../services/demo.service';
import { Subscription } from 'rxjs';

@Component({
selector: 'app-home',
@@ -13,7 +12,6 @@ export class HomeComponent implements OnInit {
showClassDetails: boolean;
selectedSegment: string = 'transcript';
showVideo: boolean = false;
demoTypeSubscriber: Subscription;
demoType: string;

classList = [];
@@ -29,17 +27,15 @@ export class HomeComponent implements OnInit {
this.showClassDetails = false;
}

this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => {
this.demoType = type;
if (type === 'Student') {
this.classList = this.demoService.studentClassList;
this.showVideo = true;
}
this.demoType = localStorage.demoType;
if (this.demoType === 'Student') {
this.classList = this.demoService.studentClassList;
this.showVideo = true;
}

if (type === 'Teacher') {
this.classList = this.demoService.teacherClassList;
}
});
if (this.demoType === 'Teacher') {
this.classList = this.demoService.teacherClassList;
}
}

public handleScroll(event: ScrollEvent) {
@@ -58,8 +54,4 @@ export class HomeComponent implements OnInit {
}
}

ngOnDestroy() {
this.demoTypeSubscriber.unsubscribe();
}

}

+ 6
- 3
src/app/tabs/more/more.component.html Datei anzeigen

@@ -12,8 +12,8 @@
<figure>
<img src="https://pbs.twimg.com/profile_images/3478244961/01ebfc40ecc194a2abc81e82ab877af4.jpeg">
</figure>
<h5> Dwayne The Rock </h5>
<p> 3000 XP </p>
<h5> {{ demoType }} </h5>
<p *ngIf="demoType === 'Student'"> 3000 XP </p>
</div>
</section>

@@ -139,7 +139,10 @@

<button class="logout-button"> Logout </button>

<button class="logout-button teacher-mode"> Login as Teacher </button>
<button class="logout-button teacher-mode" *ngIf="demoType === 'Student'"
(click)="changeLogin('Teacher')"> Login as Teacher </button>
<button class="logout-button teacher-mode" *ngIf="demoType === 'Teacher'"
(click)="changeLogin('Student')"> Login as Student </button>
</section>

</div>

+ 18
- 4
src/app/tabs/more/more.component.ts Datei anzeigen

@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
selector: 'app-more',
@@ -6,12 +7,25 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./more.component.scss']
})
export class MoreComponent implements OnInit {
selectedSegment: string = 'badges';
profileDetails: boolean = false;
selectedSegment: string = 'badges';
profileDetails: boolean = false;
demoType: string;

constructor() { }
constructor(
private router: Router
) { }

ngOnInit(): void {
ngOnInit(): void {
this.demoType = localStorage.demoType;
}

ngOnDestroy() {

}

changeLogin(type: string) {
localStorage.demoType = type;
this.router.navigate(['welcome']);
}

}

+ 9
- 14
src/app/welcome/welcome.component.ts Datei anzeigen

@@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { DemoService } from '../services/demo.service';
import { Subscription } from 'rxjs';

@Component({
selector: 'app-welcome',
@@ -8,30 +7,26 @@ import { Subscription } from 'rxjs';
styleUrls: ['./welcome.component.scss']
})
export class WelcomeComponent implements OnInit {
demoTypeSubscriber: Subscription;
demoType: string;

classList = [];
demoType: string;

constructor(
private demoService: DemoService
) { }

ngOnInit(): void {
this.demoTypeSubscriber = this.demoService.demoType.subscribe((type) => {
this.demoType = type;
if (type === 'Student') {
this.classList = this.demoService.studentClassList;
}
this.demoType = localStorage.demoType;
if (this.demoType === 'Student') {
this.classList = this.demoService.studentClassList;
}

if (type === 'Teacher') {
this.classList = this.demoService.teacherClassList;
}
});
if (this.demoType === 'Teacher') {
this.classList = this.demoService.teacherClassList;
}
}

ngOnDestroy() {
this.demoTypeSubscriber.unsubscribe();
}

}