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) {
var $form = $el.find('ul form');
// initialize smart annotation
SmartAnnotation.init($($form).find('#comment_message'));
$('.help-block', $form).addClass('hide');

View file

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

View file

@ -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");

View file

@ -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);
});

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
table.columns.adjust();
},

View file

@ -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 += '<span data-val="name">';
res += map.name;
res += '</span>';
if(map.archived) {
res += '<span>(archived)</span>';
}
res += '&nbsp;';
switch (map.type) {
case 'tsk':
res += '<span>&lt; ' + map.experimentName +
' &lt; ' + map.projectName + '</span>';
break;

View file

@ -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

View file

@ -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}"

View file

@ -1,5 +1,5 @@
<div class="panel panel-default panel-protocol-status">
<div class="panel-body">
<div class="panel-body">
<% if @protocol.linked? %>
<%= protocol_status_href(@protocol) %>
<% else %>

View file

@ -49,9 +49,13 @@
</span>
<% if experiment.description? %>
<div class='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' }
) %>
</div>
<% else %>
<span class='experiment-no-description'>

View file

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