144 lines
4.8 KiB
TypeScript
144 lines
4.8 KiB
TypeScript
|
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
||
|
|
import { ApiService } from 'src/app/app.api.service';
|
||
|
|
import { DataTransferService } from 'src/app/data.transfer.service';
|
||
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
||
|
|
import { HRMNotificationService } from 'src/app/app.notification.service';
|
||
|
|
import { loadingPanelService } from 'src/app/hrm-loding panel/loding.panel.service';
|
||
|
|
import { process, State } from '@progress/kendo-data-query';
|
||
|
|
import { ExcelExportData, ExcelExportComponent, } from '@progress/kendo-angular-excel-export';
|
||
|
|
import { Courses } from 'src/app/_models/LearningManagement/courses';
|
||
|
|
import { LMSService } from 'src/app/_services/LearningManagement/lms.service';
|
||
|
|
import { EnumDifficultyLevel, EnumStatus } from 'src/app/_models/enums';
|
||
|
|
@Component({
|
||
|
|
selector: 'app-courses',
|
||
|
|
templateUrl: './courses.component.html',
|
||
|
|
styleUrls: ['./courses.component.scss'],
|
||
|
|
changeDetection: ChangeDetectionStrategy.Eager,
|
||
|
|
standalone: false,
|
||
|
|
})
|
||
|
|
export class CoursesComponent implements OnInit {
|
||
|
|
|
||
|
|
constructor(private apiService : ApiService,
|
||
|
|
public datatransferservice: DataTransferService,
|
||
|
|
public router: Router, public notificationService: HRMNotificationService,
|
||
|
|
public loadingpanelService: loadingPanelService,public lmsService : LMSService
|
||
|
|
) {
|
||
|
|
this.apiService.selectedMenuName = "Course List";
|
||
|
|
this.allData = this.allData.bind(this);
|
||
|
|
}
|
||
|
|
statusOptions : any [] = [];
|
||
|
|
selectedStatus : EnumStatus;
|
||
|
|
|
||
|
|
courses : Courses [] = [];
|
||
|
|
coursesAll : Courses [] = [];
|
||
|
|
coursesFilter : Courses [] = [];
|
||
|
|
|
||
|
|
oCourses : Courses;
|
||
|
|
ngOnInit(): void {
|
||
|
|
this.statusOptions = [{name : 'Active', value : EnumStatus.Active},
|
||
|
|
{name : 'In Active', value : EnumStatus.Inactive},
|
||
|
|
{name : 'Regardless', value : EnumStatus.Regardless}];
|
||
|
|
this.selectedStatusChange(EnumStatus.Active);
|
||
|
|
}
|
||
|
|
selectedStatusChange(value : any){
|
||
|
|
if(value !== undefined){
|
||
|
|
this.selectedStatus = value;
|
||
|
|
this.loadCourses(this.selectedStatus);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
loadCourses(status : EnumStatus){
|
||
|
|
this.loadingpanelService.ShowLoadingPanel = true;
|
||
|
|
this.lmsService.GetCoursesByStatus(status).subscribe(
|
||
|
|
(resp: any) => {
|
||
|
|
debugger;
|
||
|
|
this.courses = resp;
|
||
|
|
this.coursesAll = resp;
|
||
|
|
},
|
||
|
|
(err: any) => {
|
||
|
|
this.loadingpanelService.ShowLoadingPanel = false;
|
||
|
|
},
|
||
|
|
() => {
|
||
|
|
this.loadingpanelService.ShowLoadingPanel = false;
|
||
|
|
}
|
||
|
|
);
|
||
|
|
}
|
||
|
|
addHandler(){
|
||
|
|
this.oCourses = new Courses();
|
||
|
|
this.datatransferservice.setData(this.oCourses);
|
||
|
|
this.router.navigateByUrl('/lms/courseentry');
|
||
|
|
}
|
||
|
|
onFilter(inputValue: string): void{
|
||
|
|
this.coursesFilter = [];
|
||
|
|
this.coursesFilter = this.coursesAll;
|
||
|
|
|
||
|
|
const filters = Object.keys(this.coursesFilter[0]).map(field => ({
|
||
|
|
field: field,
|
||
|
|
operator: typeof this.coursesFilter[0][field] === 'string' ? 'contains' : 'eq',
|
||
|
|
value: inputValue
|
||
|
|
}));
|
||
|
|
this.coursesFilter = process(this.coursesFilter, {
|
||
|
|
filter: {
|
||
|
|
logic: 'or',
|
||
|
|
filters: filters
|
||
|
|
}
|
||
|
|
}).data;
|
||
|
|
this.courses = this.coursesFilter;
|
||
|
|
}
|
||
|
|
editHandler(dataItem : Courses){
|
||
|
|
this.oCourses = dataItem;
|
||
|
|
this.datatransferservice.setData(this.oCourses);
|
||
|
|
this.router.navigateByUrl('/lms/courseentry');
|
||
|
|
}
|
||
|
|
deleteHandler(dataItem : any){
|
||
|
|
this.notificationService.showActiveConfirm('Confirmation', "Are you sure you want to delete this Course?").then((isConfirmed) => {
|
||
|
|
if (isConfirmed)
|
||
|
|
{
|
||
|
|
if(dataItem.id > 0){
|
||
|
|
this.lmsService.deleteCourses(dataItem.id).subscribe(
|
||
|
|
(resp: any) => {
|
||
|
|
|
||
|
|
},
|
||
|
|
(err: any) => {
|
||
|
|
this.loadingpanelService.ShowLoadingPanel = false;
|
||
|
|
this.notificationService.showError(err.error);
|
||
|
|
},
|
||
|
|
() => {
|
||
|
|
this.loadingpanelService.ShowLoadingPanel = false;
|
||
|
|
this.notificationService.showSuccess("Course deleted successfully.");
|
||
|
|
this.ngOnInit();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
public allData(): ExcelExportData {
|
||
|
|
let result: ExcelExportData = {
|
||
|
|
data: process(this.coursesAll, {
|
||
|
|
group: [],
|
||
|
|
sort: []
|
||
|
|
}).data,
|
||
|
|
group: [],
|
||
|
|
};
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
getDifficultyLevelStringString(type : EnumDifficultyLevel): string{
|
||
|
|
let difficultyLevel : string = "";
|
||
|
|
switch (type) {
|
||
|
|
case EnumDifficultyLevel.Advanced:
|
||
|
|
difficultyLevel = "Advanced";
|
||
|
|
break;
|
||
|
|
case EnumDifficultyLevel.Beginner:
|
||
|
|
difficultyLevel = "Beginner";
|
||
|
|
break;
|
||
|
|
case EnumDifficultyLevel.Intermediate:
|
||
|
|
difficultyLevel = "Intermediate";
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
difficultyLevel = "";
|
||
|
|
}
|
||
|
|
return difficultyLevel;
|
||
|
|
}
|
||
|
|
}
|