From 6dde945d619679e484ef3e940fdba741c426ef47 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 28 Apr 2022 11:13:38 +0200 Subject: [PATCH] Add step layout [SCI-6755] --- app/assets/stylesheets/application.scss | 1 + .../stylesheets/my_modules/protocol.scss | 30 ++++++++ .../my_modules/protocols/index.scss | 1 - app/assets/stylesheets/steps/step.scss | 55 ++++++++++++++ app/controllers/steps_controller.rb | 74 ++++++++++++------- app/javascript/vue/protocol/container.vue | 9 ++- app/javascript/vue/protocol/step.vue | 55 ++++++++++++-- app/javascript/vue/shared/inline_edit.vue | 2 +- app/serializers/step_serializer.rb | 4 +- db/structure.sql | 2 + 10 files changed, 195 insertions(+), 38 deletions(-) create mode 100644 app/assets/stylesheets/my_modules/protocol.scss create mode 100644 app/assets/stylesheets/steps/step.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d836c64a3..830297fe6 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -39,6 +39,7 @@ @import "reports/*"; @import "settings/*"; @import "shared/*"; +@import "steps/*"; @import "themes/*"; @import "*" diff --git a/app/assets/stylesheets/my_modules/protocol.scss b/app/assets/stylesheets/my_modules/protocol.scss new file mode 100644 index 000000000..681f1d49b --- /dev/null +++ b/app/assets/stylesheets/my_modules/protocol.scss @@ -0,0 +1,30 @@ +.task-protocol { + .insert-step { + align-items: center; + color: $color-concrete; + cursor: pointer; + display: flex; + + &::before, + &::after { + background-color: $color-concrete; + content: ''; + display: inline-block; + flex-grow: 1; + height: 3px; + } + + .fa-plus { + margin: 0 .5em; + } + + &:hover { + color: $brand-primary; + + &::before, + &::after { + background-color: $brand-primary; + } + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/my_modules/protocols/index.scss b/app/assets/stylesheets/my_modules/protocols/index.scss index 7dd6fbd40..6378f258d 100644 --- a/app/assets/stylesheets/my_modules/protocols/index.scss +++ b/app/assets/stylesheets/my_modules/protocols/index.scss @@ -27,7 +27,6 @@ } .task-section { - border-left: 3px solid $color-concrete; margin: 16px 0; padding-left: 16px; diff --git a/app/assets/stylesheets/steps/step.scss b/app/assets/stylesheets/steps/step.scss new file mode 100644 index 000000000..15842047b --- /dev/null +++ b/app/assets/stylesheets/steps/step.scss @@ -0,0 +1,55 @@ +.step-container { + padding: 8px 24px; + margin: 20px 0; + + .step-header { + align-items: center; + display: flex; + + .step-collapse-link { + display: inline-block; + line-height: 24px; + text-align: center; + width: 24px; + + &:not(.collapsed) { + @include rotate(90deg); + } + } + + .step-state { + border: 2px solid $color-alto; + border-radius: 50%; + cursor: pointer; + height: 24px; + text-align: center; + width: 24px; + + &.completed { + background: $brand-success; + border: 2px solid $brand-success; + + &::after { + @include font-awesome; + color: $color-white; + content: $font-fas-check; + } + } + } + + .step-position { + @include font-main; + line-height: 24px; + margin: 0 4px; + } + + .step-name-container { + flex-grow: 1; + } + + .step-actions-container { + display: flex; + justify-content: flex-end; + } + } +} \ No newline at end of file diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index 12af835c6..c8626590d 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -32,13 +32,21 @@ class StepsController < ApplicationController end def create - new_step = Step.new( + @step = Step.new( name: t('protocols.steps.default_name'), completed: false, user: current_user, last_modified_by: current_user ) - render json: @protocol.insert_step(new_step, params[:position]), serializer: StepSerializer + + @step = @protocol.insert_step(@step, params[:position]) + # Generate activity + if @protocol.in_module? + log_activity(:create_step, @my_module.experiment.project, my_module: @my_module.id) + else + log_activity(:add_step_to_protocol_repository, nil, protocol: @protocol.id) + end + render json: @step, serializer: StepSerializer end def create_old @@ -143,6 +151,20 @@ class StepsController < ApplicationController end def update + if @step.update(step_params) + # Generate activity + if @protocol.in_module? + log_activity(:edit_step, @my_module.experiment.project, my_module: @my_module.id) + else + log_activity(:edit_step_in_protocol_repository, nil, protocol: @protocol.id) + end + render json: @step, serializer: StepSerializer + else + render json: {}, status: :unprocessable_entity + end + end + + def update_old respond_to do |format| old_description = @step.description old_checklists = fetch_old_checklists_data(@step) @@ -327,34 +349,30 @@ class StepsController < ApplicationController # Complete/uncomplete step def toggle_step_state - respond_to do |format| - completed = params[:completed] == 'true' - changed = @step.completed != completed - @step.completed = completed - @step.last_modified_by = current_user + @step.completed = params[:completed] == 'true' + @step.last_modified_by = current_user - if @step.save - # Create activity - if changed - completed_steps = @protocol.steps.where(completed: true).count - all_steps = @protocol.steps.count + if @step.save + # Create activity + if @step.saved_change_to_completed + completed_steps = @protocol.steps.where(completed: true).count + all_steps = @protocol.steps.count - type_of = completed ? :complete_step : :uncomplete_step - # Toggling step state can only occur in - # module protocols, so my_module is always - # not nil; nonetheless, check if my_module is present - if @protocol.in_module? - log_activity(type_of, - @protocol.my_module.experiment.project, - my_module: @my_module.id, - num_completed: completed_steps.to_s, - num_all: all_steps.to_s) - end + type_of = @step.completed ? :complete_step : :uncomplete_step + # Toggling step state can only occur in + # module protocols, so my_module is always + # not nil; nonetheless, check if my_module is present + if @protocol.in_module? + log_activity(type_of, + @protocol.my_module.experiment.project, + my_module: @my_module.id, + num_completed: completed_steps.to_s, + num_all: all_steps.to_s) end - format.json { render json: {}, status: :ok } - else - format.json { render json: {}, status: :unprocessable_entity } end + render json: @step, serializer: StepSerializer + else + render json: {}, status: :unprocessable_entity end end @@ -514,6 +532,10 @@ class StepsController < ApplicationController end def step_params + params.require(:step).permit(:name) + end + + def step_params_old params.require(:step).permit( :name, :description, diff --git a/app/javascript/vue/protocol/container.vue b/app/javascript/vue/protocol/container.vue index 124b1b252..dda2c5db2 100644 --- a/app/javascript/vue/protocol/container.vue +++ b/app/javascript/vue/protocol/container.vue @@ -73,13 +73,13 @@
@@ -166,6 +166,9 @@ this.reorderSteps(unordered_steps) }, + updateStep(step) { + this.$set(this.steps, step.attributes.position, step) + }, reorderSteps(steps) { this.steps = steps.sort((a, b) => a.attributes.position - b.attributes.position); } diff --git a/app/javascript/vue/protocol/step.vue b/app/javascript/vue/protocol/step.vue index cec048f88..c3e95a758 100644 --- a/app/javascript/vue/protocol/step.vue +++ b/app/javascript/vue/protocol/step.vue @@ -1,15 +1,42 @@