From eab7fba7cd0dad8905fc3da9ffb48e152ec92c6c Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 12 Mar 2021 08:29:44 +0900 Subject: [PATCH] Add comment form to the ToolbarLabeling.vue --- .../tasks/toolbar/ToolbarLabeling.vue | 15 +++++++++++++- .../tasks/toolbar/forms/FormComment.vue | 20 ++++++++++--------- frontend/repositories/comment/api.ts | 8 ++++---- frontend/repositories/comment/interface.ts | 8 ++++---- .../services/application/comment.service.ts | 10 +++++----- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/frontend/components/tasks/toolbar/ToolbarLabeling.vue b/frontend/components/tasks/toolbar/ToolbarLabeling.vue index aeaa591b..21c77fe7 100644 --- a/frontend/components/tasks/toolbar/ToolbarLabeling.vue +++ b/frontend/components/tasks/toolbar/ToolbarLabeling.vue @@ -27,8 +27,14 @@ + + + import Vue from 'vue' -import { mapGetters } from 'vuex' import BaseCard from '@/components/utils/BaseCard.vue' import Comment from '@/components/comment/Comment.vue' import FormCreate from '@/components/comment/FormCreate.vue' @@ -35,6 +34,13 @@ export default Vue.extend({ FormCreate }, + props: { + docId: { + type: Number, + required: true + } + }, + async fetch() { this.user = await this.$services.user.getMyProfile() }, @@ -46,10 +52,6 @@ export default Vue.extend({ } }, - computed: { - ...mapGetters('documents', ['currentDoc']) - }, - watch: { currentDoc: { handler(val) { @@ -64,18 +66,18 @@ export default Vue.extend({ methods: { async list() { - this.comments = await this.$services.comment.list(this.$route.params.id, this.currentDoc.id) + this.comments = await this.$services.comment.list(this.$route.params.id, this.docId) }, async add(message: string) { - await this.$services.comment.create(this.$route.params.id, this.currentDoc.id, message) + await this.$services.comment.create(this.$route.params.id, this.docId, message) this.list() }, async remove(item: CommentReadDTO) { - await this.$services.comment.delete(this.$route.params.id, this.currentDoc.id, item) + await this.$services.comment.delete(this.$route.params.id, this.docId, item) this.list() }, async maybeUpdate(item: CommentReadDTO) { - await this.$services.comment.update(this.$route.params.id, this.currentDoc.id, item) + await this.$services.comment.update(this.$route.params.id, this.docId, item) this.list() } } diff --git a/frontend/repositories/comment/api.ts b/frontend/repositories/comment/api.ts index a0d485cc..397f0188 100644 --- a/frontend/repositories/comment/api.ts +++ b/frontend/repositories/comment/api.ts @@ -14,28 +14,28 @@ export class FromApiCommentItemListRepository implements CommentItemListReposito return items.map(item => CommentItem.valueOf(item)) } - async list(projectId: string, docId: string): Promise { + async list(projectId: string, docId: number): Promise { const url = `/projects/${projectId}/docs/${docId}/comments` const response = await this.request.get(url) const items: CommentItemResponse[] = response.data return items.map(item => CommentItem.valueOf(item)) } - async create(projectId: string, docId: string, text: string): Promise { + async create(projectId: string, docId: number, text: string): Promise { const url = `/projects/${projectId}/docs/${docId}/comments` const response = await this.request.post(url, { projectId, docId, text }) const responseItem: CommentItemResponse = response.data return CommentItem.valueOf(responseItem) } - async update(projectId: string, docId: string, item: CommentItem): Promise { + async update(projectId: string, docId: number, item: CommentItem): Promise { const url = `/projects/${projectId}/docs/${docId}/comments/${item.id}` const response = await this.request.put(url, item.toObject()) const responseItem: CommentItemResponse = response.data return CommentItem.valueOf(responseItem) } - async delete(projectId: string, docId: string, commentId: number): Promise { + async delete(projectId: string, docId: number, commentId: number): Promise { const url = `/projects/${projectId}/docs/${docId}/comments/${commentId}` const response = await this.request.delete(url) } diff --git a/frontend/repositories/comment/interface.ts b/frontend/repositories/comment/interface.ts index 02c273bc..30c4bc54 100644 --- a/frontend/repositories/comment/interface.ts +++ b/frontend/repositories/comment/interface.ts @@ -13,13 +13,13 @@ export interface CommentItemResponse { export interface CommentItemListRepository { listAll(projectId: string, q: string): Promise - list(projectId: string, docId: string): Promise + list(projectId: string, docId: number): Promise - create(projectId: string, docId: string, text: string): Promise + create(projectId: string, docId: number, text: string): Promise - update(projectId: string, docId: string, item: CommentItem): Promise + update(projectId: string, docId: number, item: CommentItem): Promise - delete(projectId: string, docId: string, commentId: number): Promise + delete(projectId: string, docId: number, commentId: number): Promise deleteBulk(projectId: string, items: number[]): Promise } diff --git a/frontend/services/application/comment.service.ts b/frontend/services/application/comment.service.ts index ee0d6f7d..e70172c0 100644 --- a/frontend/services/application/comment.service.ts +++ b/frontend/services/application/comment.service.ts @@ -29,23 +29,23 @@ export class CommentApplicationService { return items.map(item => new CommentReadDTO(item)) } - public async list(projectId: string, docId: string): Promise { + public async list(projectId: string, docId: number): Promise { const items = await this.repository.list(projectId, docId) return items.map(item => new CommentReadDTO(item)) } - public create(projectId: string, docId: string, text: string): Promise { + public create(projectId: string, docId: number, text: string): Promise { return this.repository.create(projectId, docId, text) } - public update(projectId: string, docId: string, item: CommentReadDTO): Promise { + public update(projectId: string, docId: number, item: CommentReadDTO): Promise { const comment = new CommentItem( - item.id, item.user, item.username, parseInt(docId), item.documentText, item.text, item.createdAt + item.id, item.user, item.username, docId, item.documentText, item.text, item.createdAt ) return this.repository.update(projectId, docId, comment) } - public delete(projectId: string, docId: string, item: CommentReadDTO): Promise { + public delete(projectId: string, docId: number, item: CommentReadDTO): Promise { return this.repository.delete(projectId, docId, item.id) }