mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Just include comments on document object
This commit is contained in:
		| @@ -22,7 +22,41 @@ | ||||
|             "archived_file_name": "2022-03-22 no latin title.pdf", | ||||
|             "owner": null, | ||||
|             "permissions": [], | ||||
|             "n_comments": 3 | ||||
|             "comments": [ | ||||
|                 { | ||||
|                     "id": 30, | ||||
|                     "comment": "One more time", | ||||
|                     "created": "2023-03-17T22:02:14.357575Z", | ||||
|                     "user": { | ||||
|                         "id": 2, | ||||
|                         "username": "username", | ||||
|                         "first_name": "", | ||||
|                         "last_name": "" | ||||
|                     } | ||||
|                 }, | ||||
|                 { | ||||
|                     "id": 6, | ||||
|                     "comment": "Lets keep going", | ||||
|                     "created": "2023-03-16T06:57:32.014027Z", | ||||
|                     "user": { | ||||
|                         "id": 2, | ||||
|                         "username": "username", | ||||
|                         "first_name": "", | ||||
|                         "last_name": "" | ||||
|                     } | ||||
|                 }, | ||||
|                 { | ||||
|                     "id": 5, | ||||
|                     "comment": "And just one more", | ||||
|                     "created": "2023-03-16T06:57:27.022729Z", | ||||
|                     "user": { | ||||
|                         "id": 2, | ||||
|                         "username": "username", | ||||
|                         "first_name": "", | ||||
|                         "last_name": "" | ||||
|                     } | ||||
|                 } | ||||
|             ] | ||||
|         }, | ||||
|         { | ||||
|             "id": 2, | ||||
| @@ -41,7 +75,7 @@ | ||||
|             "archived_file_name": "2022-03-23 llorem ipsum dolor sit amet.pdf", | ||||
|             "owner": null, | ||||
|             "permissions": [], | ||||
|             "n_comments": 0 | ||||
|             "comments": [] | ||||
|         }, | ||||
|         { | ||||
|             "id": 3, | ||||
| @@ -62,7 +96,7 @@ | ||||
|             "archived_file_name": "2022-03-24 dolor.pdf", | ||||
|             "owner": null, | ||||
|             "permissions": [], | ||||
|             "n_comments": 0 | ||||
|             "comments": [] | ||||
|         }, | ||||
|         { | ||||
|             "id": 4, | ||||
| @@ -83,7 +117,7 @@ | ||||
|             "archived_file_name": "2022-06-01 sit amet.pdf", | ||||
|             "owner": null, | ||||
|             "permissions": [], | ||||
|             "n_comments": 0 | ||||
|             "comments": [] | ||||
|         } | ||||
|     ] | ||||
| } | ||||
|   | ||||
| @@ -2157,7 +2157,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">159</context> | ||||
|           <context context-type="linenumber">165</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/filter-editor/filter-editor.component.html</context> | ||||
| @@ -2364,14 +2364,14 @@ | ||||
|         <source>Error saving comment: <x id="PH" equiv-text="e.toString()"/></source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-comments/document-comments.component.ts</context> | ||||
|           <context context-type="linenumber">75</context> | ||||
|           <context context-type="linenumber">59</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="7593210124183303626" datatype="html"> | ||||
|         <source>Error deleting comment: <x id="PH" equiv-text="e.toString()"/></source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-comments/document-comments.component.ts</context> | ||||
|           <context context-type="linenumber">91</context> | ||||
|           <context context-type="linenumber">75</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="1407560924967345762" datatype="html"> | ||||
| @@ -2514,7 +2514,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">147</context> | ||||
|           <context context-type="linenumber">153</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/filter-editor/filter-editor.component.html</context> | ||||
| @@ -2537,7 +2537,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">153</context> | ||||
|           <context context-type="linenumber">159</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/filter-editor/filter-editor.component.html</context> | ||||
| @@ -2665,7 +2665,7 @@ | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="8403302283555274795" datatype="html"> | ||||
|         <source>Comments <x id="START_TAG_SPAN" ctype="x-span" equiv-text="<span *ngIf="document?.n_comments" class="badge text-bg-secondary ms-1">"/><x id="INTERPOLATION" equiv-text="ts}}"/><x id="CLOSE_TAG_SPAN" ctype="x-span" equiv-text="</a>"/></source> | ||||
|         <source>Comments <x id="START_TAG_SPAN" ctype="x-span" equiv-text="<span *ngIf="document?.comments.length" class="badge text-bg-secondary ms-1">"/><x id="INTERPOLATION" equiv-text=".length}}"/><x id="CLOSE_TAG_SPAN" ctype="x-span" equiv-text="</a>"/></source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.html</context> | ||||
|           <context context-type="linenumber">175,176</context> | ||||
| @@ -2689,32 +2689,32 @@ | ||||
|         <source>Error retrieving metadata</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">340</context> | ||||
|           <context context-type="linenumber">341</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="2374084708811774419" datatype="html"> | ||||
|         <source>Error retrieving suggestions</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">360</context> | ||||
|           <context context-type="linenumber">361</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="448882439049417053" datatype="html"> | ||||
|         <source>Error saving document</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">474</context> | ||||
|           <context context-type="linenumber">475</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">518</context> | ||||
|           <context context-type="linenumber">519</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="9021887951960049161" datatype="html"> | ||||
|         <source>Confirm delete</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">547</context> | ||||
|           <context context-type="linenumber">548</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/manage/management-list/management-list.component.ts</context> | ||||
| @@ -2725,35 +2725,35 @@ | ||||
|         <source>Do you really want to delete document "<x id="PH" equiv-text="this.document.title"/>"?</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">548</context> | ||||
|           <context context-type="linenumber">549</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="6691075929777935948" datatype="html"> | ||||
|         <source>The files for this document will be deleted permanently. This operation cannot be undone.</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">549</context> | ||||
|           <context context-type="linenumber">550</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="719892092227206532" datatype="html"> | ||||
|         <source>Delete document</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">551</context> | ||||
|           <context context-type="linenumber">552</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="1844801255494293730" datatype="html"> | ||||
|         <source>Error deleting document: <x id="PH" equiv-text="JSON.stringify(error)"/></source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">567</context> | ||||
|           <context context-type="linenumber">568</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="7362691899087997122" datatype="html"> | ||||
|         <source>Redo OCR confirm</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">587</context> | ||||
|           <context context-type="linenumber">588</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context> | ||||
| @@ -2764,14 +2764,14 @@ | ||||
|         <source>This operation will permanently redo OCR for this document.</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">588</context> | ||||
|           <context context-type="linenumber">589</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="5641451190833696892" datatype="html"> | ||||
|         <source>This operation cannot be undone.</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">589</context> | ||||
|           <context context-type="linenumber">590</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context> | ||||
| @@ -2802,7 +2802,7 @@ | ||||
|         <source>Proceed</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">591</context> | ||||
|           <context context-type="linenumber">592</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context> | ||||
| @@ -2829,7 +2829,7 @@ | ||||
|         <source>Redo OCR operation will begin in the background. Close and re-open or reload this document after the operation has completed to see new content.</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">599</context> | ||||
|           <context context-type="linenumber">600</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="8008978164775353960" datatype="html"> | ||||
| @@ -2838,7 +2838,7 @@ | ||||
|               )"/></source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context> | ||||
|           <context context-type="linenumber">610,612</context> | ||||
|           <context context-type="linenumber">611,613</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="6857598786757174736" datatype="html"> | ||||
| @@ -3159,7 +3159,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">180</context> | ||||
|           <context context-type="linenumber">186</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="2784168796433474565" datatype="html"> | ||||
| @@ -3170,7 +3170,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">185</context> | ||||
|           <context context-type="linenumber">191</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="3758078190163790058" datatype="html"> | ||||
| @@ -3181,7 +3181,7 @@ | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="6326693689225506833" datatype="html"> | ||||
|         <source><x id="INTERPOLATION" equiv-text="_comments}}"/> Comments</source> | ||||
|         <source><x id="INTERPOLATION" equiv-text="omments.length}}"/> Comments</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-card-large/document-card-large.component.html</context> | ||||
|           <context context-type="linenumber">74</context> | ||||
| @@ -3195,7 +3195,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">189</context> | ||||
|           <context context-type="linenumber">204</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="157572966557284263" datatype="html"> | ||||
| @@ -3206,7 +3206,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">194</context> | ||||
|           <context context-type="linenumber">209</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="3727324658595204357" datatype="html"> | ||||
| @@ -3373,11 +3373,22 @@ | ||||
|           <context context-type="linenumber">18</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="3807699453257291879" datatype="html"> | ||||
|         <source>Comments</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">147</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/manage/settings/settings.component.html</context> | ||||
|           <context context-type="linenumber">159</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="231679111972850796" datatype="html"> | ||||
|         <source>Added</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">165</context> | ||||
|           <context context-type="linenumber">171</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/filter-editor/filter-editor.component.html</context> | ||||
| @@ -3392,7 +3403,7 @@ | ||||
|         <source>Edit document</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context> | ||||
|           <context context-type="linenumber">184</context> | ||||
|           <context context-type="linenumber">190</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="2155249406916744630" datatype="html"> | ||||
| @@ -4039,13 +4050,6 @@ | ||||
|           <context context-type="linenumber">155</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="3807699453257291879" datatype="html"> | ||||
|         <source>Comments</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/manage/settings/settings.component.html</context> | ||||
|           <context context-type="linenumber">159</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="4666858503087488647" datatype="html"> | ||||
|         <source>Enable comments</source> | ||||
|         <context-group purpose="location"> | ||||
|   | ||||
| @@ -17,21 +17,16 @@ export class DocumentCommentsComponent extends ComponentWithPermissions { | ||||
|   }) | ||||
|  | ||||
|   networkActive = false | ||||
|   comments: PaperlessDocumentComment[] = [] | ||||
|   newCommentError: boolean = false | ||||
|  | ||||
|   private _documentId: number | ||||
|   @Input() | ||||
|   documentId: number | ||||
|  | ||||
|   @Input() | ||||
|   set documentId(id: number) { | ||||
|     if (id != this._documentId) { | ||||
|       this._documentId = id | ||||
|       this.update() | ||||
|     } | ||||
|   } | ||||
|   comments: PaperlessDocumentComment[] = [] | ||||
|  | ||||
|   @Output() | ||||
|   updated: EventEmitter<number> = new EventEmitter<number>() | ||||
|   updated: EventEmitter<PaperlessDocumentComment[]> = new EventEmitter() | ||||
|  | ||||
|   constructor( | ||||
|     private commentsService: DocumentCommentsService, | ||||
| @@ -40,17 +35,6 @@ export class DocumentCommentsComponent extends ComponentWithPermissions { | ||||
|     super() | ||||
|   } | ||||
|  | ||||
|   update(): void { | ||||
|     this.networkActive = true | ||||
|     this.commentsService | ||||
|       .getComments(this._documentId) | ||||
|       .pipe(first()) | ||||
|       .subscribe((comments) => { | ||||
|         this.comments = comments | ||||
|         this.networkActive = false | ||||
|       }) | ||||
|   } | ||||
|  | ||||
|   addComment() { | ||||
|     const comment: string = this.commentForm | ||||
|       .get('newComment') | ||||
| @@ -62,12 +46,12 @@ export class DocumentCommentsComponent extends ComponentWithPermissions { | ||||
|     } | ||||
|     this.newCommentError = false | ||||
|     this.networkActive = true | ||||
|     this.commentsService.addComment(this._documentId, comment).subscribe({ | ||||
|     this.commentsService.addComment(this.documentId, comment).subscribe({ | ||||
|       next: (result) => { | ||||
|         this.comments = result | ||||
|         this.commentForm.get('newComment').reset() | ||||
|         this.networkActive = false | ||||
|         this.updated.emit(this.comments.length) | ||||
|         this.updated.emit(this.comments) | ||||
|       }, | ||||
|       error: (e) => { | ||||
|         this.networkActive = false | ||||
| @@ -79,11 +63,11 @@ export class DocumentCommentsComponent extends ComponentWithPermissions { | ||||
|   } | ||||
|  | ||||
|   deleteComment(commentId: number) { | ||||
|     this.commentsService.deleteComment(this._documentId, commentId).subscribe({ | ||||
|     this.commentsService.deleteComment(this.documentId, commentId).subscribe({ | ||||
|       next: (result) => { | ||||
|         this.comments = result | ||||
|         this.networkActive = false | ||||
|         this.updated.emit(this.comments.length) | ||||
|         this.updated.emit(this.comments) | ||||
|       }, | ||||
|       error: (e) => { | ||||
|         this.networkActive = false | ||||
|   | ||||
| @@ -172,9 +172,9 @@ | ||||
|                 </li> | ||||
|  | ||||
|                 <li [ngbNavItem]="DocumentDetailNavIDs.Comments" *ngIf="commentsEnabled"> | ||||
|                     <a ngbNavLink i18n>Comments <span *ngIf="document?.n_comments" class="badge text-bg-secondary ms-1">{{document.n_comments}}</span></a> | ||||
|                     <a ngbNavLink i18n>Comments <span *ngIf="document?.comments.length" class="badge text-bg-secondary ms-1">{{document.comments.length}}</span></a> | ||||
|                     <ng-template ngbNavContent> | ||||
|                         <app-document-comments [documentId]="documentId" (updated)="commentsUpdated($event)"></app-document-comments> | ||||
|                         <app-document-comments [documentId]="documentId" [comments]="document?.comments" (updated)="commentsUpdated($event)"></app-document-comments> | ||||
|                     </ng-template> | ||||
|                 </li> | ||||
|  | ||||
|   | ||||
| @@ -42,6 +42,7 @@ import { | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { PaperlessUser } from 'src/app/data/paperless-user' | ||||
| import { UserService } from 'src/app/services/rest/user.service' | ||||
| import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment' | ||||
|  | ||||
| enum DocumentDetailNavIDs { | ||||
|   Details = 1, | ||||
| @@ -667,8 +668,8 @@ export class DocumentDetailComponent | ||||
|     ) | ||||
|   } | ||||
|  | ||||
|   commentsUpdated(n_comments: number) { | ||||
|     this.document.n_comments = n_comments | ||||
|   commentsUpdated(comments: PaperlessDocumentComment[]) { | ||||
|     this.document.comments = comments | ||||
|     this.openDocumentService.refreshDocument(this.documentId) | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -67,11 +67,11 @@ | ||||
|  | ||||
|  | ||||
|           <div class="list-group list-group-horizontal border-0 card-info ms-md-auto mt-2 mt-md-0"> | ||||
|             <button routerLink="/documents/{{document.id}}/comments" *ngIf="document.n_comments" class="list-group-item btn btn-sm bg-light text-dark p-1 border-0 me-2" title="View comments" i18n-title> | ||||
|             <button routerLink="/documents/{{document.id}}/comments" *ngIf="document.comments.length" class="list-group-item btn btn-sm bg-light text-dark p-1 border-0 me-2" title="View comments" i18n-title> | ||||
|               <svg class="metadata-icon me-2 text-muted" fill="currentColor"> | ||||
|                 <use xlink:href="assets/bootstrap-icons.svg#chat-left-text"/> | ||||
|               </svg> | ||||
|               <small i18n>{{document.n_comments}} Comments</small> | ||||
|               <small i18n>{{document.comments.length}} Comments</small> | ||||
|             </button> | ||||
|             <button *ngIf="document.document_type" type="button" class="list-group-item btn btn-sm bg-light text-dark p-1 border-0 me-2" title="Filter by document type" i18n-title | ||||
|              (click)="clickDocumentType.emit(document.document_type);$event.stopPropagation()"> | ||||
|   | ||||
| @@ -18,12 +18,12 @@ | ||||
|       </div> | ||||
|     </div> | ||||
|  | ||||
|     <a routerLink="/documents/{{document.id}}/comments" *ngIf="document.n_comments" class="document-card-comments py-2 px-1"> | ||||
|     <a routerLink="/documents/{{document.id}}/comments" *ngIf="document.comments.length" class="document-card-comments py-2 px-1"> | ||||
|       <span class="badge rounded-pill bg-light border text-primary"> | ||||
|       <svg class="metadata-icon ms-1 me-1" fill="currentColor"> | ||||
|         <use xlink:href="assets/bootstrap-icons.svg#chat-left-text"/> | ||||
|       </svg> | ||||
|       {{document.n_comments}}</span> | ||||
|       {{document.comments.length}}</span> | ||||
|     </a> | ||||
|  | ||||
|     <div class="card-body p-2"> | ||||
|   | ||||
| @@ -74,7 +74,7 @@ export class DocumentCardSmallComponent extends ComponentWithPermissions { | ||||
|   } | ||||
|  | ||||
|   getTagsLimited$() { | ||||
|     const limit = this.document.n_comments > 0 ? 6 : 7 | ||||
|     const limit = this.document.comments.length > 0 ? 6 : 7 | ||||
|     return this.document.tags$.pipe( | ||||
|       map((tags) => { | ||||
|         if (tags.length > limit) { | ||||
|   | ||||
| @@ -140,7 +140,7 @@ | ||||
|         (sort)="onSort($event)" | ||||
|         i18n>Title</th> | ||||
|       <th class="d-none d-xl-table-cell" | ||||
|         appSortable="n_comments" | ||||
|         appSortable="num_comments" | ||||
|         [currentSortField]="list.sortField" | ||||
|         [currentSortReverse]="list.sortReverse" | ||||
|         (sort)="onSort($event)" | ||||
| @@ -191,12 +191,12 @@ | ||||
|           <app-tag [tag]="t" *ngFor="let t of d.tags$ | async" class="ms-1" clickable="true" linkTitle="Filter by tag" i18n-linkTitle (click)="clickTag(t.id);$event.stopPropagation()"></app-tag> | ||||
|         </td> | ||||
|         <td class="d-none d-xl-table-cell"> | ||||
|           <a routerLink="/documents/{{d.id}}/comments" *ngIf="d.n_comments" class="btn btn-sm p-0"> | ||||
|           <a routerLink="/documents/{{d.id}}/comments" *ngIf="d.comments.length" class="btn btn-sm p-0"> | ||||
|             <span class="badge rounded-pill bg-light border text-primary"> | ||||
|             <svg class="metadata-icon ms-1 me-1" fill="currentColor"> | ||||
|               <use xlink:href="assets/bootstrap-icons.svg#chat-left-text"/> | ||||
|             </svg> | ||||
|             {{d.n_comments}}</span> | ||||
|             {{d.comments.length}}</span> | ||||
|           </a> | ||||
|         </td> | ||||
|         <td class="d-none d-xl-table-cell"> | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import { PaperlessDocumentType } from './paperless-document-type' | ||||
| import { Observable } from 'rxjs' | ||||
| import { PaperlessStoragePath } from './paperless-storage-path' | ||||
| import { ObjectWithPermissions } from './object-with-permissions' | ||||
| import { PaperlessDocumentComment } from './paperless-document-comment' | ||||
|  | ||||
| export interface SearchHit { | ||||
|   score?: number | ||||
| @@ -54,7 +55,7 @@ export interface PaperlessDocument extends ObjectWithPermissions { | ||||
|  | ||||
|   archive_serial_number?: number | ||||
|  | ||||
|   n_comments?: number | ||||
|   comments?: PaperlessDocumentComment[] | ||||
|  | ||||
|   __search_hit__?: SearchHit | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,40 @@ | ||||
| # Generated by Django 4.1.5 on 2023-03-17 21:23 | ||||
|  | ||||
| from django.conf import settings | ||||
| from django.db import migrations, models | ||||
| import django.db.models.deletion | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||||
|         ("documents", "1033_alter_documenttype_options_alter_tag_options_and_more"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.AlterField( | ||||
|             model_name="comment", | ||||
|             name="document", | ||||
|             field=models.ForeignKey( | ||||
|                 blank=True, | ||||
|                 null=True, | ||||
|                 on_delete=django.db.models.deletion.CASCADE, | ||||
|                 related_name="comments", | ||||
|                 to="documents.document", | ||||
|                 verbose_name="document", | ||||
|             ), | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name="comment", | ||||
|             name="user", | ||||
|             field=models.ForeignKey( | ||||
|                 blank=True, | ||||
|                 null=True, | ||||
|                 on_delete=django.db.models.deletion.SET_NULL, | ||||
|                 related_name="comments", | ||||
|                 to=settings.AUTH_USER_MODEL, | ||||
|                 verbose_name="user", | ||||
|             ), | ||||
|         ), | ||||
|     ] | ||||
| @@ -652,7 +652,7 @@ class Comment(models.Model): | ||||
|         Document, | ||||
|         blank=True, | ||||
|         null=True, | ||||
|         related_name="documents", | ||||
|         related_name="comments", | ||||
|         on_delete=models.CASCADE, | ||||
|         verbose_name=_("document"), | ||||
|     ) | ||||
| @@ -661,7 +661,7 @@ class Comment(models.Model): | ||||
|         User, | ||||
|         blank=True, | ||||
|         null=True, | ||||
|         related_name="users", | ||||
|         related_name="comments", | ||||
|         on_delete=models.SET_NULL, | ||||
|         verbose_name=_("user"), | ||||
|     ) | ||||
|   | ||||
| @@ -16,7 +16,6 @@ from rest_framework import serializers | ||||
| from rest_framework.fields import SerializerMethodField | ||||
|  | ||||
| from . import bulk_edit | ||||
| from .models import Comment | ||||
| from .models import Correspondent | ||||
| from .models import Document | ||||
| from .models import DocumentType | ||||
| @@ -383,7 +382,7 @@ class DocumentSerializer(OwnedObjectSerializer, DynamicFieldsModelSerializer): | ||||
|     archived_file_name = SerializerMethodField() | ||||
|     created_date = serializers.DateField(required=False) | ||||
|  | ||||
|     n_comments = SerializerMethodField() | ||||
|     num_comments = serializers.IntegerField(read_only=True) | ||||
|  | ||||
|     owner = serializers.PrimaryKeyRelatedField( | ||||
|         queryset=User.objects.all(), | ||||
| @@ -400,9 +399,6 @@ class DocumentSerializer(OwnedObjectSerializer, DynamicFieldsModelSerializer): | ||||
|         else: | ||||
|             return None | ||||
|  | ||||
|     def get_n_comments(self, obj): | ||||
|         return Comment.objects.filter(document=obj).count() | ||||
|  | ||||
|     def to_representation(self, instance): | ||||
|         doc = super().to_representation(instance) | ||||
|         if self.truncate_content: | ||||
| @@ -448,7 +444,8 @@ class DocumentSerializer(OwnedObjectSerializer, DynamicFieldsModelSerializer): | ||||
|             "owner", | ||||
|             "permissions", | ||||
|             "set_permissions", | ||||
|             "n_comments", | ||||
|             "comments", | ||||
|             "num_comments", | ||||
|         ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -230,7 +230,7 @@ class DocumentViewSet( | ||||
|     GenericViewSet, | ||||
| ): | ||||
|     model = Document | ||||
|     queryset = Document.objects.all() | ||||
|     queryset = Document.objects.annotate(num_comments=Count("comments")) | ||||
|     serializer_class = DocumentSerializer | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated, PaperlessObjectPermissions) | ||||
| @@ -251,6 +251,7 @@ class DocumentViewSet( | ||||
|         "modified", | ||||
|         "added", | ||||
|         "archive_serial_number", | ||||
|         "num_comments", | ||||
|     ) | ||||
|  | ||||
|     def get_queryset(self): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon