mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
add comment function
This commit is contained in:

committed by
Michael Shamoon

parent
c2fda245ac
commit
278e9c12e1
@@ -0,0 +1,25 @@
|
||||
<div *ngIf="comments">
|
||||
<form [formGroup]='commentForm'>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" id="newcomment" rows="5" formControlName='newcomment'></textarea>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" i18n [disabled]="networkActive" (click)="addComment()">add comment</button>
|
||||
</form>
|
||||
<hr>
|
||||
<div *ngFor="let comment of comments; trackBy: byId" [disableRipple]="true" class="card border-bg-primary bg-primary mb-3 comment-card" [attr.comment-id]="comment.id">
|
||||
<div class="d-flex card-header comment-card-header text-white justify-content-between">
|
||||
<span>{{comment?.user?.firstname}} {{comment?.user?.lastname}} ({{comment?.user?.username}}) - {{ comment?.created | customDate}}</span>
|
||||
<span>
|
||||
<a class="text-white" (click)="deleteComment($event)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
|
||||
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
|
||||
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
|
||||
</svg>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="card-body bg-white text-dark comment-card-body card-text">
|
||||
{{comment.comment}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -0,0 +1,22 @@
|
||||
.comment-card-body {
|
||||
padding-top: .8rem !important;
|
||||
padding-bottom: .8rem !important;
|
||||
max-height: 10rem;
|
||||
overflow: scroll;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.comment-card-header a {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 5px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.comment-card-header a:hover {
|
||||
background: #FFF;
|
||||
}
|
||||
|
||||
.comment-card-header a:hover svg {
|
||||
fill: var(--primary);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DocumentCommentComponent } from './document-comment.component';
|
||||
|
||||
describe('DocumentCommentComponent', () => {
|
||||
let component: DocumentCommentComponent;
|
||||
let fixture: ComponentFixture<DocumentCommentComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ DocumentCommentComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DocumentCommentComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -0,0 +1,63 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { DocumentDetailComponent } from 'src/app/components/document-detail/document-detail.component';
|
||||
import { DocumentCommentService } from 'src/app/services/rest/document-comment.service';
|
||||
import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment';
|
||||
|
||||
import { take } from 'rxjs/operators';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-document-comment',
|
||||
templateUrl: './document-comment.component.html',
|
||||
styleUrls: ['./document-comment.component.scss']
|
||||
})
|
||||
export class DocumentCommentComponent implements OnInit {
|
||||
|
||||
comments:PaperlessDocumentComment[];
|
||||
networkActive = false;
|
||||
documentId: number;
|
||||
commentForm: FormGroup = new FormGroup({
|
||||
newcomment: new FormControl('')
|
||||
})
|
||||
|
||||
constructor(
|
||||
private documentDetailComponent: DocumentDetailComponent,
|
||||
private documentCommentService: DocumentCommentService,
|
||||
) { }
|
||||
|
||||
byId(index, item: PaperlessDocumentComment) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
async ngOnInit(): Promise<any> {
|
||||
try {
|
||||
this.documentId = this.documentDetailComponent.documentId;
|
||||
this.comments= await this.documentCommentService.getComments(this.documentId).pipe(take(1)).toPromise();
|
||||
} catch(err){
|
||||
this.comments = [];
|
||||
}
|
||||
}
|
||||
|
||||
addComment(){
|
||||
this.networkActive = true
|
||||
this.documentCommentService.addComment(this.documentId, this.commentForm.get("newcomment").value).subscribe(result => {
|
||||
this.comments = result;
|
||||
this.commentForm.get("newcomment").reset();
|
||||
this.networkActive = false;
|
||||
}, error => {
|
||||
this.networkActive = false;
|
||||
});
|
||||
}
|
||||
|
||||
deleteComment(event){
|
||||
let parent = event.target.parentElement.closest('div[comment-id]');
|
||||
if(parent){
|
||||
this.documentCommentService.deleteComment(this.documentId, parseInt(parent.getAttribute("comment-id"))).subscribe(result => {
|
||||
this.comments = result;
|
||||
this.networkActive = false;
|
||||
}, error => {
|
||||
this.networkActive = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -169,6 +169,13 @@
|
||||
</div>
|
||||
</ng-template>
|
||||
</li>
|
||||
<li [ngbNavItem]="5" *ngIf="isCommentsEnabled">
|
||||
<a ngbNavLink i18n>Comments</a>
|
||||
<ng-template ngbNavContent>
|
||||
<app-document-comment #commentComponent></app-document-comment>
|
||||
</ng-template>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
||||
|
@@ -35,6 +35,7 @@ import { StoragePathService } from 'src/app/services/rest/storage-path.service'
|
||||
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
|
||||
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||
import { EnvironmentService } from 'src/app/services/rest/environment.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-document-detail',
|
||||
@@ -83,6 +84,8 @@ export class DocumentDetailComponent
|
||||
previewCurrentPage: number = 1
|
||||
previewNumPages: number = 1
|
||||
|
||||
isCommentsEnabled:boolean = false
|
||||
|
||||
store: BehaviorSubject<any>
|
||||
isDirty$: Observable<boolean>
|
||||
unsubscribeNotifier: Subject<any> = new Subject()
|
||||
@@ -118,7 +121,8 @@ export class DocumentDetailComponent
|
||||
private documentTitlePipe: DocumentTitlePipe,
|
||||
private toastService: ToastService,
|
||||
private settings: SettingsService,
|
||||
private storagePathService: StoragePathService
|
||||
private storagePathService: StoragePathService,
|
||||
private environment: EnvironmentService
|
||||
) {}
|
||||
|
||||
titleKeyUp(event) {
|
||||
@@ -274,6 +278,13 @@ export class DocumentDetailComponent
|
||||
this.suggestions = null
|
||||
},
|
||||
})
|
||||
|
||||
this.environment.get("PAPERLESS_COMMENTS_ENABLED").subscribe(result => {
|
||||
this.isCommentsEnabled = (result.value.toString().toLowerCase() === "true"?true:false);
|
||||
}, error => {
|
||||
this.isCommentsEnabled = false;
|
||||
})
|
||||
|
||||
this.title = this.documentTitlePipe.transform(doc.title)
|
||||
this.documentForm.patchValue(doc)
|
||||
}
|
||||
|
Reference in New Issue
Block a user