mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 08:34:49 +08:00
Merge pull request #148 from ZmagoD/zd_SCI_342
fixes sidebar expanded elements when adding new experiments
This commit is contained in:
commit
d0a180a1e8
2 changed files with 43 additions and 7 deletions
|
@ -45,12 +45,14 @@ function sessionCollapseSidebarElement(project, id) {
|
||||||
* Expand a specified element in the sidebar.
|
* Expand a specified element in the sidebar.
|
||||||
* @param id - The expanded element's ID.
|
* @param id - The expanded element's ID.
|
||||||
*/
|
*/
|
||||||
function sessionExpandSidebarElement(project, id) {
|
function sessionExpandSidebarElement(project, id, elements) {
|
||||||
var ids = sessionGetCollapsedSidebarElements();
|
var ids = sessionGetCollapsedSidebarElements();
|
||||||
var item = _.findWhere(ids, { prid: project});
|
var item = _.findWhere(ids, { prid: project});
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
|
||||||
if ( item ) {
|
if ( item ) {
|
||||||
index = _.indexOf(item.ids, id);
|
index = _.indexOf(item.ids, id);
|
||||||
|
recalculateElementsPositions(ids, item, elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( index !== -1 ) {
|
if ( index !== -1 ) {
|
||||||
|
@ -59,6 +61,30 @@ function sessionExpandSidebarElement(project, id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculate the position of the elements after an experiment
|
||||||
|
* is added or archived.
|
||||||
|
*/
|
||||||
|
function recalculateElementsPositions(ids, item, elements) {
|
||||||
|
var diff;
|
||||||
|
|
||||||
|
if ( item.eleNum > elements ){
|
||||||
|
diff = item.eleNum - elements;
|
||||||
|
_.map(item.ids, function(element, index){
|
||||||
|
item.ids[index] = element - diff;
|
||||||
|
});
|
||||||
|
} else if ( item.eleNum < elements ) {
|
||||||
|
diff = elements - item.eleNum ;
|
||||||
|
_.map(item.ids, function(element, index){
|
||||||
|
item.ids[index] = element + diff;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( item.eleNum !== elements) {
|
||||||
|
item.eleNum = elements;
|
||||||
|
sessionStorage.setItem(STORAGE_TREE_KEY, JSON.stringify(ids));
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get the session stored toggled boolean or null value if
|
* Get the session stored toggled boolean or null value if
|
||||||
* sidebar toggle state was not changed by user. It allow for
|
* sidebar toggle state was not changed by user. It allow for
|
||||||
|
@ -133,8 +159,15 @@ function setupSidebarTree() {
|
||||||
$(el).attr("data-toggle-id", i++);
|
$(el).attr("data-toggle-id", i++);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gets the current project and the session-stored elements
|
// Get the current project
|
||||||
var project = $('[data-project-id]').data('projectId');
|
var project = $('[data-project-id]').data('projectId');
|
||||||
|
|
||||||
|
// Set number of elements
|
||||||
|
sessionExpandSidebarElement(project,
|
||||||
|
null,
|
||||||
|
$('[data-parent="candidate"]').length );
|
||||||
|
|
||||||
|
// Get the session-stored elements
|
||||||
var collapsedIds = sessionGetCollapsedSidebarElements();
|
var collapsedIds = sessionGetCollapsedSidebarElements();
|
||||||
|
|
||||||
// Get the current project stered elements
|
// Get the current project stered elements
|
||||||
|
@ -149,13 +182,14 @@ function setupSidebarTree() {
|
||||||
_.each($('li.parent_li[data-parent="candidate"]'), function(el) {
|
_.each($('li.parent_li[data-parent="candidate"]'), function(el) {
|
||||||
var id = $(el).data("toggle-id");
|
var id = $(el).data("toggle-id");
|
||||||
var li = $(".tree li.parent_li[data-toggle-id='" + id + "']");
|
var li = $(".tree li.parent_li[data-toggle-id='" + id + "']");
|
||||||
|
|
||||||
if( li.hasClass("active") || li.find(".active").length > 0){
|
if( li.hasClass("active") || li.find(".active").length > 0){
|
||||||
// Always expand the active element
|
// Always expand the active element
|
||||||
toggleLi(li,
|
toggleLi(li,
|
||||||
false,
|
false,
|
||||||
false);
|
false);
|
||||||
} else if ( $.inArray( id.toString(), currentProjectIds.ids.split(", ")) !== -1 ) {
|
} else if ( $.inArray( id.toString(),
|
||||||
|
currentProjectIds.ids.split(", ")) !== -1 ) {
|
||||||
// Expande element
|
// Expande element
|
||||||
toggleLi(li,
|
toggleLi(li,
|
||||||
false,
|
false,
|
||||||
|
@ -198,7 +232,9 @@ function setupSidebarTree() {
|
||||||
|
|
||||||
if (el.find(" > ul > li").is(":visible")) {
|
if (el.find(" > ul > li").is(":visible")) {
|
||||||
toggleLi(el, true, true);
|
toggleLi(el, true, true);
|
||||||
sessionExpandSidebarElement(project, el.data("toggle-id"));
|
sessionExpandSidebarElement(project,
|
||||||
|
el.data("toggle-id"),
|
||||||
|
$('[data-parent="candidate"]').length );
|
||||||
} else {
|
} else {
|
||||||
toggleLi(el, false, true);
|
toggleLi(el, false, true);
|
||||||
sessionCollapseSidebarElement(project, el.data("toggle-id"));
|
sessionCollapseSidebarElement(project, el.data("toggle-id"));
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<% if project.active_experiments.present? then %>
|
<% if project.active_experiments.present? then %>
|
||||||
<% project.active_experiments.each do |experiment| %>
|
<% project.active_experiments.each do |experiment| %>
|
||||||
<% if experiment_page? && experiment == @experiment %>
|
<% if experiment_page? && experiment == @experiment %>
|
||||||
<li class="active">
|
<li class="active" data-parent="candidate">
|
||||||
<span class="tree-link line-wrap">
|
<span class="tree-link line-wrap">
|
||||||
<i></i>
|
<i></i>
|
||||||
<span title="<%= @experiment.name %>"><%= @experiment.name %></span>
|
<span title="<%= @experiment.name %>"><%= @experiment.name %></span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue