From c2f8b2c5c45d934034274d67432f4a9a9a13e8b7 Mon Sep 17 00:00:00 2001 From: junyangzhang Date: Wed, 16 Jun 2021 15:09:43 +0800 Subject: [PATCH] fix --- client/src/annotator_ui.js | 44 ++++++++++++++++++++++++++++++++++++++ server/src/dispatch.py | 5 +++-- server/src/newEntity.py | 21 ++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/client/src/annotator_ui.js b/client/src/annotator_ui.js index 427c4e44..5a86bbd6 100644 --- a/client/src/annotator_ui.js +++ b/client/src/annotator_ui.js @@ -3348,6 +3348,7 @@ var AnnotatorUI = (function ($, window, undefined) { 0, fullPath.length - document.length ); + console.log(collection); $.post( "ajax.cgi", { @@ -3375,6 +3376,44 @@ var AnnotatorUI = (function ($, window, undefined) { ); }); + var deleteEntity = function () { + let entity = $('input[id^="span_"]').filter(':checked').val(); + + let fullPath = window.location.href.split("#")[1]; + let document = fullPath.split("/").reverse()[0]; + let collection = fullPath.substr( + 0, + fullPath.length - document.length + ); + + $.post( + "ajax.cgi", + { + protocol: 1, + action: "deleteEntity", + entity_name: entity, + collection: collection, + }, + function () { + dispatcher.post("ajax", [ + { + action: + "getCollectionInformation", + collection: collection, + }, + "collectionLoaded", + { + collection: collection, + keep: true, + }, + ]); + // window.location = window.location.pathname + "#" + collection + folderName; + // $("#span_form").dialog("close"); + } + ); + } + + var spanChangeLock = function (evt) { var $this = $(evt.target); var locked = $this.is(":checked"); @@ -3432,6 +3471,11 @@ var AnnotatorUI = (function ($, window, undefined) { text: "Create Entity", click: createEntity, }, + { + id: "span_form_delete_entity", + text: "Delete Entity", + click: deleteEntity, + }, ], create: function (evt) { var $ok = $("#span_form-ok").wrap( diff --git a/server/src/dispatch.py b/server/src/dispatch.py index c763df81..5e30d3ad 100644 --- a/server/src/dispatch.py +++ b/server/src/dispatch.py @@ -41,7 +41,7 @@ from newDocument import create_new_document, import_new_document, delete_new_document, create_folder from createSpanAll import create_span_all_text, create_span_all_re from utils import GLOBAL_LOGGER, fetch_all_annotations, prehandle_data, cache_model_results -from newEntity import create_new_entity +from newEntity import create_new_entity, delete_entity # no-op function that can be invoked by client to log a user action @@ -73,6 +73,7 @@ def logging_no_op(collection, document, log): 'splitSpan': split_span, 'createEntity': create_new_entity, + 'deleteEntity': delete_entity, 'createArc': create_arc, 'reverseArc': reverse_arc, @@ -133,7 +134,7 @@ def logging_no_op(collection, document, log): # Actions that correspond to labeling function functionality EXPAND_ACTION = {'labelingFunctionProcess', 'instantExecutor', 'addLabelingFunction', 'deleteLabelingFunction', 'getAvailableLabelingFunction', 'createSpanAllText', - 'createSpanAllRe', 'fetchAllAnnotations', 'preprocessModelData', 'createNewDocument', 'importNewDocument','deleteNewDocument', 'createNewUser', 'cacheModelResults', 'createFolder', 'createEntity'} + 'createSpanAllRe', 'fetchAllAnnotations', 'preprocessModelData', 'createNewDocument', 'importNewDocument','deleteNewDocument', 'createNewUser', 'cacheModelResults', 'createFolder', 'createEntity', 'deleteEntity'} # Actions that correspond to annotation functionality ANNOTATION_ACTION = {'createArc', 'deleteArc', 'createSpan', 'deleteSpan', 'splitSpan', 'suggestSpanTypes', 'undo'} diff --git a/server/src/newEntity.py b/server/src/newEntity.py index acd4bf2d..485acd82 100644 --- a/server/src/newEntity.py +++ b/server/src/newEntity.py @@ -17,6 +17,27 @@ def create_new_entity(**kwargs): config.set_allow_duplicate(False) config.archive() + res['status'] = 200 + + return res + + + +def delete_entity(**kwargs): + res = dict() + entity = kwargs['entity_name'] + collection = kwargs['collection'] + real_dir = real_directory(collection) + config_dir = real_dir + "annotation.conf" + configstr = __read_or_default(config_dir, __default_configuration) + configstr = configstr.split("\n") + + configstr.remove(entity) + + with open(config_dir, 'w') as configFile: + configFile.write("\n".join(configstr)) + + res['status'] = 200 return res \ No newline at end of file