Variants done
This commit is contained in:
parent
36cce3a86e
commit
e1ce093ff6
|
@ -42,7 +42,6 @@ def export_entry(entry):
|
||||||
homonymy = _original_xml_query_selector("head headword homonymy", entry, doc)
|
homonymy = _original_xml_query_selector("head headword homonymy", entry, doc)
|
||||||
original_homonymy = entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")
|
original_homonymy = entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")
|
||||||
|
|
||||||
# todo: How do you know which one is changed/created anew etc - Perhaps go with position in array and save it in homonymy object or something?
|
|
||||||
for hFeature in entry.homonymy:
|
for hFeature in entry.homonymy:
|
||||||
feature = doc.createElement("homonymyFeature")
|
feature = doc.createElement("homonymyFeature")
|
||||||
if hFeature.id >= 0:
|
if hFeature.id >= 0:
|
||||||
|
@ -56,8 +55,6 @@ def export_entry(entry):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log(homonymy)
|
|
||||||
# console.log(entry.original_homonymy.querySelector("head headwo")
|
|
||||||
# if({}) works uncorrectly in transcrypt
|
# if({}) works uncorrectly in transcrypt
|
||||||
if len(entry.lexical_unit) > 0:
|
if len(entry.lexical_unit) > 0:
|
||||||
lexunit = _original_xml_query_selector("head lexicalUnit", entry, doc)
|
lexunit = _original_xml_query_selector("head lexicalUnit", entry, doc)
|
||||||
|
@ -93,12 +90,16 @@ def export_entry(entry):
|
||||||
# head.appendChild(measure_list)
|
# head.appendChild(measure_list)
|
||||||
|
|
||||||
# Same problem as homonymy
|
# Same problem as homonymy
|
||||||
variants = doc.createElement("variantList")
|
variants = _original_xml_query_selector("head variantList", entry, doc)
|
||||||
head.appendChild(variants)
|
original_variants = entry.original_xml.querySelectorAll("head variantList variant")
|
||||||
|
|
||||||
for v in entry.variants:
|
for v in entry.variants:
|
||||||
variant = doc.createElement("variant")
|
variant = doc.createElement("variant")
|
||||||
variant.textContent = v
|
if v.id >= 0:
|
||||||
|
variant = original_variants[v.id]
|
||||||
|
else:
|
||||||
|
variants.appendChild(variant)
|
||||||
|
|
||||||
|
variant.textContent = v.value
|
||||||
variants.appendChild(variant)
|
variants.appendChild(variant)
|
||||||
|
|
||||||
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
|
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
|
||||||
|
|
|
@ -4,8 +4,10 @@ from browser import document
|
||||||
def generic_list_getter():
|
def generic_list_getter():
|
||||||
result = []
|
result = []
|
||||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||||
result_candidate = input_el.value
|
result_candidate = {"value": input_el.value}
|
||||||
if result_candidate != "":
|
if input_el.hasAttribute("data-id"):
|
||||||
|
result_candidate.id = int(input_el.getAttribute("data-id"))
|
||||||
|
if result_candidate.value != "":
|
||||||
result.append(result_candidate)
|
result.append(result_candidate)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -86,20 +86,15 @@ class DoChosenExamples(Message):
|
||||||
class EditVariants(Message):
|
class EditVariants(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
variants = common_accessors.generic_list_getter()
|
variants = common_accessors.generic_list_getter()
|
||||||
|
_remove_deleted_quries(variants, "head variantList variant", model)
|
||||||
|
console.log(variants)
|
||||||
model.entry.variants = variants
|
model.entry.variants = variants
|
||||||
|
|
||||||
class EditHomonymy(Message):
|
class EditHomonymy(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
homonymy = common_accessors.double_list_getter("value", "name")
|
homonymy = common_accessors.double_list_getter("value", "name")
|
||||||
|
|
||||||
keptHFeatureIds = [feature.id for feature in homonymy]
|
_remove_deleted_quries(homonymy, "head headword homonymy homonymyFeature", model)
|
||||||
for index, feature in enumerate(model.entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")):
|
|
||||||
if (index not in keptHFeatureIds):
|
|
||||||
feature.remove()
|
|
||||||
|
|
||||||
for index, feature in enumerate(homonymy):
|
|
||||||
if (feature.id >= 0):
|
|
||||||
feature.id = index
|
|
||||||
|
|
||||||
model.entry.homonymy = homonymy
|
model.entry.homonymy = homonymy
|
||||||
|
|
||||||
|
@ -128,3 +123,13 @@ class ExampleClusterAdd(DataChgClickMessage):
|
||||||
example = self.get_arg(0, Example)
|
example = self.get_arg(0, Example)
|
||||||
example.set_cluster(ExampleClusters.first_empty_cluster())
|
example.set_cluster(ExampleClusters.first_empty_cluster())
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_deleted_quries(updated_list, query, model):
|
||||||
|
keptIds = [entry.id for entry in updated_list]
|
||||||
|
for index, entry in enumerate(model.entry.original_xml.querySelectorAll(query)):
|
||||||
|
if (index not in keptIds):
|
||||||
|
entry.remove()
|
||||||
|
|
||||||
|
for index, entry in enumerate(updated_list):
|
||||||
|
if (entry.id >= 0):
|
||||||
|
entry.id = index
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Entry(Data):
|
||||||
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
||||||
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.variants = [{"value": v.textContent, "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head variantList variant"))]
|
||||||
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name"), "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head headword homonymy homonymyFeature "))]
|
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name"), "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head headword homonymy homonymyFeature "))]
|
||||||
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
|
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class Entry(Data):
|
||||||
if len(self.variants) == 0:
|
if len(self.variants) == 0:
|
||||||
view_buttons.append(buttons[0])
|
view_buttons.append(buttons[0])
|
||||||
else:
|
else:
|
||||||
view_table.append((buttons[0], ", ".join(self.variants)))
|
view_table.append((buttons[0], ", ".join(h.value for h in self.variants)))
|
||||||
|
|
||||||
if len(self.homonymy) == 0:
|
if len(self.homonymy) == 0:
|
||||||
view_buttons.append(buttons[4])
|
view_buttons.append(buttons[4])
|
||||||
|
|
|
@ -42,8 +42,11 @@ def question(question, current_value):
|
||||||
def generic_list_editor(title, element_list_getter):
|
def generic_list_editor(title, element_list_getter):
|
||||||
content = [h("p", {}, title)]
|
content = [h("p", {}, title)]
|
||||||
for slabel in element_list_getter():
|
for slabel in element_list_getter():
|
||||||
|
idAttr = {"data-id": slabel.id} if slabel.id >= 0 else {}
|
||||||
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.value or slabel}, "attrs": idAttr}, "")]))
|
||||||
|
|
||||||
|
console.log(content)
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user