Merge pull request 'definitionList UI support - v 4.1' (#10) from mt-definition-list-ui into master
Reviewed-on: #10
This commit is contained in:
commit
cc1a1b34d4
|
@ -125,11 +125,11 @@ def export_sense(doc, sense):
|
||||||
definition_list = doc.createElement("definitionList")
|
definition_list = doc.createElement("definitionList")
|
||||||
sense_xml.appendChild(definition_list)
|
sense_xml.appendChild(definition_list)
|
||||||
|
|
||||||
for typ, text in sense.definition.items():
|
for definition in sense.definitions:
|
||||||
definition = doc.createElement("definition")
|
definition_xml = doc.createElement("definition")
|
||||||
definition.textContent = text
|
definition_xml.textContent = definition["value"]
|
||||||
definition.setAttribute("type", typ)
|
definition_xml.setAttribute("type", definition["type"])
|
||||||
definition_list.appendChild(definition)
|
definition_list.appendChild(definition_xml)
|
||||||
|
|
||||||
translation_container_list = doc.createElement("translationContainerList")
|
translation_container_list = doc.createElement("translationContainerList")
|
||||||
export_translation_list(doc, sense, translation_container_list)
|
export_translation_list(doc, sense, translation_container_list)
|
||||||
|
|
|
@ -26,6 +26,11 @@ def double_list_getter(firstParameter, secondParameter, allowEmptyField = False)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def definitions_getter():
|
||||||
|
result = {}
|
||||||
|
result["indicator"] = document.getElementById("indicator-input").value
|
||||||
|
result["explanation"] = document.getElementById("explanation-input").value
|
||||||
|
return result
|
||||||
|
|
||||||
def label_list_getter():
|
def label_list_getter():
|
||||||
result = []
|
result = []
|
||||||
|
|
|
@ -16,6 +16,7 @@ class ShowSenseLabelEdit(ClickMessage):
|
||||||
class ShowSenseDefinitionEdit(ClickMessage):
|
class ShowSenseDefinitionEdit(ClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
model.sense = self.get_arg(0, Sense)
|
model.sense = self.get_arg(0, Sense)
|
||||||
|
model.sense.make_copy()
|
||||||
model.modal_set(lambda: modals.edit_sense_definition(model.sense))
|
model.modal_set(lambda: modals.edit_sense_definition(model.sense))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,15 +43,42 @@ class AddToLabelList(NoReset):
|
||||||
class AddSense(Message):
|
class AddSense(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = Sense()
|
sense = Sense()
|
||||||
sense.definition = {"indicator": "New Sense"}
|
sense.definitions = [{"type": "indicator", "value": "Nov pomen"}]
|
||||||
model.entry.senses.append(sense)
|
model.entry.senses.append(sense)
|
||||||
|
|
||||||
|
|
||||||
class EditSenseDefinition(QuestionMessage):
|
class EditSenseDefinition(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = self.get_arg(0, Sense)
|
sense = self.get_arg(0, Sense)
|
||||||
sense.definition["indicator"] = self.new_text
|
definitions_values = common_accessors.definitions_getter()
|
||||||
|
indicator = None
|
||||||
|
explanation = None
|
||||||
|
|
||||||
|
for x in sense.definitions:
|
||||||
|
if indicator is None and x["type"] == "indicator":
|
||||||
|
indicator = x
|
||||||
|
if explanation is not None:
|
||||||
|
break
|
||||||
|
if explanation is None and x["type"] == "explanation":
|
||||||
|
explanation = x
|
||||||
|
if indicator is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
if definitions_values["indicator"] != "":
|
||||||
|
if indicator is None:
|
||||||
|
indicator = {"type": "indicator"}
|
||||||
|
sense.definitions.append(indicator)
|
||||||
|
indicator["value"] = definitions_values["indicator"]
|
||||||
|
elif indicator is not None:
|
||||||
|
sense.definitions.remove(indicator)
|
||||||
|
|
||||||
|
if definitions_values["explanation"] != "":
|
||||||
|
if explanation is None:
|
||||||
|
explanation = {"type": "explanation"}
|
||||||
|
sense.definitions.append(explanation)
|
||||||
|
explanation["value"] = definitions_values["explanation"]
|
||||||
|
elif explanation is not None:
|
||||||
|
sense.definitions.remove(explanation)
|
||||||
|
|
||||||
class EditComment(QuestionMessage):
|
class EditComment(QuestionMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Sense(Data):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.original_idx = -1
|
self.original_idx = -1
|
||||||
self.id = None
|
self.id = None
|
||||||
self.definition = {}
|
self.definitions = []
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.translations = []
|
self.translations = []
|
||||||
self.examples = []
|
self.examples = []
|
||||||
|
@ -21,9 +21,7 @@ class Sense(Data):
|
||||||
self.original_idx = idx
|
self.original_idx = idx
|
||||||
self.id = sense_xml.getAttribute("id") if sense_xml.hasAttribute("id") else None
|
self.id = sense_xml.getAttribute("id") if sense_xml.hasAttribute("id") else None
|
||||||
|
|
||||||
for definition in sense_xml.querySelectorAll("definitionList definition"):
|
self.definitions = [{"value": v.textContent, "type": v.getAttribute("type")} for v in sense_xml.querySelectorAll("definitionList definition")]
|
||||||
key = definition.getAttribute("type")
|
|
||||||
self.definition[key] = definition.textContent
|
|
||||||
|
|
||||||
self.labels = import_label_list("sense > labelList label", sense_xml)
|
self.labels = import_label_list("sense > labelList label", sense_xml)
|
||||||
self.translations = from_container_list(
|
self.translations = from_container_list(
|
||||||
|
@ -39,13 +37,18 @@ class Sense(Data):
|
||||||
|
|
||||||
def view(self, model, sense_num):
|
def view(self, model, sense_num):
|
||||||
examples = [example.view(model, self) for example in self.examples]
|
examples = [example.view(model, self) for example in self.examples]
|
||||||
|
definition = ""
|
||||||
|
for x in self.definitions:
|
||||||
|
if x["type"] == "indicator":
|
||||||
|
definition = x.value
|
||||||
|
break
|
||||||
|
|
||||||
result = h("div.elm-div", {}, [
|
result = h("div.elm-div", {}, [
|
||||||
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
|
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
|
||||||
h("div.sense", {}, [
|
h("div.sense", {}, [
|
||||||
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
|
||||||
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
|
||||||
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
|
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, definition),
|
||||||
h("div", {}, View.view_translations(self.translations, self, model)),
|
h("div", {}, View.view_translations(self.translations, self, model)),
|
||||||
h("div", {}, examples)])])
|
h("div", {}, examples)])])
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -11,7 +11,7 @@ def modal_template(content, title, msg, delete_msg=None):
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
footer.append(h("a#modal-ok.button", {"on": {"click": message.msg(*msg)}}, "OK"))
|
footer.append(h("a#modal-ok.button", {"on": {"click": message.msg(*msg)}}, "OK"))
|
||||||
|
|
||||||
footer.append(h("label.button.dangerous", {"on": {"click": reset}}, "Cancel"))
|
footer.append(h("label.button.dangerous", {"on": {"click": reset}}, "Prekliči"))
|
||||||
if delete_msg is not None:
|
if delete_msg is not None:
|
||||||
footer.append(h("label.button.warning.modal-delete", {"on": {"click": message.msg(*delete_msg)}}, "🗑"))
|
footer.append(h("label.button.warning.modal-delete", {"on": {"click": message.msg(*delete_msg)}}, "🗑"))
|
||||||
|
|
||||||
|
@ -47,6 +47,34 @@ def generic_list_editor(title, element_list_getter):
|
||||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def generic_key_value_editor(title, element_list_getter, key, value = "value"):
|
||||||
|
def split_line2(left, right):
|
||||||
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
|
return h("div.{}".format(cls), {}, [
|
||||||
|
h("div.half", {}, left), h("div.half", {}, right)])
|
||||||
|
content = [h("p", {}, title)]
|
||||||
|
for i, element in enumerate(element_list_getter()):
|
||||||
|
keys = []
|
||||||
|
values = []
|
||||||
|
keys.append(h("label", {"attrs": {"for": i}}, key.capitalize() + ":"))
|
||||||
|
keys.append(h("input." + key + "-input", {"props": {"type": "text", "value": element[key], "id": i}}, ""))
|
||||||
|
values.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||||
|
values.append(
|
||||||
|
h("input.value-input", {"props": {"type": "text", "value": element[value], "id": i + "-value"}}, ""))
|
||||||
|
content.append(split_line2(keys, values))
|
||||||
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||||
|
return content
|
||||||
|
|
||||||
|
def sense_definitions_editor(title, type_value, explanation_value):
|
||||||
|
type_props = {"value": type_value, "type": "text"}
|
||||||
|
explanation_props = {"value": explanation_value, "type": "text"}
|
||||||
|
return [
|
||||||
|
h("span", {}, "Indikator:"),
|
||||||
|
h("label", {}, [h("input#indicator-input", {"props": type_props}, "")]),
|
||||||
|
h("span", {}, "Razlaga:"),
|
||||||
|
h("label", {}, [h("input#explanation-input", {"props": explanation_props}, "")])
|
||||||
|
]
|
||||||
|
|
||||||
def homonymy_editor(title, current_labels):
|
def homonymy_editor(title, current_labels):
|
||||||
def split_line2(left, right):
|
def split_line2(left, right):
|
||||||
cls = "flex.two{}".format(".double-list-row")
|
cls = "flex.two{}".format(".double-list-row")
|
||||||
|
|
|
@ -109,10 +109,9 @@ def edit_variants(entry):
|
||||||
|
|
||||||
def edit_homonymy(entry):
|
def edit_homonymy(entry):
|
||||||
hget = lambda: entry.copy().homonymy
|
hget = lambda: entry.copy().homonymy
|
||||||
content = homonymy_editor("Homonymy", hget)
|
content = generic_key_value_editor("Homonymy", hget, "name")
|
||||||
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
||||||
|
|
||||||
|
|
||||||
def edit_related_entries(entry):
|
def edit_related_entries(entry):
|
||||||
reget = lambda: entry.copy().related_entries
|
reget = lambda: entry.copy().related_entries
|
||||||
content = generic_list_editor("Related entries", reget)
|
content = generic_list_editor("Related entries", reget)
|
||||||
|
@ -125,7 +124,19 @@ def edit_entry_labels(entry):
|
||||||
|
|
||||||
|
|
||||||
def edit_sense_definition(sense):
|
def edit_sense_definition(sense):
|
||||||
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", (message.EditSenseDefinition, sense))
|
indicator = ""
|
||||||
|
explanation = ""
|
||||||
|
for x in sense.copy().definitions:
|
||||||
|
if indicator == "" and x["type"] == "indicator":
|
||||||
|
indicator = x.value
|
||||||
|
if explanation is not "":
|
||||||
|
break
|
||||||
|
if explanation == "" and x["type"] == "explanation":
|
||||||
|
explanation = x.value
|
||||||
|
if indicator is not "":
|
||||||
|
break
|
||||||
|
content = sense_definitions_editor(indicator, explanation)
|
||||||
|
return modal_template(content, "Definicije pomena", (message.EditSenseDefinition, sense))
|
||||||
|
|
||||||
|
|
||||||
def edit_comment(comment):
|
def edit_comment(comment):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user