diff --git a/res/main.less b/res/main.less index f37d3d0..1666f2b 100644 --- a/res/main.less +++ b/res/main.less @@ -43,14 +43,11 @@ font-style: italic; margin-left: 1em; } + } - #comment { - border-radius: 0em; - float: right; - - &:before { - content: "Opomba: " - } + #entry-buttons { + button { + display: block; } } diff --git a/src/message/__init__.py b/src/message/__init__.py index c6ef249..b2c954d 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 -from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList +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.message import msg diff --git a/src/message/show_messages.py b/src/message/show_messages.py index 3c8ecf0..b34e83a 100644 --- a/src/message/show_messages.py +++ b/src/message/show_messages.py @@ -46,6 +46,13 @@ class ShowCommentEdit(ClickMessage): model.modal = lambda: modals.edit_comment(model.entry.comment) +class ShowVariantsEdit(ClickMessage): + def update_model(self, model): + model.modal_shown = True + model.entry.make_copy() + model.modal = lambda: modals.edit_variants(model.entry) + + class ShowExampleEdit(ClickMessage): def update_model(self, model): model.modal_shown = True diff --git a/src/message/simple_edits.py b/src/message/simple_edits.py index 1cd4c17..b464f5f 100644 --- a/src/message/simple_edits.py +++ b/src/message/simple_edits.py @@ -24,11 +24,10 @@ class AddSenseLabel(NoReset): sense.copy().labels.append("") -class AddExampleTranslation(NoReset): +class AddToGenericList(NoReset): def update_model(self, model): - example = self.get_arg(0, Example) - # just adding to the copy to show in the modal - example.copy().translations.append("") + list_getter = self.get_arg(0) + list_getter().append("") class AddToLabelList(NoReset): @@ -69,4 +68,11 @@ class EditExample(QuestionMessage): def update_model(self, model): example = self.get_arg(0, Example) example.example = self.new_text + + +class EditVariants(Message): + def update_model(self, model): + variants = common_accessors.generic_list_getter() + model.entry.variants = variants + diff --git a/src/model/entry.py b/src/model/entry.py index ce5d1f7..a82b8ea 100644 --- a/src/model/entry.py +++ b/src/model/entry.py @@ -12,6 +12,18 @@ class Entry(Editable): self.headword = headword.textContent if headword else "" self.grammar = grammar.textContent if grammar else "" self.comment = comment.textContent if comment else "" + self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")] + + self.labels = [] + for tag_xml in entry_xml.querySelectorAll("head labelList label"): + t_type = tag_xml.getAttribute("type") + t_value = tag_xml.textContent + + if t_type not in TAGS: + # using some default + t_type = TAGS.keys()[0] + + self.labels.append((t_type, t_value)) self.senses = [Sense(sense_xml) for sense_xml in entry_xml.querySelectorAll("body senseList sense")] diff --git a/src/view/modal_templates.py b/src/view/modal_templates.py index 2dc6347..4bb6e89 100644 --- a/src/view/modal_templates.py +++ b/src/view/modal_templates.py @@ -22,12 +22,12 @@ def question(question, current_value): h("input#modal-question", {"props": {"type": "text", "value": current_value}}, "")])] -def generic_list_editor(title, element_list_getter, add_click_message): - content = [h("span.list", {}, title)] +def generic_list_editor(title, element_list_getter): + content = [h("p", {}, title)] for slabel in element_list_getter(): content.append(h("label", {}, [ h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")])) - content.append(h("button", {"on": {"click": add_click_message}}, "+")) + content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList(element_list_getter))}}, "+")) return content diff --git a/src/view/modals.py b/src/view/modals.py index 499c515..0ee6326 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -32,10 +32,16 @@ def edit_sense_label(sense): def edit_example_translation(example): etl_getter = lambda: example.copy().translations - content = generic_list_editor("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation(example))) + content = generic_list_editor("Edit example translations", etl_getter) return modal_template(content, "Example Translations", message.EditExampleTranslation(example)) +def edit_variants(entry): + vget = lambda: entry.copy().variants + content = generic_list_editor("Variants", vget) + return modal_template(content, "Add or remove variants", message.EditVariants()) + + 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 1a9896c..1bfefc8 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -32,11 +32,32 @@ class View: h("div#entry-status", {}, entry.status), h("div#entry-header", {}, [ h("span#headword", {}, entry.headword), - h("span#grammar", {}, entry.grammar), - h("button#comment.warning", {"on": {"click": msg(ShowCommentEdit())}}, entry.comment)]), + h("span#grammar", {}, entry.grammar)]), + View.view_entry_button_section(entry), h("div#sense-container", {}, view_sense_list), h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")]) + + @staticmethod + def view_entry_button_section(entry): + clk = lambda cls: {"on": {"click": msg(cls)}} + buttons = [ + h("button.warning", clk(ShowCommentEdit()), "Comment"), + h("button.normal", clk(ShowVariantsEdit()), "Variants"), + h("button.success", clk(ShowCommentEdit()), "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)) + + 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")])]) + + @staticmethod def view_sense(sense, senseNum): examples = [View.view_example(example) for example in sense.examples]