Archiving results doesn't work [SCI-9179]

This commit is contained in:
Giga Chubinidze 2023-09-05 11:55:15 +04:00
parent cb023cd9c8
commit b7da98c1dd
5 changed files with 33 additions and 2 deletions

View file

@ -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,

View file

@ -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((_) => {

View file

@ -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),

View file

@ -1141,6 +1141,7 @@ en:
option_delete: "Delete"
confirm_delete: "Are you sure you want to permanently delete result?"
delete_flash: "Successfully removed result <strong>%{result}</strong> from task <strong>%{module}</strong>."
archive_flash: "Successfully archived result <strong>%{result}</strong> in task <strong>%{module}</strong>"
archived_on: "Archived on"
archived_on_title: "Result archived on %{date} at %{time}."
option_download: "Download"

View file

@ -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