From 49a21fb4c6eb88bd479aca6aaebf1ca3a33f75f1 Mon Sep 17 00:00:00 2001 From: Ohad Cohen Date: Mon, 22 Jul 2019 17:13:48 +0300 Subject: [PATCH 1/6] Add backend support for annotation update --- backend/webserver/api/annotations.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/webserver/api/annotations.py b/backend/webserver/api/annotations.py index 2c539805..7ecdebae 100644 --- a/backend/webserver/api/annotations.py +++ b/backend/webserver/api/annotations.py @@ -19,6 +19,8 @@ create_annotation.add_argument('keypoints', type=list, location='json') create_annotation.add_argument('color', location='json') +update_annotation = reqparse.RequestParser() +update_annotation.add_argument('category_id', type=int, location='json') @api.route('/') class Annotation(Resource): @@ -90,6 +92,26 @@ def delete(self, annotation_id): set__deleted_date=datetime.datetime.now()) return {'success': True} + @api.expect(update_annotation) + @login_required + def put(self, annotation_id): + """ Updates an annotation by ID """ + annotation = current_user.annotations.filter(id=annotation_id).first() + + if annotation is None: + return { "message": "Invalid annotation id" }, 400 + + args = update_annotation.parse_args() + + new_category_id = args.get('category_id') + if new_category_id is not None: + logger.info( + f'{current_user.username} is trying to update a category for annotation id {annotation.id} ({annotation.metadata.get("name")}) from {annotation.category_id} to {new_category_id}' + ) + annotation.update(category_id=new_category_id) + + return { success: True } + # @api.route('//mask') # class AnnotationMask(Resource): From 483cd79475a05d1fd877e330e5747dc5c5131e76 Mon Sep 17 00:00:00 2001 From: Ohad Cohen Date: Mon, 22 Jul 2019 17:21:07 +0300 Subject: [PATCH 2/6] Return the new annotation from the update --- backend/webserver/api/annotations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/webserver/api/annotations.py b/backend/webserver/api/annotations.py index 7ecdebae..92bde14d 100644 --- a/backend/webserver/api/annotations.py +++ b/backend/webserver/api/annotations.py @@ -110,7 +110,7 @@ def put(self, annotation_id): ) annotation.update(category_id=new_category_id) - return { success: True } + return query_util.fix_ids(annotation) # @api.route('//mask') From 73310e98d400cd441dec9d5089fbaa3489d92165 Mon Sep 17 00:00:00 2001 From: Ohad Cohen Date: Tue, 23 Jul 2019 09:43:20 +0300 Subject: [PATCH 3/6] Pass allCategories prop to Category and Annotation --- client/src/components/annotator/Category.vue | 13 +++++++++++-- client/src/views/Annotator.vue | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/src/components/annotator/Category.vue b/client/src/components/annotator/Category.vue index 7b82be9a..065e3cb5 100755 --- a/client/src/components/annotator/Category.vue +++ b/client/src/components/annotator/Category.vue @@ -76,8 +76,8 @@ :active-tool="activeTool" :scale="scale" @deleted="annotationDeleted" + :all-categories="getCategoriesList" /> -
- @@ -181,6 +180,10 @@ export default { activeTool: { type: String, required: true + }, + allCategories: { + type: Array, + required: true } }, data: function() { @@ -393,6 +396,12 @@ export default { if (search.length === 0) return true; return this.category.name.toLowerCase().includes(search); }, + getCategoriesList() { + return this.allCategories.map(category => ({ + value: category.id, + text: category.name + })); + }, isCurrent() { return this.current.category === this.index; }, diff --git a/client/src/views/Annotator.vue b/client/src/views/Annotator.vue index 5af47287..cbdf2303 100755 --- a/client/src/views/Annotator.vue +++ b/client/src/views/Annotator.vue @@ -125,6 +125,7 @@ :simplify="simplify" :categorysearch="search" :category="category" + :all-categories="categories" :opacity="shapeOpacity" :hover="hover" :index="index" @@ -202,7 +203,6 @@ - From 40b3342fbe4c283c73edd83cc566037b2ea1c3b5 Mon Sep 17 00:00:00 2001 From: Ohad Cohen Date: Tue, 23 Jul 2019 09:45:25 +0300 Subject: [PATCH 4/6] Add annotation-update support in the client --- .../src/components/annotator/Annotation.vue | 42 +++++++++++++++---- client/src/models/annotations.js | 3 ++ client/src/views/Annotator.vue | 35 ++++++++++++---- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/client/src/components/annotator/Annotation.vue b/client/src/components/annotator/Annotation.vue index 9eab39bd..d33545b3 100755 --- a/client/src/components/annotator/Annotation.vue +++ b/client/src/components/annotator/Annotation.vue @@ -94,7 +94,7 @@ - + @@ -136,19 +136,31 @@