THE REST: mostly fixing/changing how tags/labellist stuff works

This commit is contained in:
2019-11-17 21:33:58 +01:00
parent b09a84db06
commit 0c6dcbb2f0
8 changed files with 87 additions and 56 deletions

View File

@@ -1,5 +1,7 @@
import message
from lib.snabbdom import h
from model.translation import TAGS
from browser import document
def modal_template(content, title, msg):
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):
content = [h("span", {}, title)]
content = [h("span.list", {}, 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}}, "+"))
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

View File

@@ -9,28 +9,6 @@ def edit_translation(translation, cluster_idx, num_clusters, cls):
return h("div.flex.two", {}, [
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
content = [split_line2("Prevedek:",
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)]
content.append(split_line2("Stevilka gruce:", h("select#cluster-num", {}, options)))
# tags
content.append(h("h4", {}, "Tags"))
for tag in TAGS.keys():
content.append(dropdown_right(tag))
content.extend(label_list_editor(translation.copy().tags, message.AddToLabelList(translation.copy().tags)))
return modal_template(content, "Translation", cls)