a new tag editor fixes #20

also: discard document changes button
This commit is contained in:
Jonas Winkler
2020-11-04 17:23:36 +01:00
parent 14f42b8b7a
commit c330a72188
8 changed files with 179 additions and 57 deletions

View File

@@ -33,7 +33,6 @@ export class DocumentDetailComponent implements OnInit {
correspondents: PaperlessCorrespondent[]
documentTypes: PaperlessDocumentType[]
tags: PaperlessTag[]
documentForm: FormGroup = new FormGroup({
title: new FormControl(''),
@@ -50,7 +49,6 @@ export class DocumentDetailComponent implements OnInit {
private route: ActivatedRoute,
private correspondentService: CorrespondentService,
private documentTypeService: DocumentTypeService,
private tagService: TagService,
private datePipe: DatePipe,
private router: Router,
private modalService: NgbModal,
@@ -64,7 +62,6 @@ export class DocumentDetailComponent implements OnInit {
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)
this.route.paramMap.subscribe(paramMap => {
this.documentId = +paramMap.get('id')
@@ -88,17 +85,6 @@ export class DocumentDetailComponent implements OnInit {
this.documentForm.patchValue(doc)
}
createTag() {
var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
modal.componentInstance.success.subscribe(newTag => {
this.tagService.list().subscribe(tags => {
this.tags = tags.results
this.documentForm.get('tags_id').setValue(this.documentForm.get('tags_id').value.concat([newTag.id]))
})
})
}
createDocumentType() {
var modal = this.modalService.open(DocumentTypeEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
@@ -121,28 +107,14 @@ export class DocumentDetailComponent implements OnInit {
})
}
getTag(id: number): PaperlessTag {
return this.tags.find(tag => tag.id == id)
discard() {
this.documentsService.get(this.documentId).subscribe(doc => {
Object.assign(this.document, doc)
this.title = doc.title
this.documentForm.patchValue(doc)
}, error => {this.router.navigate(['404'])})
}
getColour(id: number) {
return TAG_COLOURS.find(c => c.id == this.getTag(id).colour)
}
addTag(id: number) {
if (this.documentForm.value.tags.indexOf(id) == -1) {
this.documentForm.value.tags.push(id)
}
}
removeTag(id: number) {
let index = this.documentForm.value.tags.indexOf(id)
if (index > -1) {
this.documentForm.value.tags.splice(index, 1)
}
}
save() {
this.documentsService.update(this.document).subscribe(result => {
this.close()