diff --git a/app/controllers/names_controller.rb b/app/controllers/names_controller.rb index 8390e04..9b845ed 100644 --- a/app/controllers/names_controller.rb +++ b/app/controllers/names_controller.rb @@ -159,6 +159,17 @@ def draft render(:index) end + # GET /names/etymology_sandbox + def etymology_sandbox + @name = Name.new(name: params[:name] || '') + end + + # GET /names/syllabify?name=Abc + def syllabify + @name = Name.new(name: params[:name] || '') + @syllabification = @name.guess_syllabication + end + # GET /names/1 # GET /names/1.json # GET /names/1.pdf diff --git a/app/javascript/packs/dictionary.js b/app/javascript/packs/dictionary.js index d6e6ee5..9c9bf42 100644 --- a/app/javascript/packs/dictionary.js +++ b/app/javascript/packs/dictionary.js @@ -1,5 +1,14 @@ const perseus = "https://www.perseus.tufts.edu/hopper/"; +function flash_modal(dict_id, target) { + var modal = $("#" + dict_id); + const tgt_classes = "text-white bg-info"; + target.addClass(tgt_classes); + modal.fadeOut(100, function() { + modal.fadeIn(800, function() { target.removeClass(tgt_classes); }); + }); +} + function dictionary_search(dict_id, comp) { var select = "[data-behavior='dictionary'][data-id='" + dict_id + "']"; var modal_body = $("#" + dict_id + " div.modal-body"); @@ -43,7 +52,13 @@ function dictionary_search_grammar(dict_id, comp, modal_body) { var list = $(''); var lemmata = []; var texts = []; + var help = $('

Click on a lemma (words in parenthesis) to see its ' + + 'definition, or click "use" to copy the grammar to the ' + + 'appropriate box in the etymology table

