diff --git a/src/app/services/student.service.ts b/src/app/services/student.service.ts index 4c48fe3..417ec93 100644 --- a/src/app/services/student.service.ts +++ b/src/app/services/student.service.ts @@ -1,13 +1,22 @@ import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Certificate } from './certificate.model'; +import { Environment } from '../environments/environments'; +import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class StudentService { - constructor() { } + constructor(private http: HttpClient) { } - private getAllCertificates() { - // Fetches all the certificates issued to student + getCertificates(): Observable { + const token = 'JWT ' + localStorage.getItem('token'); + const options = { + headers: new HttpHeaders().set('Authorization', token) + }; + return this.http.get(Environment.baseUrl+"api/get_certificates", options); } + } diff --git a/src/app/student/student.component.html b/src/app/student/student.component.html index f018744..6f77d16 100644 --- a/src/app/student/student.component.html +++ b/src/app/student/student.component.html @@ -7,40 +7,25 @@
-

Saba Khukhunashvili

-

Certificates owned: 13

+

Aayushman Choudhary

+

Certificates owned: {{this.rowData.length}}

-

   Your Organizations

+

   Your Certificates

-
-
- Card image cap -
-

JBoss Outreach

-

Certificates: 11

- See certificates -
-
-
- Card image cap -
-

MetaBrainz

-

Certificates: 3

- See certificates -
-
-
- Card image cap -
-

Coala

-

Certificates: 11

- See certificates -
-
-
+ +
diff --git a/src/app/student/student.component.ts b/src/app/student/student.component.ts index 502d7e8..2120c04 100644 --- a/src/app/student/student.component.ts +++ b/src/app/student/student.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { StudentService } from '../services/student.service'; +import { Certificate } from '../services/certificate.model'; @Component({ selector: 'app-student', @@ -6,9 +8,31 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./student.component.css'] }) export class StudentComponent implements OnInit { + private gridApi; - constructor() { } + columnDefs = [ + {headerName: 'Organization Name', field: 'name', checkboxSelection: true}, + {headerName: 'Date', field: 'date' }, + {headerName: 'Certificate Description', field: 'desc'} + ]; + + rowData = []; + + constructor(private studentService: StudentService) { } ngOnInit() { + this.studentService.getCertificates().subscribe((certificates: Certificate[]) => { + + // add certificates in ag-grid + for (const certificate of certificates){ + this.rowData.push({ name: certificate.issuing_organization.name, date: certificate.date, desc: certificate.issued_for }); + } + this.gridApi.setRowData(this.rowData); + }); } + + onGridReady(event) { + this.gridApi = event.api; + } + }