From 7a86bb47c54040b4a3b369c03c0963fb953cf5f1 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Wed, 9 Sep 2020 14:17:19 +0200 Subject: [PATCH] Add styling and highligh --- .../javascripts/sitewide/atwho_res.js.erb | 80 ++++--------------- .../stylesheets/shared/smart_annotation.scss | 50 +++++++++++- app/helpers/experiments_helper.rb | 17 ++++ app/utilities/smart_annotation.rb | 16 ++-- .../_experiment_items.html.erb | 26 ++++-- .../_my_module_items.html.erb | 35 +++----- .../smart_annotation/_project_items.html.erb | 17 ++-- .../_repository_items.html.erb | 19 +++-- 8 files changed, 144 insertions(+), 116 deletions(-) create mode 100644 app/helpers/experiments_helper.rb diff --git a/app/assets/javascripts/sitewide/atwho_res.js.erb b/app/assets/javascripts/sitewide/atwho_res.js.erb index b6a5f447d..82c571af9 100644 --- a/app/assets/javascripts/sitewide/atwho_res.js.erb +++ b/app/assets/javascripts/sitewide/atwho_res.js.erb @@ -49,63 +49,26 @@ var SmartAnnotation = (function() { DEFAULT_SEARCH_FILTER = FilterTypeEnum.REPOSITORY, atWhoUpdating = false; - var defaultRepId; + function _matchHighlighter(html, query, filterType) { + var $html = $(html); + var $li_text = $html.find('.item-text'); - // helper methods for AtWho callback - function _templateEval(_tpl, map) { - var res; - try { - res = generateTemplate(map); - } catch (_error) { - res = ''; - } - return res; - } + if ($li_text.length === 0 || !query) return html; - function _matchHighlighter(li, query, filterType) { - var $li, re; + $.each($li_text, function(i, item) { + $(item).html($(item).text().replace(new RegExp(query, 'gi'), '$&')); + }) - function highlight(el, sel, re) { - var prevVal, newVal; - prevVal = el.find(sel).html(); - newVal = prevVal.replace(re, '$&'); - 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 + return $html; } function _generateInputTag(value, li) { 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 function generateFilterMenu(active, res_data) { var menu = ''; - var rep_buttons = ''; $.ajax({ async: false, dataType: 'json', @@ -117,17 +80,6 @@ var SmartAnnotation = (function() { return menu; } - function noResultsTemplate() { - return `
- <%= I18n.t("atwho.no_results") %> -
`; - } - - // Generates resources list items - function generateTemplate(map) { - return map.name; - } - function atWhoSettings(at, defaultFilterType) { return { at: at, @@ -138,7 +90,7 @@ var SmartAnnotation = (function() { var params = { query: query }; filterType = FilterTypeEnum[$currentAtWho.find('.tab-pane.active').data('object-type')] if (!filterType) { - callback([{name: noResultsTemplate()}]); + callback([{name: ''}]); return false } @@ -159,15 +111,11 @@ var SmartAnnotation = (function() { } }); }, - sorter: function(query, items, _searchKey) { - // Sorting is already done on server-side - return items; - }, - tplEval: function(_tpl, map) { - return _templateEval(_tpl, map); + tplEval: function(_tpl, items) { + return items.name; }, highlighter: function(li, query) { - //return _matchHighlighter(li, query, true); + return _matchHighlighter(li, query, true); return li; }, beforeInsert: function(value, li) { @@ -258,7 +206,7 @@ var SmartAnnotation = (function() { var res; try { if (map.no_results) { - res = noResultsTemplate(); + res = ''; } else { res = ''; res += '
  • -
  • <%= experiment.name %>
  • -<% end %> -<% if experiments.empty? %> - <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> -<% end %> +
    + <% grouped_by_prj(experiments).each do |experiment_group| %> +
    +
    + <%= experiment_group[:project_name] %> +
    +
    + <% experiment_group[:experiments].each do |experiment| %> +
  • + Exp + <%= experiment.name %> +
  • + <% end %> +
    +
    + <% end %> + <% if experiments.empty? %> + <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> + <% end %> +
    <%= render partial: 'shared/smart_annotation/footer.html.erb' %> diff --git a/app/views/shared/smart_annotation/_my_module_items.html.erb b/app/views/shared/smart_annotation/_my_module_items.html.erb index 107b917f6..816b2321a 100644 --- a/app/views/shared/smart_annotation/_my_module_items.html.erb +++ b/app/views/shared/smart_annotation/_my_module_items.html.erb @@ -1,32 +1,23 @@ -
    +
    <% grouped_by_prj_exp(my_modules).each do |task_group| %> -
    -
    - <% if task_group[:project_archived]%> - <%= t('general.archived') %> - <% end %> - <%= task_group[:project_name] %> +
    +
    + <%= task_group[:project_name] %> / - <% if task_group[:experiment_archived] %> - <%= t('general.archived') %> - <% end %> - <%= task_group[:experiment_name] %> + <%= task_group[:experiment_name] %>
    -
    +
    <% task_group[:tasks].each do |task| %> -
    - <%= draw_custom_icon('task-icon') %> - <% if task.archived %> - <%= t('general.archived') %> - <% end %> - -
    +
  • + Tsk + <%= task.name %> +
  • <% end %>
    <% end %> + <% if my_modules.empty? %> + <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> + <% end %>
    -<% if my_modules.empty? %> - <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> -<% end %> <%= render partial: 'shared/smart_annotation/footer.html.erb' %> diff --git a/app/views/shared/smart_annotation/_project_items.html.erb b/app/views/shared/smart_annotation/_project_items.html.erb index c953211c8..19b83369f 100644 --- a/app/views/shared/smart_annotation/_project_items.html.erb +++ b/app/views/shared/smart_annotation/_project_items.html.erb @@ -1,7 +1,12 @@ -<% projects.each do |project| %> -
  • <%= project.name %>
  • -<% end %> -<% if projects.empty? %> - <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> -<% end %> +
    + <% projects.each do |project| %> +
  • + Prj + <%= project.name %> +
  • + <% end %> + <% if projects.empty? %> + <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> + <% end %> +
    <%= render partial: 'shared/smart_annotation/footer.html.erb' %> diff --git a/app/views/shared/smart_annotation/_repository_items.html.erb b/app/views/shared/smart_annotation/_repository_items.html.erb index 719feafb0..390f3ae68 100644 --- a/app/views/shared/smart_annotation/_repository_items.html.erb +++ b/app/views/shared/smart_annotation/_repository_items.html.erb @@ -1,9 +1,12 @@ -<% repository_rows.each do |row| %> -
  • - [<%= row[:repository_tag] %>] <%= row[:name] %> -
  • -<% end %> -<% if repository_rows.empty? %> - <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> -<% end %> +
    + <% repository_rows.each do |row| %> +
  • + <%= row[:repository_tag] %> + <%= row[:name] %> +
  • + <% end %> + <% if repository_rows.empty? %> + <%= render partial: 'shared/smart_annotation/no_results.html.erb' %> + <% end %> +
    <%= render partial: 'shared/smart_annotation/footer.html.erb' %>