2016-02-12 23:52:43 +08:00
|
|
|
class MyModulesController < ApplicationController
|
2017-01-25 00:06:51 +08:00
|
|
|
include TeamsHelper
|
2019-03-20 18:41:36 +08:00
|
|
|
include ActionView::Helpers::TextHelper
|
2017-01-04 22:04:12 +08:00
|
|
|
include InputSanitizeHelper
|
2018-01-23 22:53:33 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
include ActionView::Helpers::UrlHelper
|
2018-02-19 21:47:36 +08:00
|
|
|
include ApplicationHelper
|
2022-12-02 18:01:40 +08:00
|
|
|
include MyModulesHelper
|
2023-04-19 16:53:39 +08:00
|
|
|
include Breadcrumbs
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2023-06-06 19:53:12 +08:00
|
|
|
before_action :load_vars, except: %i(restore_group create new save_table_state
|
|
|
|
inventory_assigning_my_module_filter actions_toolbar)
|
2022-12-05 19:55:57 +08:00
|
|
|
before_action :load_experiment, only: %i(create new)
|
2022-09-29 05:18:36 +08:00
|
|
|
before_action :check_create_permissions, only: %i(new create)
|
2021-01-04 22:11:24 +08:00
|
|
|
before_action :check_archive_permissions, only: %i(update)
|
2022-04-26 20:13:17 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(
|
2022-12-05 19:55:57 +08:00
|
|
|
description due_date update_description update_protocol_description update_protocol
|
2022-12-06 23:58:59 +08:00
|
|
|
)
|
2023-06-06 19:53:12 +08:00
|
|
|
before_action :check_read_permissions, except: %i(create new update update_description
|
|
|
|
inventory_assigning_my_module_filter
|
2023-05-04 17:29:19 +08:00
|
|
|
update_protocol_description restore_group
|
|
|
|
save_table_state actions_toolbar)
|
2020-07-15 00:48:18 +08:00
|
|
|
before_action :check_update_state_permissions, only: :update_state
|
2020-06-04 04:54:45 +08:00
|
|
|
before_action :set_inline_name_editing, only: %i(protocols results activities archive)
|
2021-06-18 22:52:19 +08:00
|
|
|
before_action :load_experiment_my_modules, only: %i(protocols results activities archive)
|
2023-05-25 22:49:33 +08:00
|
|
|
before_action :set_breadcrumbs_items, only: %i(results protocols activities archive)
|
2023-04-19 20:16:22 +08:00
|
|
|
before_action :set_navigator, only: %i(protocols results activities archive)
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2017-01-12 21:08:29 +08:00
|
|
|
layout 'fluid'.freeze
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2022-09-29 05:18:36 +08:00
|
|
|
def new
|
|
|
|
@my_module = @experiment.my_modules.new
|
2022-12-05 19:55:57 +08:00
|
|
|
assigned_users = User.where(id: @experiment.user_assignments.select(:user_id))
|
|
|
|
|
2022-09-29 05:18:36 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'my_modules/modals/new_modal', locals: { view_mode: params[:view_mode],
|
2022-12-05 19:55:57 +08:00
|
|
|
users: assigned_users }
|
2022-09-29 05:18:36 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@my_module = @experiment.my_modules.new(my_module_params)
|
2023-01-09 19:33:59 +08:00
|
|
|
new_pos = @my_module.get_new_position
|
|
|
|
@my_module.assign_attributes(
|
|
|
|
created_by: current_user,
|
|
|
|
last_modified_by: current_user,
|
|
|
|
x: new_pos[:x],
|
|
|
|
y: new_pos[:y]
|
|
|
|
)
|
2022-11-21 21:57:01 +08:00
|
|
|
@my_module.transaction do
|
|
|
|
if my_module_tags_params[:tag_ids].present?
|
2022-12-23 00:39:51 +08:00
|
|
|
@my_module.tags << @experiment.project.tags.where(id: JSON.parse(my_module_tags_params[:tag_ids]))
|
2022-11-21 21:57:01 +08:00
|
|
|
end
|
2023-01-17 20:33:04 +08:00
|
|
|
if my_module_designated_users_params[:user_ids].present? && can_designate_users_to_new_task?(@experiment)
|
2022-11-21 21:57:01 +08:00
|
|
|
@my_module.designated_users << @experiment.users.where(id: my_module_designated_users_params[:user_ids])
|
2023-01-17 20:33:04 +08:00
|
|
|
elsif !can_designate_users_to_new_task?(@experiment)
|
2023-01-16 18:28:47 +08:00
|
|
|
@my_module.designated_users << current_user
|
2022-11-21 21:57:01 +08:00
|
|
|
end
|
|
|
|
@my_module.save!
|
2023-01-12 20:48:49 +08:00
|
|
|
Activities::CreateActivityService.call(
|
|
|
|
activity_type: :create_module,
|
|
|
|
owner: current_user,
|
|
|
|
team: @my_module.experiment.project.team,
|
|
|
|
project: @my_module.experiment.project,
|
|
|
|
subject: @my_module,
|
|
|
|
message_items: { my_module: @my_module.id }
|
|
|
|
)
|
2022-11-24 21:49:42 +08:00
|
|
|
redirect_to canvas_experiment_path(@experiment) if params[:my_module][:view_mode] == 'canvas'
|
2022-11-21 21:57:01 +08:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
2022-09-29 05:18:36 +08:00
|
|
|
render json: @my_module.errors, status: :unprocessable_entity
|
2022-11-21 21:57:01 +08:00
|
|
|
raise ActiveRecord::Rollback
|
2022-09-29 05:18:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def show
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'show')
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Description modal window in full-zoom canvas
|
|
|
|
def description
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'description'),
|
|
|
|
title: t('my_modules.description.title', module: escape_input(@my_module.name))
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2022-12-06 21:51:11 +08:00
|
|
|
def save_table_state
|
|
|
|
current_user.settings.update(visible_my_module_table_columns: params[:columns])
|
|
|
|
current_user.save!
|
|
|
|
end
|
|
|
|
|
2020-09-11 22:08:03 +08:00
|
|
|
def status_state
|
2023-07-18 19:36:41 +08:00
|
|
|
if @my_module.last_transition_error && @my_module.last_transition_error['type'] == 'repository_snapshot'
|
|
|
|
flash[:repository_snapshot_error] = @my_module.last_transition_error
|
2020-09-11 22:08:03 +08:00
|
|
|
end
|
2023-07-18 19:36:41 +08:00
|
|
|
|
|
|
|
render json: { status_changing: @my_module.status_changing? }
|
2020-09-11 22:08:03 +08:00
|
|
|
end
|
|
|
|
|
2022-05-09 17:40:31 +08:00
|
|
|
def canvas_dropdown_menu
|
|
|
|
@experiment_managable = can_manage_experiment?(@experiment)
|
|
|
|
@group_my_modules = @my_module.my_module_group&.my_modules&.preload(user_assignments: %i(user user_role))
|
|
|
|
render json: {
|
|
|
|
html: render_to_string({ partial: 'canvas/edit/my_module_dropdown_menu',
|
|
|
|
locals: { my_module: @my_module } })
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def activities
|
2019-03-28 17:55:48 +08:00
|
|
|
params[:subjects] = {
|
2019-03-29 16:26:27 +08:00
|
|
|
MyModule: [@my_module.id]
|
2019-03-28 17:55:48 +08:00
|
|
|
}
|
|
|
|
@activity_types = Activity.activity_types_list
|
2023-07-20 22:46:16 +08:00
|
|
|
|
2019-04-12 21:37:45 +08:00
|
|
|
activities = ActivitiesService.load_activities(current_user, current_team, activity_filters)
|
|
|
|
|
|
|
|
@grouped_activities = activities.group_by do |activity|
|
|
|
|
Time.zone.at(activity.created_at).to_date.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
@next_page = activities.next_page
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
respond_to do |format|
|
2019-03-28 17:55:48 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
activities_html: render_to_string(
|
2023-07-17 21:36:22 +08:00
|
|
|
partial: 'global_activities/activity_list',
|
|
|
|
formats: :html
|
2019-03-28 17:55:48 +08:00
|
|
|
),
|
2023-09-15 18:32:15 +08:00
|
|
|
next_page: @next_page
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
2019-03-28 17:55:48 +08:00
|
|
|
end
|
2023-07-17 21:36:22 +08:00
|
|
|
format.html
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Different controller for showing activities inside tab
|
|
|
|
def activities_tab
|
|
|
|
@activities = @my_module.last_activities(1, @per_page)
|
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
2023-07-05 18:43:23 +08:00
|
|
|
html: render_to_string(partial: 'activities', formats: :html)
|
2023-06-21 20:13:20 +08:00
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Due date modal window in full-zoom canvas
|
|
|
|
def due_date
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
2023-07-05 18:43:23 +08:00
|
|
|
html: render_to_string(partial: 'due_date', formats: :html),
|
|
|
|
title: t('.due_date.title', module: escape_input(@my_module.name))
|
2023-06-21 20:13:20 +08:00
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-03-28 00:35:24 +08:00
|
|
|
@my_module.assign_attributes(my_module_params)
|
2016-02-12 23:52:43 +08:00
|
|
|
@my_module.last_modified_by = current_user
|
2020-05-26 21:34:20 +08:00
|
|
|
name_changed = @my_module.name_changed?
|
2016-02-12 23:52:43 +08:00
|
|
|
description_changed = @my_module.description_changed?
|
2020-03-28 00:35:24 +08:00
|
|
|
start_date_changes = @my_module.changes[:started_on]
|
2019-03-12 00:17:59 +08:00
|
|
|
due_date_changes = @my_module.changes[:due_date]
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2023-05-24 16:47:27 +08:00
|
|
|
render_403 && return if @my_module.completed_on_changed? && !can_complete_my_module?(@my_module)
|
2021-11-19 20:24:57 +08:00
|
|
|
|
2023-05-24 16:47:27 +08:00
|
|
|
render_403 && return if description_changed && !can_update_my_module_description?(@my_module)
|
2021-11-19 20:24:57 +08:00
|
|
|
|
2023-05-24 16:47:27 +08:00
|
|
|
render_403 && return if start_date_changes.present? && !can_update_my_module_start_date?(@my_module)
|
2021-11-19 20:24:57 +08:00
|
|
|
|
2023-05-24 16:47:27 +08:00
|
|
|
render_403 && return if due_date_changes.present? && !can_update_my_module_start_date?(@my_module)
|
2021-11-19 20:24:57 +08:00
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
if @my_module.archived_changed?(from: false, to: true)
|
|
|
|
saved = @my_module.archive(current_user)
|
|
|
|
else
|
2021-09-14 17:08:35 +08:00
|
|
|
render_403 && return unless can_manage_my_module?(@my_module)
|
2020-09-09 18:04:43 +08:00
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
saved = @my_module.save
|
2019-03-15 17:30:51 +08:00
|
|
|
if saved
|
|
|
|
if description_changed
|
2019-03-18 22:03:14 +08:00
|
|
|
log_activity(:change_module_description)
|
2019-08-09 15:47:07 +08:00
|
|
|
TinyMceAsset.update_images(@my_module, params[:tiny_mce_images], current_user)
|
2019-03-15 17:30:51 +08:00
|
|
|
end
|
|
|
|
|
2020-05-26 21:34:20 +08:00
|
|
|
log_activity(:rename_task) if name_changed
|
2020-03-28 00:35:24 +08:00
|
|
|
log_start_date_change_activity(start_date_changes) if start_date_changes.present?
|
|
|
|
log_due_date_change_activity(due_date_changes) if due_date_changes.present?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
2023-06-21 20:13:20 +08:00
|
|
|
if saved
|
|
|
|
alerts = []
|
|
|
|
alerts << 'alert-green' if @my_module.completed?
|
|
|
|
unless @my_module.completed?
|
|
|
|
alerts << 'alert-red' if @my_module.is_overdue?
|
|
|
|
alerts << 'alert-yellow' if @my_module.is_one_day_prior?
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
|
|
|
status: :ok,
|
|
|
|
start_date_label: render_to_string(
|
|
|
|
partial: 'my_modules/start_date_label',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module, start_date_editable: true }
|
|
|
|
),
|
|
|
|
due_date_label: render_to_string(
|
|
|
|
partial: 'my_modules/due_date_label',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module, due_date_editable: true }
|
|
|
|
),
|
|
|
|
card_due_date_label: render_to_string(
|
|
|
|
partial: 'my_modules/card_due_date_label',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
|
|
|
table_due_date_label: {
|
|
|
|
html: render_to_string(partial: 'experiments/table_due_date_label',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module, user: current_user }),
|
|
|
|
due_status: my_module_due_status(@my_module)
|
|
|
|
},
|
|
|
|
module_header_due_date: render_to_string(
|
|
|
|
partial: 'my_modules/module_header_due_date',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
|
|
|
description_label: render_to_string(
|
|
|
|
partial: 'my_modules/description_label',
|
2023-07-11 15:21:22 +08:00
|
|
|
formats: :html,
|
2023-06-21 20:13:20 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
|
|
|
alerts: alerts
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: @my_module.errors, status: :unprocessable_entity
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-20 18:41:36 +08:00
|
|
|
def update_description
|
2021-11-19 20:24:57 +08:00
|
|
|
render_403 && return unless can_update_my_module_description?(@my_module)
|
2023-05-24 16:47:27 +08:00
|
|
|
|
2021-03-20 00:11:19 +08:00
|
|
|
old_description = @my_module.description
|
2023-07-18 19:36:41 +08:00
|
|
|
if @my_module.update(description: params.require(:my_module)[:description])
|
|
|
|
log_activity(:change_module_description)
|
|
|
|
TinyMceAsset.update_images(@my_module, params[:tiny_mce_images], current_user)
|
|
|
|
my_module_annotation_notification(old_description)
|
|
|
|
render json: {
|
|
|
|
html: custom_auto_link(
|
|
|
|
@my_module.tinymce_render(:description),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: current_team
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: @my_module.errors, status: :unprocessable_entity
|
2019-03-20 18:41:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-14 23:08:52 +08:00
|
|
|
def update_protocol_description
|
|
|
|
protocol = @my_module.protocol
|
2021-03-20 00:11:19 +08:00
|
|
|
old_description = protocol.description
|
2019-03-14 23:08:52 +08:00
|
|
|
return render_404 unless protocol
|
2021-03-20 00:11:19 +08:00
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
if protocol.update(description: params.require(:protocol)[:description])
|
|
|
|
log_activity(:protocol_description_in_task_edited)
|
|
|
|
TinyMceAsset.update_images(protocol, params[:tiny_mce_images], current_user)
|
|
|
|
protocol_annotation_notification(old_description)
|
|
|
|
render json: {
|
|
|
|
html: custom_auto_link(
|
|
|
|
protocol.tinymce_render(:description),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: current_team
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: protocol.errors, status: :unprocessable_entity
|
2019-03-14 23:08:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def protocols
|
|
|
|
@protocol = @my_module.protocol
|
2020-05-13 18:58:31 +08:00
|
|
|
@assigned_repositories = @my_module.live_and_snapshot_repositories_list
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2022-04-21 21:12:34 +08:00
|
|
|
def protocol
|
2022-05-11 22:08:04 +08:00
|
|
|
render json: @my_module.protocol, serializer: ProtocolSerializer, user: current_user
|
2022-04-21 21:12:34 +08:00
|
|
|
end
|
|
|
|
|
2022-04-26 20:13:17 +08:00
|
|
|
def update_protocol
|
|
|
|
protocol = @my_module.protocol
|
2022-12-01 21:55:23 +08:00
|
|
|
old_description = protocol.description
|
2022-08-11 20:09:01 +08:00
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
protocol.update!(protocol_params)
|
|
|
|
log_activity(:protocol_name_in_task_edited) if protocol.saved_change_to_name?
|
2022-09-06 17:03:13 +08:00
|
|
|
log_activity(:protocol_description_in_task_edited) if protocol.saved_change_to_description?
|
2022-08-11 20:09:01 +08:00
|
|
|
TinyMceAsset.update_images(protocol, params[:tiny_mce_images], current_user)
|
2022-12-01 21:55:23 +08:00
|
|
|
protocol_annotation_notification(old_description)
|
2022-08-11 20:09:01 +08:00
|
|
|
end
|
2022-04-26 20:13:17 +08:00
|
|
|
|
2022-05-11 22:08:04 +08:00
|
|
|
render json: protocol, serializer: ProtocolSerializer, user: current_user
|
2022-08-11 20:09:01 +08:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
2023-04-03 21:34:59 +08:00
|
|
|
render json: protocol.errors, status: :unprocessable_entity
|
2022-04-26 20:13:17 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def results
|
2020-07-28 21:39:29 +08:00
|
|
|
@results_order = params[:order] || 'new'
|
2021-01-14 21:04:35 +08:00
|
|
|
|
|
|
|
@results = @my_module.archived_branch? ? @my_module.results : @my_module.results.active
|
|
|
|
@results = @results.page(params[:page]).per(Constants::RESULTS_PER_PAGE_LIMIT)
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2020-07-28 21:39:29 +08:00
|
|
|
@results = case @results_order
|
2022-12-02 00:13:26 +08:00
|
|
|
when 'old' then @results.order(created_at: :asc)
|
|
|
|
when 'old_updated' then @results.order(updated_at: :asc)
|
|
|
|
when 'new_updated' then @results.order(updated_at: :desc)
|
2020-07-28 21:39:29 +08:00
|
|
|
when 'atoz' then @results.order(name: :asc)
|
|
|
|
when 'ztoa' then @results.order(name: :desc)
|
2022-12-02 00:13:26 +08:00
|
|
|
else @results.order(created_at: :desc)
|
2020-07-28 21:39:29 +08:00
|
|
|
end
|
2017-05-18 20:21:00 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def archive
|
|
|
|
@archived_results = @my_module.archived_results
|
|
|
|
end
|
|
|
|
|
2020-12-29 00:44:47 +08:00
|
|
|
def restore_group
|
|
|
|
experiment = Experiment.find(params[:id])
|
|
|
|
return render_403 unless can_read_experiment?(experiment)
|
|
|
|
|
|
|
|
my_modules = experiment.my_modules.archived.where(id: params[:my_modules_ids])
|
|
|
|
counter = 0
|
|
|
|
my_modules.each do |my_module|
|
2021-09-14 17:08:35 +08:00
|
|
|
next unless can_restore_my_module?(my_module)
|
2020-12-29 00:44:47 +08:00
|
|
|
|
2021-01-04 22:11:24 +08:00
|
|
|
my_module.transaction do
|
|
|
|
my_module.restore!(current_user)
|
|
|
|
log_activity(:restore_module, my_module)
|
|
|
|
counter += 1
|
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error e.message
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
2020-12-29 00:44:47 +08:00
|
|
|
end
|
2021-01-04 22:11:24 +08:00
|
|
|
if counter == my_modules.size
|
|
|
|
flash[:success] = t('my_modules.restore_group.success_flash_html', number: counter)
|
|
|
|
elsif counter.positive?
|
|
|
|
flash[:warning] = t('my_modules.restore_group.partial_success_flash_html', number: counter)
|
2020-12-29 00:44:47 +08:00
|
|
|
else
|
|
|
|
flash[:error] = t('my_modules.restore_group.error_flash')
|
|
|
|
end
|
2022-11-28 19:44:15 +08:00
|
|
|
|
|
|
|
if params[:view] == 'table'
|
|
|
|
redirect_to table_experiment_path(experiment, view_mode: :archived)
|
|
|
|
else
|
|
|
|
redirect_to module_archive_experiment_path(experiment)
|
|
|
|
end
|
2020-12-29 00:44:47 +08:00
|
|
|
end
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
def update_state
|
2020-08-04 22:40:06 +08:00
|
|
|
old_status_id = @my_module.my_module_status_id
|
2020-09-01 17:07:02 +08:00
|
|
|
if @my_module.update(my_module_status_id: update_status_params[:status_id])
|
|
|
|
log_activity(:change_status_on_task_flow, @my_module, my_module_status_old: old_status_id,
|
|
|
|
my_module_status_new: @my_module.my_module_status.id)
|
2017-06-06 23:35:29 +08:00
|
|
|
|
2023-08-23 20:02:11 +08:00
|
|
|
render json: { status: :changed }
|
2020-09-01 17:07:02 +08:00
|
|
|
else
|
|
|
|
render json: { errors: @my_module.errors.messages.values.flatten.join('\n') }, status: :unprocessable_entity
|
2017-05-04 18:41:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 18:49:25 +08:00
|
|
|
def permissions
|
2022-11-22 22:01:12 +08:00
|
|
|
if stale?(@my_module)
|
2022-11-07 18:49:25 +08:00
|
|
|
render json: {
|
|
|
|
editable: can_manage_my_module?(@my_module),
|
|
|
|
moveable: can_move_my_module?(@my_module),
|
|
|
|
archivable: can_archive_my_module?(@my_module),
|
|
|
|
restorable: can_restore_my_module?(@my_module)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-22 22:01:12 +08:00
|
|
|
def actions_dropdown
|
|
|
|
if stale?(@my_module)
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'experiments/table_row_actions',
|
|
|
|
locals: { my_module: @my_module }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 17:29:19 +08:00
|
|
|
def actions_toolbar
|
|
|
|
render json: {
|
|
|
|
actions:
|
|
|
|
Toolbars::MyModulesService.new(
|
|
|
|
current_user,
|
|
|
|
my_module_ids: params[:my_module_ids].split(',')
|
|
|
|
).actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-12-01 22:08:59 +08:00
|
|
|
def provisioning_status
|
|
|
|
render json: { provisioning_status: @my_module.provisioning_status }
|
|
|
|
end
|
|
|
|
|
2023-06-06 19:53:12 +08:00
|
|
|
def inventory_assigning_my_module_filter
|
2023-06-09 20:20:41 +08:00
|
|
|
viewable_experiments = Experiment.viewable_by_user(current_user, current_team)
|
2023-06-06 19:53:12 +08:00
|
|
|
assignable_my_modules = MyModule.repository_row_assignable_by_user(current_user)
|
2023-05-24 16:47:27 +08:00
|
|
|
|
2023-06-09 20:20:41 +08:00
|
|
|
experiment = Experiment.viewable_by_user(current_user, current_team)
|
2023-05-24 16:47:27 +08:00
|
|
|
.joins(:my_modules)
|
2023-06-09 20:20:41 +08:00
|
|
|
.where(experiments: { id: viewable_experiments })
|
2023-06-06 19:53:12 +08:00
|
|
|
.where(my_modules: { id: assignable_my_modules })
|
2023-05-24 16:47:27 +08:00
|
|
|
.find_by(id: params[:experiment_id])
|
|
|
|
|
2023-05-10 22:12:20 +08:00
|
|
|
return render_404 if experiment.blank?
|
|
|
|
|
|
|
|
my_modules = experiment.my_modules
|
2023-06-06 19:53:12 +08:00
|
|
|
.where(my_modules: { id: assignable_my_modules })
|
2023-05-10 22:12:20 +08:00
|
|
|
.pluck(:id, :name)
|
|
|
|
|
|
|
|
return render plain: [].to_json if my_modules.blank?
|
|
|
|
|
|
|
|
render json: my_modules
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_vars
|
2022-05-09 17:40:31 +08:00
|
|
|
@my_module = MyModule.preload(user_assignments: %i(user user_role)).find_by(id: params[:id])
|
2016-02-12 23:52:43 +08:00
|
|
|
if @my_module
|
2016-07-29 21:47:41 +08:00
|
|
|
@experiment = @my_module.experiment
|
2016-07-29 22:46:25 +08:00
|
|
|
@project = @my_module.experiment.project if @experiment
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-05 19:55:57 +08:00
|
|
|
def load_experiment
|
|
|
|
@experiment = Experiment.preload(user_assignments: %i(user user_role)).find_by(id: params[:id])
|
|
|
|
render_404 unless @experiment
|
|
|
|
end
|
|
|
|
|
2021-06-18 22:52:19 +08:00
|
|
|
def load_experiment_my_modules
|
2022-01-03 17:48:17 +08:00
|
|
|
@experiment_my_modules = if @my_module.experiment.archived_branch?
|
|
|
|
@my_module.experiment.my_modules.order(:name)
|
|
|
|
else
|
|
|
|
@my_module.experiment.my_modules.where(archived: @my_module.archived?).order(:name)
|
|
|
|
end
|
2021-06-18 22:52:19 +08:00
|
|
|
end
|
|
|
|
|
2022-09-29 05:18:36 +08:00
|
|
|
def check_create_permissions
|
2023-07-11 15:29:17 +08:00
|
|
|
render_403 && return unless can_create_experiment_tasks?(@experiment)
|
2022-09-29 05:18:36 +08:00
|
|
|
end
|
|
|
|
|
2018-02-02 01:41:28 +08:00
|
|
|
def check_manage_permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
render_403 && return unless can_manage_my_module?(@my_module)
|
2018-05-24 22:44:10 +08:00
|
|
|
end
|
|
|
|
|
2021-01-04 22:11:24 +08:00
|
|
|
def check_archive_permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
return render_403 if my_module_params[:archived] == 'true' && !can_archive_my_module?(@my_module)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:32:11 +08:00
|
|
|
def check_read_permissions
|
2022-11-18 18:47:27 +08:00
|
|
|
current_team_switch(@project.team) if current_team != @project.team
|
2021-09-30 17:32:11 +08:00
|
|
|
render_403 unless can_read_my_module?(@my_module)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
def check_update_state_permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
return render_403 unless can_update_my_module_status?(@my_module)
|
2020-11-20 18:59:15 +08:00
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
render_404 unless @my_module.my_module_status
|
2017-05-04 18:41:22 +08:00
|
|
|
end
|
|
|
|
|
2019-05-20 19:13:31 +08:00
|
|
|
def set_inline_name_editing
|
2021-09-14 17:08:35 +08:00
|
|
|
return unless can_manage_my_module?(@my_module)
|
|
|
|
|
2019-05-20 19:13:31 +08:00
|
|
|
@inline_editable_title_config = {
|
|
|
|
name: 'title',
|
|
|
|
params_group: 'my_module',
|
2020-01-06 23:07:23 +08:00
|
|
|
item_id: @my_module.id,
|
2019-05-20 19:13:31 +08:00
|
|
|
field_to_udpate: 'name',
|
|
|
|
path_to_update: my_module_path(@my_module)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def my_module_params
|
2022-09-29 05:18:36 +08:00
|
|
|
permitted_params = params.require(:my_module).permit(:name, :description, :started_on, :due_date, :archived)
|
2020-03-28 00:35:24 +08:00
|
|
|
|
2022-09-29 05:18:36 +08:00
|
|
|
if permitted_params[:started_on].present?
|
|
|
|
permitted_params[:started_on] =
|
|
|
|
Time.zone.strptime(permitted_params[:started_on], I18n.backend.date_format.dup.gsub(/%-/, '%') + ' %H:%M')
|
2020-03-28 00:35:24 +08:00
|
|
|
end
|
2022-09-29 05:18:36 +08:00
|
|
|
if permitted_params[:due_date].present?
|
|
|
|
permitted_params[:due_date] =
|
|
|
|
Time.zone.strptime(permitted_params[:due_date], I18n.backend.date_format.dup.gsub(/%-/, '%') + ' %H:%M')
|
2020-03-28 00:35:24 +08:00
|
|
|
end
|
|
|
|
|
2022-09-29 05:18:36 +08:00
|
|
|
permitted_params
|
2020-03-28 00:35:24 +08:00
|
|
|
end
|
|
|
|
|
2022-11-21 21:57:01 +08:00
|
|
|
def my_module_tags_params
|
2022-12-23 00:39:51 +08:00
|
|
|
params.require(:my_module).permit(:tag_ids)
|
2022-11-21 21:57:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def my_module_designated_users_params
|
|
|
|
params.require(:my_module).permit(user_ids: [])
|
|
|
|
end
|
|
|
|
|
2022-04-26 20:13:17 +08:00
|
|
|
def protocol_params
|
2022-05-11 22:08:04 +08:00
|
|
|
params.require(:protocol).permit(:name, :description)
|
2022-04-26 20:13:17 +08:00
|
|
|
end
|
|
|
|
|
2020-07-15 00:48:18 +08:00
|
|
|
def update_status_params
|
2020-07-23 21:53:46 +08:00
|
|
|
params.require(:my_module).permit(:status_id)
|
2020-07-15 00:48:18 +08:00
|
|
|
end
|
|
|
|
|
2020-03-28 00:35:24 +08:00
|
|
|
def log_start_date_change_activity(start_date_changes)
|
|
|
|
type_of = if start_date_changes[0].nil? # set started_on
|
2020-05-06 18:34:45 +08:00
|
|
|
message_items = { my_module_started_on: @my_module.started_on }
|
2020-03-28 00:35:24 +08:00
|
|
|
:set_task_start_date
|
|
|
|
elsif start_date_changes[1].nil? # remove started_on
|
|
|
|
message_items = { my_module_started_on: start_date_changes[0] }
|
|
|
|
:remove_task_start_date
|
|
|
|
else # change started_on
|
2020-05-06 18:34:45 +08:00
|
|
|
message_items = { my_module_started_on: @my_module.started_on }
|
2020-03-28 00:35:24 +08:00
|
|
|
:change_task_start_date
|
|
|
|
end
|
|
|
|
log_activity(type_of, @my_module, message_items)
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_due_date_change_activity(due_date_changes)
|
|
|
|
type_of = if due_date_changes[0].nil? # set due_date
|
|
|
|
message_items = { my_module_duedate: @my_module.due_date }
|
|
|
|
:set_task_due_date
|
|
|
|
elsif due_date_changes[1].nil? # remove due_date
|
|
|
|
message_items = { my_module_duedate: due_date_changes[0] }
|
|
|
|
:remove_task_due_date
|
|
|
|
else # change due_date
|
|
|
|
message_items = { my_module_duedate: @my_module.due_date }
|
|
|
|
:change_task_due_date
|
|
|
|
end
|
|
|
|
log_activity(type_of, @my_module, message_items)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2019-03-18 22:03:14 +08:00
|
|
|
|
2019-04-02 17:50:37 +08:00
|
|
|
def log_activity(type_of, my_module = nil, message_items = {})
|
|
|
|
my_module ||= @my_module
|
|
|
|
message_items = { my_module: my_module.id }.merge(message_items)
|
2019-03-18 22:03:14 +08:00
|
|
|
|
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: my_module.team,
|
|
|
|
project: my_module.project,
|
2019-04-02 17:50:37 +08:00
|
|
|
subject: my_module,
|
2019-03-21 04:34:47 +08:00
|
|
|
message_items: message_items)
|
2019-03-18 22:03:14 +08:00
|
|
|
end
|
2019-03-28 17:55:48 +08:00
|
|
|
|
|
|
|
def activity_filters
|
|
|
|
params.permit(
|
2023-09-15 18:32:15 +08:00
|
|
|
:page, :from_date, :to_date, types: [], users: [], subjects: {}
|
2019-03-28 17:55:48 +08:00
|
|
|
)
|
|
|
|
end
|
2021-03-20 00:11:19 +08:00
|
|
|
|
|
|
|
def my_module_annotation_notification(old_text = nil)
|
|
|
|
smart_annotation_notification(
|
|
|
|
old_text: old_text,
|
|
|
|
new_text: @my_module.description,
|
|
|
|
title: t('notifications.my_module_description_annotation_title',
|
|
|
|
my_module: @my_module.name,
|
|
|
|
user: current_user.full_name),
|
|
|
|
message: t('notifications.my_module_description_annotation_message_html',
|
|
|
|
project: link_to(@my_module.experiment.project.name, project_url(@my_module.experiment.project)),
|
2023-01-12 18:31:04 +08:00
|
|
|
experiment: link_to(@my_module.experiment.name, my_modules_experiment_url(@my_module.experiment)),
|
2021-03-20 00:11:19 +08:00
|
|
|
my_module: link_to(@my_module.name, protocols_my_module_url(@my_module)))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def protocol_annotation_notification(old_text = nil)
|
|
|
|
smart_annotation_notification(
|
|
|
|
old_text: old_text,
|
|
|
|
new_text: @my_module.protocol.description,
|
|
|
|
title: t('notifications.my_module_protocol_annotation_title',
|
|
|
|
my_module: @my_module.name,
|
|
|
|
user: current_user.full_name),
|
|
|
|
message: t('notifications.my_module_protocol_annotation_message_html',
|
|
|
|
project: link_to(@my_module.experiment.project.name, project_url(@my_module.experiment.project)),
|
2023-01-12 18:31:04 +08:00
|
|
|
experiment: link_to(@my_module.experiment.name, my_modules_experiment_url(@my_module.experiment)),
|
2021-03-20 00:11:19 +08:00
|
|
|
my_module: link_to(@my_module.name, protocols_my_module_url(@my_module)))
|
|
|
|
)
|
|
|
|
end
|
2023-04-19 20:16:22 +08:00
|
|
|
|
|
|
|
def set_navigator
|
2023-04-21 21:25:52 +08:00
|
|
|
@navigator = {
|
|
|
|
url: tree_navigator_my_module_path(@my_module),
|
2023-05-23 21:29:14 +08:00
|
|
|
archived: params[:view_mode] == 'archived',
|
2023-04-21 21:25:52 +08:00
|
|
|
id: @my_module.code
|
|
|
|
}
|
2023-04-19 20:16:22 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|