SCI-4780 Added archive and restore items to repository actions dropdown, minor refactoring of controller

This commit is contained in:
miha 2020-06-23 22:59:21 +02:00
parent efbc05e00e
commit 41bb825f33
8 changed files with 46 additions and 25 deletions

View file

@ -173,7 +173,21 @@
});
$('.create-new-repository').initializeModal('#create-repo-modal');
function initArchivingActionsInDropdown(){
$('.archive-repository-option').on('click', function(event){
event.preventDefault();
var link = event.target.getAttribute("href");
$.ajax({
type: 'GET',
url: link,
success: pageReload
});
});
}
initImportRecordsModal();
initTable();
initRepositoryViewSwitcher();
initArchivingActionsInDropdown();
}(window));

View file

@ -128,7 +128,7 @@ class RepositoriesController < ApplicationController
end
def archive
service = Repositories::ArchiveRepositoryService.call(repositories: selected_repos_params,
service = Repositories::ArchiveRepositoryService.call(repositories: selected_repositories,
user: current_user,
team: current_team)
if service.succeed?
@ -139,7 +139,7 @@ class RepositoriesController < ApplicationController
end
def restore
service = Repositories::RestoreRepositoryService.call(repositories: selected_repos_params,
service = Repositories::RestoreRepositoryService.call(repositories: selected_repositories,
user: current_user,
team: current_team)
if service.succeed?
@ -430,9 +430,15 @@ class RepositoriesController < ApplicationController
params.permit(:id, :file, :file_id, mappings: {}).to_h
end
def selected_repos_params
process_ids = params[:selected_repos].map(&:to_i).uniq
Repository.where(id: process_ids, team_id: current_team).pluck(:id)
def selected_repositories
if params[:repository_id].present?
repository_ids = params[:repository_id]
elsif params[:selected_repos].any?
repository_ids = params[:selected_repos].map(&:to_i).uniq
else
render status: :not_found
end
current_team.repositories.where(id: repository_ids)
end
def repository_response(message)

View file

@ -9,7 +9,7 @@ module Repositories
def initialize(user:, team:, repositories:)
@user = user
@team = team
@repositories = scoped_repositories(repositories)
@repositories = repositories
@errors = {}
end
@ -27,10 +27,6 @@ module Repositories
private
def scoped_repositories(_ids)
raise NotImplementedError
end
def valid?
unless @user
@errors[:invalid_arguments] =

View file

@ -24,11 +24,5 @@ module Repositories
self
end
private
def scoped_repositories(ids)
Repository.where(id: ids, team_id: @team)
end
end
end

View file

@ -24,11 +24,5 @@ module Repositories
self
end
private
def scoped_repositories(ids)
Repository.where(id: ids, team_id: @team)
end
end
end

View file

@ -94,12 +94,25 @@
<% end %>
<% if can_manage_repository?(@repository)%>
<li data-view-mode="active" data-hook="destroy-repository-option" role="separator" class="divider"></li>
<li data-view-mode="active" data-hook="destroy-repository-option">
<li data-view-mode="active" data-hook="archive-repository-option">
<%= link_to t('repositories.index.options_dropdown.archive'),
team_repository_archive_path(current_team, @repository),
class: "archive-repository-option",
remote: true %>
</li>
<li data-view-mode="archived" data-hook="restore-repository-option">
<%= link_to t('repositories.index.options_dropdown.restore'),
team_repository_restore_path(current_team, @repository),
class: "archive-repository-option",
remote: true %>
</li>
<li data-view-mode="archived" data-hook="destroy-repository-option">
<%= link_to t('repositories.index.options_dropdown.delete'),
team_repository_destroy_modal_path(current_team, repository_id: @repository),
class: "delete-repo-option",
remote: true %>
</li>
<% end %>
</ul>
<% end %>

View file

@ -1086,6 +1086,8 @@ en:
rename: "Rename inventory"
copy: "Copy inventory"
delete: "Delete inventory"
archive: 'Archive inventory'
restore: 'Restore inventory'
modal_delete:
title_html: "Delete inventory <em>%{name}</em>"
message_html: "Are you sure you want to delete inventory <em>%{name}</em>? This action is irreversible."

View file

@ -180,6 +180,8 @@ Rails.application.routes.draw do
post 'copy', to: 'repositories#copy',
defaults: { format: 'json' }
get :share_modal
get :archive, to: 'repositories#archive'
get :restore, to: 'repositories#restore'
resources :team_repositories, only: %i(destroy) do
collection do