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 a8c0307d54
commit 4e904cf912
8 changed files with 179 additions and 57 deletions

View File

@@ -3,19 +3,19 @@
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#trash" />
</svg>
Delete
<span class="d-none d-lg-inline">Delete</span>
</button>
<a [href]="downloadUrl" class="btn btn-sm btn-outline-secondary mr-2">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#download" />
</svg>
Download
<span class="d-none d-lg-inline">Download</span>
</a>
<button type="button" class="btn btn-sm btn-outline-secondary" (click)="close()">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#x" />
</svg>
Close
<span class="d-none d-lg-inline">Close</span>
</button>
</app-page-header>
@@ -43,26 +43,9 @@
<app-input-select [items]="documentTypes" title="Document type" formControlName="document_type_id" allowNull="true" (createNew)="createDocumentType()"></app-input-select>
<div class="form-group">
<label for="exampleFormControlTextarea1">Tags</label>
<app-input-tags formControlName="tags_id" title="Tags"></app-input-tags>
<div class="input-group">
<select multiple class="form-control" id="tags" formControlName="tags_id">
<option *ngFor="let t of tags" [ngValue]="t.id">{{t.name}}</option>
</select>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" (click)="createTag()">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg>
</button>
</div>
</div>
<small class="form-text text-muted">Hold CTRL to (de)select multiple tags.</small>
</div>
<button type="button" class="btn btn-outline-secondary" (click)="discard()">Discard</button>&nbsp;
<button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()">Save & edit next</button>&nbsp;
<button type="submit" class="btn btn-primary">Save</button>&nbsp;
</form>

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()