Adding variants and labels to entry, not yet done.
This commit is contained in:
parent
a058a50017
commit
4bdb3bfc7f
|
@ -43,14 +43,11 @@
|
|||
font-style: italic;
|
||||
margin-left: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
#comment {
|
||||
border-radius: 0em;
|
||||
float: right;
|
||||
|
||||
&:before {
|
||||
content: "Opomba: "
|
||||
}
|
||||
#entry-buttons {
|
||||
button {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
@ -70,3 +69,10 @@ class EditExample(QuestionMessage):
|
|||
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
|
||||
|
||||
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue
Block a user