THE REST: mostly fixing/changing how tags/labellist stuff works
This commit is contained in:
parent
b09a84db06
commit
0c6dcbb2f0
|
@ -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
|
||||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation
|
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList
|
||||||
|
|
||||||
from message.message import msg
|
from message.message import msg
|
||||||
|
|
||||||
|
|
|
@ -9,3 +9,20 @@ def generic_list_getter():
|
||||||
result.append(result_candidate)
|
result.append(result_candidate)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def label_list_getter():
|
||||||
|
result = []
|
||||||
|
for row in document.getElementsByClassName("label-list-row"):
|
||||||
|
ltype = row.querySelector(".label-type")
|
||||||
|
lvalue = row.querySelector(".label-value")
|
||||||
|
lother = row.querySelector(".label-value-other")
|
||||||
|
|
||||||
|
value = lother.value
|
||||||
|
if not value:
|
||||||
|
value = lvalue.options[lvalue.selectedIndex].text
|
||||||
|
|
||||||
|
if not value:
|
||||||
|
continue
|
||||||
|
|
||||||
|
result.append((ltype.textContent, value))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from message.message import Message, ClickMessage
|
from message.message import Message, ClickMessage
|
||||||
from message.translation_edit import AddTranslation ,EditTranslation
|
from message.translation_edit import AddTranslation, EditTranslation
|
||||||
|
|
||||||
from model.sense import NewSense
|
from model import Example, Sense, Translation
|
||||||
from view import modals
|
from view import modals
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,9 +72,10 @@ class ShowEditTranslation(ClickMessage):
|
||||||
for cidx, cluster in enumerate(sense.translations):
|
for cidx, cluster in enumerate(sense.translations):
|
||||||
for t in cluster:
|
for t in cluster:
|
||||||
if t == translation:
|
if t == translation:
|
||||||
# fount the one!
|
# fount the one!
|
||||||
|
translation.make_copy()
|
||||||
model.modal = lambda: modals.edit_translation(
|
model.modal = lambda: modals.edit_translation(
|
||||||
translation, cidx, num_clusters, EditTranslation, (translation, cidx))
|
translation, cidx, num_clusters, EditTranslation(translation, cidx))
|
||||||
return
|
return
|
||||||
|
|
||||||
console.log("Should not be here!")
|
console.log("Should not be here!")
|
||||||
|
|
|
@ -34,9 +34,15 @@ class AddExampleTranslation(NoReset):
|
||||||
# just adding to the copy to show in the modal
|
# just adding to the copy to show in the modal
|
||||||
example.copy().translations.append("")
|
example.copy().translations.append("")
|
||||||
|
|
||||||
|
|
||||||
|
class AddToLabelList(NoReset):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
|
list_to_add_to = self.get_arg(0, list)
|
||||||
|
thing_to_add_getter = self.get_arg(1)
|
||||||
|
thing_to_add = thing_to_add_getter()
|
||||||
|
|
||||||
# just adding to the copy to show in the modal
|
# just adding to the copy to show in the modal
|
||||||
self.example.copy().translations.append("")
|
list_to_add_to.append(thing_to_add)
|
||||||
|
|
||||||
|
|
||||||
class EditExampleTranslation(Message):
|
class EditExampleTranslation(Message):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from message.message import Message, ClickMessage
|
from message.message import Message, ClickMessage
|
||||||
|
import message.common_accessors as common_accessors
|
||||||
from browser import document, window
|
from browser import document, window
|
||||||
from model.translation import TAGS, NewTranslation
|
from model.translation import TAGS, Translation
|
||||||
|
from model.sense import Sense
|
||||||
|
|
||||||
|
|
||||||
def get_translation_location(entry, translation):
|
def get_translation_location(entry, translation):
|
||||||
|
@ -11,24 +13,16 @@ def get_translation_location(entry, translation):
|
||||||
return (si, ci, ti), (sense, cluster)
|
return (si, ci, ti), (sense, cluster)
|
||||||
|
|
||||||
|
|
||||||
class EditTranslation(TranslationActionMessage):
|
class EditTranslation(ClickMessage):
|
||||||
def __init__(self, _, prop):
|
|
||||||
self.translation, self.old_cluster_idx = prop
|
|
||||||
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
|
self.translation = self.get_arg(0, Translation)
|
||||||
|
self.old_cluster_idx = self.get_arg(1, int)
|
||||||
|
|
||||||
self.translation.translation = document.getElementById("etv").value
|
self.translation.translation = document.getElementById("etv").value
|
||||||
self.translation.explanation = document.getElementById("ete").value
|
self.translation.explanation = document.getElementById("ete").value
|
||||||
for tag in TAGS.keys():
|
|
||||||
select = document.getElementById("{}-s".format(tag))
|
# common_accessors.label_list_getter()
|
||||||
other = document.getElementById("{}-o".format(tag))
|
self.translation.tags = common_accessors.label_list_getter()
|
||||||
|
|
||||||
if other.value:
|
|
||||||
self.translation.tags[tag] = other.value
|
|
||||||
elif select.selectedIndex > 0:
|
|
||||||
self.translation.tags[tag] = select.options[select.selectedIndex].text
|
|
||||||
else:
|
|
||||||
if tag in self.translation.tags:
|
|
||||||
del self.translation.tags[tag]
|
|
||||||
|
|
||||||
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
|
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
|
||||||
self.handle_cluster_change(new_cluster_idx, model)
|
self.handle_cluster_change(new_cluster_idx, model)
|
||||||
|
@ -97,15 +91,10 @@ class BinTranslation(ClickMessage):
|
||||||
|
|
||||||
|
|
||||||
class AddTranslation(EditTranslation):
|
class AddTranslation(EditTranslation):
|
||||||
def __init__(self, _, prop):
|
|
||||||
self.translation = NewTranslation()
|
|
||||||
self.old_cluster_idx = -1
|
|
||||||
self.sense = prop
|
|
||||||
|
|
||||||
def handle_cluster_change(self, new_cluster_idx, _):
|
def handle_cluster_change(self, new_cluster_idx, _):
|
||||||
# we need to cheat here
|
# we need to cheat here
|
||||||
# sense was actually given in constructor
|
# sense was actually given in constructor in third place
|
||||||
# we make a dummy cluster, cluster_idx and translation_idx
|
# we make a dummy cluster, cluster_idx and translation_idx
|
||||||
# we give a correct new_cluster_idx
|
# we give a correct new_cluster_idx
|
||||||
self.do_cluster_change(self.sense, [None, None], None, None, new_cluster_idx)
|
self.do_cluster_change(self.get_arg(2, Sense), [None, None], None, None, new_cluster_idx)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from model.sense import Sense
|
from model.sense import Sense
|
||||||
|
from model.editable import Editable
|
||||||
|
|
||||||
class Entry:
|
class Entry(Editable):
|
||||||
def __init__(self, entry_xml):
|
def __init__(self, entry_xml):
|
||||||
status = entry_xml.querySelector("head status")
|
status = entry_xml.querySelector("head status")
|
||||||
headword = entry_xml.querySelector("head headword lemma")
|
headword = entry_xml.querySelector("head headword lemma")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import message
|
import message
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
|
from model.translation import TAGS
|
||||||
|
from browser import document
|
||||||
|
|
||||||
def modal_template(content, title, msg):
|
def modal_template(content, title, msg):
|
||||||
reset = message.msg(message.ModalNotOkClose())
|
reset = message.msg(message.ModalNotOkClose())
|
||||||
|
@ -21,9 +23,48 @@ def question(question, current_value):
|
||||||
|
|
||||||
|
|
||||||
def generic_list_editor(title, element_list_getter, add_click_message):
|
def generic_list_editor(title, element_list_getter, add_click_message):
|
||||||
content = [h("span", {}, title)]
|
content = [h("span.list", {}, 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": add_click_message}}, "+"))
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def label_list_editor(current_labels, add_label_message_class):
|
||||||
|
def split_line3(left, center, right, is_llr=True):
|
||||||
|
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
|
||||||
|
return h("div.{}".format(cls), {}, [
|
||||||
|
h("span.third", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
||||||
|
|
||||||
|
def dropdown_right(label_type, label):
|
||||||
|
left = h("span.label-type", {}, label_type)
|
||||||
|
|
||||||
|
options = [h("option", {}, [])]
|
||||||
|
for value in TAGS[label_type]:
|
||||||
|
options.append(h("option", {"props": {"selected": label == value}}, value))
|
||||||
|
center = h("select.label-value", {}, options)
|
||||||
|
|
||||||
|
right_value = label if label not in TAGS[label_type] else ""
|
||||||
|
right = h("input.label-value-other",
|
||||||
|
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
||||||
|
[])
|
||||||
|
|
||||||
|
return split_line3(left, center, right)
|
||||||
|
|
||||||
|
content = [dropdown_right(key, value) for key, value in current_labels]
|
||||||
|
|
||||||
|
# add a way to get new element to add to tag list
|
||||||
|
def get_new_label_type():
|
||||||
|
select = document.getElementById("new-tag-select")
|
||||||
|
return (select.options[select.selectedIndex].text, "")
|
||||||
|
add_label_message_class.add_arg(get_new_label_type)
|
||||||
|
|
||||||
|
left = h("span", {}, "Add more!")
|
||||||
|
center = h("select#new-tag-select", {}, [h("option", {}, ltype) for ltype in TAGS.keys()])
|
||||||
|
right = h("button", {"style": {"float": "right"}, "on": {"click": message.msg(add_label_message_class)}}, "+")
|
||||||
|
|
||||||
|
content.append(split_line3(left, center, right, False))
|
||||||
|
content.append(h("hr", {}, []))
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
|
@ -9,28 +9,6 @@ def edit_translation(translation, cluster_idx, num_clusters, cls):
|
||||||
return h("div.flex.two", {}, [
|
return h("div.flex.two", {}, [
|
||||||
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)])
|
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)])
|
||||||
|
|
||||||
def split_line3(left, center, right):
|
|
||||||
return h("div.flex.three", {}, [
|
|
||||||
h("span.third.span-left-of-input", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
|
||||||
|
|
||||||
def dropdown_right(tag_name):
|
|
||||||
left = tag_name + ":"
|
|
||||||
|
|
||||||
values = TAGS[tag_name]
|
|
||||||
selected_value = translation.tags[tag_name] if tag_name in translation.tags else None
|
|
||||||
|
|
||||||
options = [h("option", {}, [])]
|
|
||||||
for value in values:
|
|
||||||
options.append(h("option", {"props": {"selected": selected_value == value}}, value))
|
|
||||||
center = h("select#{}-s".format(tag_name), {}, options)
|
|
||||||
|
|
||||||
right_value = selected_value if selected_value not in values and selected_value is not None else ""
|
|
||||||
right = h("input#{}-o".format(tag_name),
|
|
||||||
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
|
||||||
[])
|
|
||||||
|
|
||||||
return split_line3(left, center, right)
|
|
||||||
|
|
||||||
# first line: transalation itself
|
# first line: transalation itself
|
||||||
content = [split_line2("Prevedek:",
|
content = [split_line2("Prevedek:",
|
||||||
h("input#etv", {"props": {"type": "text", "value": translation.translation}}, "")),
|
h("input#etv", {"props": {"type": "text", "value": translation.translation}}, "")),
|
||||||
|
@ -41,10 +19,8 @@ def edit_translation(translation, cluster_idx, num_clusters, cls):
|
||||||
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
||||||
content.append(split_line2("Stevilka gruce:", h("select#cluster-num", {}, options)))
|
content.append(split_line2("Stevilka gruce:", h("select#cluster-num", {}, options)))
|
||||||
|
|
||||||
# tags
|
|
||||||
content.append(h("h4", {}, "Tags"))
|
content.append(h("h4", {}, "Tags"))
|
||||||
for tag in TAGS.keys():
|
content.extend(label_list_editor(translation.copy().tags, message.AddToLabelList(translation.copy().tags)))
|
||||||
content.append(dropdown_right(tag))
|
|
||||||
|
|
||||||
return modal_template(content, "Translation", cls)
|
return modal_template(content, "Translation", cls)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user