fixed date editing, fixes #10

This commit is contained in:
Jonas Winkler
2020-11-04 13:10:23 +01:00
parent 8dd773e059
commit a8c0307d54
7 changed files with 127 additions and 38 deletions

View File

@@ -32,16 +32,7 @@
formControlName='archive_serial_number'>
</div>
<div class="form-row">
<div class="form-group col">
<label for="created_date">Date created</label>
<input type="date" class="form-control" id="created_date" formControlName='created_date'>
</div>
<div class="form-group col">
<label for="created_time">Time created</label>
<input type="time" class="form-control" id="created_time" formControlName='created_time'>
</div>
</div>
<app-input-date-time title="Date created" titleTime="Time created" formControlName="created"></app-input-date-time>
<div class="form-group">
<label for="content">Content</label>

View File

@@ -38,8 +38,7 @@ export class DocumentDetailComponent implements OnInit {
documentForm: FormGroup = new FormGroup({
title: new FormControl(''),
content: new FormControl(''),
created_date: new FormControl(),
created_time: new FormControl(),
created: new FormControl(),
correspondent_id: new FormControl(),
document_type_id: new FormControl(),
archive_serial_number: new FormControl(),
@@ -59,6 +58,10 @@ export class DocumentDetailComponent implements OnInit {
private documentListViewService: DocumentListViewService) { }
ngOnInit(): void {
this.documentForm.valueChanges.subscribe(wow => {
Object.assign(this.document, this.documentForm.value)
})
this.correspondentService.list(1,100000).subscribe(result => this.correspondents = result.results)
this.documentTypeService.list(1,100000).subscribe(result => this.documentTypes = result.results)
this.tagService.list(1,100000).subscribe(result => this.tags = result.results)
@@ -67,18 +70,24 @@ export class DocumentDetailComponent implements OnInit {
this.documentId = +paramMap.get('id')
this.previewUrl = this.documentsService.getPreviewUrl(this.documentId)
this.downloadUrl = this.documentsService.getDownloadUrl(this.documentId)
this.documentsService.get(this.documentId).subscribe(doc => {
this.openDocumentService.openDocument(doc)
this.document = doc
this.title = doc.title
this.documentForm.patchValue(doc)
this.documentForm.get('created_date').patchValue(this.datePipe.transform(doc.created, 'yyyy-MM-dd'))
this.documentForm.get('created_time').patchValue(this.datePipe.transform(doc.created, 'HH:mm:ss'))
}, error => {this.router.navigate(['404'])})
if (this.openDocumentService.getOpenDocument(this.documentId)) {
this.updateComponent(this.openDocumentService.getOpenDocument(this.documentId))
} else {
this.documentsService.get(this.documentId).subscribe(doc => {
this.openDocumentService.openDocument(doc)
this.updateComponent(doc)
}, error => {this.router.navigate(['404'])})
}
})
}
updateComponent(doc: PaperlessDocument) {
this.document = doc
this.title = doc.title
this.documentForm.patchValue(doc)
}
createTag() {
var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
@@ -133,29 +142,15 @@ export class DocumentDetailComponent implements OnInit {
}
}
getDateCreated() {
let newDate = this.documentForm.value.created_date
let newTime = this.documentForm.value.created_time
return formatDate(newDate + "T" + newTime,"yyyy-MM-ddTHH:mm:ssZZZZZ", "en-us", "UTC")
}
save() {
let newDocument = Object.assign(Object.assign({}, this.document), this.documentForm.value)
newDocument.created = this.getDateCreated()
this.documentsService.update(newDocument).subscribe(result => {
save() {
this.documentsService.update(this.document).subscribe(result => {
this.close()
})
}
saveEditNext() {
let newDocument = Object.assign(Object.assign({}, this.document), this.documentForm.value)
newDocument.created = this.getDateCreated()
this.documentsService.update(newDocument).subscribe(result => {
this.documentsService.update(this.document).subscribe(result => {
this.documentListViewService.getNext(this.document.id).subscribe(nextDocId => {
if (nextDocId) {
this.openDocumentService.closeDocument(this.document)