Merge pull request #1783 from okriuchykhin/ok_SCI_3471

Refactor title inline editing permission checking [SCI-3471]
This commit is contained in:
Alex Kriuchykhin 2019-05-20 13:34:23 +02:00 committed by GitHub
commit 36243ff04c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 48 deletions

View file

@ -20,6 +20,7 @@ class ExperimentsController < ApplicationController
before_action :check_archive_permissions, only: :archive
before_action :check_clone_permissions, only: %i(clone_modal clone)
before_action :check_move_permissions, only: %i(move_modal move)
before_action :set_inline_name_editing, only: %i(canvas module_archive)
layout 'fluid'.freeze
@ -311,6 +312,16 @@ class ExperimentsController < ApplicationController
render_403 unless can_move_experiment?(@experiment)
end
def set_inline_name_editing
return unless can_manage_experiment?(@experiment)
@inline_editable_title_config = {
name: 'title',
params_group: 'experiment',
field_to_udpate: 'name',
path_to_update: experiment_path(@experiment)
}
end
def experiment_annotation_notification(old_text = nil)
smart_annotation_notification(
old_text: old_text,

View file

@ -39,6 +39,7 @@ class MyModulesController < ApplicationController
unassign_repository_records
assign_samples
unassign_samples)
before_action :set_inline_name_editing, only: %i(protocols results activities repository archive)
layout 'fluid'.freeze
@ -703,6 +704,16 @@ class MyModulesController < ApplicationController
render_403 unless can_complete_module?(@my_module)
end
def set_inline_name_editing
return unless can_manage_module?(@my_module)
@inline_editable_title_config = {
name: 'title',
params_group: 'my_module',
field_to_udpate: 'name',
path_to_update: my_module_path(@my_module)
}
end
def my_module_params
params.require(:my_module).permit(:name, :description, :due_date,
:archived)

View file

@ -16,6 +16,7 @@ class ProjectsController < ApplicationController
samples_index)
before_action :check_create_permissions, only: %i(new create)
before_action :check_manage_permissions, only: :edit
before_action :set_inline_name_editing, only: %i(show experiment_archive)
# except parameter could be used but it is not working.
layout 'fluid'
@ -339,6 +340,16 @@ class ProjectsController < ApplicationController
render_403 unless can_manage_project?(@project)
end
def set_inline_name_editing
return unless can_manage_project?(@project)
@inline_editable_title_config = {
name: 'title',
params_group: 'project',
field_to_udpate: 'name',
path_to_update: project_path(@project)
}
end
def log_activity(type_of, message_items = {})
message_items = { project: @project.id }.merge(message_items)

View file

@ -1,15 +1,6 @@
<% provide(:head_title, t("experiments.canvas.head_title", project: h(@project.name)).html_safe) %>
<%= render partial: "shared/sidebar", locals: { current_experiment: @experiment, page: 'canvas' } %>
<%= render partial: "shared/secondary_navigation" , locals: {
editable: {
name: 'title',
active: can_manage_experiment?(@experiment),
width: 'calc(100% - 500px)',
params_group: 'experiment',
field_to_udpate: 'name',
path_to_update: experiment_path(@experiment)
}
}%>
<%= render partial: "shared/secondary_navigation" %>
<div class="content-pane" id="experiment-canvas">
<div class="row">

View file

@ -2,16 +2,7 @@
<%= render partial: 'shared/drag_n_drop_overlay' %>
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
<%= render partial: "shared/secondary_navigation", locals: {
editable: {
name: 'title',
active: can_manage_module?(@my_module),
width: 'calc(100% - 580px)',
params_group: 'my_module',
field_to_udpate: 'name',
path_to_update: my_module_path(@my_module)
}
} %>
<%= render partial: "shared/secondary_navigation" %>
<div class="content-pane my-modules-protocols-index">
<span class="module-header">

View file

@ -1,15 +1,6 @@
<% provide(:head_title, t("projects.show.head_title", project: h(@project.name)).html_safe) %>
<%= render partial: "shared/sidebar", locals: { current_project: @project, page: 'project' } %>
<%= render partial: "shared/secondary_navigation", locals: {
editable: {
name: 'title',
active: can_manage_project?(@project),
width: 'calc(100% - 500px)',
params_group: 'project',
field_to_udpate: 'name',
path_to_update: project_path(@project)
}
}%>
<%= render partial: "shared/secondary_navigation" %>
<div class="content-pane" id="project-show">
<div class="row">

View file

@ -1,8 +1,8 @@
<div
class="inline-editing-container <%= name %>-editable-field"
data-field-to-update="<%= field_to_udpate %>"
data-params-group="<%= params_group %>"
data-path-to-update="<%= path_to_update %>"
<div
class="inline-editing-container <%= @inline_editable_title_config[:name] %>-editable-field"
data-field-to-update="<%= @inline_editable_title_config[:field_to_udpate] %>"
data-params-group="<%= @inline_editable_title_config[:params_group] %>"
data-path-to-update="<%= @inline_editable_title_config[:path_to_update] %>"
data-original-name="<%= initial_value %>"
error="false"
>
@ -15,5 +15,5 @@
<span class="error-block"></span>
</div>
<script>
initInlineEditing('<%= name %>')
</script>
initInlineEditing('<%= @inline_editable_title_config[:name] %>')
</script>

View file

@ -149,17 +149,10 @@
</ul>
<!-- Secondary navigation title -->
<% editable = false if local_assigns[:editable].nil? %>
<h4 class="nav-name <%= (editable && editable[:active]) ? 'editable' : '' %>">
<% if editable && editable[:active] %>
<%= render partial: "shared/inline_editing", locals: {
initial_value: truncate(title_element.name, length: Constants::MAX_EDGE_LENGTH),
width: editable[:width] || '100%',
name: editable[:name],
field_to_udpate: editable[:field_to_udpate],
path_to_update: editable[:path_to_update],
params_group: editable[:params_group]
} %>
<h4 class="nav-name <%= @inline_editable_title_config.present? ? 'editable' : '' %>">
<% if @inline_editable_title_config.present? %>
<%= render partial: "shared/inline_editing",
locals: { initial_value: truncate(title_element.name, length: Constants::MAX_EDGE_LENGTH) } %>
<% else %>
<%= truncate(title_element.name,
length: Constants::MAX_EDGE_LENGTH) %>