I am struggling to figure out how to render the workload component's learningHours method after the setStatusOfUser() method in confirmation.ts. Can someone please help me with this issue?
Here is my confirmation.ts component:
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { courses } from '../models/courses';
import { CoursesService } from '../services/course.service';
@Component({
selector: 'app-confirmation',
templateUrl: './confirmation.component.html',
styleUrls: ['./confirmation.component.css']
})
export class ConfirmationComponent implements OnInit {
msg: string = '';
condition:boolean;
courseList: Array<courses>;
constructor(private courseService: CoursesService, @Inject(MAT_DIALOG_DATA) public data: any,
public dialog: MatDialog,) { }
ngOnInit(): void {
}
getAllCourses(){
this.courseService.getAllCourses('PATKRISH').subscribe((data) => {
this.courseList = data;
console.log(this.courseList);
});
}
setStatusOfUser(){
this.courseService.setStatus(this.data.courseId,'PATKRISH').subscribe((data)=>{
this.msg=data;
this.getAllCourses()
})
this.condition=true;
this.courseService.getAllCourses('PATKRISH').subscribe((data) => {
this.courseList = data;
console.log(this.courseList);
});
}
}
My goal is to render the workload component's learningHours method after the setStatusOfUser() method.
Here is the workload.component.ts:
import { Component, OnInit } from '@angular/core';
import { WorkloadService } from '../services/workload.service';
@Component({
selector: 'app-workload',
templateUrl: './workload.component.html',
styleUrls: ['./workload.component.css']
})
export class WorkloadComponent implements OnInit {
constructor(private workloadService:WorkloadService) { }
workload:number=0;
ngOnInit(): void {
this.learningHours()
}
learningHours (){
this.workloadService.getWorkloadPercentage("PATKRISH").subscribe(
data => {
if(data==0){
this.workload=0;
}else{
this.workload=data;
}
console.log(data);
},
error=>{console.log(error);
this.workload=0;}
);
}
}
course.service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, Subject } from 'rxjs';
import { courses } from '../models/courses';
// import { AddProgress } from '../interface/progress';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
};
@Injectable({
providedIn: 'root',
})
export class CoursesService {
private subject = new Subject<any>();
constructor(private httpClient: HttpClient) {}
// http://localhost:8080/api/addassignment/coursebyuserid/PERAVIKA
getAllCourses(userId: any): Observable<courses[]> {
return this.httpClient.get<courses[]>(
`http://localhost:8080/api/addassignment/coursebyuserid/${userId}`
);
}
setStatus(courseId: any, userId: any): Observable<string> {
return this.httpClient.put<string>(
`http://localhost:8080/api/addassignment/${courseId}/${userId}`,
httpOptions
);
}
}
workload.sevice.ts
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class WorkloadService {
constructor(private _http: HttpClient) {}
getWorkloadPercentage(id: string): Observable<number> {
return this._http.get<number>(
`http://localhost:8080/api/learningmeter/getmeter/PATKRISH`
);
}
}