'); + help.addClass("text-muted small border-left px-2 mx-2"); + if ($(data).find("analyses analysis").length == 0) { + help = ''; list = $('Term not found'); } else { $(data).find("analyses analysis").each(function() { @@ -60,9 +75,8 @@ function dictionary_search_grammar(dict_id, comp, modal_body) { if (i == "case" & val != "gen") return; if (i == "pos" & val == "noun") val = "n"; text = text + " " + val; - if (i != "dialect") text = text + "."; + if (i != "dialect" & val != "verb") text = text + "."; }); - if (texts.includes(text)) return; texts.push(text); var item = $("
  • "); var lemma_anchor = $( @@ -77,7 +91,9 @@ function dictionary_search_grammar(dict_id, comp, modal_body) { var anchor = $("use"); anchor.on("click", function() { - $(select + " #name_etymology_" + comp + "_grammar").val(text); + var target = $(select + " #name_etymology_" + comp + "_grammar"); + target.val(text); + flash_modal(dict_id, target); }); // Build item and add to list @@ -91,7 +107,8 @@ function dictionary_search_grammar(dict_id, comp, modal_body) { }); } modal_body.children('.analyses').html('

    Grammatical analyses

    '); - modal_body.children('.analyses').append(list); + modal_body.children(".analyses").append(help); + modal_body.children(".analyses").append(list); if (!lemmata.includes(part)) lemmata.push(part); dictionary_search_definition(dict_id, comp, modal_body, lemmata[0], 1); }).fail(function() { @@ -139,6 +156,10 @@ function dictionary_search_definition(dict_id, comp, modal_body, part, src) { '' ); + var help = $('

    Click on "use" to copy the definition to the appropriate ' + + 'box in the etymology table, or see the full formatted ' + + 'definition for the term below in the grey box

    '); + help.addClass("text-muted small border-left px-2 mx-2"); // Definition $.ajax({ @@ -155,6 +176,7 @@ function dictionary_search_definition(dict_id, comp, modal_body, part, src) { // Parse definitions var cont = modal_body.children('.definition'); cont.html(title); + cont.append(help); var list = $(''); result.find("div.lex_sense > i").each(function() { var description = $(this).text(); @@ -163,7 +185,9 @@ function dictionary_search_definition(dict_id, comp, modal_body, part, src) { var anchor = $("use"); anchor.on("click", function() { - $(select + " #name_etymology_" + comp + "_description").val(description); + var target = $(select + " #name_etymology_" + comp + "_description"); + target.val(description); + flash_modal(dict_id, target); }); item.append(description); item.append(anchor); @@ -189,10 +213,12 @@ function dictionary_search_button(dict_id, comp) { var td = $(select + " #name_etymology_" + comp + "_dict"); td.html(''); var latin = [ - "", "L", "L.", "Latin", "N.L.", "NL", "NL.", "Neolatin", "Neo Latin", + "L", "L.", "Latin", "N.L.", "NL", "NL.", "Neolatin", "Neo Latin", "Neo-Latin", // The dictionary includes Greek entries - "Greek", "Gr." + "Greek", "Gr.", + // We might as well try if the language is blank + "" ]; var lang = $(select + " #name_etymology_" + comp + "_lang").val(); if (!latin.includes(lang)) return; @@ -217,10 +243,11 @@ $(document).on("turbolinks:load", function() { $("[data-behavior='dictionary']").each(function() { console.log('Initializing Dictionary Lookup'); var dict_id = $(this).data("id"); + var select = "[data-behavior='dictionary'][data-id='" + dict_id + "']"; components.forEach(function(comp_i) { fields.forEach(function(field_i) { var id = "name_etymology_" + comp_i + "_" + field_i; - $("#" + id).on("change", function() { + $(select + " #" + id).on("change", function() { dictionary_search_button(dict_id, comp_i); }); }); diff --git a/app/models/name/etymology.rb b/app/models/name/etymology.rb index 94e6cc2..cd8f88a 100644 --- a/app/models/name/etymology.rb +++ b/app/models/name/etymology.rb @@ -411,8 +411,8 @@ def guess_syllabication(word = last_epithet) end # Propose emphasis - if syllables.size == 1 - # No accent for monosyllabic words + if syllables.size <= 1 + # Ignore empty words, and no accent for monosyllabic words elsif word =~ /(aceae|ia|icus|iae|icola|ium)$/ syllables[-3] += "'" else diff --git a/app/views/names/_etymology_table.html.erb b/app/views/names/_etymology_table.html.erb new file mode 100644 index 0000000..24327f8 --- /dev/null +++ b/app/views/names/_etymology_table.html.erb @@ -0,0 +1,38 @@ +<% dict_id = modal('Dictionary lookup', size: 'lg') do %> +<% end %> + + + + + + + + + + + <% + components = { + p1: '1st morpheme', p2: '2nd morpheme', p3: '3rd morpheme', + p4: '4th morpheme', p5: '5th morpheme', xx: 'Full word' + } + fields = { lang: 5, grammar: 15, particle: 15, description: 30 } + %> + <% components.each do |k, v| %> + '> + + <% fields.each do |i, size| %> + <% entry = :"etymology_#{ k }_#{ i }" %> + + <% end %> + + + <% end %> + +
    ComponentLanguageGrammarParticleDescription or translation
    <%= v %> + <% if i == :particle && k == :xx %> + <%= content_tag(:i, name.last_epithet, id: "name_#{entry}") %> + <% else %> + <%= form.input(entry, input_html: { size: size }, label: false) %> + <% end %> +
    diff --git a/app/views/names/edit_etymology.html.erb b/app/views/names/edit_etymology.html.erb index eda65a0..22840ad 100644 --- a/app/views/names/edit_etymology.html.erb +++ b/app/views/names/edit_etymology.html.erb @@ -38,57 +38,7 @@ <% end %> -
    - <% dict_id = modal('Dictionary lookup', size: 'lg') do %> - <% end %> - - - - - - - - - - - <% - components = { - p1: '1st morpheme', p2: '2nd morpheme', p3: '3rd morpheme', - p4: '4th morpheme', p5: '5th morpheme', xx: 'Full word' - } - fields = { lang: 5, grammar: 15, particle: 15, description: 30 } - %> - <% components.each do |k, v| %> - '> - - <% fields.each do |i, size| %> - <% entry = :"etymology_#{ k }_#{ i }" %> - - <% end %> - - - <% end %> - -
    ComponentLanguageGrammarParticleDescription or translation
    <%= v %> - <% if i == :particle && k == :xx %> - <%= content_tag(:i, @name.last_epithet, id: "name_#{entry}") %> - <% else %> - <%= f.input entry, input_html: { size: size }, label: false %> - <% end %> -
    -
    - - + <%= render(partial: 'etymology_table', locals: { form: f, name: @name }) %>
    <% if @tutorial %> diff --git a/app/views/names/etymology_sandbox.html.erb b/app/views/names/etymology_sandbox.html.erb new file mode 100644 index 0000000..4669b5c --- /dev/null +++ b/app/views/names/etymology_sandbox.html.erb @@ -0,0 +1,45 @@ +

    Etymology sandbox

    +<%= simple_form_for(@name) do |f| %> +
    +

    + The etymology sandbox is designed to provide all the tools available to + you in the etymology table of names, without having to create or modify + a name in the system. +

    +

    + To get started, simply write the Latin or Latinized name in the field + below, which should trigger an automated proposal of the syllabification. + Continue by filling up the etymology table below, including the usage of + the dictionary lookups. +

    +
    + <%= help_topic('etymology', + 'How do I fill the etymology table?', size: 'xl') %> + <%= help_topic('dictionary', + 'How do I use dictionary lookups?', size: 'xl') %> +
    + + <%= f.input(:name) %> + <%= f.input(:syllabification, label: 'Inferred syllabification') %> + <% @name.name = '...' %> + <%= render(partial: 'etymology_table', locals: { form: f, name: @name }) %> +<% end %> + + + diff --git a/app/views/names/syllabify.json.jbuilder b/app/views/names/syllabify.json.jbuilder new file mode 100644 index 0000000..92130b0 --- /dev/null +++ b/app/views/names/syllabify.json.jbuilder @@ -0,0 +1,6 @@ +json.response do + json.status 'ok' + json.message_type 'syllabify' +end +json.syllabification(@syllabification) +json.(@name, :last_epithet) diff --git a/config/routes.rb b/config/routes.rb index baf2311..b9ecedb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,8 +57,11 @@ get :draft get :user get :observing - get :autocomplete get :linkout + # --> User utilities + get :autocomplete + get :etymology_sandbox + get :syllabify # --> Curator utilities get :unranked get :unknown_proposal diff --git a/documentation b/documentation index a004a0d..0ed30c4 160000 --- a/documentation +++ b/documentation @@ -1 +1 @@ -Subproject commit a004a0d8041f195646fa73f38a1eba392a2bcc81 +Subproject commit 0ed30c408fccc8337ab536dc8da2f452ec618d22