From 06ab8f2230dab1215c4a4a78c09116ab4c11c845 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Mon, 18 Nov 2019 20:57:33 +0100 Subject: [PATCH] Editing entry labels --- src/message/__init__.py | 4 ++-- src/message/show_messages.py | 7 +++++++ src/message/simple_edits.py | 7 +++++++ src/view/modals.py | 5 +++++ src/view/view.py | 8 +++----- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/message/__init__.py b/src/message/__init__.py index b2c954d..41648eb 100644 --- a/src/message/__init__.py +++ b/src/message/__init__.py @@ -1,7 +1,7 @@ from message.simple_messages import NoReset, Reset, ModalNotOkClose from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation -from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit -from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants +from message.show_messages import ShowMenu, ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit +from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels from message.message import msg diff --git a/src/message/show_messages.py b/src/message/show_messages.py index b34e83a..b06d058 100644 --- a/src/message/show_messages.py +++ b/src/message/show_messages.py @@ -102,3 +102,10 @@ class ShowAddTranslation(ClickMessage): return console.log("Should not be here!") + + +class ShowEntryLabelsEdit(ClickMessage): + def update_model(self, model): + model.modal_shown = True + model.entry.make_copy() + model.modal = lambda: modals.edit_entry_labels(model.entry) diff --git a/src/message/simple_edits.py b/src/message/simple_edits.py index b464f5f..e679652 100644 --- a/src/message/simple_edits.py +++ b/src/message/simple_edits.py @@ -74,5 +74,12 @@ class EditVariants(Message): def update_model(self, model): variants = common_accessors.generic_list_getter() model.entry.variants = variants + + +class EditEntryLabels(Message): + def update_model(self, model): + labels = common_accessors.label_list_getter() + model.entry.labels = labels + diff --git a/src/view/modals.py b/src/view/modals.py index 0ee6326..d639c78 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -42,6 +42,11 @@ def edit_variants(entry): return modal_template(content, "Add or remove variants", message.EditVariants()) +def edit_entry_labels(entry): + content = label_list_editor(entry.copy().labels, message.AddToLabelList(entry.copy().labels)) + return modal_template(content, "Translation", message.EditEntryLabels()) + + def add_sense(): return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense()) diff --git a/src/view/view.py b/src/view/view.py index 1bfefc8..c211aab 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -44,18 +44,16 @@ class View: buttons = [ h("button.warning", clk(ShowCommentEdit()), "Comment"), h("button.normal", clk(ShowVariantsEdit()), "Variants"), - h("button.success", clk(ShowCommentEdit()), "Labels")] + h("button.success", clk(ShowEntryLabelsEdit()), "Labels")] if entry.comment == "" and len(entry.labels) == 0 and len(entry.variants) == 0: return h("div", {}, buttons) - # if entry.comment != "": - # buttons[0] = h("button.warning", clk(ShowCommentEdit()), "Comment: {}".format(entry.comment)) - + labels = ", ".join([val for _, val in entry.labels]) return h("table", {}, [ h("tr", {}, [ h("td", {}, buttons[0]), h("td", {}, entry.comment)]), h("tr", {}, [ h("td", {}, buttons[1]), h("td", {}, ", ".join(entry.variants))]), - h("tr", {}, [ h("td", {}, buttons[2]), h("td", {}, "TODO")])]) + h("tr", {}, [ h("td", {}, buttons[2]), h("td", {}, labels)])]) @staticmethod