From bf8ae22f3fc2d4145946170f2b3e226c869a0db9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 17 Mar 2023 16:36:08 -0700 Subject: [PATCH] Rename comments --> notes --- docker/docker-prepare.sh | 2 +- .../e2e/documents/document-detail.cy.ts | 62 ++++----- .../fixtures/documents/1/comments.json | 46 ------- .../cypress/fixtures/documents/1/notes.json | 26 ++++ .../cypress/fixtures/documents/documents.json | 47 +++---- src-ui/cypress/fixtures/groups/groups.json | 16 +-- .../fixtures/ui_settings/settings.json | 8 +- .../ui_settings/settings_restricted.json | 2 +- src-ui/cypress/fixtures/users/users.json | 32 ++--- src-ui/messages.xlf | 126 +++++++++--------- src-ui/src/app/app.module.ts | 4 +- .../document-comments.component.ts | 99 -------------- .../document-detail.component.html | 6 +- .../document-detail.component.ts | 12 +- .../document-card-large.component.html | 6 +- .../document-card-large.component.ts | 14 +- .../document-card-small.component.html | 8 +- .../document-card-small.component.scss | 4 +- .../document-card-small.component.ts | 6 +- .../document-list.component.html | 12 +- .../document-list/document-list.component.ts | 9 +- .../document-notes.component.html} | 20 +-- .../document-notes.component.scss} | 0 .../document-notes.component.ts | 106 +++++++++++++++ .../manage/settings/settings.component.html | 4 +- .../manage/settings/settings.component.ts | 8 +- .../app/data/paperless-document-comment.ts | 8 -- .../src/app/data/paperless-document-note.ts | 7 + src-ui/src/app/data/paperless-document.ts | 6 +- src-ui/src/app/data/paperless-uisettings.ts | 4 +- .../src/app/services/permissions.service.ts | 2 +- .../rest/document-comments.service.ts | 37 ----- .../services/rest/document-notes.service.ts | 37 +++++ .../src/app/services/rest/document.service.ts | 1 + src-ui/src/theme.scss | 4 + src/documents/admin.py | 9 ++ src/documents/index.py | 10 +- .../management/commands/document_exporter.py | 12 +- ...ter_comment_document_alter_comment_user.py | 40 ------ .../migrations/1035_rename_comment_note.py | 61 +++++++++ src/documents/models.py | 16 +-- src/documents/serialisers.py | 5 +- src/documents/tests/test_api.py | 70 +++++----- .../tests/test_management_exporter.py | 10 +- src/documents/views.py | 44 +++--- 45 files changed, 540 insertions(+), 528 deletions(-) delete mode 100644 src-ui/cypress/fixtures/documents/1/comments.json create mode 100644 src-ui/cypress/fixtures/documents/1/notes.json delete mode 100644 src-ui/src/app/components/document-comments/document-comments.component.ts rename src-ui/src/app/components/{document-comments/document-comments.component.html => document-notes/document-notes.component.html} (50%) rename src-ui/src/app/components/{document-comments/document-comments.component.scss => document-notes/document-notes.component.scss} (100%) create mode 100644 src-ui/src/app/components/document-notes/document-notes.component.ts delete mode 100644 src-ui/src/app/data/paperless-document-comment.ts create mode 100644 src-ui/src/app/data/paperless-document-note.ts delete mode 100644 src-ui/src/app/services/rest/document-comments.service.ts create mode 100644 src-ui/src/app/services/rest/document-notes.service.ts delete mode 100644 src/documents/migrations/1034_alter_comment_document_alter_comment_user.py create mode 100644 src/documents/migrations/1035_rename_comment_note.py diff --git a/docker/docker-prepare.sh b/docker/docker-prepare.sh index b088cef405..d6eab42815 100755 --- a/docker/docker-prepare.sh +++ b/docker/docker-prepare.sh @@ -80,7 +80,7 @@ django_checks() { search_index() { - local -r index_version=3 + local -r index_version=4 local -r index_version_file=${DATA_DIR}/.index_version if [[ (! -f "${index_version_file}") || $(<"${index_version_file}") != "$index_version" ]]; then diff --git a/src-ui/cypress/e2e/documents/document-detail.cy.ts b/src-ui/cypress/e2e/documents/document-detail.cy.ts index 8f6d8bde97..dd5f8fac85 100644 --- a/src-ui/cypress/e2e/documents/document-detail.cy.ts +++ b/src-ui/cypress/e2e/documents/document-detail.cy.ts @@ -17,28 +17,28 @@ describe('document-detail', () => { req.reply({ result: 'OK' }) }).as('saveDoc') - cy.fixture('documents/1/comments.json').then((commentsJson) => { + cy.fixture('documents/1/notes.json').then((notesJson) => { cy.intercept( 'GET', - 'http://localhost:8000/api/documents/1/comments/', + 'http://localhost:8000/api/documents/1/notes/', (req) => { - req.reply(commentsJson.filter((c) => c.id != 10)) // 3 + req.reply(notesJson.filter((c) => c.id != 10)) // 3 } ) cy.intercept( 'DELETE', - 'http://localhost:8000/api/documents/1/comments/?id=9', + 'http://localhost:8000/api/documents/1/notes/?id=9', (req) => { - req.reply(commentsJson.filter((c) => c.id != 9 && c.id != 10)) // 2 + req.reply(notesJson.filter((c) => c.id != 9 && c.id != 10)) // 2 } ) cy.intercept( 'POST', - 'http://localhost:8000/api/documents/1/comments/', + 'http://localhost:8000/api/documents/1/notes/', (req) => { - req.reply(commentsJson) // 4 + req.reply(notesJson) // 4 } ) }) @@ -75,48 +75,40 @@ describe('document-detail', () => { cy.get('pdf-viewer').should('be.visible') }) - it('should show a list of comments', () => { - cy.wait(1000) - .get('a') - .contains('Comments') - .click({ force: true }) - .wait(1000) - cy.get('app-document-comments').find('.card').its('length').should('eq', 3) + it('should show a list of notes', () => { + cy.wait(1000).get('a').contains('Notes').click({ force: true }).wait(1000) + cy.get('app-document-notes').find('.card').its('length').should('eq', 3) }) - it('should support comment deletion', () => { - cy.wait(1000).get('a').contains('Comments').click().wait(1000) - cy.get('app-document-comments') + it('should support note deletion', () => { + cy.wait(1000).get('a').contains('Notes').click().wait(1000) + cy.get('app-document-notes') .find('.card') .first() .find('button') .click({ force: true }) .wait(500) - cy.get('app-document-comments').find('.card').its('length').should('eq', 2) + cy.get('app-document-notes').find('.card').its('length').should('eq', 2) }) - it('should support comment insertion', () => { - cy.wait(1000).get('a').contains('Comments').click().wait(1000) - cy.get('app-document-comments') + it('should support note insertion', () => { + cy.wait(1000).get('a').contains('Notes').click().wait(1000) + cy.get('app-document-notes') .find('form textarea') - .type('Testing new comment') + .type('Testing new note') .wait(500) - cy.get('app-document-comments').find('form button').click().wait(1500) - cy.get('app-document-comments').find('.card').its('length').should('eq', 4) + cy.get('app-document-notes').find('form button').click().wait(1500) + cy.get('app-document-notes').find('.card').its('length').should('eq', 4) }) - it('should support navigation to comments tab by url', () => { - cy.visit('/documents/1/comments') - cy.get('app-document-comments').should('exist') + it('should support navigation to notes tab by url', () => { + cy.visit('/documents/1/notes') + cy.get('app-document-notes').should('exist') }) - it('should dynamically update comment counts', () => { - cy.visit('/documents/1/comments') - cy.get('app-document-comments').within(() => cy.contains('Delete').click()) - cy.get('ul.nav') - .find('li') - .contains('Comments') - .find('.badge') - .contains('2') + it('should dynamically update note counts', () => { + cy.visit('/documents/1/notes') + cy.get('app-document-notes').within(() => cy.contains('Delete').click()) + cy.get('ul.nav').find('li').contains('Notes').find('.badge').contains('2') }) }) diff --git a/src-ui/cypress/fixtures/documents/1/comments.json b/src-ui/cypress/fixtures/documents/1/comments.json deleted file mode 100644 index a6013b5133..0000000000 --- a/src-ui/cypress/fixtures/documents/1/comments.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "id": 10, - "comment": "Testing new comment", - "created": "2022-08-08T04:24:55.176008Z", - "user": { - "id": 1, - "username": "user2", - "first_name": "", - "last_name": "" - } - }, - { - "id": 9, - "comment": "Testing one more time", - "created": "2022-02-18T04:24:55.176008Z", - "user": { - "id": 2, - "username": "user1", - "first_name": "", - "last_name": "" - } - }, - { - "id": 8, - "comment": "Another comment", - "created": "2021-11-08T04:24:47.925042Z", - "user": { - "id": 2, - "username": "user33", - "first_name": "", - "last_name": "" - } - }, - { - "id": 7, - "comment": "Cupcake ipsum dolor sit amet cheesecake candy cookie tiramisu. Donut chocolate chupa chups macaroon brownie halvah pie cheesecake gummies. Sweet chocolate bar candy donut gummi bears bear claw liquorice bonbon shortbread.\n\nDonut chocolate bar candy wafer wafer tiramisu. Gummies chocolate cake muffin toffee carrot cake macaroon. Toffee toffee jelly beans danish lollipop cake.", - "created": "2021-02-08T02:37:49.724132Z", - "user": { - "id": 3, - "username": "admin", - "first_name": "", - "last_name": "" - } - } -] diff --git a/src-ui/cypress/fixtures/documents/1/notes.json b/src-ui/cypress/fixtures/documents/1/notes.json new file mode 100644 index 0000000000..97c8e5ace6 --- /dev/null +++ b/src-ui/cypress/fixtures/documents/1/notes.json @@ -0,0 +1,26 @@ +[ + { + "id": 10, + "note": "Testing new note", + "created": "2022-08-08T04:24:55.176008Z", + "user": 3 + }, + { + "id": 9, + "note": "Testing one more time", + "created": "2022-02-18T04:24:55.176008Z", + "user": 15 + }, + { + "id": 8, + "note": "Another note", + "created": "2021-11-08T04:24:47.925042Z", + "user": 3 + }, + { + "id": 7, + "note": "Cupcake ipsum dolor sit amet cheesecake candy cookie tiramisu. Donut chocolate chupa chups macaroon brownie halvah pie cheesecake gummies. Sweet chocolate bar candy donut gummi bears bear claw liquorice bonbon shortbread.\n\nDonut chocolate bar candy wafer wafer tiramisu. Gummies chocolate cake muffin toffee carrot cake macaroon. Toffee toffee jelly beans danish lollipop cake.", + "created": "2021-02-08T02:37:49.724132Z", + "user": 3 + } +] diff --git a/src-ui/cypress/fixtures/documents/documents.json b/src-ui/cypress/fixtures/documents/documents.json index b67cfa4df7..be7640c8f3 100644 --- a/src-ui/cypress/fixtures/documents/documents.json +++ b/src-ui/cypress/fixtures/documents/documents.json @@ -22,39 +22,24 @@ "archived_file_name": "2022-03-22 no latin title.pdf", "owner": null, "permissions": [], - "comments": [ + "notes": [ { - "id": 30, - "comment": "One more time", - "created": "2023-03-17T22:02:14.357575Z", - "user": { - "id": 2, - "username": "username", - "first_name": "", - "last_name": "" - } + "id": 9, + "note": "Testing one more time", + "created": "2022-02-18T04:24:55.176008Z", + "user": 15 }, { - "id": 6, - "comment": "Lets keep going", - "created": "2023-03-16T06:57:32.014027Z", - "user": { - "id": 2, - "username": "username", - "first_name": "", - "last_name": "" - } + "id": 8, + "note": "Another note", + "created": "2021-11-08T04:24:47.925042Z", + "user": 3 }, { - "id": 5, - "comment": "And just one more", - "created": "2023-03-16T06:57:27.022729Z", - "user": { - "id": 2, - "username": "username", - "first_name": "", - "last_name": "" - } + "id": 7, + "note": "Cupcake ipsum dolor sit amet cheesecake candy cookie tiramisu. Donut chocolate chupa chups macaroon brownie halvah pie cheesecake gummies. Sweet chocolate bar candy donut gummi bears bear claw liquorice bonbon shortbread.\n\nDonut chocolate bar candy wafer wafer tiramisu. Gummies chocolate cake muffin toffee carrot cake macaroon. Toffee toffee jelly beans danish lollipop cake.", + "created": "2021-02-08T02:37:49.724132Z", + "user": 3 } ] }, @@ -75,7 +60,7 @@ "archived_file_name": "2022-03-23 llorem ipsum dolor sit amet.pdf", "owner": null, "permissions": [], - "comments": [] + "notes": [] }, { "id": 3, @@ -96,7 +81,7 @@ "archived_file_name": "2022-03-24 dolor.pdf", "owner": null, "permissions": [], - "comments": [] + "notes": [] }, { "id": 4, @@ -117,7 +102,7 @@ "archived_file_name": "2022-06-01 sit amet.pdf", "owner": null, "permissions": [], - "comments": [] + "notes": [] } ] } diff --git a/src-ui/cypress/fixtures/groups/groups.json b/src-ui/cypress/fixtures/groups/groups.json index 0bf2655d91..f6051be90a 100644 --- a/src-ui/cypress/fixtures/groups/groups.json +++ b/src-ui/cypress/fixtures/groups/groups.json @@ -11,10 +11,10 @@ "change_user", "delete_user", "view_user", - "add_comment", - "change_comment", - "delete_comment", - "view_comment" + "add_note", + "change_note", + "delete_note", + "view_note" ] }, { @@ -73,10 +73,10 @@ "change_task", "delete_task", "view_task", - "add_comment", - "change_comment", - "delete_comment", - "view_comment", + "add_note", + "change_note", + "delete_note", + "view_note", "add_correspondent", "change_correspondent", "delete_correspondent", diff --git a/src-ui/cypress/fixtures/ui_settings/settings.json b/src-ui/cypress/fixtures/ui_settings/settings.json index f552054df4..3183943fe6 100644 --- a/src-ui/cypress/fixtures/ui_settings/settings.json +++ b/src-ui/cypress/fixtures/ui_settings/settings.json @@ -94,10 +94,10 @@ "change_task", "delete_task", "view_task", - "add_comment", - "change_comment", - "delete_comment", - "view_comment", + "add_note", + "change_note", + "delete_note", + "view_note", "add_correspondent", "change_correspondent", "delete_correspondent", diff --git a/src-ui/cypress/fixtures/ui_settings/settings_restricted.json b/src-ui/cypress/fixtures/ui_settings/settings_restricted.json index 921d4274d6..72ebe51b1a 100644 --- a/src-ui/cypress/fixtures/ui_settings/settings_restricted.json +++ b/src-ui/cypress/fixtures/ui_settings/settings_restricted.json @@ -74,7 +74,7 @@ "change_task", "delete_task", "view_task", - "add_comment", + "add_note", "add_frontendsettings", "change_frontendsettings", "delete_frontendsettings", diff --git a/src-ui/cypress/fixtures/users/users.json b/src-ui/cypress/fixtures/users/users.json index ca477667a3..a69a86b92c 100644 --- a/src-ui/cypress/fixtures/users/users.json +++ b/src-ui/cypress/fixtures/users/users.json @@ -30,7 +30,7 @@ "django_celery_results.delete_taskresult", "paperless_mail.add_mailaccount", "auth.change_group", - "documents.add_comment", + "documents.add_note", "paperless_mail.delete_mailaccount", "authtoken.delete_tokenproxy", "guardian.delete_groupobjectpermission", @@ -44,7 +44,7 @@ "documents.add_documenttype", "django_q.change_success", "documents.delete_tag", - "documents.change_comment", + "documents.change_note", "django_q.delete_task", "documents.add_savedviewfilterrule", "django_q.view_task", @@ -59,7 +59,7 @@ "documents.add_savedview", "auth.delete_user", "documents.view_log", - "documents.view_comment", + "documents.view_note", "guardian.change_groupobjectpermission", "sessions.delete_session", "django_q.change_failure", @@ -139,7 +139,7 @@ "django_celery_results.view_taskresult", "contenttypes.add_contenttype", "django_q.delete_success", - "documents.delete_comment", + "documents.delete_note", "django_q.add_failure", "guardian.add_userobjectpermission", "sessions.view_session", @@ -216,10 +216,10 @@ "change_task", "delete_task", "view_task", - "add_comment", - "change_comment", - "delete_comment", - "view_comment", + "add_note", + "change_note", + "delete_note", + "view_note", "add_frontendsettings", "change_frontendsettings", "delete_frontendsettings", @@ -256,7 +256,7 @@ "django_celery_results.delete_taskresult", "authtoken.change_token", "auth.change_group", - "documents.add_comment", + "documents.add_note", "authtoken.delete_tokenproxy", "documents.view_documenttype", "contenttypes.delete_contenttype", @@ -285,7 +285,7 @@ "django_q.change_task", "sessions.add_session", "documents.change_taskattributes", - "documents.change_comment", + "documents.change_note", "django_q.delete_task", "django_q.delete_ormq", "auth.change_permission", @@ -311,7 +311,7 @@ "documents.view_document", "documents.add_savedview", "django_q.view_failure", - "documents.view_comment", + "documents.view_note", "documents.view_log", "documents.add_log", "documents.change_savedview", @@ -324,7 +324,7 @@ "django_celery_results.view_taskresult", "contenttypes.add_contenttype", "django_q.delete_success", - "documents.delete_comment", + "documents.delete_note", "django_q.add_failure", "sessions.view_session", "contenttypes.view_contenttype", @@ -373,7 +373,7 @@ "django_celery_results.delete_taskresult", "authtoken.change_token", "auth.change_group", - "documents.add_comment", + "documents.add_note", "authtoken.delete_tokenproxy", "documents.view_documenttype", "contenttypes.delete_contenttype", @@ -402,7 +402,7 @@ "django_q.change_task", "sessions.add_session", "documents.change_taskattributes", - "documents.change_comment", + "documents.change_note", "django_q.delete_task", "django_q.delete_ormq", "auth.change_permission", @@ -429,7 +429,7 @@ "documents.view_document", "documents.add_savedview", "django_q.view_failure", - "documents.view_comment", + "documents.view_note", "documents.view_log", "auth.delete_user", "documents.add_log", @@ -443,7 +443,7 @@ "django_celery_results.view_taskresult", "contenttypes.add_contenttype", "django_q.delete_success", - "documents.delete_comment", + "documents.delete_note", "django_q.add_failure", "sessions.view_session", "contenttypes.view_contenttype", diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index c10758158d..ce470a9a43 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -492,7 +492,7 @@ src/app/components/document-list/document-list.component.ts - 94 + 97 src/app/components/manage/management-list/management-list.component.html @@ -1826,7 +1826,7 @@ Not assigned src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts - 321 + 335 Filter drop down element to filter for documents with no correspondent/type/tag assigned @@ -2328,52 +2328,6 @@ 1 - - Enter comment - - src/app/components/document-comments/document-comments.component.html - 4 - - - - Please enter a comment. - - src/app/components/document-comments/document-comments.component.html - 5,7 - - - - Add comment - - src/app/components/document-comments/document-comments.component.html - 11 - - - - Delete comment - - src/app/components/document-comments/document-comments.component.html - 21 - - - src/app/components/document-comments/document-comments.component.html - 25 - - - - Error saving comment: - - src/app/components/document-comments/document-comments.component.ts - 59 - - - - Error deleting comment: - - src/app/components/document-comments/document-comments.component.ts - 75 - - Page @@ -2664,8 +2618,8 @@ 215 - - Comments + + Notes src/app/components/document-detail/document-detail.component.html 175,176 @@ -3173,15 +3127,15 @@ 191 - - View comments + + View notes src/app/components/document-list/document-card-large/document-card-large.component.html 70 - - Comments + + Notes src/app/components/document-list/document-card-large/document-card-large.component.html 74 @@ -3373,8 +3327,8 @@ 18 - - Comments + + Notes src/app/components/document-list/document-list.component.html 147 @@ -3383,6 +3337,10 @@ src/app/components/manage/settings/settings.component.html 159 + + src/app/services/rest/document.service.ts + 25 + Added @@ -3410,14 +3368,14 @@ View "" saved successfully. src/app/components/document-list/document-list.component.ts - 202 + 205 View "" created successfully. src/app/components/document-list/document-list.component.ts - 243 + 246 @@ -3582,6 +3540,52 @@ 13 + + Enter note + + src/app/components/document-notes/document-notes.component.html + 4 + + + + Please enter a note. + + src/app/components/document-notes/document-notes.component.html + 5,7 + + + + Add note + + src/app/components/document-notes/document-notes.component.html + 11 + + + + Delete note + + src/app/components/document-notes/document-notes.component.html + 21 + + + src/app/components/document-notes/document-notes.component.html + 25 + + + + Error saving note: + + src/app/components/document-notes/document-notes.component.ts + 65 + + + + Error deleting note: + + src/app/components/document-notes/document-notes.component.ts + 81 + + correspondent @@ -4050,8 +4054,8 @@ 155 - - Enable comments + + Enable notes src/app/components/manage/settings/settings.component.html 163 @@ -4931,7 +4935,7 @@ Search score src/app/services/rest/document.service.ts - 31 + 32 Score is a value returned by the full text search engine and specifies how well a result matches the given query diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index beb3b09359..446f63254e 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -70,7 +70,7 @@ import { ApiVersionInterceptor } from './interceptors/api-version.interceptor' import { ColorSliderModule } from 'ngx-color/slider' import { ColorComponent } from './components/common/input/color/color.component' import { DocumentAsnComponent } from './components/document-asn/document-asn.component' -import { DocumentCommentsComponent } from './components/document-comments/document-comments.component' +import { DocumentNotesComponent } from './components/document-notes/document-notes.component' import { PermissionsGuard } from './guards/permissions.guard' import { DirtyDocGuard } from './guards/dirty-doc.guard' import { DirtySavedViewGuard } from './guards/dirty-saved-view.guard' @@ -196,7 +196,7 @@ function initializeApp(settings: SettingsService) { DateComponent, ColorComponent, DocumentAsnComponent, - DocumentCommentsComponent, + DocumentNotesComponent, TasksComponent, UserEditDialogComponent, GroupEditDialogComponent, diff --git a/src-ui/src/app/components/document-comments/document-comments.component.ts b/src-ui/src/app/components/document-comments/document-comments.component.ts deleted file mode 100644 index 405ddd2087..0000000000 --- a/src-ui/src/app/components/document-comments/document-comments.component.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core' -import { DocumentCommentsService } from 'src/app/services/rest/document-comments.service' -import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment' -import { FormControl, FormGroup } from '@angular/forms' -import { first } from 'rxjs/operators' -import { ToastService } from 'src/app/services/toast.service' -import { ComponentWithPermissions } from '../with-permissions/with-permissions.component' - -@Component({ - selector: 'app-document-comments', - templateUrl: './document-comments.component.html', - styleUrls: ['./document-comments.component.scss'], -}) -export class DocumentCommentsComponent extends ComponentWithPermissions { - commentForm: FormGroup = new FormGroup({ - newComment: new FormControl(''), - }) - - networkActive = false - newCommentError: boolean = false - - @Input() - documentId: number - - @Input() - comments: PaperlessDocumentComment[] = [] - - @Output() - updated: EventEmitter = new EventEmitter() - - constructor( - private commentsService: DocumentCommentsService, - private toastService: ToastService - ) { - super() - } - - addComment() { - const comment: string = this.commentForm - .get('newComment') - .value.toString() - .trim() - if (comment.length == 0) { - this.newCommentError = true - return - } - this.newCommentError = false - this.networkActive = true - 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) - }, - error: (e) => { - this.networkActive = false - this.toastService.showError( - $localize`Error saving comment: ${e.toString()}` - ) - }, - }) - } - - deleteComment(commentId: number) { - this.commentsService.deleteComment(this.documentId, commentId).subscribe({ - next: (result) => { - this.comments = result - this.networkActive = false - this.updated.emit(this.comments) - }, - error: (e) => { - this.networkActive = false - this.toastService.showError( - $localize`Error deleting comment: ${e.toString()}` - ) - }, - }) - } - - displayName(comment: PaperlessDocumentComment): string { - if (!comment.user) return '' - let nameComponents = [] - if (comment.user.first_name) nameComponents.unshift(comment.user.first_name) - if (comment.user.last_name) nameComponents.unshift(comment.user.last_name) - if (comment.user.username) { - if (nameComponents.length > 0) - nameComponents.push(`(${comment.user.username})`) - else nameComponents.push(comment.user.username) - } - return nameComponents.join(' ') - } - - commentFormKeydown(event: KeyboardEvent) { - if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') { - this.addComment() - } - } -} diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index ee1c159138..3cd4c9a17e 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -171,10 +171,10 @@ -
  • - Comments {{document.comments.length}} +
  • + Notes {{document.notes.length}} - +
  • diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 3ca7755e28..e154cd03bf 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -42,14 +42,14 @@ 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' +import { PaperlessDocumentNote } from 'src/app/data/paperless-document-note' enum DocumentDetailNavIDs { Details = 1, Content = 2, Metadata = 3, Preview = 4, - Comments = 5, + Notes = 5, Permissions = 6, } @@ -658,9 +658,9 @@ export class DocumentDetailComponent } } - get commentsEnabled(): boolean { + get notesEnabled(): boolean { return ( - this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED) && + this.settings.get(SETTINGS_KEYS.NOTES_ENABLED) && this.permissionsService.currentUserCan( PermissionAction.View, PermissionType.Document @@ -668,8 +668,8 @@ export class DocumentDetailComponent ) } - commentsUpdated(comments: PaperlessDocumentComment[]) { - this.document.comments = comments + notesUpdated(notes: PaperlessDocumentNote[]) { + this.document.notes = notes this.openDocumentService.refreshDocument(this.documentId) } diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html index 01ea1e8b61..6f4e36b733 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html @@ -26,7 +26,7 @@

    - + @@ -67,11 +67,11 @@

    -
    - + - {{document.comments.length}} + {{document.notes.length}} -
    +

    {{(document.correspondent$ | async)?.name}}: diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss index 95c66d7d69..9affa52ec4 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss @@ -34,10 +34,10 @@ display: block; } -.document-card-comments { +.document-card-notes { position: absolute; right: 0; - bottom: 170px; + top: 142px; } .card-selected { diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts index 745f2b3e44..28b3541542 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts @@ -74,7 +74,7 @@ export class DocumentCardSmallComponent extends ComponentWithPermissions { } getTagsLimited$() { - const limit = this.document.comments.length > 0 ? 6 : 7 + const limit = this.document.notes.length > 0 ? 6 : 7 return this.document.tags$.pipe( map((tags) => { if (tags.length > limit) { @@ -111,4 +111,8 @@ export class DocumentCardSmallComponent extends ComponentWithPermissions { mouseLeaveCard() { this.popover.close() } + + get notesEnabled(): boolean { + return this.settingsService.get(SETTINGS_KEYS.NOTES_ENABLED) + } } diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index 02015380e8..70ff168f6b 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -139,12 +139,12 @@ [currentSortReverse]="list.sortReverse" (sort)="onSort($event)" i18n>Title - Comments + i18n>Notes {{d.title | documentTitle}} - - + + - {{d.comments.length}} + {{d.notes.length}} diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index d4a6544443..7847097bc2 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -17,6 +17,7 @@ import { import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type' import { PaperlessDocument } from 'src/app/data/paperless-document' import { PaperlessSavedView } from 'src/app/data/paperless-saved-view' +import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings' import { SortableDirective, SortEvent, @@ -29,6 +30,7 @@ import { DOCUMENT_SORT_FIELDS_FULLTEXT, } from 'src/app/services/rest/document.service' import { SavedViewService } from 'src/app/services/rest/saved-view.service' +import { SettingsService } from 'src/app/services/settings.service' import { ToastService } from 'src/app/services/toast.service' import { ComponentWithPermissions } from '../with-permissions/with-permissions.component' import { FilterEditorComponent } from './filter-editor/filter-editor.component' @@ -51,7 +53,8 @@ export class DocumentListComponent private toastService: ToastService, private modalService: NgbModal, private consumerStatusService: ConsumerStatusService, - public openDocumentsService: OpenDocumentsService + public openDocumentsService: OpenDocumentsService, + private settingsService: SettingsService ) { super() } @@ -289,4 +292,8 @@ export class DocumentListComponent trackByDocumentId(index, item: PaperlessDocument) { return item.id } + + get notesEnabled(): boolean { + return this.settingsService.get(SETTINGS_KEYS.NOTES_ENABLED) + } } diff --git a/src-ui/src/app/components/document-comments/document-comments.component.html b/src-ui/src/app/components/document-notes/document-notes.component.html similarity index 50% rename from src-ui/src/app/components/document-comments/document-comments.component.html rename to src-ui/src/app/components/document-notes/document-notes.component.html index b303524147..f6c46cd47a 100644 --- a/src-ui/src/app/components/document-comments/document-comments.component.html +++ b/src-ui/src/app/components/document-notes/document-notes.component.html @@ -1,28 +1,28 @@ -

    -
    +
    +
    - +
    - Please enter a comment. + Please enter a note.
    - +

    -
    +
    -

    {{comment.comment}}

    +

    {{note.note}}

    diff --git a/src-ui/src/app/components/document-comments/document-comments.component.scss b/src-ui/src/app/components/document-notes/document-notes.component.scss similarity index 100% rename from src-ui/src/app/components/document-comments/document-comments.component.scss rename to src-ui/src/app/components/document-notes/document-notes.component.scss diff --git a/src-ui/src/app/components/document-notes/document-notes.component.ts b/src-ui/src/app/components/document-notes/document-notes.component.ts new file mode 100644 index 0000000000..c8bb3cc2ba --- /dev/null +++ b/src-ui/src/app/components/document-notes/document-notes.component.ts @@ -0,0 +1,106 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core' +import { DocumentNotesService } from 'src/app/services/rest/document-notes.service' +import { PaperlessDocumentNote } from 'src/app/data/paperless-document-note' +import { FormControl, FormGroup } from '@angular/forms' +import { first } from 'rxjs/operators' +import { ToastService } from 'src/app/services/toast.service' +import { ComponentWithPermissions } from '../with-permissions/with-permissions.component' +import { UserService } from 'src/app/services/rest/user.service' +import { PaperlessUser } from 'src/app/data/paperless-user' + +@Component({ + selector: 'app-document-notes', + templateUrl: './document-notes.component.html', + styleUrls: ['./document-notes.component.scss'], +}) +export class DocumentNotesComponent extends ComponentWithPermissions { + noteForm: FormGroup = new FormGroup({ + newNote: new FormControl(''), + }) + + networkActive = false + newNoteError: boolean = false + + @Input() + documentId: number + + @Input() + notes: PaperlessDocumentNote[] = [] + + @Output() + updated: EventEmitter = new EventEmitter() + users: PaperlessUser[] + + constructor( + private notesService: DocumentNotesService, + private toastService: ToastService, + private usersService: UserService + ) { + super() + this.usersService.listAll().subscribe({ + next: (users) => { + this.users = users.results + }, + }) + } + + addNote() { + const note: string = this.noteForm.get('newNote').value.toString().trim() + if (note.length == 0) { + this.newNoteError = true + return + } + this.newNoteError = false + this.networkActive = true + this.notesService.addNote(this.documentId, note).subscribe({ + next: (result) => { + this.notes = result + this.noteForm.get('newNote').reset() + this.networkActive = false + this.updated.emit(this.notes) + }, + error: (e) => { + this.networkActive = false + this.toastService.showError( + $localize`Error saving note: ${e.toString()}` + ) + }, + }) + } + + deleteNote(noteId: number) { + this.notesService.deleteNote(this.documentId, noteId).subscribe({ + next: (result) => { + this.notes = result + this.networkActive = false + this.updated.emit(this.notes) + }, + error: (e) => { + this.networkActive = false + this.toastService.showError( + $localize`Error deleting note: ${e.toString()}` + ) + }, + }) + } + + displayName(note: PaperlessDocumentNote): string { + if (!note.user) return '' + const user = this.users.find((u) => u.id === note.user) + if (!user) return '' + const nameComponents = [] + if (user.first_name) nameComponents.unshift(user.first_name) + if (user.last_name) nameComponents.unshift(user.last_name) + if (user.username) { + if (nameComponents.length > 0) nameComponents.push(`(${user.username})`) + else nameComponents.push(user.username) + } + return nameComponents.join(' ') + } + + noteFormKeydown(event: KeyboardEvent) { + if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') { + this.addNote() + } + } +} diff --git a/src-ui/src/app/components/manage/settings/settings.component.html b/src-ui/src/app/components/manage/settings/settings.component.html index b7e7d64b45..3357aff789 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.html +++ b/src-ui/src/app/components/manage/settings/settings.component.html @@ -156,11 +156,11 @@
    -

    Comments

    +

    Notes

    - +
    diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts index 39aaaae283..d795d7f0e7 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.ts +++ b/src-ui/src/app/components/manage/settings/settings.component.ts @@ -85,7 +85,7 @@ export class SettingsComponent displayLanguage: new FormControl(null), dateLocale: new FormControl(null), dateFormat: new FormControl(null), - commentsEnabled: new FormControl(null), + notesEnabled: new FormControl(null), updateCheckingEnabled: new FormControl(null), notificationsConsumerNewDocument: new FormControl(null), @@ -196,7 +196,7 @@ export class SettingsComponent displayLanguage: this.settings.getLanguage(), dateLocale: this.settings.get(SETTINGS_KEYS.DATE_LOCALE), dateFormat: this.settings.get(SETTINGS_KEYS.DATE_FORMAT), - commentsEnabled: this.settings.get(SETTINGS_KEYS.COMMENTS_ENABLED), + notesEnabled: this.settings.get(SETTINGS_KEYS.NOTES_ENABLED), updateCheckingEnabled: this.settings.get( SETTINGS_KEYS.UPDATE_CHECKING_ENABLED ), @@ -552,8 +552,8 @@ export class SettingsComponent this.settingsForm.value.notificationsConsumerSuppressOnDashboard ) this.settings.set( - SETTINGS_KEYS.COMMENTS_ENABLED, - this.settingsForm.value.commentsEnabled + SETTINGS_KEYS.NOTES_ENABLED, + this.settingsForm.value.notesEnabled ) this.settings.set( SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, diff --git a/src-ui/src/app/data/paperless-document-comment.ts b/src-ui/src/app/data/paperless-document-comment.ts deleted file mode 100644 index 884e59096f..0000000000 --- a/src-ui/src/app/data/paperless-document-comment.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ObjectWithId } from './object-with-id' -import { PaperlessUser } from './paperless-user' - -export interface PaperlessDocumentComment extends ObjectWithId { - created?: Date - comment?: string - user?: PaperlessUser -} diff --git a/src-ui/src/app/data/paperless-document-note.ts b/src-ui/src/app/data/paperless-document-note.ts new file mode 100644 index 0000000000..569b494488 --- /dev/null +++ b/src-ui/src/app/data/paperless-document-note.ts @@ -0,0 +1,7 @@ +import { ObjectWithId } from './object-with-id' + +export interface PaperlessDocumentNote extends ObjectWithId { + created?: Date + note?: string + user?: number // PaperlessUser +} diff --git a/src-ui/src/app/data/paperless-document.ts b/src-ui/src/app/data/paperless-document.ts index be15efb01d..755d44f6ae 100644 --- a/src-ui/src/app/data/paperless-document.ts +++ b/src-ui/src/app/data/paperless-document.ts @@ -4,14 +4,14 @@ 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' +import { PaperlessDocumentNote } from './paperless-document-note' export interface SearchHit { score?: number rank?: number highlights?: string - comment_highlights?: string + note_highlights?: string } export interface PaperlessDocument extends ObjectWithPermissions { @@ -55,7 +55,7 @@ export interface PaperlessDocument extends ObjectWithPermissions { archive_serial_number?: number - comments?: PaperlessDocumentComment[] + notes?: PaperlessDocumentNote[] __search_hit__?: SearchHit } diff --git a/src-ui/src/app/data/paperless-uisettings.ts b/src-ui/src/app/data/paperless-uisettings.ts index d2b4c583d5..4701a43008 100644 --- a/src-ui/src/app/data/paperless-uisettings.ts +++ b/src-ui/src/app/data/paperless-uisettings.ts @@ -34,7 +34,7 @@ export const SETTINGS_KEYS = { 'general-settings:notifications:consumer-failed', NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD: 'general-settings:notifications:consumer-suppress-on-dashboard', - COMMENTS_ENABLED: 'general-settings:comments-enabled', + NOTES_ENABLED: 'general-settings:notes-enabled', SLIM_SIDEBAR: 'general-settings:slim-sidebar', UPDATE_CHECKING_ENABLED: 'general-settings:update-checking:enabled', UPDATE_CHECKING_BACKEND_SETTING: @@ -125,7 +125,7 @@ export const SETTINGS: PaperlessUiSetting[] = [ default: true, }, { - key: SETTINGS_KEYS.COMMENTS_ENABLED, + key: SETTINGS_KEYS.NOTES_ENABLED, type: 'boolean', default: true, }, diff --git a/src-ui/src/app/services/permissions.service.ts b/src-ui/src/app/services/permissions.service.ts index a7ba7638d9..e1ce949773 100644 --- a/src-ui/src/app/services/permissions.service.ts +++ b/src-ui/src/app/services/permissions.service.ts @@ -18,7 +18,7 @@ export enum PermissionType { SavedView = '%s_savedview', PaperlessTask = '%s_paperlesstask', UISettings = '%s_uisettings', - Comment = '%s_comment', + Note = '%s_note', MailAccount = '%s_mailaccount', MailRule = '%s_mailrule', User = '%s_user', diff --git a/src-ui/src/app/services/rest/document-comments.service.ts b/src-ui/src/app/services/rest/document-comments.service.ts deleted file mode 100644 index a697c0e939..0000000000 --- a/src-ui/src/app/services/rest/document-comments.service.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Injectable } from '@angular/core' -import { HttpClient, HttpParams } from '@angular/common/http' -import { PaperlessDocumentComment } from 'src/app/data/paperless-document-comment' -import { AbstractPaperlessService } from './abstract-paperless-service' -import { Observable } from 'rxjs' - -@Injectable({ - providedIn: 'root', -}) -export class DocumentCommentsService extends AbstractPaperlessService { - constructor(http: HttpClient) { - super(http, 'documents') - } - - getComments(documentId: number): Observable { - return this.http.get( - this.getResourceUrl(documentId, 'comments') - ) - } - - addComment(id: number, comment): Observable { - return this.http.post( - this.getResourceUrl(id, 'comments'), - { comment: comment } - ) - } - - deleteComment( - documentId: number, - commentId: number - ): Observable { - return this.http.delete( - this.getResourceUrl(documentId, 'comments'), - { params: new HttpParams({ fromString: `id=${commentId}` }) } - ) - } -} diff --git a/src-ui/src/app/services/rest/document-notes.service.ts b/src-ui/src/app/services/rest/document-notes.service.ts new file mode 100644 index 0000000000..11bbde447d --- /dev/null +++ b/src-ui/src/app/services/rest/document-notes.service.ts @@ -0,0 +1,37 @@ +import { Injectable } from '@angular/core' +import { HttpClient, HttpParams } from '@angular/common/http' +import { PaperlessDocumentNote } from 'src/app/data/paperless-document-note' +import { AbstractPaperlessService } from './abstract-paperless-service' +import { Observable } from 'rxjs' + +@Injectable({ + providedIn: 'root', +}) +export class DocumentNotesService extends AbstractPaperlessService { + constructor(http: HttpClient) { + super(http, 'documents') + } + + getNotes(documentId: number): Observable { + return this.http.get( + this.getResourceUrl(documentId, 'notes') + ) + } + + addNote(id: number, note: string): Observable { + return this.http.post( + this.getResourceUrl(id, 'notes'), + { note: note } + ) + } + + deleteNote( + documentId: number, + noteId: number + ): Observable { + return this.http.delete( + this.getResourceUrl(documentId, 'notes'), + { params: new HttpParams({ fromString: `id=${noteId}` }) } + ) + } +} diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 4e7e97110f..63b447b9af 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -22,6 +22,7 @@ export const DOCUMENT_SORT_FIELDS = [ { field: 'created', name: $localize`Created` }, { field: 'added', name: $localize`Added` }, { field: 'modified', name: $localize`Modified` }, + { field: 'num_notes', name: $localize`Notes` }, ] export const DOCUMENT_SORT_FIELDS_FULLTEXT = [ diff --git a/src-ui/src/theme.scss b/src-ui/src/theme.scss index 7090d8d40f..92b078994e 100644 --- a/src-ui/src/theme.scss +++ b/src-ui/src/theme.scss @@ -137,6 +137,10 @@ $form-check-radio-checked-bg-image-dark: url("data:image/svg+xml,