Add styling and highligh

This commit is contained in:
aignatov-bio 2020-09-09 14:17:19 +02:00
parent 661220890f
commit 7a86bb47c5
8 changed files with 144 additions and 116 deletions

View file

@ -49,63 +49,26 @@ var SmartAnnotation = (function() {
DEFAULT_SEARCH_FILTER = FilterTypeEnum.REPOSITORY, DEFAULT_SEARCH_FILTER = FilterTypeEnum.REPOSITORY,
atWhoUpdating = false; atWhoUpdating = false;
var defaultRepId; function _matchHighlighter(html, query, filterType) {
var $html = $(html);
var $li_text = $html.find('.item-text');
// helper methods for AtWho callback if ($li_text.length === 0 || !query) return html;
function _templateEval(_tpl, map) {
var res;
try {
res = generateTemplate(map);
} catch (_error) {
res = '';
}
return res;
}
function _matchHighlighter(li, query, filterType) { $.each($li_text, function(i, item) {
var $li, re; $(item).html($(item).text().replace(new RegExp(query, 'gi'), '<span class="atwho-highlight">$&</span>'));
})
function highlight(el, sel, re) { return $html;
var prevVal, newVal;
prevVal = el.find(sel).html();
newVal = prevVal.replace(re, '<strong>$&</strong>');
el.find(sel).html(newVal);
}
if (!query || $(li).data('no-results')) {
return li;
}
$li = $(li);
re = new RegExp(query, 'gi');
// search_filter is not passed for the user
if(filterType) {
highlight($li, '[data-val=name]', re);
} else {
highlight($li, '[data-val=full-name]', re);
highlight($li, '[data-val=email]', re);
}
return $li[0].outerHTML
} }
function _generateInputTag(value, li) { function _generateInputTag(value, li) {
return `[#${li.attr('data-name')}~${li.attr('data-type')}~${li.attr('data-id')}]`; return `[#${li.attr('data-name')}~${li.attr('data-type')}~${li.attr('data-id')}]`;
} }
// initialise dropdown dismiss button
function initDismissButton($currentAtWho) {
$currentAtWho.find('.dismiss').off('click')
.on('click', function() {
$(field).atwho('destroy');
init();
});
}
// Generates suggestion dropdown filter // Generates suggestion dropdown filter
function generateFilterMenu(active, res_data) { function generateFilterMenu(active, res_data) {
var menu = ''; var menu = '';
var rep_buttons = '';
$.ajax({ $.ajax({
async: false, async: false,
dataType: 'json', dataType: 'json',
@ -117,17 +80,6 @@ var SmartAnnotation = (function() {
return menu; return menu;
} }
function noResultsTemplate() {
return `<div class="atwho-no-results" data-no-results="1">
<span><%= I18n.t("atwho.no_results") %></span>
</div>`;
}
// Generates resources list items
function generateTemplate(map) {
return map.name;
}
function atWhoSettings(at, defaultFilterType) { function atWhoSettings(at, defaultFilterType) {
return { return {
at: at, at: at,
@ -138,7 +90,7 @@ var SmartAnnotation = (function() {
var params = { query: query }; var params = { query: query };
filterType = FilterTypeEnum[$currentAtWho.find('.tab-pane.active').data('object-type')] filterType = FilterTypeEnum[$currentAtWho.find('.tab-pane.active').data('object-type')]
if (!filterType) { if (!filterType) {
callback([{name: noResultsTemplate()}]); callback([{name: ''}]);
return false return false
} }
@ -159,15 +111,11 @@ var SmartAnnotation = (function() {
} }
}); });
}, },
sorter: function(query, items, _searchKey) { tplEval: function(_tpl, items) {
// Sorting is already done on server-side return items.name;
return items;
},
tplEval: function(_tpl, map) {
return _templateEval(_tpl, map);
}, },
highlighter: function(li, query) { highlighter: function(li, query) {
//return _matchHighlighter(li, query, true); return _matchHighlighter(li, query, true);
return li; return li;
}, },
beforeInsert: function(value, li) { beforeInsert: function(value, li) {
@ -258,7 +206,7 @@ var SmartAnnotation = (function() {
var res; var res;
try { try {
if (map.no_results) { if (map.no_results) {
res = noResultsTemplate(); res = '';
} else { } else {
res = ''; res = '';
res += '<li class="atwho-li atwho-li-user" '; res += '<li class="atwho-li atwho-li-user" ';
@ -284,7 +232,7 @@ var SmartAnnotation = (function() {
return res; return res;
}, },
highlighter: function(li, query) { highlighter: function(li, query) {
return _matchHighlighter(li, query); return li;//_matchHighlighter(li, query);
}, },
beforeInsert: function(value, li) { beforeInsert: function(value, li) {
var res = ''; var res = '';

View file

@ -22,27 +22,71 @@
display: flex; display: flex;
padding: .25em; padding: .25em;
} }
.repository-object {
max-width: 250px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
} }
.atwho-view-ul { .atwho-view-ul {
margin: 0; margin: 0;
padding: .25em; padding: 0;
} }
.atwho-footer { .atwho-footer {
@include font-small; @include font-small;
border-top: $border-default; border-top: $border-default;
color: $color-silver-chalice; color: $color-silver-chalice;
margin-left: -.25em;
padding: .5em; padding: .5em;
width: calc(100% + .5em);
white-space: pre; white-space: pre;
} }
.atwho-scroll-container { .atwho-scroll-container {
max-height: 200px; max-height: 200px;
overflow-y: auto; overflow-y: auto;
padding: .5em;
position: relative; position: relative;
.atwho-breadcrumbs {
@include font-small;
color: $color-silver-chalice;
display: flex;
.atwho-breadcrumb {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.slash {
margin: 0 .5em;
}
}
.sa-type {
font-size: 8px;
}
.item {
cursor: pointer;
margin-left: -.5em;
overflow: hidden;
padding: .25em .5em;
text-overflow: ellipsis;
width: calc(100% + 1em);
white-space: nowrap;
&.cur {
background: $color-concrete;
}
.atwho-highlight {
background: $brand-warning-light;
}
}
} }
} }

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module ExperimentsHelper
def grouped_by_prj(experiments)
ungrouped_experiments = experiments.joins(:project)
.select('projects.name as project_name,
projects.archived as project_archived,
experiments.*')
ungrouped_experiments.group_by { |i| [i[:project_name]] }.map do |group, exps|
{
project_name: group[0],
project_archived: exps[0]&.project_archived,
experiments: exps
}
end
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class SmartAnnotation class SmartAnnotation
include ActionView::Helpers::SanitizeHelper include ActionView::Helpers::SanitizeHelper
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
@ -12,20 +14,24 @@ class SmartAnnotation
def my_modules def my_modules
# Search tasks # Search tasks
task_ids = MyModule.search(@current_user, false, @query, 1, @current_team) MyModule.search_by_name(@current_user, @current_team, @query).active
.limit(Constants::ATWHO_SEARCH_LIMIT).pluck(:id) .joins(experiment: :project)
MyModule.where(id: task_ids) .where(projects: { archived: false }, experiments: { archived: false })
.limit(Constants::ATWHO_SEARCH_LIMIT)
end end
def projects def projects
# Search projects # Search projects
Project.search(@current_user, false, @query, 1, @current_team) Project.search_by_name(@current_user, @current_team, @query)
.where(archived: false)
.limit(Constants::ATWHO_SEARCH_LIMIT) .limit(Constants::ATWHO_SEARCH_LIMIT)
end end
def experiments def experiments
# Search experiments # Search experiments
Experiment.search(@current_user, false, @query, 1, @current_team) Experiment.search_by_name(@current_user, @current_team, @query)
.joins(:project)
.where(projects: { archived: false }, experiments: { archived: false })
.limit(Constants::ATWHO_SEARCH_LIMIT) .limit(Constants::ATWHO_SEARCH_LIMIT)
end end

View file

@ -1,7 +1,21 @@
<% experiments.each do |experiment| %> <div class="atwho-scroll-container">
<li data-name="<%= experiment.name %>" data-id="<%= experiment.id.base62_encode %>" data-type="exp"><%= experiment.name %></li> <% grouped_by_prj(experiments).each do |experiment_group| %>
<% end %> <div class="item-group">
<% if experiments.empty? %> <div class="atwho-breadcrumbs">
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %> <span class="atwho-breadcrumb" title="<%= experiment_group[:project_name] %>"><%= experiment_group[:project_name] %></span>
<% end %> </div>
<div class="items">
<% experiment_group[:experiments].each do |experiment| %>
<li class="item" data-name="<%= experiment.name %>" data-id="<%= experiment.id.base62_encode %>" data-type="exp">
<span class='sa-type'>Exp</span>
<span class="item-text"><%= experiment.name %></span>
</li>
<% end %>
</div>
</div>
<% end %>
<% if experiments.empty? %>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %>
<% end %>
</div>
<%= render partial: 'shared/smart_annotation/footer.html.erb' %> <%= render partial: 'shared/smart_annotation/footer.html.erb' %>

View file

@ -1,32 +1,23 @@
<div class="my-modules-list-partial atwho-scroll-container"> <div class="atwho-scroll-container">
<% grouped_by_prj_exp(my_modules).each do |task_group| %> <% grouped_by_prj_exp(my_modules).each do |task_group| %>
<div class="task-group"> <div class="item-group">
<div class="header"> <div class="atwho-breadcrumbs">
<% if task_group[:project_archived]%> <span class="atwho-breadcrumb" title="<%= task_group[:project_name] %>"><%= task_group[:project_name] %></span>
<span class="archived"><%= t('general.archived') %></span>
<% end %>
<span class="project" title="<%= task_group[:project_name] %>"><%= task_group[:project_name] %></span>
<span class="slash">/</span> <span class="slash">/</span>
<% if task_group[:experiment_archived] %> <span class="atwho-breadcrumb" title="<%= task_group[:experiment_name] %>"><%= task_group[:experiment_name] %></span>
<span class="archived"><%= t('general.archived') %></span>
<% end %>
<span class="experiment" title="<%= task_group[:experiment_name] %>"><%= task_group[:experiment_name] %></span>
</div> </div>
<div class="tasks"> <div class="items">
<% task_group[:tasks].each do |task| %> <% task_group[:tasks].each do |task| %>
<div class="task"> <li class="item" data-name="<%= task.name %>" data-id="<%= task.id.base62_encode %>" data-type="tsk">
<%= draw_custom_icon('task-icon') %> <span class='sa-type'>Tsk</span>
<% if task.archived %> <span class="item-text"><%= task.name %></span>
<span class="archived"><%= t('general.archived') %></span> </li>
<% end %>
<li class="task-link" data-name="<%= task.name %>" data-id="<%= task.id.base62_encode %>" data-type="tsk"><%= task.name %></li>
</div>
<% end %> <% end %>
</div> </div>
</div> </div>
<% end %> <% end %>
<% if my_modules.empty? %>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %>
<% end %>
</div> </div>
<% if my_modules.empty? %>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %>
<% end %>
<%= render partial: 'shared/smart_annotation/footer.html.erb' %> <%= render partial: 'shared/smart_annotation/footer.html.erb' %>

View file

@ -1,7 +1,12 @@
<% projects.each do |project| %> <div class="atwho-scroll-container">
<li data-name="<%= project.name %>" data-id="<%= project.id.base62_encode %>" data-type="prj"><%= project.name %></li> <% projects.each do |project| %>
<% end %> <li class="item" data-name="<%= project.name %>" data-id="<%= project.id.base62_encode %>" data-type="prj">
<% if projects.empty? %> <span class='sa-type'>Prj</span>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %> <span class="item-text"><%= project.name %></span>
<% end %> </li>
<% end %>
<% if projects.empty? %>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %>
<% end %>
</div>
<%= render partial: 'shared/smart_annotation/footer.html.erb' %> <%= render partial: 'shared/smart_annotation/footer.html.erb' %>

View file

@ -1,9 +1,12 @@
<% repository_rows.each do |row| %> <div class="atwho-scroll-container">
<li data-name="<%= row[:name] %>" data-id="<%= row[:id] %>" data-type="rep_item"> <% repository_rows.each do |row| %>
[<%= row[:repository_tag] %>] <%= row[:name] %> <li class="item" data-name="<%= row[:name] %>" data-id="<%= row[:id] %>" data-type="rep_item">
</li> <span class='sa-type'><%= row[:repository_tag] %></span>
<% end %> <span class="item-text"><%= row[:name] %></span>
<% if repository_rows.empty? %> </li>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %> <% end %>
<% end %> <% if repository_rows.empty? %>
<%= render partial: 'shared/smart_annotation/no_results.html.erb' %>
<% end %>
</div>
<%= render partial: 'shared/smart_annotation/footer.html.erb' %> <%= render partial: 'shared/smart_annotation/footer.html.erb' %>