@@ -65,10 +65,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
6565 courseTitle : [
6666 '' ,
6767 Validators . required ,
68- // an arrow function is for lexically binding 'this' otherwise 'this' would be undefined
69- this . route . snapshot . url [ 0 ] . path === 'update'
70- ? ac => this . validatorService . isNameAvailible$ ( this . dbName , 'courseTitle' , ac , this . route . snapshot . params . id )
71- : ac => this . validatorService . isUnique$ ( this . dbName , 'courseTitle' , ac )
68+ this . courseTitleValidator ( this . route . snapshot . paramMap . get ( 'id' ) || this . coursesService . course . _id )
7269 ] ,
7370 description : [ '' , Validators . required ] ,
7471 languageOfInstruction : '' ,
@@ -90,6 +87,10 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
9087 } ) ;
9188 }
9289
90+ courseTitleValidator ( id : string = '' ) {
91+ return ac => this . validatorService . isUnique$ ( this . dbName , 'courseTitle' , ac , { selectors : { '_id' : { '$ne' : id } } } ) ;
92+ }
93+
9394 ngOnInit ( ) {
9495 if ( this . route . snapshot . url [ 0 ] . path === 'update' ) {
9596 this . couchService . get ( 'courses/' + this . route . snapshot . paramMap . get ( 'id' ) )
@@ -107,6 +108,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
107108 } ) ;
108109 }
109110 if ( this . route . snapshot . params . continue === 'true' ) {
111+ this . documentInfo = { '_rev' : this . coursesService . course . _rev , '_id' : this . coursesService . course . _id } ;
110112 this . setFormAndSteps ( this . coursesService . course ) ;
111113 this . submitAddedExam ( ) ;
112114 }
@@ -173,7 +175,9 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
173175 if ( shouldNavigate ) {
174176 this . navigateBack ( ) ;
175177 }
178+ this . courseForm . get ( 'courseTitle' ) . setAsyncValidators ( this . courseTitleValidator ( response . id ) ) ;
176179 this . documentInfo = { '_id' : response . id , '_rev' : response . rev } ;
180+ this . coursesService . course = { ...this . documentInfo } ;
177181 this . planetMessageService . showMessage ( message ) ;
178182 }
179183
0 commit comments