2026-11-03 13:06:00 +06:00
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 { SearchEmployee } from 'src/app/_models/Employee/searchEmployee' ;
import { HRMNotificationService } from 'src/app/app.notification.service' ;
import { loadingPanelService } from 'src/app/hrm-loding panel/loding.panel.service' ;
import { Courses } from 'src/app/_models/LearningManagement/courses' ;
import { debug } from 'console' ;
import { Lessons } from 'src/app/_models/LearningManagement/lessons' ;
import { LessonContent } from 'src/app/_models/LearningManagement/lesson-content' ;
import { LMSService } from 'src/app/_services/LearningManagement/lms.service' ;
import { EnumAccessLevel , EnumContentType , EnumDifficultyLevel , EnumFileType , EnumStatus , EnumTemplateType } from 'src/app/_models/enums' ;
import { CourseType } from 'src/app/_models/LearningManagement/course-type' ;
import { LMSTemplate } from 'src/app/_models/LearningManagement/lmstemplate' ;
@Component ( {
selector : 'app-courses-entry' ,
templateUrl : './courses-entry.component.html' ,
styleUrls : [ './courses-entry.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.Eager ,
standalone : false ,
} )
export class CoursesEntryComponent implements OnInit {
constructor ( public apiService : ApiService ,
private datatransferservice : DataTransferService ,
private router : Router , public notificationService : HRMNotificationService ,
public loadingpanelService : loadingPanelService , public lmsService : LMSService ) {
this . apiService . selectedMenuName = "Course Entry" ;
}
whomForThisCoursetext : string = "" ;
whatWillLearntext : string = "" ;
howDoStartText : string = "" ;
courseIncludeText : string = "" ;
whomForThisCourses : any [ ] = [ ] ;
whatWillLearns : any [ ] = [ ] ;
howDoStarts : any [ ] = [ ] ;
courseIncludes : any [ ] = [ ] ;
templateFile : any ;
templateCurrentFile :any
templateFileTobase64 : string ;
templateFileName : string ;
selectedEmployee : SearchEmployee ;
isShowNewContent : boolean = false ;
isShowNewLesson : boolean = false ;
oCourse : Courses ;
oLesson : Lessons = new Lessons ( ) ;
oLessonContent : LessonContent = new LessonContent ( ) ;
allCourseType : CourseType [ ] = [ ] ;
displayAttachment : boolean ;
fileType = '' ;
fileData : any ;
difficultyLevelList : any [ ] = [ ] ;
contentTypeList : any [ ] = [ ] ;
accessLevelList : any [ ] = [ ] ;
ngOnInit ( ) : void {
this . oCourse = this . datatransferservice . getData ( ) ;
this . loadCourseType ( EnumStatus . Active ) ;
if ( this . oCourse !== undefined && this . oCourse . id > 0 ) {
this . loadCoursesData ( ) ;
}
else if ( this . oCourse === undefined ) {
this . onBack ( ) ;
}
else {
this . oCourse = new Courses ( ) ;
}
}
loadCourseType ( status : EnumStatus ) {
this . loadingpanelService . ShowLoadingPanel = true ;
this . lmsService . GetCourseTypeByStatus ( status ) . subscribe (
( resp : any ) = > {
this . allCourseType = resp ;
} ,
( err : any ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
} ,
( ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . difficultyLevelList = [ { name : 'Beginner' , value : EnumDifficultyLevel.Beginner } ,
{ name : 'Advanced' , value : EnumDifficultyLevel.Advanced } ,
{ name : 'Intermediate' , value : EnumDifficultyLevel.Intermediate } ] ;
this . contentTypeList = [ { name : 'Video' , value : EnumContentType.Video } ,
{ name : 'Pdf' , value : EnumContentType.Pdf } ,
{ name : 'Doc' , value : EnumContentType.Doc } ,
{ name : 'Powerpoint' , value : EnumContentType.Powerpoint } ,
{ name : 'Image' , value : EnumContentType.Image } ,
{ name : 'Excel' , value : EnumContentType.Excel } ,
{ name : 'others' , value : EnumContentType.others }
] ;
this . accessLevelList = [ { name : 'Public' , value : EnumAccessLevel.Public } ,
{ name : 'Private' , value : EnumAccessLevel.Private } ,
{ name : 'Restricted' , value : EnumAccessLevel.Restricted } ,
{ name : 'Premium' , value : EnumAccessLevel.Premium } ,
]
}
) ;
}
loadCoursesData ( ) {
this . loadingpanelService . ShowLoadingPanel = true ;
this . lmsService . GetCourse ( this . oCourse . id ) . subscribe (
( resp : any ) = > {
this . oCourse = undefined ;
this . oCourse = resp ;
} ,
( err : any ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
} ,
( ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
if ( this . oCourse !== undefined && this . oCourse . id > 0 ) {
//#region SET DATA
if ( this . oCourse . targetedAudience !== undefined && this . oCourse . targetedAudience !== "" ) {
this . oCourse . targetedAudience . split ( /, (?=\d+\.)/g ) . forEach ( item = > {
const [ serial , . . . descriptionParts ] = item . split ( '.' ) ;
this . whomForThisCourses . push ( {
serial : parseInt ( serial . trim ( ) , 10 ) ,
targetAudience : descriptionParts.join ( '.' ) . trim ( )
} ) ;
} ) ;
}
if ( this . oCourse . learningOutcomes !== undefined && this . oCourse . learningOutcomes !== "" ) {
this . oCourse . learningOutcomes . split ( /, (?=\d+\.)/g ) . forEach ( item = > {
const [ serial , . . . descriptionParts ] = item . split ( '.' ) ;
this . whatWillLearns . push ( {
serial : parseInt ( serial . trim ( ) , 10 ) ,
learningOutcome : descriptionParts.join ( '.' ) . trim ( )
} ) ;
} ) ;
}
if ( this . oCourse . startGuideLine !== undefined && this . oCourse . startGuideLine !== "" ) {
this . oCourse . startGuideLine . split ( /, (?=\d+\.)/g ) . forEach ( item = > {
const [ serial , . . . descriptionParts ] = item . split ( '.' ) ;
this . howDoStarts . push ( {
serial : parseInt ( serial . trim ( ) , 10 ) ,
startGuideLine : descriptionParts.join ( '.' ) . trim ( )
} ) ;
} ) ;
}
if ( this . oCourse . courseIncludes !== undefined && this . oCourse . courseIncludes !== "" ) {
this . oCourse . courseIncludes . split ( /, (?=\d+\.)/g ) . forEach ( item = > {
const [ serial , . . . descriptionParts ] = item . split ( '.' ) ;
this . courseIncludes . push ( {
serial : parseInt ( serial . trim ( ) , 10 ) ,
courseInclude : descriptionParts.join ( '.' ) . trim ( )
} ) ;
} ) ;
}
//#endregion
2026-11-23 11:49:34 +06:00
;
2026-11-03 13:06:00 +06:00
//#region FOR Template
if ( this . oCourse . courseTemplate !== undefined ) {
this . oCourse . courseTemplate . fileData = this . oCourse . courseTemplate . fileTobase64 ;
}
//#endregion
}
}
) ;
}
onBack ( ) {
this . router . navigateByUrl ( '/lms/courses' ) ;
}
onSave ( ) {
2026-11-23 11:49:34 +06:00
;
2026-11-03 13:06:00 +06:00
if ( this . oCourse . courseTitle === "" ) {
this . notificationService . showWarning ( "Please enter Course Title." , "Warning!" ) ;
return ;
}
if ( this . oCourse . courseCode === "" ) {
this . notificationService . showWarning ( "Please enter Course Code." , "Warning!" ) ;
return ;
}
if ( this . oCourse . courseTypeID === undefined ) {
this . notificationService . showWarning ( "Please select a Course type" , "Warning!" ) ;
return ;
}
if ( this . oCourse . trainerID === undefined || this . oCourse . trainerID === 0 ) {
this . notificationService . showWarning ( "Please select a Trainer." , "Warning!" ) ;
return ;
}
if ( this . oCourse . difficultyLevel === undefined || this . oCourse . trainerID === 0 ) {
this . notificationService . showWarning ( "Please select a Difficulty Level." , "Warning!" ) ;
return ;
}
if ( this . oCourse . courseTemplate === undefined || this . oCourse . courseTemplate . fileName === "" ) {
this . notificationService . showWarning ( "Please select Course Template." , "Warning!" ) ;
return ;
}
if ( this . oCourse . targetedAudience === "" ) {
this . notificationService . showWarning ( "Please specify the intended audience for this course." , "Warning!" ) ;
return ;
}
if ( this . oCourse . learningOutcomes === "" ) {
this . notificationService . showWarning ( "Please specify the learning outcomes for this course." , "Warning!" ) ;
return ;
}
if ( this . oCourse . startGuideLine === "" ) {
this . notificationService . showWarning ( "Please specify the course start guidelines." , "Warning!" ) ;
return ;
}
if ( this . oCourse . courseIncludes === "" ) {
this . notificationService . showWarning ( "Please list what is included in this course." , "Warning!" ) ;
return ;
}
if ( this . oCourse . lessons === undefined || this . oCourse . lessons . length === 0 ) {
this . notificationService . showWarning ( "Please create lesson's for this course" , "Warning!" ) ;
return ;
}
let description = "" ;
if ( this . oCourse !== undefined && this . oCourse . id === 0 ) {
description = "save" ;
}
if ( this . oCourse !== undefined && this . oCourse . id > 0 ) {
description = "edit" ;
}
this . notificationService . showActiveConfirm ( 'Confirmation' , "Are you sure you want to " + description + " this course? Make sure you've double-checked everything before " + ( description === "save" ? "saving" : "editing" ) + "!" ) . then ( ( isConfirmed ) = > {
if ( isConfirmed )
{
this . lmsService . saveCourses ( this . oCourse ) . subscribe (
( resp : any ) = > {
} ,
( err : any ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . notificationService . showError ( err . error ) ;
} ,
( ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
if ( this . oCourse . id > 0 ) {
this . notificationService . showSuccess ( "Updated successfully" ) ;
}
else {
this . notificationService . showSuccess ( "Save successfully." ) ;
}
this . onBack ( ) ;
} ) ;
}
else {
}
} ) ;
}
GetSelectedEmployee ( selectedEmp : SearchEmployee ) {
if ( selectedEmp !== undefined ) {
this . oCourse . trainerID = selectedEmp . employeeID ;
}
else {
this . oCourse . trainerID = 0 ;
}
}
//#region FOR LIST
whomForThisCourse ( ) {
if ( this . whomForThisCoursetext === "" || this . whomForThisCoursetext === undefined ) {
this . notificationService . showWarning ( "Please enter targeted audience." , "Warning!" ) ;
return ;
}
else {
if ( this . whomForThisCourses . length > 0 ) {
const data = this . whomForThisCourses . find ( x = > x . targetAudience . toLowerCase ( ) === this . whomForThisCoursetext . toLowerCase ( ) ) ;
if ( data !== undefined ) {
this . notificationService . showWarning ( "This type of audience has already been added." , "Warning!" ) ;
return ;
}
}
this . whomForThisCourses . push ( { serial :this.whomForThisCourses.length + 1 , targetAudience : this.whomForThisCoursetext } ) ;
this . setData ( "targetedAudience" ) ;
this . whomForThisCoursetext = '' ;
}
}
whatWillLearn ( ) {
if ( this . whatWillLearntext === "" || this . whatWillLearntext === undefined ) {
this . notificationService . showWarning ( "Please enter learning outcomes." , "Warning!" ) ;
return ;
}
else {
if ( this . whatWillLearns . length > 0 ) {
const data = this . whatWillLearns . find ( x = > x . learningOutcome . toLowerCase ( ) === this . whatWillLearntext . toLowerCase ( ) ) ;
if ( data !== undefined ) {
this . notificationService . showWarning ( "This type of learning outcome has already been added." , "Warning!" ) ;
return ;
}
}
this . whatWillLearns . push ( { serial :this.whatWillLearns.length + 1 , learningOutcome : this.whatWillLearntext } ) ;
this . setData ( "learningOutcomes" ) ;
this . whatWillLearntext = '' ;
}
}
howDoStart ( ) {
if ( this . howDoStartText === "" || this . howDoStartText === undefined ) {
this . notificationService . showWarning ( "Please enter starting steps for this course." , "Warning!" ) ;
return ;
}
else {
if ( this . howDoStarts . length > 0 ) {
const data = this . howDoStarts . find ( x = > x . startGuideLine . toLowerCase ( ) === this . howDoStartText . toLowerCase ( ) ) ;
if ( data !== undefined ) {
this . notificationService . showWarning ( "This type of guideline has already been added." , "Warning!" ) ;
return ;
}
}
this . howDoStarts . push ( { serial :this.howDoStarts.length + 1 , startGuideLine : this.howDoStartText } ) ;
this . setData ( "startGuideLine" ) ;
this . howDoStartText = '' ;
}
}
courseInclude ( ) {
if ( this . courseIncludeText === "" || this . courseIncludeText === undefined ) {
this . notificationService . showWarning ( "Please enter included course." , "Warning!" ) ;
return ;
}
else {
if ( this . courseIncludes . length != 0 ) {
const data = this . courseIncludes . find ( x = > x . courseInclude . toLowerCase ( ) === this . courseIncludeText . toLowerCase ( ) ) ;
if ( data !== undefined ) {
this . notificationService . showWarning ( "This type of audience has already been added." , "Warning!" ) ;
return ;
}
}
this . courseIncludes . push ( { serial :this.courseIncludes.length + 1 , courseInclude : this.courseIncludeText } ) ;
this . setData ( "courseIncludes" ) ;
this . courseIncludeText = '' ;
}
}
deletewhomForThisCourse ( dataItem : any ) {
const index = this . whomForThisCourses . findIndex ( i = > i . targetAudience === dataItem . targetAudience ) ;
if ( index > - 1 ) {
this . whomForThisCourses . splice ( index , 1 ) ;
this . setData ( "targetedAudience" ) ;
}
}
deletewhatWillLearn ( dataItem : any ) {
const index = this . whatWillLearns . findIndex ( i = > i . learningOutcome === dataItem . learningOutcome ) ;
if ( index > - 1 ) {
this . whatWillLearns . splice ( index , 1 ) ;
this . setData ( "learningOutcomes" ) ;
}
}
deletehowDoStart ( dataItem : any ) {
const index = this . howDoStarts . findIndex ( i = > i . startGuideLine === dataItem . startGuideLine ) ;
if ( index > - 1 ) {
this . howDoStarts . splice ( index , 1 ) ;
this . setData ( "startGuideLine" ) ;
}
}
deletecourseInclude ( dataItem : any ) {
const index = this . courseIncludes . findIndex ( i = > i . courseInclude === dataItem . courseInclude ) ;
if ( index > - 1 ) {
this . courseIncludes . splice ( index , 1 ) ;
this . setData ( "courseIncludes" ) ;
}
}
setData ( type : string ) {
2026-11-23 11:49:34 +06:00
;
2026-11-03 13:06:00 +06:00
if ( type === "targetedAudience" ) {
if ( this . oCourse !== undefined ) {
this . oCourse . targetedAudience = "" ;
this . oCourse . targetedAudience = this . whomForThisCourses . map ( x = > ` ${ x . serial } . ${ x . targetAudience } ` ) . join ( ', ' ) ;
}
}
if ( type === "learningOutcomes" ) {
if ( this . oCourse !== undefined ) {
this . oCourse . learningOutcomes = "" ;
this . oCourse . learningOutcomes = this . whatWillLearns . map ( x = > ` ${ x . serial } . ${ x . learningOutcome } ` ) . join ( ', ' ) ;
}
}
if ( type === "startGuideLine" ) {
if ( this . oCourse !== undefined ) {
this . oCourse . startGuideLine = "" ;
this . oCourse . startGuideLine = this . howDoStarts . map ( x = > ` ${ x . serial } . ${ x . startGuideLine } ` ) . join ( ', ' ) ;
}
}
if ( type === "courseIncludes" ) {
if ( this . oCourse !== undefined ) {
this . oCourse . courseIncludes = "" ;
this . oCourse . courseIncludes = this . courseIncludes . map ( x = > ` ${ x . serial } . ${ x . courseInclude } ` ) . join ( ', ' ) ;
}
}
}
//#endregion
//#endregion For Template
selectTemplatenHandler ( e : any ) {
var selectedFiles = e . target . files ;
let fileType = ( '.' + selectedFiles [ 0 ] . name . substring ( selectedFiles [ 0 ] . name . lastIndexOf ( '.' ) + 1 ) ) . toLowerCase ( ) ;
if ( fileType === '.jpg' || fileType === '.png' || fileType === '.jpeg' ) {
this . getBase64 ( selectedFiles [ 0 ] ) . then (
data = > {
//console.log(data);
this . templateFileTobase64 = data . toString ( ) ;
this . templateCurrentFile = selectedFiles [ 0 ] ;
this . templateFileName = selectedFiles [ 0 ] . name ;
this . oCourse . courseTemplate = new LMSTemplate ( ) ;
this . oCourse . courseTemplate . fileName = this . templateFileName ;
this . oCourse . courseTemplate . fileData = this . templateFileTobase64 ;
this . oCourse . courseTemplate . currentFile = this . templateCurrentFile ;
this . oCourse . courseTemplate . templateType = EnumTemplateType . Course ;
} ,
( ) = > {
}
) ;
}
else {
this . notificationService . showWarning ( 'The selected file type is not allowed. Please upload a file in one of the following formats: JPG, JPEG, PNG' , 'Warning!' ) ;
this . templateClear ( ) ;
return ;
}
}
templateClear() {
this . templateCurrentFile = undefined ;
this . templateFile = undefined ;
this . templateFileTobase64 = undefined ;
this . templateFileName = undefined ;
this . oCourse . courseTemplate = new LMSTemplate ( ) ;
}
getBase64 ( file : Blob ) {
return new Promise ( ( resolve , reject ) = > {
const reader = new FileReader ( ) ;
reader . readAsDataURL ( file ) ;
reader . onload = ( ) = > resolve ( reader . result ) ;
reader . onerror = error = > reject ( error ) ;
} ) ;
}
showAttachment ( ) {
if ( this . oCourse !== undefined && this . oCourse . id === 0 && this . oCourse . courseTemplate . fileName !== "" ) {
this . showCourseTemplate ( this . oCourse . courseTemplate ) ;
}
if ( this . oCourse !== undefined && this . oCourse . id > 0 && this . oCourse . courseTemplate . fileName !== "" ) {
this . showCourseTemplate ( this . oCourse . courseTemplate ) ;
}
}
showCourseTemplate ( item : LMSTemplate ) {
2026-11-23 11:49:34 +06:00
;
2026-11-03 13:06:00 +06:00
this . displayAttachment = true ;
if ( item . templateID > 0 ) {
this . fileData = item . fileTobase64 ;
} else {
this . fileData = item . fileData . split ( ',' ) . pop ( ) ;
}
const type = item . fileName . split ( '.' ) . pop ( ) ;
if ( type === 'png' || type === 'jpg' || type === 'jpeg' ) {
this . fileType = 'image' ;
}
else if ( type === 'pdf' ) {
this . fileType = 'pdf' ;
}
}
cloasDisplayAttachment ( ) {
this . displayAttachment = false ;
}
//#endregion
//#region For Lesson
isLessonEdit : boolean = false ;
lessonIndex : number = - 1 ;
addNewLesson ( ) {
this . isLessonEdit = false ;
this . lessonIndex = - 1 ;
this . oLesson = new Lessons ( ) ;
this . oLesson . lessonNo = this . generateLessonNO ( this . oCourse . lessons ) ;
this . isShowNewLesson = true ;
}
onAddNewLessonClose ( ) {
this . isShowNewLesson = false ;
this . oLesson = new Lessons ( ) ;
this . oLessonContent = new LessonContent ( ) ;
}
addLesson ( ) {
if ( this . oLesson . lessonTitle === "" ) {
this . notificationService . showWarning ( "Please enter Lesson Title." , "Warning!" ) ;
return ;
}
if ( this . oLesson . lessonNo === "" ) {
this . notificationService . showWarning ( "Please enter Lesson Number." , "Warning!" ) ;
return ;
}
if ( this . oLesson . difficultyLevel === undefined ) {
this . notificationService . showWarning ( "Please select a Difficulty Level." , "Warning!" ) ;
return ;
}
if ( this . oLesson . description === "" ) {
this . notificationService . showWarning ( "Please enter Lesson's Description." , "Warning!" ) ;
return ;
}
if ( this . oLesson . lessonContents === undefined || this . oLesson . lessonContents . length === 0 ) {
this . notificationService . showWarning ( "Please enter lesson content." , "Warning!" ) ;
return ;
}
if ( this . isLessonEdit === false ) {
this . notificationService . showActiveConfirm ( 'Confirmation' , "Are you sure tou want to add this lesson for this Course?" ) . then ( ( isConfirmed ) = > {
if ( isConfirmed )
{
if ( this . oCourse !== undefined && this . oCourse . lessons !== undefined ) {
this . oCourse . lessons . push ( this . oLesson ) ;
}
this . onAddNewLessonClose ( ) ;
}
else {
}
} ) ;
}
else {
if ( this . lessonIndex > - 1 ) {
this . oCourse . lessons [ this . lessonIndex ] = this . oLesson ;
}
this . onAddNewLessonClose ( ) ;
}
}
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 ;
}
editLesson ( olesson : Lessons ) {
this . isLessonEdit = true ;
this . lessonIndex = this . oCourse . lessons . findIndex ( i = > i . lessonTitle === olesson . lessonTitle ) ; ;
this . oLesson = olesson ;
this . isShowNewLesson = true ;
}
deleteLesson ( olesson : Lessons ) {
this . notificationService . showActiveConfirm ( 'Confirmation' , "Are you sure you want to delete this Lesson?" ) . then ( ( isConfirmed ) = > {
if ( isConfirmed )
{
if ( olesson . id > 0 ) {
this . lmsService . deleteLessons ( olesson . id ) . subscribe (
( resp : any ) = > {
} ,
( err : any ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . notificationService . showError ( err . error ) ;
} ,
( ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . notificationService . showSuccess ( "Lesson deleted successfully." ) ;
this . loadCoursesData ( ) ;
} ) ;
}
else {
const index = this . oCourse . lessons . findIndex ( i = > i . lessonTitle === olesson . lessonTitle ) ;
if ( index > - 1 ) {
this . oCourse . lessons . splice ( index , 1 ) ;
}
}
}
else {
}
} ) ;
}
generateLessonNO ( lessons : Lessons [ ] ) : string {
if ( lessons . length === 0 ) {
return 'Lesson 01' ;
}
const lastLesson = lessons [ lessons . length - 1 ] ;
const lastLessonNo = parseInt ( lastLesson . lessonNo . split ( ' ' ) [ 1 ] , 10 ) ;
const nextLessonNo = lastLessonNo + 1 ;
const paddedLessonNo = nextLessonNo . toString ( ) . padStart ( 2 , '0' ) ;
return ` Lesson ${ paddedLessonNo } ` ;
}
//#endregion
//#region For Lesson's Content
isLessonContentEdit : boolean = false ;
lessonContentIndex : number = - 1 ;
addNewContent ( ) {
this . isLessonContentEdit = false ;
this . lessonContentIndex = - 1 ;
this . oLessonContent = new LessonContent ( ) ;
this . isShowNewContent = true ;
}
addNewContentClose ( ) {
this . isShowNewContent = false ;
this . oLessonContent = new LessonContent ( ) ;
}
addContent ( ) {
if ( this . oLessonContent . contentTitle === "" ) {
this . notificationService . showWarning ( "Please enter Content Title." , "Warning!" ) ;
return ;
}
if ( this . oLessonContent . contentType === undefined ) {
this . notificationService . showWarning ( "Please select a Content Type." , "Warning!" ) ;
return ;
}
if ( this . oLessonContent . contentUrl === "" ) {
this . notificationService . showWarning ( "Please enter correct Content URL." , "Warning!" ) ;
return ;
}
if ( this . oLessonContent . accessLevel === undefined ) {
this . notificationService . showWarning ( "Please select an Access Level." , "Warning!" ) ;
return ;
}
if ( this . oLessonContent . description === "" ) {
this . notificationService . showWarning ( "Please enter Content Description." , "Warning!" ) ;
return ;
}
if ( this . isLessonContentEdit === false ) {
this . notificationService . showActiveConfirm ( 'Confirmation' , "Are you sure tou want to add this content for this lesson?" ) . then ( ( isConfirmed ) = > {
if ( isConfirmed )
{
2026-11-23 11:49:34 +06:00
;
2026-11-03 13:06:00 +06:00
if ( this . oLesson !== undefined && this . oLesson . lessonContents !== undefined ) {
this . oLesson . lessonContents . push ( this . oLessonContent ) ;
}
this . addNewContentClose ( ) ;
}
else {
}
} ) ;
}
else {
if ( this . lessonContentIndex > - 1 ) {
this . oLesson . lessonContents [ this . lessonContentIndex ] = this . oLessonContent ;
}
this . addNewContentClose ( ) ;
}
}
getContentTypeString ( type : EnumContentType ) : string {
let contentType : string = "" ;
switch ( type ) {
case EnumContentType . Video :
contentType = "Video" ;
break ;
case EnumContentType . Doc :
contentType = "Doc" ;
break ;
case EnumContentType . Image :
contentType = "Image" ;
break ;
case EnumContentType . Excel :
contentType = "Excel" ;
break ;
case EnumContentType . Powerpoint :
contentType = "Powerpoint" ;
break ;
case EnumContentType . Pdf :
contentType = "Pdf" ;
break ;
default :
contentType = "" ;
}
return contentType ;
}
editLessonContent ( olessonContent : LessonContent ) {
this . isLessonContentEdit = true ;
this . lessonContentIndex = this . oLesson . lessonContents . findIndex ( i = > i . contentTitle === olessonContent . contentTitle ) ;
this . oLessonContent = olessonContent ;
this . isShowNewContent = true ;
}
deleteLessonContent ( olessonContent : LessonContent ) {
this . notificationService . showActiveConfirm ( 'Confirmation' , "Are you sure you want to delete this Lesson's Content?" ) . then ( ( isConfirmed ) = > {
if ( isConfirmed )
{
if ( olessonContent . id > 0 ) {
this . lmsService . deleteLessonContent ( olessonContent . id ) . subscribe (
( resp : any ) = > {
} ,
( err : any ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . notificationService . showError ( err . error ) ;
} ,
( ) = > {
this . loadingpanelService . ShowLoadingPanel = false ;
this . notificationService . showSuccess ( "Lesson Content deleted successfully." ) ;
this . loadCoursesData ( ) ;
} ) ;
}
else {
const index = this . oLesson . lessonContents . findIndex ( i = > i . contentTitle === olessonContent . contentTitle ) ;
if ( index > - 1 ) {
this . oLesson . lessonContents . splice ( index , 1 ) ;
}
}
}
else {
}
} ) ;
}
//#endregion
}