Merge pull request #2844 from aignatov-bio/ai-sci-4950-implement-remember-selection-of-smart-annotation

Add remembered state for smart annotation [SCI-4950]
This commit is contained in:
aignatov-bio 2020-09-17 14:49:35 +02:00 committed by GitHub
commit d560470df2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 11 deletions

View file

@ -54,7 +54,7 @@ var SmartAnnotation = (function() {
at: at,
callbacks: {
remoteFilter: function(query, callback) {
var $currentAtWho = $('.atwho-view[style]');
var $currentAtWho = $(`.atwho-view[data-at-who-id=${$(field).attr('data-smart-annotation')}]`);
var filterType;
var params = { query: query };
filterType = FilterTypeEnum[$currentAtWho.find('.tab-pane.active').data('object-type')];
@ -62,7 +62,6 @@ var SmartAnnotation = (function() {
callback([{ name: '' }]);
return false;
}
if (filterType.tag === 'sa-repositories') {
let repositoryTab = $currentAtWho.find('[data-object-type="REPOSITORY"]');
let activeRepository = repositoryTab.find('.btn-primary');
@ -71,6 +70,11 @@ var SmartAnnotation = (function() {
}
}
$.getJSON(filterType.dataUrl, params, function(data) {
localStorage.setItem('smart_annotation_states/teams/' + data.team, JSON.stringify({
tag: filterType.tag,
repository: data.repository
}));
callback(data.res);
if (data.repository) {
@ -118,7 +122,11 @@ var SmartAnnotation = (function() {
function init() {
$(field)
.on('shown.atwho', function() {
var $currentAtWho = $('.atwho-view[style]');
var $currentAtWho = $('.atwho-view[style]:not(.old)');
var atWhoId = $currentAtWho.find('.atwho-header-res').data('at-who-key')
$currentAtWho.addClass('old').attr('data-at-who-id', atWhoId);
$(field).attr('data-smart-annotation', atWhoId);
$currentAtWho.find('.tab-button').off().on('shown.bs.tab', function() {
$(field).click().focus();
$(this).closest('.nav-tabs').find('.tab-button').removeClass('active');
@ -132,8 +140,18 @@ var SmartAnnotation = (function() {
});
if ($currentAtWho.find('.tab-pane.active').length === 0) {
let filterType = DEFAULT_SEARCH_FILTER;
$currentAtWho.find(`.${filterType.tag}`).click();
let filterType = DEFAULT_SEARCH_FILTER.tag;
let teamId = $currentAtWho.find('.atwho-header-res').data('team-id');
let remeberedState = localStorage.getItem('smart_annotation_states/teams/' + teamId);
if (remeberedState) {
try {
remeberedState = JSON.parse(remeberedState);
filterType = remeberedState.tag;
$currentAtWho.find(`.repository-object[data-object-id=${remeberedState.repository}]`)
.addClass('btn-primary');
} catch {};
}
$currentAtWho.find(`.${filterType}`).click();
}
})
.on('reposition.atwho', function(event, flag, query) {

View file

@ -17,7 +17,7 @@
margin-bottom: 0;
}
.rep-tab.active {
.rep-tab.active:not(:empty) {
border-bottom: $border-default;
display: flex;
padding: .25em;

View file

@ -48,6 +48,7 @@ class AtWhoController < ApplicationController
repository_rows: items
})],
repository: repository.id,
team: current_team.id,
status: :ok
}
end
@ -68,6 +69,7 @@ class AtWhoController < ApplicationController
res: [render_to_string(partial: 'shared/smart_annotation/project_items.html.erb', locals: {
projects: res.projects
})],
team: current_team.id,
status: :ok
}
end
@ -82,6 +84,7 @@ class AtWhoController < ApplicationController
res: [render_to_string(partial: 'shared/smart_annotation/experiment_items.html.erb', locals: {
experiments: res.experiments
})],
team: current_team.id,
status: :ok
}
end
@ -96,6 +99,7 @@ class AtWhoController < ApplicationController
res: [render_to_string(partial: 'shared/smart_annotation/my_module_items.html.erb', locals: {
my_modules: res.my_modules
})],
team: current_team.id,
status: :ok
}
end

View file

@ -1 +1,2 @@
<div class="atwho-footer"><%= I18n.t("atwho.users.help") %></div>
<span style="display: none"><%= @query %></span>

View file

@ -1,5 +1,5 @@
<% at_who_key = SecureRandom.hex %>
<div class="atwho-header-res">
<div class="atwho-header-res" data-team-id="<%= current_team.id %>" data-at-who-key="<%= SecureRandom.hex %>">
<div class="nav nav-tabs sci-nav-tabs">
<a class="tab-button sa-projects" href="#prj-tab-<%= at_who_key %>" role="tab" data-toggle="tab"><%= t('atwho.projects') %></a>
<a class="tab-button sa-experiments" href="#exp-tab-<%= at_who_key %>" data-toggle="tab"><%= t('atwho.experiments') %></a>
@ -10,8 +10,7 @@
<div class="tab-pane" role="tabpanel" id="prj-tab-<%= at_who_key %>" data-object-type="PROJECT"></div>
<div class="tab-pane" role="tabpanel" id="exp-tab-<%= at_who_key %>" data-object-type="EXPERIMENT"></div>
<div class="tab-pane" role="tabpanel" id="tsk-tab-<%= at_who_key %>" data-object-type="TASK"></div>
<div class="tab-pane rep-tab" role="tabpanel" id="rep-tab-<%= at_who_key %>" data-object-type="REPOSITORY">
<% if repositories.length > 1 %>
<div class="tab-pane rep-tab" role="tabpanel" id="rep-tab-<%= at_who_key %>" data-object-type="REPOSITORY"><% if repositories.length > 1 %>
<div class=sci-btn-group>
<% repositories.each do |repository| %>
<button class="btn btn-light repository-object" data-object-id="<%= repository.id %>">
@ -19,7 +18,6 @@
</button>
<% end %>
</div>
<% end %>
</div>
<% end %></div>
</div>
</div>