Skip to content

Commit

Permalink
added report for Blended program batch
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-K-P committed Nov 8, 2024
1 parent 1932a08 commit 05725e3
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
details
<!-- <span *ngIf="rejectedUsers" class="ws-mat-black60-text">({{rejectedUsers.length}})</span> -->
</a>
<a class="filter-option cursor-pointer" [ngClass]="{'ws-mat-accent-border-active font-bold' : currentFilter === 'reportStatus',
'ws-mat-accent-border font-medium':currentFilter !== 'reportStatus'}" mat-button
(click)="filter('reportStatus')" role="button">Report
<!-- <span *ngIf="rejectedUsers" class="ws-mat-black60-text">({{rejectedUsers.length}})</span> -->
</a>
</div>
<div class="flex-2 right-align margin-top-l" *ngIf="currentFilter === 'approved' && allowToNominate()">
<button type="button" mat-button class="add-nomine-btn" (click)="onNominateUsersClick('nominateUsers')"
Expand Down Expand Up @@ -141,6 +146,75 @@
<p class="padding-m">No sessions yet</p>
</div>
</ng-container>
<ng-container *ngIf="currentFilter === 'reportStatus'">
<ng-container>
<ng-container *ngIf="checkSurveyLink">
<div class="card-container">
<mat-card class="mat-elevation-z2 main_info_card margin-bottom-m">
<div class="flex flex-col justify-start">
<mat-card-title>
<p class="mat-h2 margin-remove main_heading_text">Download Report</p>
</mat-card-title>
<mat-card-content>
<!-- <p class="mat-body-2" *ngIf="currentContent.details?.subTitle">{{currentContent.details?.subTitle}}</p> -->
<ng-container>
<div class="flex gap-3 flex-middle mb-5">
<mat-icon class="mat-icon ws-mat-black60-text">error_outline</mat-icon>
<p class="mat-body-1 margin-remove">
Click "Generate Report" to view details of all participants requesting enrollment in this
batch of the
blended program.
</p>
</div>
<div class="flex gap-3 flex-middle mb-5">
<mat-icon class="mat-icon ws-mat-black60-text">error_outline</mat-icon>
<p class="mat-body-1 margin-remove">
Report generation may take some time. Once ready, click "Download". If it's still
processing, use the
"Refresh" button.
</p>
</div>
</ng-container>
<ng-container>
<div>
<button mat-button class="text-white ws-mat-primary-background" type="button"
(click)="generateReport()"
[ngClass]="{disabled: reportStatusList[0]?.status.toLowerCase() === 'in-progress'}"
[disabled]="reportStatusList[0]?.status.toLowerCase() === 'in-progress'">Generate
Report</button>
<p class="mat-small margin-remove-bottom margin-top-xs" *ngIf="reportStatusList?.length > 0">
Last generated on: {{reportStatusList[0]?.lastReportGeneratedOn | date: 'MMM dd, yyyy H:mm'
}}</p>
</div>
</ng-container>
</mat-card-content>
</div>
</mat-card>
</div>

<ng-container *ngIf="reportStatusList?.length > 0">
<ws-widget-org-user-table [isSearchBar]="false" [tableData]="tabledata" [data]="reportStatusList"
(actionsClick)="actionsClick($event)">
</ws-widget-org-user-table>
</ng-container>

<ng-container *ngIf="!reportStatusList?.length">
<div class="text-center margin-m">
<img class="block mx-auto mb-3" src="/assets/instances/eagle/app_logos/allocation_empty.svg"
alt="No Report Generated">
<span class="block mat-subheading-2 mt-3">No Report Generated</span>
</div>
</ng-container>
</ng-container>
<ng-container *ngIf="!checkSurveyLink">
<div class="text-center margin-m">
<img class="block mx-auto mb-3" src="/assets/instances/eagle/app_logos/allocation_empty.svg"
alt="No Report Generated">
<span class="block mat-subheading-2 mt-3">No survey link added to this blended program.</span>
</div>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
</mat-card-content>
</mat-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@
.mat-button[disabled] {
opacity: 0.6;
}

