Adding variants and labels to entry, not yet done.

pull/1/head
Ozbolt Menegatti 5 years ago
parent a058a50017
commit 4bdb3bfc7f

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

@ -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

@ -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

@ -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):
@ -69,4 +68,11 @@ class EditExample(QuestionMessage):
def update_model(self, model): def update_model(self, model):
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

@ -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")]

@ -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

@ -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())

@ -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]

Loading…
Cancel
Save