From b7da98c1dd6236f6a1d4fb5dec5dfae380a7d1d7 Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Tue, 5 Sep 2023 11:55:15 +0400 Subject: [PATCH 1/2] Archiving results doesn't work [SCI-9179] --- app/controllers/results_controller.rb | 23 ++++++++++++++++++++++- app/javascript/vue/results/result.vue | 7 ++++++- app/serializers/result_serializer.rb | 1 + config/locales/en.yml | 1 + config/routes.rb | 3 +++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/controllers/results_controller.rb b/app/controllers/results_controller.rb index f2e96f055..cadbc21e3 100644 --- a/app/controllers/results_controller.rb +++ b/app/controllers/results_controller.rb @@ -14,7 +14,7 @@ class ResultsController < ApplicationController respond_to do |format| format.json do # API endpoint - @results = @my_module.results + @results = @my_module.results.active apply_sort! apply_filters! @@ -46,6 +46,27 @@ class ResultsController < ApplicationController render json: @result end + def archive + result = @my_module.results.find(params[:result_id]) + result.archive(current_user) + + if result.save + Activities::CreateActivityService + .call(activity_type: :destroy_result, + owner: current_user, + subject: result, + team: @my_module.team, + project: @my_module.project, + message_items: { result: result.id }) + + flash[:success] = t('my_modules.module_archive.archive_flash', + result: result.name, + module: @my_module.name) + + redirect_to my_module_results_path(@my_module) + end + end + def elements render json: @result.result_orderable_elements.order(:position), each_serializer: ResultOrderableElementSerializer, diff --git a/app/javascript/vue/results/result.vue b/app/javascript/vue/results/result.vue index d3845ffd0..1eea57fec 100644 --- a/app/javascript/vue/results/result.vue +++ b/app/javascript/vue/results/result.vue @@ -327,7 +327,12 @@ }); }, archiveResult() { - + if (this.urls.archive_url) { + axios.post(this.urls.archive_url).then((response) => { + this.$emit('resultArchived', response.data); + location.reload(); + }); + } }, duplicateResult() { axios.post(this.urls.duplicate_url).then((_) => { diff --git a/app/serializers/result_serializer.rb b/app/serializers/result_serializer.rb index dd8010d04..7cc6b8148 100644 --- a/app/serializers/result_serializer.rb +++ b/app/serializers/result_serializer.rb @@ -73,6 +73,7 @@ class ResultSerializer < ActiveModel::Serializer if can_manage_result?(object) urls_list.merge!({ delete_url: result_path(object), + archive_url: my_module_result_archive_path(object.my_module, object), update_url: my_module_result_path(object.my_module, object), create_table_url: my_module_result_tables_path(object.my_module, object), create_text_url: my_module_result_texts_path(object.my_module, object), diff --git a/config/locales/en.yml b/config/locales/en.yml index 874210977..e59be1f40 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1141,6 +1141,7 @@ en: option_delete: "Delete" confirm_delete: "Are you sure you want to permanently delete result?" delete_flash: "Successfully removed result %{result} from task %{module}." + archive_flash: "Successfully archived result %{result} in task %{module}" archived_on: "Archived on" archived_on_title: "Result archived on %{date} at %{time}." option_download: "Download" diff --git a/config/routes.rb b/config/routes.rb index 05179fcc6..3ca2d4b14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ Rails.application.routes.draw do post 'access_tokens/revoke', to: 'doorkeeper/access_tokens#revoke' # Addons + mount Scinote::AI::Engine => '/' + def draw(routes_name) instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) @@ -555,6 +557,7 @@ Rails.application.routes.draw do post :duplicate end end + post 'archive', to: 'results#archive' end end From ff7743b7e8566b127365d60f240b9ff406ee46ac Mon Sep 17 00:00:00 2001 From: G-Chubinidze <112488503+G-Chubinidze@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:57:47 +0400 Subject: [PATCH 2/2] Update routes.rb --- config/routes.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 3ca2d4b14..09e3d586f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,8 +6,6 @@ Rails.application.routes.draw do post 'access_tokens/revoke', to: 'doorkeeper/access_tokens#revoke' # Addons - mount Scinote::AI::Engine => '/' - def draw(routes_name) instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))