.text-white {
color: white !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NominateUsersDialogComponent } from '../nominate-users-dialog/nominate-
import moment from 'moment'
import { NsContent } from '../../../../head/_services/widget-content.model'
import { DialogConfirmComponent } from '../../../../../../../../../src/app/component/dialog-confirm/dialog-confirm.component'
import { ITableData } from '@sunbird-cb/collection/lib/ui-org-table/interface/interfaces'
@Component({
selector: 'ws-app-batch-details',
templateUrl: './batch-details.component.html',
Expand Down Expand Up @@ -38,6 +39,25 @@ export class BatchDetailsComponent implements OnInit {
userscount: any
showUserDetails = false
selectedUser: any
fetchStatus: boolean = true
checkSurveyLink: boolean = false
reportStatusList: any[] = []

tabledata: ITableData = {
actions: [],
columns: [
{ displayName: 'Sl.No', key: 'SlNo' },
{ displayName: 'Name', key: 'name' },
{ displayName: 'Requested On', key: 'requestedon' },
// { displayName: 'Learners', key: 'learners', isList: true },
{ displayName: 'Status', key: 'status', isList: true },
],
needCheckBox: false,
needHash: false,
sortColumn: 'fullname',
sortState: 'asc',
needUserMenus: false,
}

constructor(private router: Router, private activeRouter: ActivatedRoute,
// tslint:disable-next-line:align
Expand All @@ -64,7 +84,7 @@ export class BatchDetailsComponent implements OnInit {

ngOnInit() { }

filter(key: 'pending' | 'approved' | 'rejected' | 'sessions' | 'approvalStatus') {
filter(key: 'pending' | 'approved' | 'rejected' | 'sessions' | 'approvalStatus' | 'reportStatus') {
this.approvedUsers = []
this.rejectedUsers = []
this.newUsers = []
Expand All @@ -89,6 +109,10 @@ export class BatchDetailsComponent implements OnInit {
this.currentFilter = 'approvalStatus'
this.getApprovalStatusList()
break
case 'reportStatus':
this.currentFilter = 'reportStatus'
this.getBpReportStatus()
break
default:
break
}
Expand Down Expand Up @@ -141,6 +165,9 @@ export class BatchDetailsComponent implements OnInit {
getBPDetails(programID: any) {
this.bpService.getBlendedProgramsDetails(programID).subscribe((res: any) => {
this.programData = res.result.content
if (this.programData && this.programData.wfSurveyLink && this.programData.wfSurveyLink.length) {
this.checkSurveyLink = true
}
if (!this.batchData) {
this.programData.batches.forEach((b: any) => {
if (b.batchId === this.batchID) {
Expand Down Expand Up @@ -286,7 +313,7 @@ export class BatchDetailsComponent implements OnInit {
this.filter('rejected')
}
this.showUserDetails = false
}, (error: any) => {
}, (error: any) => {
this.openSnackbar(_.get(error, 'error.params.errmsg') ||
_.get(error, 'error.result.errmsg') ||
'Something went wrong, please try again later!')
Expand Down Expand Up @@ -518,4 +545,82 @@ export class BatchDetailsComponent implements OnInit {
this.selectedUser = null
}
}

actionsClick(evt: any) {
if (evt.action === 'refreshStatus') {
this.getBpReportStatus()
}
if (evt.action === 'downloadReport') {
this.getBpReportStatus()
}
}

async getBpReportStatus() {
const batchDetails = this.batchData
const req = {
request: {
orgId: this.programData.channel || '',
courseId: this.programData.identifier || '',
batchId: batchDetails.batchId || ''
}
}
const resData: any = await this.bpService.getBpReportStatusApi(req).toPromise().catch(_error => { })
if (!resData) {
this.fetchStatus = false
this.snackBar.open('Something went wrong while fetching the report status. Please try again after sometime.')
this.reportStatusList = []
} else if (!resData.result && Object.keys(resData.result).length <= 0) {
this.reportStatusList = []
} else {
this.reportStatusList = resData.result.content
this.reportStatusList[0]['requestedon'] = this.reportStatusList[0]['lastReportGeneratedOn']
this.reportStatusList[0]['name'] = 'Enrollment Request Report'
this.reportStatusList[0]['SlNo'] = '1'
if (this.reportStatusList[0]['status'].toLowerCase() === 'completed') {
this.tabledata.actions = [{ icon: 'cloud_download', label: 'Download', name: 'download', type: 'link', disabled: false }]
} else if (this.reportStatusList[0]['status'].toLowerCase() === 'in-progress' ||
this.reportStatusList[0]['status'].toLowerCase() === 'failed') {
this.tabledata.actions = [{ icon: 'refresh', label: 'Refresh', name: 'refreshStatus', type: 'link', disabled: false }]
}
}
}
async generateReport() {
const batchDetails = this.batchData
const reqBody = {
request: {
orgId: this.programData.channel || '',
courseId: this.programData.identifier || '',
batchId: batchDetails.batchId || '',
surveyId: this.programData.wfSurveyLink.split('/')[this.programData.wfSurveyLink.split('/').length - 1] || '',
}
}
const resData: any = await this.bpService.generateBpReport(reqBody).toPromise().catch(_error => { })
if (resData && resData.params && resData.params.status.toLowerCase() === 'success') {
this.reportStatusList = []
this.getBpReportStatus()
} else {
this.snackBar.open('Something went wrong while generating the report. Please try again after sometime.')
this.reportStatusList = []
}
}

async downloadReport() {
const batchDetails = this.batchData
const downloadUrl = this.reportStatusList[0].downloadLink.split('gcpbpreports/')
[this.reportStatusList[0].downloadLink.split('gcpbpreports/').length - 1]
const fileExtension = downloadUrl.split('.').pop()?.toLowerCase()
// tslint:disable-next-line: max-line-length
const fileName = `Program_Coordinator_${batchDetails.name.split(' ').join('')}_Enrollment_Requests_Report_${this.formatDate(this.reportStatusList[0].lastReportGeneratedOn)}.${fileExtension}`
await this.bpService.downloadReport(downloadUrl, fileName)
}

formatDate(item: string): string {
const date = new Date(item)
const day = date.getDate().toString().padStart(2, '0') // Get day and pad with leading zero if needed
const month = (date.getMonth() + 1).toString().padStart(2, '0') // Get month (0-indexed, so add 1)
const year = date.getFullYear() // Get full year
// const hour = date.getHours()
// const minutes = date.getMinutes()
return `${day}-${month}-${year}`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const API_END_POINTS = {
NOMINATE_LEARNERS: '/apis/proxies/v8/workflow/blendedprogram/admin/enrol',
REMOVE_LEARNER: '/apis/proxies/v8/workflow/blendedprogram/remove/mdo',
BLENDED_USER_COUNT: `apis/proxies/v8/workflow/blendedprogram/enrol/status/count`,
BPREPORT_STATUS: 'apis/proxies/v8/bp/v1/bpreport/status',
GENERATE_REPORT: `apis/proxies/v8/bp/v1/generate/report`,
DOWNLOAD_REPORT: `apis/proxies/v8/bp/v1/bpreport/download/`
}

@Injectable({
Expand Down Expand Up @@ -81,4 +84,21 @@ export class BlendedApporvalService {
.post(API_END_POINTS.BLENDED_USER_COUNT, req)
.toPromise()
}

getBpReportStatusApi(reqBody: any) {
return this.http.post<null>(API_END_POINTS.BPREPORT_STATUS, reqBody)
}
generateBpReport(reqBody: any) {
return this.http.post<null>(API_END_POINTS.GENERATE_REPORT, reqBody)
}
downloadReport(fileUrl: string, fileName: string) {
this.http.get(`${API_END_POINTS.DOWNLOAD_REPORT}${fileUrl}`, { responseType: 'blob' }).subscribe((response: Blob) => {
const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
window.URL.revokeObjectURL(link.href)
})
}
}

0 comments on commit 05725e3

Please sign in to comment.