show/hide examples

This commit is contained in:
2020-01-25 23:22:23 +01:00
parent 27409b6f63
commit 932400a06c
5 changed files with 31 additions and 4 deletions

View File

@@ -34,17 +34,28 @@ class View:
def view_entry(entry, model):
view_sense_list = [View.view_sense(sense, idx, model) for idx, sense in enumerate(entry.senses)]
buttons_left = View.view_entry_button_section(entry, model)
buttons_right = View.view_toggle_buttons(model)
return h("div#entry", {}, [
h("div#entry-status", {}, entry.status),
h("div#entry-header", {}, [
h("span#headword", {}, entry.headword),
h("span#grammar", {}, entry.grammar),
h("span#measure", {}, entry.get_measure_text())]),
View.view_entry_button_section(entry, model),
h("div.flex.five", {}, [
h("div.four-fifth", {}, buttons_left),
h("div.one-fifth", {}, buttons_right)]),
h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")])
@staticmethod
def view_toggle_buttons(model):
txt = "Hide examples" if model.examples_shown else "Show examples"
return [ h("span.button.toggle", {"on": {"click": msg(ToggleExamples())}}, txt) ]
@staticmethod
def view_entry_button_section(entry, model):
clk = lambda cls: {"on": {"click": msg(cls)}}
@@ -130,7 +141,11 @@ class View:
if "logDice" in example.other_attributes:
example_content.append(h("span.example-logdice", {}, example.other_attributes["logDice"]))
return h("div.example", {}, [
parent_display = "inherit"
if not model.examples_shown and not example.is_collocation():
parent_display = "none"
return h("div.example", {"style": {"display": parent_display}}, [
h("div.example-dot", dot_attr, ""),
h(example_tag, {}, [
h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content),