Adding variants and labels to entry, not yet done.

This commit is contained in:
Ozbolt Menegatti 2019-11-18 20:27:11 +01:00
parent a058a50017
commit 4bdb3bfc7f
8 changed files with 68 additions and 19 deletions

View File

@ -43,14 +43,11 @@
font-style: italic; font-style: italic;
margin-left: 1em; margin-left: 1em;
} }
#comment {
border-radius: 0em;
float: right;
&:before {
content: "Opomba: "
} }
#entry-buttons {
button {
display: block;
} }
} }

View File

@ -1,7 +1,7 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose from message.simple_messages import NoReset, Reset, ModalNotOkClose
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation 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.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 from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants
from message.message import msg from message.message import msg

View File

@ -46,6 +46,13 @@ class ShowCommentEdit(ClickMessage):
model.modal = lambda: modals.edit_comment(model.entry.comment) 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): class ShowExampleEdit(ClickMessage):
def update_model(self, model): def update_model(self, model):
model.modal_shown = True model.modal_shown = True

View File

@ -24,11 +24,10 @@ class AddSenseLabel(NoReset):
sense.copy().labels.append("") sense.copy().labels.append("")
class AddExampleTranslation(NoReset): class AddToGenericList(NoReset):
def update_model(self, model): def update_model(self, model):
example = self.get_arg(0, Example) list_getter = self.get_arg(0)
# just adding to the copy to show in the modal list_getter().append("")
example.copy().translations.append("")
class AddToLabelList(NoReset): class AddToLabelList(NoReset):
@ -70,3 +69,10 @@ class EditExample(QuestionMessage):
example = self.get_arg(0, Example) example = self.get_arg(0, Example)
example.example = self.new_text example.example = self.new_text
class EditVariants(Message):
def update_model(self, model):
variants = common_accessors.generic_list_getter()
model.entry.variants = variants

View File

@ -12,6 +12,18 @@ class Entry(Editable):
self.headword = headword.textContent if headword else "" self.headword = headword.textContent if headword else ""
self.grammar = grammar.textContent if grammar else "" self.grammar = grammar.textContent if grammar else ""
self.comment = comment.textContent if comment 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 self.senses = [Sense(sense_xml) for sense_xml in
entry_xml.querySelectorAll("body senseList sense")] entry_xml.querySelectorAll("body senseList sense")]

View File

@ -22,12 +22,12 @@ def question(question, current_value):
h("input#modal-question", {"props": {"type": "text", "value": current_value}}, "")])] h("input#modal-question", {"props": {"type": "text", "value": current_value}}, "")])]
def generic_list_editor(title, element_list_getter, add_click_message): def generic_list_editor(title, element_list_getter):
content = [h("span.list", {}, title)] content = [h("p", {}, title)]
for slabel in element_list_getter(): for slabel in element_list_getter():
content.append(h("label", {}, [ content.append(h("label", {}, [
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")])) 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 return content

View File

@ -32,10 +32,16 @@ def edit_sense_label(sense):
def edit_example_translation(example): def edit_example_translation(example):
etl_getter = lambda: example.copy().translations 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)) 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(): def add_sense():
return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense()) return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense())

View File

@ -32,11 +32,32 @@ class View:
h("div#entry-status", {}, entry.status), h("div#entry-status", {}, entry.status),
h("div#entry-header", {}, [ h("div#entry-header", {}, [
h("span#headword", {}, entry.headword), h("span#headword", {}, entry.headword),
h("span#grammar", {}, entry.grammar), h("span#grammar", {}, entry.grammar)]),
h("button#comment.warning", {"on": {"click": msg(ShowCommentEdit())}}, entry.comment)]), View.view_entry_button_section(entry),
h("div#sense-container", {}, view_sense_list), h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")]) 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 @staticmethod
def view_sense(sense, senseNum): def view_sense(sense, senseNum):
examples = [View.view_example(example) for example in sense.examples] examples = [View.view_example(example) for example in sense.examples]