mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Merge pull request #654 from paperless-ngx/fix-doc-detail-time
Fix: frontend document editing erases time data
This commit is contained in:
		@@ -87,6 +87,8 @@ export class DocumentDetailComponent
 | 
			
		||||
  requiresPassword: boolean = false
 | 
			
		||||
  password: string
 | 
			
		||||
 | 
			
		||||
  ogDate: Date
 | 
			
		||||
 | 
			
		||||
  @ViewChild('nav') nav: NgbNav
 | 
			
		||||
  @ViewChild('pdfPreview') set pdfPreview(element) {
 | 
			
		||||
    // this gets called when compontent added or removed from DOM
 | 
			
		||||
@@ -142,7 +144,21 @@ export class DocumentDetailComponent
 | 
			
		||||
  ngOnInit(): void {
 | 
			
		||||
    this.documentForm.valueChanges
 | 
			
		||||
      .pipe(takeUntil(this.unsubscribeNotifier))
 | 
			
		||||
      .subscribe((wow) => {
 | 
			
		||||
      .subscribe((changes) => {
 | 
			
		||||
        if (this.ogDate) {
 | 
			
		||||
          let newDate = new Date(changes['created'])
 | 
			
		||||
          newDate.setHours(
 | 
			
		||||
            this.ogDate.getHours(),
 | 
			
		||||
            this.ogDate.getMinutes(),
 | 
			
		||||
            this.ogDate.getSeconds(),
 | 
			
		||||
            this.ogDate.getMilliseconds()
 | 
			
		||||
          )
 | 
			
		||||
          this.documentForm.patchValue(
 | 
			
		||||
            { created: this.formatDate(newDate) },
 | 
			
		||||
            { emitEvent: false }
 | 
			
		||||
          )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Object.assign(this.document, this.documentForm.value)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
@@ -183,17 +199,25 @@ export class DocumentDetailComponent
 | 
			
		||||
            this.updateComponent(doc)
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          this.ogDate = new Date(doc.created)
 | 
			
		||||
 | 
			
		||||
          // Initialize dirtyCheck
 | 
			
		||||
          this.store = new BehaviorSubject({
 | 
			
		||||
            title: doc.title,
 | 
			
		||||
            content: doc.content,
 | 
			
		||||
            created: doc.created,
 | 
			
		||||
            created: this.formatDate(this.ogDate),
 | 
			
		||||
            correspondent: doc.correspondent,
 | 
			
		||||
            document_type: doc.document_type,
 | 
			
		||||
            archive_serial_number: doc.archive_serial_number,
 | 
			
		||||
            tags: [...doc.tags],
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
          // ensure we're always starting with 24-char ISO8601 string
 | 
			
		||||
          this.documentForm.patchValue(
 | 
			
		||||
            { created: this.formatDate(this.ogDate) },
 | 
			
		||||
            { emitEvent: false }
 | 
			
		||||
          )
 | 
			
		||||
 | 
			
		||||
          this.isDirty$ = dirtyCheck(
 | 
			
		||||
            this.documentForm,
 | 
			
		||||
            this.store.asObservable()
 | 
			
		||||
@@ -461,4 +485,8 @@ export class DocumentDetailComponent
 | 
			
		||||
      this.password = (event.target as HTMLInputElement).value
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  formatDate(date: Date): string {
 | 
			
		||||
    return date.toISOString().split('.')[0] + 'Z'
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user