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
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2020-12-29 00:44:47 +08:00
|
|
|
before_action :load_vars, except: %i(restore_group)
|
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(
|
|
|
|
description due_date update_description update_protocol_description update_protocol
|
|
|
|
)
|
2021-09-30 17:32:11 +08:00
|
|
|
before_action :check_read_permissions, except: %i(update update_description update_protocol_description restore_group)
|
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)
|
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
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json {
|
|
|
|
render :json => {
|
|
|
|
:html => render_to_string({
|
|
|
|
:partial => "show.html.erb"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Description modal window in full-zoom canvas
|
|
|
|
def description
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json {
|
|
|
|
render json: {
|
|
|
|
html: render_to_string({
|
|
|
|
partial: "description.html.erb"
|
|
|
|
}),
|
2017-01-04 22:04:12 +08:00
|
|
|
title: t('my_modules.description.title',
|
2017-01-11 22:50:11 +08:00
|
|
|
module: escape_input(@my_module.name))
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-11 22:08:03 +08:00
|
|
|
def status_state
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2022-04-04 17:04:03 +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
|
|
|
|
end
|
|
|
|
|
2020-09-11 22:08:03 +08:00
|
|
|
render json: { status_changing: @my_module.status_changing? }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
@user_list = User.where(id: UserTeam.where(team: current_user.teams).select(:user_id))
|
|
|
|
.distinct
|
|
|
|
.pluck(:full_name, :id)
|
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
|
2019-04-15 16:51:59 +08:00
|
|
|
@starting_timestamp = activities.first&.created_at.to_i
|
2019-04-12 21:37:45 +08:00
|
|
|
|
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(
|
|
|
|
partial: 'global_activities/activity_list.html.erb'
|
|
|
|
),
|
2019-04-12 21:37:45 +08:00
|
|
|
next_page: @next_page,
|
|
|
|
starting_timestamp: @starting_timestamp
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
2019-03-28 17:55:48 +08:00
|
|
|
end
|
|
|
|
format.html do
|
|
|
|
end
|
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)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json {
|
|
|
|
render :json => {
|
|
|
|
:html => render_to_string({
|
|
|
|
:partial => "activities.html.erb"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Due date modal window in full-zoom canvas
|
|
|
|
def due_date
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json {
|
|
|
|
render json: {
|
|
|
|
html: render_to_string({
|
|
|
|
partial: "due_date.html.erb"
|
|
|
|
}),
|
2017-01-04 22:04:12 +08:00
|
|
|
title: t('my_modules.due_date.title',
|
2017-01-11 22:50:11 +08:00
|
|
|
module: escape_input(@my_module.name))
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
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
|
|
|
|
2021-11-22 16:49:44 +08:00
|
|
|
if @my_module.completed_on_changed? && !can_complete_my_module?(@my_module)
|
2021-11-19 20:24:57 +08:00
|
|
|
render_403 && return
|
|
|
|
end
|
|
|
|
|
|
|
|
if description_changed && !can_update_my_module_description?(@my_module)
|
|
|
|
render_403 && return
|
|
|
|
end
|
|
|
|
|
|
|
|
if start_date_changes.present? && !can_update_my_module_start_date?(@my_module)
|
|
|
|
render_403 && return
|
|
|
|
end
|
|
|
|
|
|
|
|
if due_date_changes.present? && !can_update_my_module_start_date?(@my_module)
|
|
|
|
render_403 && return
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
respond_to do |format|
|
2021-01-04 22:11:24 +08:00
|
|
|
if saved
|
2020-03-28 00:35:24 +08:00
|
|
|
format.json do
|
2016-02-12 23:52:43 +08:00
|
|
|
alerts = []
|
2017-02-16 18:45:07 +08:00
|
|
|
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?
|
2017-02-10 21:27:20 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
render json: {
|
|
|
|
status: :ok,
|
2020-03-28 00:35:24 +08:00
|
|
|
start_date_label: render_to_string(
|
|
|
|
partial: 'my_modules/start_date_label.html.erb',
|
2021-11-22 18:18:05 +08:00
|
|
|
locals: { my_module: @my_module, start_date_editable: true }
|
2020-03-28 00:35:24 +08:00
|
|
|
),
|
2016-02-12 23:52:43 +08:00
|
|
|
due_date_label: render_to_string(
|
2020-03-17 00:55:35 +08:00
|
|
|
partial: 'my_modules/due_date_label.html.erb',
|
2021-11-22 18:18:05 +08:00
|
|
|
locals: { my_module: @my_module, due_date_editable: true }
|
2016-02-12 23:52:43 +08:00
|
|
|
),
|
2020-03-17 00:55:35 +08:00
|
|
|
card_due_date_label: render_to_string(
|
|
|
|
partial: 'my_modules/card_due_date_label.html.erb',
|
2016-02-12 23:52:43 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
2020-03-17 00:55:35 +08:00
|
|
|
module_header_due_date: render_to_string(
|
|
|
|
partial: 'my_modules/module_header_due_date.html.erb',
|
2016-02-12 23:52:43 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
|
|
|
description_label: render_to_string(
|
2020-03-17 00:55:35 +08:00
|
|
|
partial: 'my_modules/description_label.html.erb',
|
2016-02-12 23:52:43 +08:00
|
|
|
locals: { my_module: @my_module }
|
|
|
|
),
|
|
|
|
alerts: alerts
|
|
|
|
}
|
2020-03-28 00:35:24 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
2020-03-28 00:35:24 +08:00
|
|
|
format.json do
|
2016-09-21 21:54:12 +08:00
|
|
|
render json: @my_module.errors,
|
2016-02-12 23:52:43 +08:00
|
|
|
status: :unprocessable_entity
|
2020-03-28 00:35:24 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
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)
|
2021-03-20 00:11:19 +08:00
|
|
|
old_description = @my_module.description
|
2019-03-20 18:41:36 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
if @my_module.update(description: params.require(:my_module)[:description])
|
2019-11-27 21:37:53 +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)
|
2021-03-20 00:11:19 +08:00
|
|
|
my_module_annotation_notification(old_description)
|
2019-03-20 18:41:36 +08:00
|
|
|
render json: {
|
|
|
|
html: custom_auto_link(
|
2019-03-22 17:52:26 +08:00
|
|
|
@my_module.tinymce_render(:description),
|
2019-03-20 18:41:36 +08:00
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: current_team
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: @my_module.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
2019-03-14 23:08:52 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
if protocol.update(description: params.require(:protocol)[:description])
|
2019-11-27 21:37:53 +08:00
|
|
|
log_activity(:protocol_description_in_task_edited)
|
2019-08-09 15:47:07 +08:00
|
|
|
TinyMceAsset.update_images(protocol, params[:tiny_mce_images], current_user)
|
2021-03-20 00:11:19 +08:00
|
|
|
protocol_annotation_notification(old_description)
|
2019-03-20 18:41:36 +08:00
|
|
|
render json: {
|
|
|
|
html: custom_auto_link(
|
2019-03-22 17:52:26 +08:00
|
|
|
protocol.tinymce_render(:description),
|
2019-03-20 18:41:36 +08:00
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: current_team
|
|
|
|
)
|
|
|
|
}
|
2019-03-14 23:08:52 +08:00
|
|
|
else
|
|
|
|
render json: protocol.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
2017-01-24 23:57:14 +08:00
|
|
|
current_team_switch(@protocol.team)
|
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
|
|
|
|
protocol.update!(protocol_params)
|
|
|
|
|
2022-05-11 22:08:04 +08:00
|
|
|
render json: protocol, serializer: ProtocolSerializer, user: current_user
|
2022-04-26 20:13:17 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def results
|
2017-01-24 23:57:14 +08:00
|
|
|
current_team_switch(@my_module
|
2016-10-11 22:46:30 +08:00
|
|
|
.experiment
|
|
|
|
.project
|
2017-01-24 23:57:14 +08:00
|
|
|
.team)
|
2021-06-18 22:52:19 +08:00
|
|
|
|
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
|
2021-05-17 21:17:32 +08:00
|
|
|
when 'old' then @results.order(updated_at: :asc)
|
2020-07-28 21:39:29 +08:00
|
|
|
when 'atoz' then @results.order(name: :asc)
|
|
|
|
when 'ztoa' then @results.order(name: :desc)
|
2021-05-17 21:17:32 +08:00
|
|
|
else @results.order(updated_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
|
2020-07-15 00:48:18 +08:00
|
|
|
current_team_switch(@my_module.experiment.project.team)
|
2016-02-12 23:52:43 +08:00
|
|
|
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
|
|
|
|
redirect_to module_archive_experiment_path(experiment)
|
|
|
|
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
|
|
|
|
2020-09-09 17:26:43 +08:00
|
|
|
return redirect_to protocols_my_module_path(@my_module)
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
2020-03-28 00:35:24 +08:00
|
|
|
update_params = params.require(:my_module).permit(:name, :description, :started_on, :due_date, :archived)
|
|
|
|
|
|
|
|
if update_params[:started_on].present?
|
|
|
|
update_params[:started_on] =
|
|
|
|
Time.zone.strptime(update_params[:started_on], I18n.backend.date_format.dup.gsub(/%-/, '%') + ' %H:%M')
|
|
|
|
end
|
|
|
|
if update_params[:due_date].present?
|
|
|
|
update_params[:due_date] =
|
|
|
|
Time.zone.strptime(update_params[:due_date], I18n.backend.date_format.dup.gsub(/%-/, '%') + ' %H:%M')
|
|
|
|
end
|
|
|
|
|
|
|
|
update_params
|
|
|
|
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,
|
2019-04-02 17:50:37 +08:00
|
|
|
team: my_module.experiment.project.team,
|
|
|
|
project: my_module.experiment.project,
|
|
|
|
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(
|
2019-04-12 21:37:45 +08:00
|
|
|
:page, :starting_timestamp, :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)),
|
|
|
|
experiment: link_to(@my_module.experiment.name, canvas_experiment_url(@my_module.experiment)),
|
|
|
|
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)),
|
|
|
|
experiment: link_to(@my_module.experiment.name, canvas_experiment_url(@my_module.experiment)),
|
|
|
|
my_module: link_to(@my_module.name, protocols_my_module_url(@my_module)))
|
|
|
|
)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|