diff --git a/app/assets/javascripts/comments.js.erb b/app/assets/javascripts/comments.js.erb index 18aef4c0d..b94e317e0 100644 --- a/app/assets/javascripts/comments.js.erb +++ b/app/assets/javascripts/comments.js.erb @@ -86,6 +86,8 @@ var Comments = (function() { function initCommentForm($el) { var $form = $el.find('ul form'); + // initialize smart annotation + SmartAnnotation.init($($form).find('#comment_message')); $('.help-block', $form).addClass('hide'); diff --git a/app/assets/javascripts/experiments/dropdown_actions.js b/app/assets/javascripts/experiments/dropdown_actions.js index a15c27597..a10c8700b 100644 --- a/app/assets/javascripts/experiments/dropdown_actions.js +++ b/app/assets/javascripts/experiments/dropdown_actions.js @@ -18,6 +18,8 @@ validateMoveModal(id); clearModal($(id)); validateExperimentForm($(id)); + // initialize smart annotation + SmartAnnotation.init('#experiment-description'); }) .on("ajax:error", function() { animateSpinner(null, false); diff --git a/app/assets/javascripts/protocols/steps.js.erb b/app/assets/javascripts/protocols/steps.js.erb index 98e854a71..27d6de980 100644 --- a/app/assets/javascripts/protocols/steps.js.erb +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -9,7 +9,6 @@ function applyCheckboxCallBack() { $("[data-action='check-item']").on('click', function(e){ var checkboxitem = $(this).find("input"); - var checked = checkboxitem.is(":checked"); $.ajax({ url: checkboxitem.data("link-url"), @@ -113,6 +112,7 @@ function applyEditCallBack() { $("#step_name").focus(); }); openLinksInNewTab(); + initSmartAnnotation(); }); } @@ -430,6 +430,8 @@ function reorderCheckboxData(checkboxUl) { $posInput.attr("id", posId); $posInput.val(itemPos); $destroyLink.attr("data-delete-association-field-name", destroyLink); + debugger; + SmartAnnotation.init(); var $idInput = $this.find("> input"); if ($idInput.length) { @@ -471,7 +473,6 @@ function initializeCheckboxSorting() { // inserted into DOM. setTimeout(function () { var list = el.parent().find("fieldset.nested_step_checklists:last ul"); - enableCheckboxSorting(list.get(0)); }); }); @@ -566,6 +567,27 @@ function initHighlightjs() { } } +// initialize the smart annotations +function initSmartAnnotation() { + $('#new-step-checklists').on('click', function() { + setTimeout(function() { + SmartAnnotation.init('.checklist_name'); + }, 300); + + $('[data-object-class="checklist"]').on('click', function() { + setTimeout(function() { + SmartAnnotation.init('.checklist_name'); + }, 300); + }); + + $('[data-object-class="checklist_item"]').on('click', function() { + setTimeout(function() { + $('.checklist-item-text').atwho('destroy'); + SmartAnnotation.init('.checklist-item-text'); + }, 300); + }); + }); +} function initStepsComments() { Comments.initialize(); Comments.initCommentOptions("ul.content-comments"); diff --git a/app/assets/javascripts/results/result_texts.js b/app/assets/javascripts/results/result_texts.js index 8363f9c84..fe919a7ce 100644 --- a/app/assets/javascripts/results/result_texts.js +++ b/app/assets/javascripts/results/result_texts.js @@ -14,6 +14,8 @@ $("#new-result-text").on("ajax:success", function(e, data) { toggleResultEditButtons(false); $("#result_name").focus(); + + SmartAnnotation.init('.ql-editor'); }); $("#new-result-text").on("ajax:error", function(e, xhr, status, error) { @@ -88,11 +90,3 @@ $(document).ready(function() { initHighlightjs(); }); applyEditResultTextCallback(); - - - -$(document).ready(function() { - setTimeout(function(){ - SmartAnnotation.init('[data-atwho-res-edit]'); - }, 2000); -}); diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index bdd205888..33f4c622a 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -433,6 +433,11 @@ function onClickEdit() { } }); + // initialize smart annotation + _.each($('[data-object="custom_fields"]'), function(el) { + SmartAnnotation.init(el); + }); + // Adjust columns width in table header table.columns.adjust(); }, diff --git a/app/assets/javascripts/sitewide/atwho_tasks.js b/app/assets/javascripts/sitewide/atwho_res.js similarity index 89% rename from app/assets/javascripts/sitewide/atwho_tasks.js rename to app/assets/javascripts/sitewide/atwho_res.js index 798939544..838333c2d 100644 --- a/app/assets/javascripts/sitewide/atwho_tasks.js +++ b/app/assets/javascripts/sitewide/atwho_res.js @@ -136,30 +136,39 @@ var SmartAnnotation = (function() { $('.atwho-header button').on('click', function(e) { var $button, $prevButton; e.stopPropagation(); + $('.atwho-header button').off(); $button = $(this); $prevButton = $button.closest('.atwho-header').children('.btn-primary'); switch ($button.attr('data-filter')) { case 'prj': - generateNewQuery('/organizations/1/atwho_projects.json', - $prevButton, - $button); + setTimeout(function() { + generateNewQuery('/organizations/1/atwho_projects.json', + $prevButton, + $button); + }, 300); break; case 'exp': - generateNewQuery('/organizations/1/atwho_experiments.json', - $prevButton, - $button); + setTimeout(function() { + generateNewQuery('/organizations/1/atwho_experiments.json', + $prevButton, + $button); + }, 300); break; case 'tsk': - generateNewQuery('/organizations/1/atwho_my_modules.json', - $prevButton, - $button); + setTimeout(function() { + generateNewQuery('/organizations/1/atwho_my_modules.json', + $prevButton, + $button); + }, 300); break; case 'sam': - generateNewQuery('/organizations/1/atwho_samples.json', - $prevButton, - $button); + setTimeout(function() { + generateNewQuery('/organizations/1/atwho_samples.json', + $prevButton, + $button); + }, 300); break; } }); @@ -167,21 +176,33 @@ var SmartAnnotation = (function() { // Generates new query when user filters the results function generateNewQuery(link, prevBtn, selectedBtn) { - var regexp, _a, _y, new_query, query_obj; + var regexp, _a, _y, new_query, query_obj, field_selected; _a = decodeURI("%C3%80"); _y = decodeURI("%C3%BF"); regexp = new RegExp("(#|task#|project#|sample#|experiment#)([A-Za-z" + _a + "-" + _y + "0-9_ \'\.\+\-]*)$|" + "(#|task#|project#|sample#|experiment#)([^\\x00-\\xff]*)$", 'gi'); - query_obj = regexp.exec($(field).val()); - new_query = query_obj.input.replace(query_obj[1], ''); + // filters field if multiple input fields on the page + _.each($(field), function(e) { + if($(e).atwho('isSelecting')){ + field_selected = e; + }}); + + if(field_selected) { + query_obj = regexp.exec($(field_selected).val()); + new_query = query_obj.input.replace(query_obj[1], ''); + } else { + query_obj = ['']; + new_query = ''; + } + $.getJSON( link, {query: new_query}, function(data) { - if(data.res.length > 0) { - $(field) + if(data.res.length > 0 && field_selected) { + $(field_selected) .atwho('load', query_obj[0], data.res) .atwho('run'); @@ -259,10 +280,14 @@ var SmartAnnotation = (function() { res += ''; res += map.name; res += ''; + if(map.archived) { + res += '(archived)'; + } res += ' '; switch (map.type) { case 'tsk': + res += '< ' + map.experimentName + ' < ' + map.projectName + ''; break; diff --git a/app/datatables/sample_datatable.rb b/app/datatables/sample_datatable.rb index 90af5ec62..da3832738 100644 --- a/app/datatables/sample_datatable.rb +++ b/app/datatables/sample_datatable.rb @@ -3,6 +3,9 @@ require 'active_record' class SampleDatatable < AjaxDatatablesRails::Base include ActionView::Helpers::TextHelper include SamplesHelper + include Rails.application.routes.url_helpers + include ActionView::Helpers::UrlHelper + include ApplicationHelper ASSIGNED_SORT_COL = 'assigned' @@ -118,11 +121,11 @@ class SampleDatatable < AjaxDatatablesRails::Base # Add custom attributes record.sample_custom_fields.each do |scf| - sample[@cf_mappings[scf.custom_field_id]] = auto_link(scf.value, - link: :urls, - html: { - target: '_blank' - }) + sample[@cf_mappings[scf.custom_field_id]] = auto_link( + smart_annotation_parser(scf.value), + link: :urls, + html: { target: '_blank' } + ) end sample end diff --git a/app/models/smart_annotation.rb b/app/models/smart_annotation.rb index 0048261d2..6eece8143 100644 --- a/app/models/smart_annotation.rb +++ b/app/models/smart_annotation.rb @@ -74,7 +74,7 @@ class SmartAnnotation length: Constants::NAME_TRUNCATION_LENGTH) ) exp['type'] = 'exp' - exp['project'] = truncate( + exp['projectName'] = truncate( sanitize(experiment_res.project.name, length: Constants::NAME_TRUNCATION_LENGTH) ) @@ -102,10 +102,10 @@ class SmartAnnotation )} #{I18n.t('by')} #{truncate( sanitize(sample_res.user.full_name, length: Constants::NAME_TRUNCATION_LENGTH) - )} #{(',' + truncate( + )} #{(', ' + truncate( sanitize(sample_res.sample_type.name, length: Constants::NAME_TRUNCATION_LENGTH) - )) if sample_res.sample_type}, #{(',' + truncate( + )) if sample_res.sample_type} #{(', ' + truncate( sanitize(sample_res.sample_group.name, length: Constants::NAME_TRUNCATION_LENGTH) )) if sample_res.sample_group}" diff --git a/app/views/my_modules/protocols/_protocol_status_bar.html.erb b/app/views/my_modules/protocols/_protocol_status_bar.html.erb index 1438e4ce3..e53b85725 100644 --- a/app/views/my_modules/protocols/_protocol_status_bar.html.erb +++ b/app/views/my_modules/protocols/_protocol_status_bar.html.erb @@ -1,5 +1,5 @@
-
+
<% if @protocol.linked? %> <%= protocol_status_href(@protocol) %> <% else %> diff --git a/app/views/projects/show/_experiment.html.erb b/app/views/projects/show/_experiment.html.erb index 586c0f17c..51d28781c 100644 --- a/app/views/projects/show/_experiment.html.erb +++ b/app/views/projects/show/_experiment.html.erb @@ -49,9 +49,13 @@ <% if experiment.description? %>
- <%= auto_link(simple_format(experiment.description), - link: :urls, - html: { target: '_blank' }) %> + <%= auto_link( + simple_format( + smart_annotation_parser(experiment.description) + ), + link: :urls, + html: { target: '_blank' } + ) %>
<% else %> diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index 7bf224a51..3ea37d7cc 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -88,9 +88,12 @@ <% unless step.checklists.blank? then %>
<% step.checklists.each do |checklist| %> - <%= auto_link(simple_format(checklist.name), - link: :urls, - html: { target: '_blank' }) %> + <%= auto_link( + simple_format( + smart_annotation_parser(checklist.name) + ), + link: :urls, + html: { target: '_blank' }) %> <% if checklist.checklist_items.empty? %>
<%= t("protocols.steps.empty_checklist") %> @@ -104,9 +107,12 @@ <% else %> <% end %> - <%= auto_link(simple_format(checklist_item.text), - link: :urls, - html: { target: '_blank' }) %> + <%= auto_link( + simple_format( + smart_annotation_parser(checklist_item.text) + ), + link: :urls, + html: { target: '_blank' }) %>
<% end %>