expand smart annotation

This commit is contained in:
zmagod 2017-01-10 14:13:37 +01:00
parent e0e998a0d8
commit 89e8946a47
11 changed files with 108 additions and 45 deletions

View file

@ -86,6 +86,8 @@ var Comments = (function() {
function initCommentForm($el) { function initCommentForm($el) {
var $form = $el.find('ul form'); var $form = $el.find('ul form');
// initialize smart annotation
SmartAnnotation.init($($form).find('#comment_message'));
$('.help-block', $form).addClass('hide'); $('.help-block', $form).addClass('hide');

View file

@ -18,6 +18,8 @@
validateMoveModal(id); validateMoveModal(id);
clearModal($(id)); clearModal($(id));
validateExperimentForm($(id)); validateExperimentForm($(id));
// initialize smart annotation
SmartAnnotation.init('#experiment-description');
}) })
.on("ajax:error", function() { .on("ajax:error", function() {
animateSpinner(null, false); animateSpinner(null, false);

View file

@ -9,7 +9,6 @@
function applyCheckboxCallBack() { function applyCheckboxCallBack() {
$("[data-action='check-item']").on('click', function(e){ $("[data-action='check-item']").on('click', function(e){
var checkboxitem = $(this).find("input"); var checkboxitem = $(this).find("input");
var checked = checkboxitem.is(":checked"); var checked = checkboxitem.is(":checked");
$.ajax({ $.ajax({
url: checkboxitem.data("link-url"), url: checkboxitem.data("link-url"),
@ -113,6 +112,7 @@ function applyEditCallBack() {
$("#step_name").focus(); $("#step_name").focus();
}); });
openLinksInNewTab(); openLinksInNewTab();
initSmartAnnotation();
}); });
} }
@ -430,6 +430,8 @@ function reorderCheckboxData(checkboxUl) {
$posInput.attr("id", posId); $posInput.attr("id", posId);
$posInput.val(itemPos); $posInput.val(itemPos);
$destroyLink.attr("data-delete-association-field-name", destroyLink); $destroyLink.attr("data-delete-association-field-name", destroyLink);
debugger;
SmartAnnotation.init();
var $idInput = $this.find("> input"); var $idInput = $this.find("> input");
if ($idInput.length) { if ($idInput.length) {
@ -471,7 +473,6 @@ function initializeCheckboxSorting() {
// inserted into DOM. // inserted into DOM.
setTimeout(function () { setTimeout(function () {
var list = el.parent().find("fieldset.nested_step_checklists:last ul"); var list = el.parent().find("fieldset.nested_step_checklists:last ul");
enableCheckboxSorting(list.get(0)); 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() { function initStepsComments() {
Comments.initialize(); Comments.initialize();
Comments.initCommentOptions("ul.content-comments"); Comments.initCommentOptions("ul.content-comments");

View file

@ -14,6 +14,8 @@ $("#new-result-text").on("ajax:success", function(e, data) {
toggleResultEditButtons(false); toggleResultEditButtons(false);
$("#result_name").focus(); $("#result_name").focus();
SmartAnnotation.init('.ql-editor');
}); });
$("#new-result-text").on("ajax:error", function(e, xhr, status, error) { $("#new-result-text").on("ajax:error", function(e, xhr, status, error) {
@ -88,11 +90,3 @@ $(document).ready(function() {
initHighlightjs(); initHighlightjs();
}); });
applyEditResultTextCallback(); applyEditResultTextCallback();
$(document).ready(function() {
setTimeout(function(){
SmartAnnotation.init('[data-atwho-res-edit]');
}, 2000);
});

View file

@ -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 // Adjust columns width in table header
table.columns.adjust(); table.columns.adjust();
}, },

View file

@ -136,30 +136,39 @@ var SmartAnnotation = (function() {
$('.atwho-header button').on('click', function(e) { $('.atwho-header button').on('click', function(e) {
var $button, $prevButton; var $button, $prevButton;
e.stopPropagation(); e.stopPropagation();
$('.atwho-header button').off(); $('.atwho-header button').off();
$button = $(this); $button = $(this);
$prevButton = $button.closest('.atwho-header').children('.btn-primary'); $prevButton = $button.closest('.atwho-header').children('.btn-primary');
switch ($button.attr('data-filter')) { switch ($button.attr('data-filter')) {
case 'prj': case 'prj':
setTimeout(function() {
generateNewQuery('/organizations/1/atwho_projects.json', generateNewQuery('/organizations/1/atwho_projects.json',
$prevButton, $prevButton,
$button); $button);
}, 300);
break; break;
case 'exp': case 'exp':
setTimeout(function() {
generateNewQuery('/organizations/1/atwho_experiments.json', generateNewQuery('/organizations/1/atwho_experiments.json',
$prevButton, $prevButton,
$button); $button);
}, 300);
break; break;
case 'tsk': case 'tsk':
setTimeout(function() {
generateNewQuery('/organizations/1/atwho_my_modules.json', generateNewQuery('/organizations/1/atwho_my_modules.json',
$prevButton, $prevButton,
$button); $button);
}, 300);
break; break;
case 'sam': case 'sam':
setTimeout(function() {
generateNewQuery('/organizations/1/atwho_samples.json', generateNewQuery('/organizations/1/atwho_samples.json',
$prevButton, $prevButton,
$button); $button);
}, 300);
break; break;
} }
}); });
@ -167,21 +176,33 @@ var SmartAnnotation = (function() {
// Generates new query when user filters the results // Generates new query when user filters the results
function generateNewQuery(link, prevBtn, selectedBtn) { 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"); _a = decodeURI("%C3%80");
_y = decodeURI("%C3%BF"); _y = decodeURI("%C3%BF");
regexp = new RegExp("(#|task#|project#|sample#|experiment#)([A-Za-z" + regexp = new RegExp("(#|task#|project#|sample#|experiment#)([A-Za-z" +
_a + "-" + _y + "0-9_ \'\.\+\-]*)$|" + _a + "-" + _y + "0-9_ \'\.\+\-]*)$|" +
"(#|task#|project#|sample#|experiment#)([^\\x00-\\xff]*)$", 'gi'); "(#|task#|project#|sample#|experiment#)([^\\x00-\\xff]*)$", 'gi');
query_obj = regexp.exec($(field).val()); // 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], ''); new_query = query_obj.input.replace(query_obj[1], '');
} else {
query_obj = [''];
new_query = '';
}
$.getJSON( $.getJSON(
link, link,
{query: new_query}, {query: new_query},
function(data) { function(data) {
if(data.res.length > 0) { if(data.res.length > 0 && field_selected) {
$(field) $(field_selected)
.atwho('load', query_obj[0], data.res) .atwho('load', query_obj[0], data.res)
.atwho('run'); .atwho('run');
@ -259,10 +280,14 @@ var SmartAnnotation = (function() {
res += '<span data-val="name">'; res += '<span data-val="name">';
res += map.name; res += map.name;
res += '</span>'; res += '</span>';
if(map.archived) {
res += '<span>(archived)</span>';
}
res += '&nbsp;'; res += '&nbsp;';
switch (map.type) { switch (map.type) {
case 'tsk': case 'tsk':
res += '<span>&lt; ' + map.experimentName + res += '<span>&lt; ' + map.experimentName +
' &lt; ' + map.projectName + '</span>'; ' &lt; ' + map.projectName + '</span>';
break; break;

View file

@ -3,6 +3,9 @@ require 'active_record'
class SampleDatatable < AjaxDatatablesRails::Base class SampleDatatable < AjaxDatatablesRails::Base
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
include SamplesHelper include SamplesHelper
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
include ApplicationHelper
ASSIGNED_SORT_COL = 'assigned' ASSIGNED_SORT_COL = 'assigned'
@ -118,11 +121,11 @@ class SampleDatatable < AjaxDatatablesRails::Base
# Add custom attributes # Add custom attributes
record.sample_custom_fields.each do |scf| record.sample_custom_fields.each do |scf|
sample[@cf_mappings[scf.custom_field_id]] = auto_link(scf.value, sample[@cf_mappings[scf.custom_field_id]] = auto_link(
smart_annotation_parser(scf.value),
link: :urls, link: :urls,
html: { html: { target: '_blank' }
target: '_blank' )
})
end end
sample sample
end end

View file

@ -74,7 +74,7 @@ class SmartAnnotation
length: Constants::NAME_TRUNCATION_LENGTH) length: Constants::NAME_TRUNCATION_LENGTH)
) )
exp['type'] = 'exp' exp['type'] = 'exp'
exp['project'] = truncate( exp['projectName'] = truncate(
sanitize(experiment_res.project.name, sanitize(experiment_res.project.name,
length: Constants::NAME_TRUNCATION_LENGTH) length: Constants::NAME_TRUNCATION_LENGTH)
) )
@ -105,7 +105,7 @@ class SmartAnnotation
)} #{(', ' + truncate( )} #{(', ' + truncate(
sanitize(sample_res.sample_type.name, sanitize(sample_res.sample_type.name,
length: Constants::NAME_TRUNCATION_LENGTH) length: Constants::NAME_TRUNCATION_LENGTH)
)) if sample_res.sample_type}, #{(',' + truncate( )) if sample_res.sample_type} #{(', ' + truncate(
sanitize(sample_res.sample_group.name, sanitize(sample_res.sample_group.name,
length: Constants::NAME_TRUNCATION_LENGTH) length: Constants::NAME_TRUNCATION_LENGTH)
)) if sample_res.sample_group}" )) if sample_res.sample_group}"

View file

@ -49,9 +49,13 @@
</span> </span>
<% if experiment.description? %> <% if experiment.description? %>
<div class='experiment-description'> <div class='experiment-description'>
<%= auto_link(simple_format(experiment.description), <%= auto_link(
simple_format(
smart_annotation_parser(experiment.description)
),
link: :urls, link: :urls,
html: { target: '_blank' }) %> html: { target: '_blank' }
) %>
</div> </div>
<% else %> <% else %>
<span class='experiment-no-description'> <span class='experiment-no-description'>

View file

@ -88,7 +88,10 @@
<% unless step.checklists.blank? then %> <% unless step.checklists.blank? then %>
<div class="col-xs-12"> <div class="col-xs-12">
<% step.checklists.each do |checklist| %> <% step.checklists.each do |checklist| %>
<strong><%= auto_link(simple_format(checklist.name), <strong><%= auto_link(
simple_format(
smart_annotation_parser(checklist.name)
),
link: :urls, link: :urls,
html: { target: '_blank' }) %></strong> html: { target: '_blank' }) %></strong>
<% if checklist.checklist_items.empty? %> <% if checklist.checklist_items.empty? %>
@ -104,7 +107,10 @@
<% else %> <% else %>
<input type="checkbox" value="" disabled="disabled" /> <input type="checkbox" value="" disabled="disabled" />
<% end %> <% end %>
<%= auto_link(simple_format(checklist_item.text), <%= auto_link(
simple_format(
smart_annotation_parser(checklist_item.text)
),
link: :urls, link: :urls,
html: { target: '_blank' }) %> html: { target: '_blank' }) %>
</label> </label>