Moved a few other views and some bugfixes from this refactoring
This commit is contained in:
parent
b6cb2dbce5
commit
46fd628f11
|
@ -72,7 +72,7 @@ class ExampleComponentAdd(NoReset):
|
||||||
example = self.get_arg(0, Example)
|
example = self.get_arg(0, Example)
|
||||||
component_num = self.get_arg(1, int)
|
component_num = self.get_arg(1, int)
|
||||||
|
|
||||||
new_component = ComponentLexeme.new_empty()
|
new_component = ComponentLexeme()
|
||||||
example.copy().components.insert(component_num + 1, new_component)
|
example.copy().components.insert(component_num + 1, new_component)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,9 @@ class Message:
|
||||||
self._args = []
|
self._args = []
|
||||||
|
|
||||||
|
|
||||||
def msg(message_class, params):
|
def msg(message_class, *params):
|
||||||
def callback(event):
|
def callback(event):
|
||||||
message = message_class(params)
|
message = message_class(*params)
|
||||||
if not issubclass(type(message), Message):
|
if not issubclass(type(message), Message):
|
||||||
window.console.log("Not scheduling a Message type, this will not work!")
|
window.console.log("Not scheduling a Message type, this will not work!")
|
||||||
return
|
return
|
||||||
|
|
|
@ -41,7 +41,7 @@ class AddToLabelList(NoReset):
|
||||||
|
|
||||||
class AddSense(Message):
|
class AddSense(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = Sense.new_empty()
|
sense = Sense()
|
||||||
sense.definition = {"indicator": "New Sense"}
|
sense.definition = {"indicator": "New Sense"}
|
||||||
model.entry.senses.append(sense)
|
model.entry.senses.append(sense)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@ from model.data import Data
|
||||||
class ComponentLexeme(Data):
|
class ComponentLexeme(Data):
|
||||||
def __init__(self, xml):
|
def __init__(self, xml):
|
||||||
self.other_attributes = {}
|
self.other_attributes = {}
|
||||||
|
self.text = ""
|
||||||
|
self.role = ""
|
||||||
|
|
||||||
|
def import_xml(self, xml):
|
||||||
if xml.nodeName == "#text":
|
if xml.nodeName == "#text":
|
||||||
self.text = xml.data
|
self.text = xml.data
|
||||||
self.role = None
|
self.role = None
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
from model.data import Data as Editable
|
from model.data import Data
|
||||||
from model.translation import from_container_list
|
from model.translation import from_container_list
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
|
import message as M
|
||||||
|
from view import View
|
||||||
|
from view.utils import show_toggle_cluster_buttons
|
||||||
|
|
||||||
from model.example.component_lexeme import ComponentLexeme
|
from model.example.component_lexeme import ComponentLexeme
|
||||||
from model.example.corpus_example import CorpusExample
|
from model.example.corpus_example import CorpusExample
|
||||||
from model.example.multiword_example import MultiwordExample
|
from model.example.multiword_example import MultiwordExample
|
||||||
|
|
||||||
|
|
||||||
class Example(Editable):
|
class Example(Data):
|
||||||
def __init__(self, example_xml):
|
def __init__(self):
|
||||||
|
self.translations = []
|
||||||
|
self.inner = None
|
||||||
|
self.components = []
|
||||||
|
|
||||||
|
|
||||||
|
def import_xml(self, example_xml):
|
||||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
||||||
|
|
||||||
inner_xml = example_xml.querySelector("corpusExample")
|
inner_xml = example_xml.querySelector("corpusExample")
|
||||||
|
@ -18,9 +27,11 @@ class Example(Editable):
|
||||||
inner_xml = example_xml.querySelector("multiwordExample")
|
inner_xml = example_xml.querySelector("multiwordExample")
|
||||||
self.inner = MultiwordExample(inner_xml)
|
self.inner = MultiwordExample(inner_xml)
|
||||||
|
|
||||||
all_components = [ComponentLexeme(el) for el in inner_xml.childNodes]
|
for comp_xml in inner_xml.childNodes:
|
||||||
self.components = [comp for comp in all_components if comp.isValid()]
|
comp = ComponentLexeme()
|
||||||
|
comp.import_xml(comp_xml)
|
||||||
|
if comp.isValid():
|
||||||
|
self.components.append(comp)
|
||||||
|
|
||||||
def export(self, doc):
|
def export(self, doc):
|
||||||
result = doc.createElement("exampleContainer")
|
result = doc.createElement("exampleContainer")
|
||||||
|
@ -33,8 +44,43 @@ class Example(Editable):
|
||||||
result.appendChild(inner)
|
result.appendChild(inner)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def view(self):
|
def view(self, model, sense):
|
||||||
return self.inner.view(self.components)
|
example_tag = "div.example-rest"
|
||||||
|
if self in model.chosen_examples:
|
||||||
|
example_tag += ".example-chosen"
|
||||||
|
|
||||||
|
cluster = self.get_cluster()
|
||||||
|
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
|
||||||
|
|
||||||
|
example_content = []
|
||||||
|
if cluster is not None:
|
||||||
|
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
||||||
|
|
||||||
|
example_text_inner_tag = "span.example-text-{}".format(self.get_view_type())
|
||||||
|
example_content.append(h(example_text_inner_tag, {}, self.inner.view(self.components)))
|
||||||
|
|
||||||
|
other_attributes = self.get_other_attributes()
|
||||||
|
if "frequency" in other_attributes:
|
||||||
|
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
|
||||||
|
if "logDice" in other_attributes:
|
||||||
|
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
|
||||||
|
|
||||||
|
parent_display = "inherit"
|
||||||
|
if not model.examples_shown and not self.is_multiword():
|
||||||
|
parent_display = "none"
|
||||||
|
|
||||||
|
clusters_display = "inherit"
|
||||||
|
if not model.clusters_shown:
|
||||||
|
clusters_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": M.msg(M.ShowExampleMenu, self)} }, example_content),
|
||||||
|
h("div.example-translation-list", {}, [
|
||||||
|
h("div.example-translation", {}, View.view_translations(self.translations, self, model))]),
|
||||||
|
h("div.example-clusters",
|
||||||
|
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, self))])])
|
||||||
|
|
||||||
def get_cluster(self):
|
def get_cluster(self):
|
||||||
return self.inner.get_cluster()
|
return self.inner.get_cluster()
|
||||||
|
|
|
@ -25,16 +25,19 @@ class Sense(Data):
|
||||||
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(
|
||||||
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
sense_xml.querySelectorAll("translationContainerList translationContainer"))
|
||||||
|
|
||||||
self.examples = [Example(example_xml) for example_xml in
|
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
|
||||||
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]
|
example = Example()
|
||||||
|
example.import_xml(example_xml)
|
||||||
|
self.examples.append(example)
|
||||||
|
|
||||||
|
|
||||||
def merge_labels(self):
|
def merge_labels(self):
|
||||||
return ", ".join(val for _, val in self.labels)
|
return ", ".join(val for _, val in self.labels)
|
||||||
|
|
||||||
|
|
||||||
def view(self, model, sense_num):
|
def view(self, model, sense_num):
|
||||||
examples = [View.view_example(example, self, model) for example in self.examples]
|
examples = [example.view(model, self) for example in self.examples]
|
||||||
|
|
||||||
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)),
|
||||||
|
|
|
@ -44,45 +44,6 @@ class View:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def view_example(example, sense, model):
|
|
||||||
example_tag = "div.example-rest"
|
|
||||||
if example in model.chosen_examples:
|
|
||||||
example_tag += ".example-chosen"
|
|
||||||
|
|
||||||
cluster = example.get_cluster()
|
|
||||||
dot_attr = {"style": { "visibility": "visible" if cluster is None else "hidden"}}
|
|
||||||
|
|
||||||
example_content = []
|
|
||||||
if cluster is not None:
|
|
||||||
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
|
|
||||||
|
|
||||||
example_text_inner_tag = "span.example-text-{}".format(example.get_view_type())
|
|
||||||
example_content.append(h(example_text_inner_tag, {}, example.view()))
|
|
||||||
|
|
||||||
other_attributes = example.get_other_attributes()
|
|
||||||
if "frequency" in other_attributes:
|
|
||||||
example_content.append(h("span.example-frequency", {}, other_attributes["frequency"]))
|
|
||||||
if "logDice" in other_attributes:
|
|
||||||
example_content.append(h("span.example-logdice", {}, other_attributes["logDice"]))
|
|
||||||
|
|
||||||
parent_display = "inherit"
|
|
||||||
if not model.examples_shown and not example.is_multiword():
|
|
||||||
parent_display = "none"
|
|
||||||
|
|
||||||
clusters_display = "inherit"
|
|
||||||
if not model.clusters_shown:
|
|
||||||
clusters_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),
|
|
||||||
h("div.example-translation-list", {}, [
|
|
||||||
h("div.example-translation", {}, View.view_translations(example.translations, example, model))]),
|
|
||||||
h("div.example-clusters",
|
|
||||||
{"style": {"display": clusters_display }}, show_toggle_cluster_buttons(sense, example))])])
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def view_translations(translations, parent, model):
|
def view_translations(translations, parent, model):
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user