mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +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
|
||||
|
||||
class FormFieldValuesController < ApplicationController
|
||||
before_action :check_forms_enabled
|
||||
before_action :load_form_response
|
||||
before_action :load_form_field
|
||||
before_action :check_create_permissions
|
||||
|
@ -40,6 +41,10 @@ class FormFieldValuesController < ApplicationController
|
|||
render_403 unless can_submit_form_response?(@form_response)
|
||||
end
|
||||
|
||||
def check_forms_enabled
|
||||
render_404 unless Form.forms_enabled?
|
||||
end
|
||||
|
||||
def log_form_field_value_create_activity
|
||||
step = @form_response.step
|
||||
protocol = step.protocol
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FormFieldsController < ApplicationController
|
||||
before_action :check_forms_enabled
|
||||
before_action :load_form
|
||||
before_action :load_form_field, only: %i(update destroy)
|
||||
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)
|
||||
end
|
||||
|
||||
def check_forms_enabled
|
||||
render_404 unless Form.forms_enabled?
|
||||
end
|
||||
|
||||
def log_activity(type_of, message_items = {})
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
class FormsController < ApplicationController
|
||||
include UserRolesHelper
|
||||
|
||||
before_action :check_forms_enabled
|
||||
before_action :load_form, only: %i(show update publish unpublish export_form_responses)
|
||||
before_action :set_breadcrumbs_items, only: %i(index show)
|
||||
before_action :check_manage_permissions, only: :update
|
||||
|
@ -221,6 +222,10 @@ class FormsController < ApplicationController
|
|||
params.require(:form).permit(:name, :description)
|
||||
end
|
||||
|
||||
def check_forms_enabled
|
||||
render_404 unless Form.forms_enabled?
|
||||
end
|
||||
|
||||
def log_activity(form, type_of, message_items = {})
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
module StepElements
|
||||
class FormResponsesController < BaseController
|
||||
before_action :check_forms_enabled, except: %i(destroy)
|
||||
before_action :load_form, only: :create
|
||||
before_action :load_step, only: :create
|
||||
before_action :load_form_response, except: :create
|
||||
|
@ -90,6 +91,10 @@ module StepElements
|
|||
render_404 unless @form_response
|
||||
end
|
||||
|
||||
def check_forms_enabled
|
||||
render_404 unless Form.forms_enabled?
|
||||
end
|
||||
|
||||
def log_step_form_activity(element_type_of, message_items = {})
|
||||
message_items[:my_module] = @protocol.my_module.id if @protocol.in_module?
|
||||
|
||||
|
|
|
@ -34,19 +34,7 @@ module LeftMenuBarHelper
|
|||
name: t('left_menu_bar.templates'),
|
||||
icon: 'sn-icon-protocols-templates',
|
||||
active: protocols_are_selected? || label_templates_are_selected? || forms_are_selected?,
|
||||
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?
|
||||
}]
|
||||
submenu: template_submenu
|
||||
}, {
|
||||
url: reports_path,
|
||||
name: t('left_menu_bar.reports'),
|
||||
|
@ -103,4 +91,27 @@ module LeftMenuBarHelper
|
|||
def activities_are_selected?
|
||||
controller_name == 'global_activities'
|
||||
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
|
||||
|
|
|
@ -410,14 +410,18 @@
|
|||
emit: 'create:checklist',
|
||||
icon: 'sn-icon sn-icon-checkllist',
|
||||
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;
|
||||
},
|
||||
actionsMenu() {
|
||||
|
|
|
@ -65,6 +65,10 @@ class Form < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.forms_enabled?
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_automatic_user_assignments
|
||||
|
|
|
@ -30,19 +30,21 @@ class StepFormResponseSerializer < ActiveModel::Serializer
|
|||
|
||||
def urls
|
||||
user = scope[:user] || @instance_options[:user]
|
||||
list = {}
|
||||
|
||||
list = {
|
||||
add_value: form_response_form_field_values_path(object)
|
||||
}
|
||||
if Form.forms_enabled?
|
||||
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)
|
||||
list[:reset] = reset_step_form_response_path(object.step, object) if can_reset_form_response?(user, object)
|
||||
if can_manage_step?(user, object.step)
|
||||
list[:move_url] = move_step_form_response_path(object.step, object)
|
||||
list[:move_targets_url] = move_targets_step_text_path(object.step, object)
|
||||
list[:delete_url] = step_form_response_path(object.step, object)
|
||||
if can_manage_step?(user, object.step)
|
||||
list[:move_url] = move_step_form_response_path(object.step, object)
|
||||
list[:move_targets_url] = move_targets_step_text_path(object.step, object)
|
||||
end
|
||||
end
|
||||
|
||||
list[:delete_url] = step_form_response_path(object.step, object) if can_manage_step?(user, object.step)
|
||||
|
||||
list
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,13 +97,14 @@ class StepSerializer < ActiveModel::Serializer
|
|||
create_table_url: step_tables_path(object),
|
||||
create_text_url: step_texts_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_view_state_url: update_view_state_step_path(object),
|
||||
direct_upload_url: rails_direct_uploads_url,
|
||||
upload_attachment_url: upload_attachment_step_path(object),
|
||||
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
|
||||
|
||||
urls_list
|
||||
|
|
Loading…
Add table
Reference in a new issue