Editing explanation and examples, adding senses

This commit is contained in:
Ozbolt Menegatti 2019-11-15 22:24:32 +01:00
parent 78a80c03a7
commit f0f95b16c0
8 changed files with 70 additions and 13 deletions

View File

@ -1,7 +1,7 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample
from message.message import msg

View File

@ -1,6 +1,7 @@
from message.message import Message, ClickMessage
from message.translation_edit import AddTranslation ,EditTranslation
from model.sense import NewSense
import modals
@ -16,7 +17,10 @@ class GenericShowModal(ClickMessage):
class ShowMenu(ClickMessage):
def __init__(self, event, translation):
super().__init__(event)
self.menu_location = (event.layerX, event.layerY)
location_x = event.currentTarget.offsetLeft
location_y = event.currentTarget.offsetTop + event.currentTarget.offsetHeight
self.menu_location = (location_x, location_y)
console.log(self.menu_location, event.currentTarget)
self.translation = translation
def update_model(self, model):
@ -39,6 +43,12 @@ class ShowSenseDefinitionEdit(GenericShowModal):
super().update_model(model)
model.sense = self.arg
model.modal = lambda: modals.edit_sense_definition(self.arg)
class ShowSenseAdd(GenericShowModal):
def update_model(self, model):
super().update_model(model)
model.modal = lambda: modals.add_sense(NewSense())
class ShowCommentEdit(ClickMessage):
@ -47,6 +57,12 @@ class ShowCommentEdit(ClickMessage):
model.modal = lambda: modals.edit_comment(model.entry.comment)
class ShowExampleEdit(GenericShowModal):
def update_model(self, model):
super().update_model(model)
model.modal = lambda: modals.edit_example(self.arg)
class ShowEditTranslation(GenericShowModal):
def update_model(self, model):
model.modal_shown = True

View File

@ -1,7 +1,7 @@
from message.message import Message
from message.simple_messages import NoReset
from browser import document
from model import Sense
from model import Sense, Example
class SimpleEditMessage(Message):
@ -32,6 +32,13 @@ class AddSenseLabel(NoReset):
def update_model(self, model):
# just adding to the copy to show in the modal
self.sense.copy().labels.append("")
class AddSense(SimpleEditMessage):
def update_model(self, model):
sense = self.prop
sense.labels = [self.new_text]
model.entry.senses.append(sense)
class EditSenseDefinition(SimpleEditMessage):
@ -44,3 +51,11 @@ class EditSenseDefinition(SimpleEditMessage):
class EditComment(SimpleEditMessage):
def update_model(self, model):
model.entry.comment = self.new_text
class EditExample(SimpleEditMessage):
def update_model(self, model):
example = self.prop
assert(type(example) is Example)
example.example = self.new_text

View File

@ -22,10 +22,11 @@ class EditTranslation(TranslationActionMessage):
self.translation, self.old_cluster_idx = prop
def update_model(self, model):
self.translation.translation = document.getElementById("etv").value;
self.translation.translation = document.getElementById("etv").value
self.translation.explanation = document.getElementById("ete").value
for tag in TAGS.keys():
select = document.getElementById("{}-s".format(tag));
other = document.getElementById("{}-o".format(tag));
select = document.getElementById("{}-s".format(tag))
other = document.getElementById("{}-o".format(tag))
if other.value:
self.translation.tags[tag] = other.value
@ -35,7 +36,7 @@ class EditTranslation(TranslationActionMessage):
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)
def handle_cluster_change(self, new_cluster_idx, model):

View File

@ -53,7 +53,9 @@ def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
# first line: transalation itself
content = [split_line2("Prevedek:",
h("input#etv", {"props": {"type": "text", "value": translation.translation}}, ""))]
h("input#etv", {"props": {"type": "text", "value": translation.translation}}, "")),
split_line2("Razlaga:",
h("input#ete", {"props": {"type": "text", "value": translation.explanation}}, ""))]
# cluster number
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
@ -79,9 +81,17 @@ def edit_sense_label(sense):
return modal_template(content, "Sense", message.EditSenseLabel, sense)
def add_sense(sense):
return one_question_modal("Add sense", message.AddSense, "Add sense with a label", "", sense)
def edit_sense_definition(sense):
return one_question_modal("Sense definition", message.EditSenseDefinition, "Edit sense definition", sense.definition, sense)
def edit_comment(comment):
return one_question_modal("Comment", message.EditComment, "Edit comment", comment, None)
def edit_example(example):
return one_question_modal("Example", message.EditExample, "Edit example", example.example, example)

View File

@ -1,3 +1,4 @@
from model.model import Model
from model.sense import Sense
from model.translation import Translation
from model.example import Example

View File

@ -25,3 +25,10 @@ class Sense(Editable):
for clusterNum, translation in translations:
self.translations[clusterNum - 1].append(translation)
class NewSense(Sense):
def __init__(self):
self.translations = []
self.labels = []
self.definition = []
self.examples= []

View File

@ -34,7 +34,8 @@ class View:
h("span#headword", {}, entry.headword),
h("span#grammar", {}, entry.grammar),
h("button#comment.warning", {"on": {"click": msg(ShowCommentEdit)}}, entry.comment)]),
h("div#sense-container", {}, view_sense_list)])
h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(ShowSenseAdd)}}, "+")])
@staticmethod
def view_sense(sense, senseNum):
@ -54,7 +55,7 @@ class View:
return h("div.example", {}, [
h("div.example-dot", {}, ""),
h("div.example-rest", {}, [
h("span.example-text", {}, example.example),
h("span.example-text", {"on": {"click": msg(ShowExampleEdit, example)} }, example.example),
h("div.example-translation", {}, [
h("span.example-arrow", {}, ""),
h("span", {}, example.translation)])])])
@ -65,7 +66,7 @@ class View:
for cluster in translations:
result.append(h("div.translation-div-cluster", {}, [View.view_one_translation(t) for t in cluster]))
result.append(h("button", {"on": {"click": msg(ShowAddTranslation, sense)}}, "+"))
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation, sense)}}, "+"))
return result
@staticmethod
@ -79,6 +80,12 @@ class View:
elements.append(tags)
elements.append(h("span.translation-text", {}, translation.translation))
if translation.source:
elements.append(h("span.translation-source", {}, translation.source))
explanation_class = ".translation-explanation" if translation.translation else ""
elements.append(h("span{}".format(explanation_class), {}, translation.explanation))
return h("div.translation-div", {"on": {"click": msg(ShowMenu, translation) }}, elements)
@ -104,5 +111,5 @@ class View:
return h("div.modal", {}, [
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
h("label.overlay", {}, ""),
h("article", {"on": { "click": NoReset }}, modal())])
h("article", {"on": { "click": msg(NoReset) }}, modal())])