mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Adding / removal of parents in UI
This commit is contained in:
		@@ -14,6 +14,7 @@
 | 
				
			|||||||
          [addTag]="allowCreate ? createTagRef : false"
 | 
					          [addTag]="allowCreate ? createTagRef : false"
 | 
				
			||||||
          addTagText="Add tag"
 | 
					          addTagText="Add tag"
 | 
				
			||||||
          i18n-addTagText
 | 
					          i18n-addTagText
 | 
				
			||||||
 | 
					          (add)="onAdd($event)"
 | 
				
			||||||
          (change)="onChange(value)">
 | 
					          (change)="onChange(value)">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <ng-template ng-label-tmp let-item="item">
 | 
					          <ng-template ng-label-tmp let-item="item">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,13 +129,40 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let index = this.value.indexOf(id)
 | 
					    let index = this.value.indexOf(id)
 | 
				
			||||||
    if (index > -1) {
 | 
					    if (index > -1) {
 | 
				
			||||||
 | 
					      const tag = this.getTag(id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // remove tag
 | 
				
			||||||
      let oldValue = this.value
 | 
					      let oldValue = this.value
 | 
				
			||||||
      oldValue.splice(index, 1)
 | 
					      oldValue.splice(index, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // remove children
 | 
				
			||||||
 | 
					      oldValue = this.removeChildren(oldValue, tag)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      this.value = [...oldValue]
 | 
					      this.value = [...oldValue]
 | 
				
			||||||
      this.onChange(this.value)
 | 
					      this.onChange(this.value)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private removeChildren(tagIDs: number[], tag: Tag) {
 | 
				
			||||||
 | 
					    if (tag.children.length > 0) {
 | 
				
			||||||
 | 
					      const childIDs = tag.children.map((child) => child.id)
 | 
				
			||||||
 | 
					      tagIDs = tagIDs.filter((id) => !childIDs.includes(id))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for (const child of tag.children) {
 | 
				
			||||||
 | 
					      tagIDs = this.removeChildren(tagIDs, child)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return tagIDs
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public onAdd(tag: Tag) {
 | 
				
			||||||
 | 
					    if (tag.parent) {
 | 
				
			||||||
 | 
					      // add all parents recursively
 | 
				
			||||||
 | 
					      const parent = this.getTag(tag.parent)
 | 
				
			||||||
 | 
					      this.value = [...this.value, parent.id]
 | 
				
			||||||
 | 
					      this.onAdd(parent)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createTag(name: string = null) {
 | 
					  createTag(name: string = null) {
 | 
				
			||||||
    var modal = this.modalService.open(TagEditDialogComponent, {
 | 
					    var modal = this.modalService.open(TagEditDialogComponent, {
 | 
				
			||||||
      backdrop: 'static',
 | 
					      backdrop: 'static',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user