mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-02 10:20:51 +08:00
Fix sidebar update for inline editing [SCI-4000]
This commit is contained in:
parent
c79b25d5d2
commit
16b591b110
11 changed files with 44 additions and 23 deletions
app
assets/javascripts
controllers
views
repositories
shared
|
@ -2,6 +2,8 @@
|
||||||
/* global SmartAnnotation */
|
/* global SmartAnnotation */
|
||||||
|
|
||||||
var inlineEditing = (function() {
|
var inlineEditing = (function() {
|
||||||
|
const SIDEBAR_ITEM_TYPES = ['project', 'experiment', 'my_module', 'repository'];
|
||||||
|
|
||||||
var editBlocks = '.inline-init-handler';
|
var editBlocks = '.inline-init-handler';
|
||||||
|
|
||||||
function appendAfterLabel(container) {
|
function appendAfterLabel(container) {
|
||||||
|
@ -29,9 +31,17 @@ var inlineEditing = (function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSideBarNav(itemType, itemId, newData) {
|
||||||
|
let sidebar = $('#slide-panel');
|
||||||
|
let link = sidebar.find(`a[data-type="${itemType}"][data-id="${itemId}"]`);
|
||||||
|
link.prop('title', newData);
|
||||||
|
link.text(newData);
|
||||||
|
}
|
||||||
|
|
||||||
function updateField(container) {
|
function updateField(container) {
|
||||||
var params;
|
var params;
|
||||||
var paramsGroup = container.data('params-group');
|
var paramsGroup = container.data('params-group');
|
||||||
|
var itemId = container.data('item-id');
|
||||||
var fieldToUpdate = container.data('field-to-update');
|
var fieldToUpdate = container.data('field-to-update');
|
||||||
|
|
||||||
if (inputField(container).val() === container.attr('data-original-name')) {
|
if (inputField(container).val() === container.attr('data-original-name')) {
|
||||||
|
@ -83,6 +93,10 @@ var inlineEditing = (function() {
|
||||||
.addClass('hidden')
|
.addClass('hidden')
|
||||||
.attr('value', inputField(container).val());
|
.attr('value', inputField(container).val());
|
||||||
appendAfterLabel(container);
|
appendAfterLabel(container);
|
||||||
|
|
||||||
|
if (SIDEBAR_ITEM_TYPES.includes(paramsGroup)) {
|
||||||
|
updateSideBarNav(paramsGroup, itemId, viewData);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(response) {
|
error: function(response) {
|
||||||
var error = response.responseJSON[fieldToUpdate];
|
var error = response.responseJSON[fieldToUpdate];
|
||||||
|
|
|
@ -121,22 +121,22 @@
|
||||||
var experimentId = sidebar.data('current-experiment');
|
var experimentId = sidebar.data('current-experiment');
|
||||||
var taskId = sidebar.data('current-task');
|
var taskId = sidebar.data('current-task');
|
||||||
var currentPage = sidebar.data('page');
|
var currentPage = sidebar.data('page');
|
||||||
var li;
|
var link;
|
||||||
|
|
||||||
if (currentPage === 'project') {
|
if (currentPage === 'project') {
|
||||||
li = sidebar.find('li[data-project-id="' + projectId + '"]');
|
link = sidebar.find(`a[data-type="project"][data-id="${projectId}"]`);
|
||||||
} else if (currentPage === 'experiment') {
|
} else if (currentPage === 'experiment') {
|
||||||
li = sidebar.find('[data-experiment-id="' + experimentId + '"]');
|
link = sidebar.find(`a[data-type="experiment"][data-id="${experimentId}"]`);
|
||||||
} else if (currentPage === 'canvas') {
|
} else if (currentPage === 'canvas') {
|
||||||
li = sidebar.find('[data-experiment-id="' + experimentId + '"]');
|
link = sidebar.find(`a[data-type="experiment"][data-id="${experimentId}"]`);
|
||||||
li.find('.task-tree-link')
|
let treeLink = link.closest('li').find('.task-tree-link');
|
||||||
.append('<a href="" class="canvas-center-on">'
|
treeLink.find('.canvas-center-on').remove();
|
||||||
+ '<span class="fas fa-map-marker-alt"></span></a>');
|
treeLink.append('<a href="" class="canvas-center-on"><span class="fas fa-map-marker-alt"></span></a>');
|
||||||
} else if (currentPage === 'task') {
|
} else if (currentPage === 'task') {
|
||||||
li = sidebar.find('[data-module-id="' + taskId + '"]');
|
link = sidebar.find(`a[data-type="my_module"][data-id="${taskId}"]`);
|
||||||
}
|
}
|
||||||
li.find('a:first').addClass('disabled');
|
link.addClass('disabled');
|
||||||
li.addClass('active');
|
link.closest('li').addClass('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
activateCurrent();
|
activateCurrent();
|
||||||
|
|
|
@ -314,6 +314,7 @@ class ExperimentsController < ApplicationController
|
||||||
@inline_editable_title_config = {
|
@inline_editable_title_config = {
|
||||||
name: 'title',
|
name: 'title',
|
||||||
params_group: 'experiment',
|
params_group: 'experiment',
|
||||||
|
item_id: @experiment.id,
|
||||||
field_to_udpate: 'name',
|
field_to_udpate: 'name',
|
||||||
path_to_update: experiment_path(@experiment)
|
path_to_update: experiment_path(@experiment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -720,6 +720,7 @@ class MyModulesController < ApplicationController
|
||||||
@inline_editable_title_config = {
|
@inline_editable_title_config = {
|
||||||
name: 'title',
|
name: 'title',
|
||||||
params_group: 'my_module',
|
params_group: 'my_module',
|
||||||
|
item_id: @my_module.id,
|
||||||
field_to_udpate: 'name',
|
field_to_udpate: 'name',
|
||||||
path_to_update: my_module_path(@my_module)
|
path_to_update: my_module_path(@my_module)
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,6 +331,7 @@ class ProjectsController < ApplicationController
|
||||||
@inline_editable_title_config = {
|
@inline_editable_title_config = {
|
||||||
name: 'title',
|
name: 'title',
|
||||||
params_group: 'project',
|
params_group: 'project',
|
||||||
|
item_id: @project.id,
|
||||||
field_to_udpate: 'name',
|
field_to_udpate: 'name',
|
||||||
path_to_update: project_path(@project)
|
path_to_update: project_path(@project)
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,6 +336,7 @@ class RepositoriesController < ApplicationController
|
||||||
@inline_editable_title_config = {
|
@inline_editable_title_config = {
|
||||||
name: 'title',
|
name: 'title',
|
||||||
params_group: 'repository',
|
params_group: 'repository',
|
||||||
|
item_id: @repository.id,
|
||||||
field_to_udpate: 'name',
|
field_to_udpate: 'name',
|
||||||
path_to_update: team_repository_path(@repository),
|
path_to_update: team_repository_path(@repository),
|
||||||
label_after: "<span class=\"repository-share-icon\">#{inventory_shared_status_icon(@repository, current_team)}</span>"
|
label_after: "<span class=\"repository-share-icon\">#{inventory_shared_status_icon(@repository, current_team)}</span>"
|
||||||
|
|
|
@ -16,13 +16,11 @@
|
||||||
<% repositories.each do |repository| %>
|
<% repositories.each do |repository| %>
|
||||||
<li class="<%= 'active parent_li' if current_page?(repository_path(repository)) %>" >
|
<li class="<%= 'active parent_li' if current_page?(repository_path(repository)) %>" >
|
||||||
<span class="tree-link line-wrap no-indent">
|
<span class="tree-link line-wrap no-indent">
|
||||||
<% if current_page?(repository_path(repository)) %>
|
<%= link_to repository.name,
|
||||||
<span title="<%= repository.name %>"><%= repository.name %></span>
|
repository_path(repository),
|
||||||
<% else %>
|
class: current_page?(repository_path(repository)) ? 'disabled' : '',
|
||||||
<%= link_to repository.name,
|
title: repository.name,
|
||||||
repository_path(repository),
|
data: { 'no-turbolink' => 'true', type: 'repository', id: repository.id } %>
|
||||||
data: { 'no-turbolink' => 'true' } %>
|
|
||||||
<% end %>
|
|
||||||
<%= inventory_shared_status_icon(repository, current_team) %>
|
<%= inventory_shared_status_icon(repository, current_team) %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
class="inline-editing-container inline-init-handler"
|
class="inline-editing-container inline-init-handler"
|
||||||
data-field-to-update="<%= config[:field_to_udpate] %>"
|
data-field-to-update="<%= config[:field_to_udpate] %>"
|
||||||
data-params-group="<%= config[:params_group] %>"
|
data-params-group="<%= config[:params_group] %>"
|
||||||
|
data-item-id="<%= config[:item_id] %>"
|
||||||
data-path-to-update="<%= config[:path_to_update] %>"
|
data-path-to-update="<%= config[:path_to_update] %>"
|
||||||
data-original-name="<%= initial_value %>"
|
data-original-name="<%= initial_value %>"
|
||||||
data-label-after='<%= config[:label_after]&.html_safe %>'
|
data-label-after='<%= config[:label_after]&.html_safe %>'
|
||||||
|
@ -14,4 +15,4 @@
|
||||||
<span class="cancel-button"><i class="fas fa-times"></i></span>
|
<span class="cancel-button"><i class="fas fa-times"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<span class="error-block"></span>
|
<span class="error-block"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
<ul>
|
<ul>
|
||||||
<% project.active_experiments.each do |experiment| %>
|
<% project.active_experiments.each do |experiment| %>
|
||||||
<% cache [action_name, current_user, experiment] do %>
|
<% cache [action_name, current_user, experiment] do %>
|
||||||
<li data-parent="candidate" data-experiment-id="<%= experiment.id %>">
|
<li data-parent="candidate">
|
||||||
<span class="tree-link line-wrap first-indent">
|
<span class="tree-link line-wrap first-indent">
|
||||||
<i class="no-arrow"></i>
|
<i class="no-arrow"></i>
|
||||||
<%= link_to experiment.name,
|
<%= link_to experiment.name,
|
||||||
experiment_action_to_link_to(experiment),
|
experiment_action_to_link_to(experiment),
|
||||||
title: experiment.name,
|
title: experiment.name,
|
||||||
class: 'overview_exp_label'
|
class: 'overview_exp_label',
|
||||||
|
data: { type: 'experiment', id: experiment.id }
|
||||||
%>
|
%>
|
||||||
</span>
|
</span>
|
||||||
<%= render partial: 'shared/sidebar/my_modules', locals: { experiment: experiment } %>
|
<%= render partial: 'shared/sidebar/my_modules', locals: { experiment: experiment } %>
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
<% experiment.active_my_modules.each do |my_module| %>
|
<% experiment.active_my_modules.each do |my_module| %>
|
||||||
<li class="leaf" data-module-id="<%= my_module.id %>">
|
<li class="leaf" data-module-id="<%= my_module.id %>">
|
||||||
<span class="tree-link task-tree-link second-indent">
|
<span class="tree-link task-tree-link second-indent">
|
||||||
<%= link_to my_module.name, module_action_to_link_to(my_module) %>
|
<%= link_to my_module.name,
|
||||||
|
module_action_to_link_to(my_module),
|
||||||
|
title: my_module.name,
|
||||||
|
data: { type: 'my_module', id: my_module.id } %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<ul>
|
<ul>
|
||||||
<% @projects_tree.each do |project| %>
|
<% @projects_tree.each do |project| %>
|
||||||
<% cache [action_name, current_user, project] do %>
|
<% cache [action_name, current_user, project] do %>
|
||||||
<li data-parent="candidate" data-project-id="<%= project.id %>">
|
<li data-parent="candidate">
|
||||||
<span class="tree-link line-wrap no-indent">
|
<span class="tree-link line-wrap no-indent">
|
||||||
<i class="no-arrow"></i>
|
<i class="no-arrow"></i>
|
||||||
<%= link_to project.name,
|
<%= link_to project.name,
|
||||||
project_action_to_link_to(project),
|
project_action_to_link_to(project),
|
||||||
title: project.name,
|
title: project.name,
|
||||||
data: { project_id: project.id } %>
|
data: { type: 'project', id: project.id } %>
|
||||||
</span>
|
</span>
|
||||||
<%= render partial: 'shared/sidebar/experiments', locals: { project: project } %>
|
<%= render partial: 'shared/sidebar/experiments', locals: { project: project } %>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Add table
Reference in a new issue