2019-11-11 22:04:45 +00:00
|
|
|
from message.message import Message
|
2020-02-16 16:46:55 +00:00
|
|
|
from message.simple_messages import NoReset, DataChgClickMessage
|
2019-11-16 13:59:23 +00:00
|
|
|
import message.common_accessors as common_accessors
|
2019-11-11 22:04:45 +00:00
|
|
|
from browser import document
|
2019-11-15 21:24:32 +00:00
|
|
|
from model import Sense, Example
|
2020-03-30 18:32:52 +00:00
|
|
|
from model.example_clusters import ExampleClusters
|
2019-11-11 22:04:45 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class QuestionMessage(Message):
|
|
|
|
def on_event(self, event):
|
|
|
|
input_element = document.getElementById("modal-question")
|
2019-11-11 22:04:45 +00:00
|
|
|
self.new_text = input_element.value
|
|
|
|
|
|
|
|
|
2019-11-11 23:34:52 +00:00
|
|
|
class EditSenseLabel(Message):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
sense = self.get_arg(0, Sense)
|
2019-11-17 21:09:09 +00:00
|
|
|
sense.labels = common_accessors.label_list_getter()
|
2019-11-11 23:34:52 +00:00
|
|
|
|
2020-08-27 07:15:46 +00:00
|
|
|
keptIds = [entry[2] for entry in sense.labels]
|
|
|
|
for index, entry in enumerate(sense.original_xml.querySelectorAll("labelList label")):
|
|
|
|
if (index not in keptIds):
|
|
|
|
entry.remove()
|
|
|
|
|
|
|
|
for index, entry in enumerate(sense.labels):
|
|
|
|
if (entry[2] >= 0):
|
|
|
|
entry[2] = index
|
2019-11-11 23:34:52 +00:00
|
|
|
|
2019-11-18 19:27:11 +00:00
|
|
|
class AddToGenericList(NoReset):
|
2019-11-17 20:30:30 +00:00
|
|
|
def update_model(self, model):
|
2019-11-18 19:27:11 +00:00
|
|
|
list_getter = self.get_arg(0)
|
|
|
|
list_getter().append("")
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2019-11-20 21:25:31 +00:00
|
|
|
def data_change(self):
|
|
|
|
return False
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:33:58 +00:00
|
|
|
class AddToLabelList(NoReset):
|
2019-11-16 13:18:37 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:33:58 +00:00
|
|
|
list_to_add_to = self.get_arg(0, list)
|
|
|
|
thing_to_add_getter = self.get_arg(1)
|
|
|
|
thing_to_add = thing_to_add_getter()
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2019-11-16 13:18:37 +00:00
|
|
|
# just adding to the copy to show in the modal
|
2019-11-17 20:33:58 +00:00
|
|
|
list_to_add_to.append(thing_to_add)
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2019-11-20 21:25:31 +00:00
|
|
|
def data_change(self):
|
|
|
|
return False
|
2019-11-16 13:18:37 +00:00
|
|
|
|
|
|
|
|
2019-11-20 17:58:48 +00:00
|
|
|
class AddSense(Message):
|
2019-11-15 21:24:32 +00:00
|
|
|
def update_model(self, model):
|
2020-02-16 23:00:03 +00:00
|
|
|
sense = Sense()
|
2020-08-27 07:15:46 +00:00
|
|
|
sense.definitions.append({"type": "indicator", "value": "New Sense"})
|
2019-11-15 21:24:32 +00:00
|
|
|
model.entry.senses.append(sense)
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class EditSenseDefinition(QuestionMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
2019-11-17 20:30:30 +00:00
|
|
|
sense = self.get_arg(0, Sense)
|
2020-08-27 07:15:46 +00:00
|
|
|
sense.definitions[0].value = self.new_text
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
|
2019-11-17 20:30:30 +00:00
|
|
|
class EditComment(QuestionMessage):
|
2019-11-11 22:04:45 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
model.entry.comment = self.new_text
|
2019-11-15 21:24:32 +00:00
|
|
|
|
|
|
|
|
2020-01-02 13:22:35 +00:00
|
|
|
class DoChosenExamples(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
chosen_examples = self.get_arg(0, list)
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2020-01-14 20:57:11 +00:00
|
|
|
inputs = document.getElementsByClassName("checkable-input")
|
|
|
|
selected = None
|
|
|
|
for idx, el in enumerate(inputs):
|
|
|
|
if el.checked:
|
|
|
|
selected = idx
|
|
|
|
break
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2020-01-14 20:57:11 +00:00
|
|
|
# none was selected
|
|
|
|
if selected is None:
|
|
|
|
return
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2020-01-02 13:22:35 +00:00
|
|
|
# first, remove the selected examples from wherever they were
|
|
|
|
for sense in model.entry.senses:
|
|
|
|
for example in chosen_examples:
|
|
|
|
if example in sense.examples:
|
|
|
|
sense.examples.remove(example)
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2020-01-02 13:22:35 +00:00
|
|
|
# now, append selected examples to chosen sense
|
|
|
|
model.entry.senses[selected].examples.extend(chosen_examples)
|
|
|
|
|
|
|
|
|
2019-11-18 19:27:11 +00:00
|
|
|
class EditVariants(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
variants = common_accessors.generic_list_getter()
|
2020-08-25 12:56:48 +00:00
|
|
|
update_entries(variants, "head variantList variant", model)
|
2019-11-18 19:27:11 +00:00
|
|
|
model.entry.variants = variants
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
class EditHomonymy(Message):
|
|
|
|
def update_model(self, model):
|
2020-08-06 10:47:52 +00:00
|
|
|
homonymy = common_accessors.double_list_getter("value", "name")
|
2020-08-24 16:03:14 +00:00
|
|
|
|
2020-08-25 12:56:48 +00:00
|
|
|
update_entries(homonymy, "head headword homonymy homonymyFeature", model)
|
2020-08-24 16:03:14 +00:00
|
|
|
|
2020-07-15 11:17:58 +00:00
|
|
|
model.entry.homonymy = homonymy
|
|
|
|
|
|
|
|
|
2020-01-21 21:18:43 +00:00
|
|
|
class EditRelatedEntries(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
related_entries = common_accessors.generic_list_getter()
|
2020-08-25 12:56:48 +00:00
|
|
|
update_entries(related_entries, "head relatedEntryList relatedEntry", model)
|
2020-01-21 21:18:43 +00:00
|
|
|
model.entry.related_entries = related_entries
|
2019-11-18 19:57:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditEntryLabels(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
labels = common_accessors.label_list_getter()
|
2020-08-27 07:15:46 +00:00
|
|
|
keptIds = [entry[2] for entry in labels]
|
|
|
|
for index, entry in enumerate(model.entry.original_xml.querySelectorAll("labelList label")):
|
|
|
|
if (index not in keptIds):
|
|
|
|
entry.remove()
|
|
|
|
|
|
|
|
for index, entry in enumerate(labels):
|
|
|
|
if (entry[2] >= 0):
|
|
|
|
entry[2] = index
|
2019-11-18 19:57:33 +00:00
|
|
|
model.entry.labels = labels
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
|
2020-02-16 16:46:55 +00:00
|
|
|
class ExampleClusterEdit(DataChgClickMessage):
|
2020-01-28 22:22:52 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
cluster = self.get_arg(1, int)
|
|
|
|
example.set_cluster(cluster)
|
2020-07-15 11:17:58 +00:00
|
|
|
|
|
|
|
|
2020-02-16 16:46:55 +00:00
|
|
|
class ExampleClusterAdd(DataChgClickMessage):
|
2020-02-01 23:07:42 +00:00
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
2020-04-05 15:14:06 +00:00
|
|
|
example.set_cluster(ExampleClusters.first_empty_cluster())
|
2020-07-15 11:17:58 +00:00
|
|
|
|
2020-08-25 09:12:23 +00:00
|
|
|
|
2020-08-25 12:56:48 +00:00
|
|
|
def update_entries(updated_list, query, model):
|
2020-08-25 09:12:23 +00:00
|
|
|
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
|