From 46631a1f46f93fe8802e94aef9978ef2e12c7bf7 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 7 Jun 2022 12:10:10 +0200 Subject: [PATCH] Finalize protocol repository [SCI-6870] --- app/assets/javascripts/protocols/index.js | 1 - .../stylesheets/protocols/protocol.scss | 1 + .../step_elements/base_controller.rb | 5 ++-- .../checklist_items_controller.rb | 2 +- .../step_elements/checklists_controller.rb | 2 +- .../step_elements/tables_controller.rb | 2 +- .../step_elements/texts_controller.rb | 2 +- app/javascript/vue/protocol/container.vue | 2 +- .../vue/protocol/mixins/attachments.js | 6 ++--- app/javascript/vue/protocol/step.vue | 2 ++ .../vue/protocol/step_elements/checklist.vue | 5 ++++ .../protocol/step_elements/checklistItem.vue | 24 +++++++++++++++---- .../vue/protocol/step_elements/table.vue | 4 ++++ .../vue/protocol/step_elements/text.vue | 4 ++++ app/serializers/checklist_serializer.rb | 2 +- app/serializers/protocol_serializer.rb | 4 ++-- app/serializers/step_text_serializer.rb | 2 +- app/serializers/table_serializer.rb | 2 +- 18 files changed, 51 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index cc46b477c..921cf04de 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -16,7 +16,6 @@ function init() { initKeywordFiltering(); initProtocolPreviewModal(); initLinkedChildrenModal(); - initCreateNewModal(); initModals(); initImport(); } diff --git a/app/assets/stylesheets/protocols/protocol.scss b/app/assets/stylesheets/protocols/protocol.scss index c83c99a07..a315c2347 100644 --- a/app/assets/stylesheets/protocols/protocol.scss +++ b/app/assets/stylesheets/protocols/protocol.scss @@ -7,6 +7,7 @@ .content-pane.protocols-show { background-color: $color-alto; margin: 0 -16px; + min-height: calc(100vh - var(--navbar-height)); overflow: hidden; padding: 36px 10px 10px; width: calc(100% + 31px); diff --git a/app/controllers/step_elements/base_controller.rb b/app/controllers/step_elements/base_controller.rb index efbb97548..4af41ccba 100644 --- a/app/controllers/step_elements/base_controller.rb +++ b/app/controllers/step_elements/base_controller.rb @@ -35,8 +35,10 @@ module StepElements end def log_step_activity(element_type_of, message_items) + message_items[:my_module] = @protocol.my_module.id if @protocol.in_module? + Activities::CreateActivityService.call( - activity_type: "#{@step.protocol.in_module? ? 'protocol_step_' : 'task_step_'}#{element_type_of}", + activity_type: "#{!@step.protocol.in_module? ? 'protocol_step_' : 'task_step_'}#{element_type_of}", owner: current_user, team: @protocol.in_module? ? @protocol.my_module.experiment.project.team : @protocol.team, project: @protocol.in_module? ? @protocol.my_module.experiment.project : nil, @@ -47,7 +49,6 @@ module StepElements id: @step.id, value_for: 'position_plus_one' }, - my_module: @protocol.my_module.id }.merge(message_items) ) end diff --git a/app/controllers/step_elements/checklist_items_controller.rb b/app/controllers/step_elements/checklist_items_controller.rb index 042100a41..465d2a526 100644 --- a/app/controllers/step_elements/checklist_items_controller.rb +++ b/app/controllers/step_elements/checklist_items_controller.rb @@ -124,7 +124,7 @@ module StepElements owner: current_user, subject: @step.protocol, team: @step.protocol.team, - project: @step.protocol.my_module.experiment.project, + project: @step.protocol.in_module? ? @step.protocol.my_module.experiment.project : nil, message_items: message_items ) end diff --git a/app/controllers/step_elements/checklists_controller.rb b/app/controllers/step_elements/checklists_controller.rb index 6df62f5c9..4ae72573d 100644 --- a/app/controllers/step_elements/checklists_controller.rb +++ b/app/controllers/step_elements/checklists_controller.rb @@ -23,7 +23,7 @@ module StepElements log_step_activity(:checklist_edited, { checklist_name: @checklist.name }) end - render json: @checklist, serializer: ChecklistSerializer + render json: @checklist, serializer: ChecklistSerializer, user: current_user rescue ActiveRecord::RecordInvalid head :unprocessable_entity end diff --git a/app/controllers/step_elements/tables_controller.rb b/app/controllers/step_elements/tables_controller.rb index aa3854e5c..b58b0edd6 100644 --- a/app/controllers/step_elements/tables_controller.rb +++ b/app/controllers/step_elements/tables_controller.rb @@ -28,7 +28,7 @@ module StepElements log_step_activity(:table_edited, { table_name: @table.name }) end - render json: @table, serializer: TableSerializer + render json: @table, serializer: TableSerializer, user: current_user rescue ActiveRecord::RecordInvalid head :unprocessable_entity end diff --git a/app/controllers/step_elements/texts_controller.rb b/app/controllers/step_elements/texts_controller.rb index dad1ca80e..4e33d1178 100644 --- a/app/controllers/step_elements/texts_controller.rb +++ b/app/controllers/step_elements/texts_controller.rb @@ -24,7 +24,7 @@ module StepElements log_step_activity(:text_edited, { text_name: @step_text.name }) end - render json: @step_text, serializer: StepTextSerializer + render json: @step_text, serializer: StepTextSerializer, user: current_user rescue ActiveRecord::RecordInvalid head :unprocessable_entity end diff --git a/app/javascript/vue/protocol/container.vue b/app/javascript/vue/protocol/container.vue index 3067cd726..589f3a81c 100644 --- a/app/javascript/vue/protocol/container.vue +++ b/app/javascript/vue/protocol/container.vue @@ -38,7 +38,7 @@ {{ protocol.attributes.name }} - + GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB * 1024 * 1024) { - fileObject.error = i18n.t('protocols.steps.attachments.new.file_too_big'); + fileObject.error = I18n.t('protocols.steps.attachments.new.file_too_big'); this.attachments.push(fileObject); return; } @@ -51,7 +51,7 @@ export default { upload.create((error, blob) => { if (error) { - fileObject.error = i18n.t('protocols.steps.attachments.new.general_error'); + fileObject.error = I18n.t('protocols.steps.attachments.new.general_error'); reject(error); } else { const signedId = blob.signed_id; diff --git a/app/javascript/vue/protocol/step.vue b/app/javascript/vue/protocol/step.vue index 1c766a30d..7f8f3b36f 100644 --- a/app/javascript/vue/protocol/step.vue +++ b/app/javascript/vue/protocol/step.vue @@ -69,6 +69,7 @@
-
+
- -
@@ -65,6 +65,10 @@ type: Boolean, default: false }, + inRepository: { + type: Boolean, + required: true + }, reorderChecklistItemUrl: { type: String } @@ -82,6 +86,16 @@ position: this.checklistItem.attributes.position } }); + }, + updateUrl() { + if (!this.checklistItem.attributes.urls) return + + return this.checklistItem.attributes.urls.update_url; + }, + deleteUrl() { + if (!this.checklistItem.attributes.urls) return + + return this.checklistItem.attributes.urls.delete_url; } }, methods: { @@ -94,7 +108,7 @@ this.$emit('editEnd'); }, toggleChecked(e) { - if (!this.checklistItem.attributes.urls.update_url) return + if (!this.updateUrl) return this.checklistItem.attributes.checked = this.$refs.checkbox.checked; this.update(); }, diff --git a/app/javascript/vue/protocol/step_elements/table.vue b/app/javascript/vue/protocol/step_elements/table.vue index 13fc7fd78..f3038d0d3 100644 --- a/app/javascript/vue/protocol/step_elements/table.vue +++ b/app/javascript/vue/protocol/step_elements/table.vue @@ -66,6 +66,10 @@ type: Object, required: true }, + inRepository: { + type: Boolean, + required: true + }, reorderElementUrl: { type: String } diff --git a/app/javascript/vue/protocol/step_elements/text.vue b/app/javascript/vue/protocol/step_elements/text.vue index 1438fd78e..3379de15a 100644 --- a/app/javascript/vue/protocol/step_elements/text.vue +++ b/app/javascript/vue/protocol/step_elements/text.vue @@ -46,6 +46,10 @@ type: Object, required: true }, + inRepository: { + type: Boolean, + required: true + }, reorderElementUrl: { type: String } diff --git a/app/serializers/checklist_serializer.rb b/app/serializers/checklist_serializer.rb index b9bb296a1..54943a2ca 100644 --- a/app/serializers/checklist_serializer.rb +++ b/app/serializers/checklist_serializer.rb @@ -12,7 +12,7 @@ class ChecklistSerializer < ActiveModel::Serializer end def urls - return {} if object.destroyed? || !can_manage_step?(scope[:user], object.step) + return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step) { delete_url: step_checklist_path(object.step, object), diff --git a/app/serializers/protocol_serializer.rb b/app/serializers/protocol_serializer.rb index 9b1c57657..cdb490f27 100644 --- a/app/serializers/protocol_serializer.rb +++ b/app/serializers/protocol_serializer.rb @@ -15,8 +15,8 @@ class ProtocolSerializer < ActiveModel::Serializer def added_by { - avatar: object.added_by.avatar_url(:icon_small), - name: object.added_by.full_name + avatar: object.added_by&.avatar_url(:icon_small), + name: object.added_by&.full_name } end diff --git a/app/serializers/step_text_serializer.rb b/app/serializers/step_text_serializer.rb index df654b5ce..3ee0ecfb5 100644 --- a/app/serializers/step_text_serializer.rb +++ b/app/serializers/step_text_serializer.rb @@ -29,7 +29,7 @@ class StepTextSerializer < ActiveModel::Serializer end def urls - return {} if object.destroyed? || !can_manage_step?(scope[:user], object.step) + return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step) { delete_url: step_text_path(object.step, object), diff --git a/app/serializers/table_serializer.rb b/app/serializers/table_serializer.rb index a33a573e3..5c6511821 100644 --- a/app/serializers/table_serializer.rb +++ b/app/serializers/table_serializer.rb @@ -19,7 +19,7 @@ class TableSerializer < ActiveModel::Serializer object.reload unless object.step - return {} unless can_manage_step?(scope[:user], object.step) + return {} unless can_manage_step?(scope[:user] || @instance_options[:user], object.step) { delete_url: step_table_path(object.step, object),