@@ -39,6 +39,8 @@ export class EntryFormComponent implements OnInit {
3939 metaDescription : new FormControl ( '' , [ Validators . maxLength ( 160 ) ] ) ,
4040 excerpt : new FormControl ( '' , [ Validators . maxLength ( 300 ) ] ) ,
4141 tags : new FormControl ( '' ) ,
42+ author : new FormControl ( '' ) ,
43+ date : new FormControl ( '' ) ,
4244 content : new FormControl ( '' , [ Validators . required ] ) ,
4345 } ) ;
4446
@@ -70,6 +72,8 @@ export class EntryFormComponent implements OnInit {
7072 this . entryForm . controls [ 'metaDescription' ] . setValue ( blogInfo . metaDescription || '' ) ;
7173 this . entryForm . controls [ 'excerpt' ] . setValue ( blogInfo . excerpt || '' ) ;
7274 this . entryForm . controls [ 'tags' ] . setValue ( this . formatTagsForInput ( blogInfo . tags ) ) ;
75+ this . entryForm . controls [ 'author' ] . setValue ( ( blogInfo . author || '' ) . toString ( ) . trim ( ) ) ;
76+ this . entryForm . controls [ 'date' ] . setValue ( this . formatDateForInput ( blogInfo . date ) ) ;
7377 this . slugManuallyEdited = slugValue . length > 0 && slugValue !== this . slugify ( blogInfo . title || '' ) ;
7478 this . entryForm . controls [ 'content' ] . setValue ( blogInfo . content ) ;
7579 } else {
@@ -88,17 +92,22 @@ export class EntryFormComponent implements OnInit {
8892 return ;
8993 }
9094
91- let body = {
95+ const authorFromForm = this . normalizeOptionalText ( this . entryForm . controls [ 'author' ] . value ) ;
96+ const dateFromForm = this . normalizeOptionalText ( this . entryForm . controls [ 'date' ] . value ) ;
97+ let body :any = {
9298 title : this . entryForm . value . title ,
9399 slug : this . entryForm . value . slug ,
94100 featuredImage : this . getFeaturedImageUrl ( ) ,
95101 metaDescription : this . entryForm . value . metaDescription ,
96102 excerpt : this . entryForm . value . excerpt ,
97103 tags : this . parseTagsFromForm ( ) ,
98104 partyId : this . partyId ,
99- author : this . name ,
105+ author : authorFromForm || this . name ,
100106 content : this . entryForm . value . content ,
101107 }
108+ if ( dateFromForm ) {
109+ body . date = dateFromForm ;
110+ }
102111 //await lastValueFrom(this.domeBlogService.createBlogEntry(body))
103112 this . domeBlogService . createBlogEntry ( body ) . subscribe ( {
104113 next : data => {
@@ -128,7 +137,9 @@ export class EntryFormComponent implements OnInit {
128137 return ;
129138 }
130139
131- let body = {
140+ const authorFromForm = this . normalizeOptionalText ( this . entryForm . controls [ 'author' ] . value ) ;
141+ const dateFromForm = this . normalizeOptionalText ( this . entryForm . controls [ 'date' ] . value ) ;
142+ let body :any = {
132143 title : this . entryForm . value . title ,
133144 slug : this . entryForm . value . slug ,
134145 featuredImage : this . getFeaturedImageUrl ( ) ,
@@ -137,6 +148,12 @@ export class EntryFormComponent implements OnInit {
137148 tags : this . parseTagsFromForm ( ) ,
138149 content : this . entryForm . value . content
139150 }
151+ if ( authorFromForm ) {
152+ body . author = authorFromForm ;
153+ }
154+ if ( dateFromForm ) {
155+ body . date = dateFromForm ;
156+ }
140157 //await lastValueFrom(this.domeBlogService.createBlogEntry(body))
141158 try {
142159 await this . domeBlogService . updateBlogEntry ( body , this . blogId )
@@ -404,6 +421,32 @@ export class EntryFormComponent implements OnInit {
404421 return '' ;
405422 }
406423
424+ private normalizeOptionalText ( value : any ) : string {
425+ if ( value === null || value === undefined ) {
426+ return '' ;
427+ }
428+
429+ return value . toString ( ) . trim ( ) ;
430+ }
431+
432+ private formatDateForInput ( value : any ) : string {
433+ const rawDate = this . normalizeOptionalText ( value ) ;
434+ if ( ! rawDate ) {
435+ return '' ;
436+ }
437+
438+ if ( / ^ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } $ / . test ( rawDate ) ) {
439+ return rawDate ;
440+ }
441+
442+ const parsedDate = moment ( rawDate ) ;
443+ if ( ! parsedDate . isValid ( ) ) {
444+ return '' ;
445+ }
446+
447+ return parsedDate . format ( 'YYYY-MM-DDTHH:mm' ) ;
448+ }
449+
407450 private showTemporaryError ( message : string ) {
408451 this . errorMessage = message ;
409452 this . showError = true ;
0 commit comments