mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-14 09:04:56 +08:00
Make form switchable [SCI-11455]
This commit is contained in:
parent
f00420198b
commit
882de3b9f0
9 changed files with 70 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FormFieldValuesController < ApplicationController
|
class FormFieldValuesController < ApplicationController
|
||||||
|
before_action :check_forms_enabled
|
||||||
before_action :load_form_response
|
before_action :load_form_response
|
||||||
before_action :load_form_field
|
before_action :load_form_field
|
||||||
before_action :check_create_permissions
|
before_action :check_create_permissions
|
||||||
|
@ -40,6 +41,10 @@ class FormFieldValuesController < ApplicationController
|
||||||
render_403 unless can_submit_form_response?(@form_response)
|
render_403 unless can_submit_form_response?(@form_response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_forms_enabled
|
||||||
|
render_404 unless Form.forms_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def log_form_field_value_create_activity
|
def log_form_field_value_create_activity
|
||||||
step = @form_response.step
|
step = @form_response.step
|
||||||
protocol = step.protocol
|
protocol = step.protocol
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FormFieldsController < ApplicationController
|
class FormFieldsController < ApplicationController
|
||||||
|
before_action :check_forms_enabled
|
||||||
before_action :load_form
|
before_action :load_form
|
||||||
before_action :load_form_field, only: %i(update destroy)
|
before_action :load_form_field, only: %i(update destroy)
|
||||||
before_action :check_manage_permissions, only: %i(create update destroy reorder)
|
before_action :check_manage_permissions, only: %i(create update destroy reorder)
|
||||||
|
@ -85,6 +86,10 @@ class FormFieldsController < ApplicationController
|
||||||
params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid)
|
params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_forms_enabled
|
||||||
|
render_404 unless Form.forms_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def log_activity(type_of, message_items = {})
|
def log_activity(type_of, message_items = {})
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: type_of,
|
.call(activity_type: type_of,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
class FormsController < ApplicationController
|
class FormsController < ApplicationController
|
||||||
include UserRolesHelper
|
include UserRolesHelper
|
||||||
|
|
||||||
|
before_action :check_forms_enabled
|
||||||
before_action :load_form, only: %i(show update publish unpublish export_form_responses)
|
before_action :load_form, only: %i(show update publish unpublish export_form_responses)
|
||||||
before_action :set_breadcrumbs_items, only: %i(index show)
|
before_action :set_breadcrumbs_items, only: %i(index show)
|
||||||
before_action :check_manage_permissions, only: :update
|
before_action :check_manage_permissions, only: :update
|
||||||
|
@ -221,6 +222,10 @@ class FormsController < ApplicationController
|
||||||
params.require(:form).permit(:name, :description)
|
params.require(:form).permit(:name, :description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_forms_enabled
|
||||||
|
render_404 unless Form.forms_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def log_activity(form, type_of, message_items = {})
|
def log_activity(form, type_of, message_items = {})
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: type_of,
|
.call(activity_type: type_of,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
module StepElements
|
module StepElements
|
||||||
class FormResponsesController < BaseController
|
class FormResponsesController < BaseController
|
||||||
|
before_action :check_forms_enabled, except: %i(destroy)
|
||||||
before_action :load_form, only: :create
|
before_action :load_form, only: :create
|
||||||
before_action :load_step, only: :create
|
before_action :load_step, only: :create
|
||||||
before_action :load_form_response, except: :create
|
before_action :load_form_response, except: :create
|
||||||
|
@ -90,6 +91,10 @@ module StepElements
|
||||||
render_404 unless @form_response
|
render_404 unless @form_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_forms_enabled
|
||||||
|
render_404 unless Form.forms_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def log_step_form_activity(element_type_of, message_items = {})
|
def log_step_form_activity(element_type_of, message_items = {})
|
||||||
message_items[:my_module] = @protocol.my_module.id if @protocol.in_module?
|
message_items[:my_module] = @protocol.my_module.id if @protocol.in_module?
|
||||||
|
|
||||||
|
|
|
@ -34,19 +34,7 @@ module LeftMenuBarHelper
|
||||||
name: t('left_menu_bar.templates'),
|
name: t('left_menu_bar.templates'),
|
||||||
icon: 'sn-icon-protocols-templates',
|
icon: 'sn-icon-protocols-templates',
|
||||||
active: protocols_are_selected? || label_templates_are_selected? || forms_are_selected?,
|
active: protocols_are_selected? || label_templates_are_selected? || forms_are_selected?,
|
||||||
submenu: [{
|
submenu: template_submenu
|
||||||
url: forms_path,
|
|
||||||
name: t('left_menu_bar.forms'),
|
|
||||||
active: forms_are_selected?
|
|
||||||
}, {
|
|
||||||
url: protocols_path,
|
|
||||||
name: t('left_menu_bar.protocol'),
|
|
||||||
active: protocols_are_selected?
|
|
||||||
}, {
|
|
||||||
url: label_templates_path,
|
|
||||||
name: t('left_menu_bar.label'),
|
|
||||||
active: label_templates_are_selected?
|
|
||||||
}]
|
|
||||||
}, {
|
}, {
|
||||||
url: reports_path,
|
url: reports_path,
|
||||||
name: t('left_menu_bar.reports'),
|
name: t('left_menu_bar.reports'),
|
||||||
|
@ -103,4 +91,27 @@ module LeftMenuBarHelper
|
||||||
def activities_are_selected?
|
def activities_are_selected?
|
||||||
controller_name == 'global_activities'
|
controller_name == 'global_activities'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def template_submenu
|
||||||
|
submenu = [
|
||||||
|
{
|
||||||
|
url: protocols_path,
|
||||||
|
name: t('left_menu_bar.protocol'),
|
||||||
|
active: protocols_are_selected?
|
||||||
|
}, {
|
||||||
|
url: label_templates_path,
|
||||||
|
name: t('left_menu_bar.label'),
|
||||||
|
active: label_templates_are_selected?
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
if Form.forms_enabled?
|
||||||
|
submenu.unshift({
|
||||||
|
url: forms_path,
|
||||||
|
name: t('left_menu_bar.forms'),
|
||||||
|
active: forms_are_selected?
|
||||||
|
})
|
||||||
|
end
|
||||||
|
submenu
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -410,14 +410,18 @@
|
||||||
emit: 'create:checklist',
|
emit: 'create:checklist',
|
||||||
icon: 'sn-icon sn-icon-checkllist',
|
icon: 'sn-icon sn-icon-checkllist',
|
||||||
data_e2e: `e2e-BT-protocol-step${this.step.id}-insertChecklist`
|
data_e2e: `e2e-BT-protocol-step${this.step.id}-insertChecklist`
|
||||||
},{
|
|
||||||
text: this.i18n.t('protocols.steps.insert.form'),
|
|
||||||
emit: 'create:form',
|
|
||||||
icon: 'sn-icon sn-icon-forms',
|
|
||||||
data_e2e: `e2e-BT-protocol-step${this.step.id}-insertForm`
|
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.urls.create_form_response_url) {
|
||||||
|
menu = menu.concat([{
|
||||||
|
text: this.i18n.t('protocols.steps.insert.form'),
|
||||||
|
emit: 'create:form',
|
||||||
|
icon: 'sn-icon sn-icon-forms',
|
||||||
|
data_e2e: `e2e-BT-protocol-step${this.step.id}-insertForm`
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
},
|
},
|
||||||
actionsMenu() {
|
actionsMenu() {
|
||||||
|
|
|
@ -65,6 +65,10 @@ class Form < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.forms_enabled?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_automatic_user_assignments
|
def update_automatic_user_assignments
|
||||||
|
|
|
@ -30,19 +30,21 @@ class StepFormResponseSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
def urls
|
def urls
|
||||||
user = scope[:user] || @instance_options[:user]
|
user = scope[:user] || @instance_options[:user]
|
||||||
|
list = {}
|
||||||
|
|
||||||
list = {
|
if Form.forms_enabled?
|
||||||
add_value: form_response_form_field_values_path(object)
|
list[:add_value] = form_response_form_field_values_path(object)
|
||||||
}
|
list[:submit] = submit_step_form_response_path(object.step, object) if can_submit_form_response?(user, object)
|
||||||
|
list[:reset] = reset_step_form_response_path(object.step, object) if can_reset_form_response?(user, object)
|
||||||
|
|
||||||
list[:submit] = submit_step_form_response_path(object.step, object) if can_submit_form_response?(user, object)
|
if can_manage_step?(user, object.step)
|
||||||
list[:reset] = reset_step_form_response_path(object.step, object) if can_reset_form_response?(user, object)
|
list[:move_url] = move_step_form_response_path(object.step, object)
|
||||||
if can_manage_step?(user, object.step)
|
list[:move_targets_url] = move_targets_step_text_path(object.step, object)
|
||||||
list[:move_url] = move_step_form_response_path(object.step, object)
|
end
|
||||||
list[:move_targets_url] = move_targets_step_text_path(object.step, object)
|
|
||||||
list[:delete_url] = step_form_response_path(object.step, object)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
list[:delete_url] = step_form_response_path(object.step, object) if can_manage_step?(user, object.step)
|
||||||
|
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,13 +97,14 @@ class StepSerializer < ActiveModel::Serializer
|
||||||
create_table_url: step_tables_path(object),
|
create_table_url: step_tables_path(object),
|
||||||
create_text_url: step_texts_path(object),
|
create_text_url: step_texts_path(object),
|
||||||
create_checklist_url: step_checklists_path(object),
|
create_checklist_url: step_checklists_path(object),
|
||||||
create_form_response_url: step_form_responses_path(object),
|
|
||||||
update_asset_view_mode_url: update_asset_view_mode_step_path(object),
|
update_asset_view_mode_url: update_asset_view_mode_step_path(object),
|
||||||
update_view_state_url: update_view_state_step_path(object),
|
update_view_state_url: update_view_state_step_path(object),
|
||||||
direct_upload_url: rails_direct_uploads_url,
|
direct_upload_url: rails_direct_uploads_url,
|
||||||
upload_attachment_url: upload_attachment_step_path(object),
|
upload_attachment_url: upload_attachment_step_path(object),
|
||||||
reorder_elements_url: reorder_step_step_orderable_elements_path(step_id: object.id)
|
reorder_elements_url: reorder_step_step_orderable_elements_path(step_id: object.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
urls_list[:create_form_response_url] = step_form_responses_path(object) if Form.forms_enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
urls_list
|
urls_list
|
||||||
|
|
Loading…
Add table
Reference in a new issue