diff --git a/src/app/organization/organization.component.html b/src/app/organization/organization.component.html
old mode 100644
new mode 100755
index f26a97b..89e8b4f
--- a/src/app/organization/organization.component.html
+++ b/src/app/organization/organization.component.html
@@ -3,7 +3,7 @@
-
@JBossOutreach
+ {{this.orgname}}
Mentor @ JBoss
Mumbai, IN
@@ -14,32 +14,32 @@
Download
-
+
+
-
Events:
-
+
Certificates Issued
+
+
+
+
+ | Name |
+ Date |
+ Issued For |
+
+
+
+ No Certificates Issued
+
+ | {{student.name}} |
+ {{student.date}} |
+ {{student.desc}} |
+
+
+
+
diff --git a/src/app/organization/organization.component.ts b/src/app/organization/organization.component.ts
old mode 100644
new mode 100755
index 35c1f8b..4f8aad7
--- a/src/app/organization/organization.component.ts
+++ b/src/app/organization/organization.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { OrganizationService } from '../services/organization.service';
import { Certificate } from '../services/certificate.model';
+import { HttpEvent, HttpResponse } from '@angular/common/http';
@Component({
selector: 'app-organization',
@@ -10,6 +11,7 @@ import { Certificate } from '../services/certificate.model';
export class OrganizationComponent implements OnInit {
private gridApi;
+ private orgname;
constructor(private orgService: OrganizationService) { }
@@ -23,14 +25,34 @@ export class OrganizationComponent implements OnInit {
rowData = [];
+ importCSV(event) {
+ const csv = event.target.files[0];
+ if(event.target.files[0].type != "text/csv" && event.target.files[0].type != "application/vnd.ms-excel"){
+ console.log('type 1 is! '+ event.target.files[0].type);
+ }
+ else{
+ console.log('type 2 is! '+ event.target.files[0].type);
+ }
+ if (csv.size > 5_242_880) {
+ alert(`CSV is larger than 5MBs.`);
+ } else {
+ this.orgService.generateBulkCertificate(event.target.files[0]).subscribe(event => {
+ if (event instanceof HttpResponse) {
+ console.log('Uploaded!');
+ }
+ },
+ error => {console.log("Error: "+error.message);});
+ }
+ }
+
ngOnInit() {
this.orgService.getCertificates().subscribe((certificates: Certificate[]) => {
// add certificates in ag-grid
for (const certificate of certificates){
this.rowData.push({ name: certificate.student.name, date: certificate.date, desc: certificate.issued_for });
+ this.orgname = certificate.issuing_organization.name;
}
- this.gridApi.setRowData(this.rowData);
});
}
diff --git a/src/app/services/organization.service.ts b/src/app/services/organization.service.ts
old mode 100644
new mode 100755
index e97353b..ab43afd
--- a/src/app/services/organization.service.ts
+++ b/src/app/services/organization.service.ts
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
-import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http';
import { Certificate } from './certificate.model';
import { Environment } from '../environments/environments';
-import { Observable } from 'rxjs';
+import { Observable,of } from 'rxjs';
@Injectable({
providedIn: 'root'
@@ -23,7 +23,15 @@ export class OrganizationService {
// Would be used when organization wants to generate single certificate
}
- private generateBulkCertificate() {
+ generateBulkCertificate(file:File) {
// Would be used when organization wants to many certificates by using csv/excel file
+ const data = new FormData();
+ data.append('file', file);
+ const token = 'JWT '+localStorage.getItem('token');
+ const options = {
+ headers: new HttpHeaders().set('Authorization', token)
+ };
+ const req = new HttpRequest('POST', Environment.baseUrl+'api/issue_certificate/csv/', data, options);
+ return this.http.request(req);
}
}