Implement GUI for copying repositories

Closes SCI.1270.
This commit is contained in:
Luka Murn 2017-06-07 19:11:25 +02:00
parent 38361e4bb4
commit 61eb52f86f
5 changed files with 99 additions and 0 deletions

View file

@ -3,6 +3,8 @@ class RepositoriesController < ApplicationController
before_action :check_view_all_permissions, only: :index
before_action :check_edit_and_destroy_permissions, only:
%(destroy destroy_modal rename_modal update)
before_action :check_copy_permissions, only:
%(copy_modal copy)
before_action :check_create_permissions, only:
%(create_new_modal create)
@ -99,6 +101,58 @@ class RepositoriesController < ApplicationController
end
end
def copy_modal
@repository = Repository.find(params[:repository_id])
@tmp_repository = Repository.new(
team: @team,
created_by: current_user,
name: @repository.name
)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: 'copy_repository_modal.html.erb'
)
}
end
end
end
def copy
@repository = Repository.find(params[:repository_id])
@tmp_repository = Repository.new(
team: @team,
created_by: current_user
)
@tmp_repository.assign_attributes(repository_params)
respond_to do |format|
format.json do
if !@tmp_repository.valid?
render json: @tmp_repository.errors, status: :unprocessable_entity
else
copied_repository =
@repository.copy(current_user, @tmp_repository.name)
if !copied_repository
render json: { 'name': ['Server error'] },
status: :unprocessable_entity
else
flash[:success] = t(
'repositories.index.copy_flash',
old: @repository.name,
new: copied_repository.name
)
render json: {
url: team_repositories_path(repository: copied_repository)
}, status: :ok
end
end
end
end
end
# AJAX actions
def repository_table_index
@repository = Repository.find_by_id(params[:repository_id])
@ -137,6 +191,10 @@ class RepositoriesController < ApplicationController
render_403 unless can_edit_and_destroy_repository(@repository)
end
def check_copy_permissions
render_403 unless can_copy_repository(@repository)
end
def repository_params
params.require(:repository).permit(:name)
end

View file

@ -18,6 +18,7 @@ class RepositoryTableState < ActiveRecord::Base
user: user,
repository: custom_column.repository
)
return if table_state.empty?
repository_state = table_state.first['state']
if column_index
# delete column

View file

@ -0,0 +1,32 @@
<div class="modal fade" id="copy-repo-modal" tabindex="-1" role="dialog">
<%= bootstrap_form_for @tmp_repository,
url: team_repository_copy_path(id: @repository, format: :json),
remote: true do |f| %>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title"><%= t("repositories.index.modal_copy.title_html", name: @repository.name ) %></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<%= f.text_field :name,
label: t("repositories.index.modal_copy.name"),
autofocus: true,
placeholder: t("repositories.index.modal_copy.name_placeholder") %>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<%= f.submit t("repositories.index.modal_copy.copy"), class: "btn btn-primary" %>
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t "general.cancel" %></button>
</div>
</div>
</div>
<% end %>
</div>

View file

@ -843,6 +843,7 @@ en:
add_new_repository_tab: "Create new repository"
delete_flash: "\"%{name}\" repository was successfully deleted!"
rename_flash: "\"%{old_name}\" repository was successfully renamed to \"%{new_name}\"!"
copy_flash: "\"%{new}\" repository was successfully copied from \"%{old}\"!"
no_teams:
title: "Your dashboard is empty!"
text: "It seems you're not a member of any team. See team management to sort it out."
@ -863,6 +864,11 @@ en:
name: "New repository name"
name_placeholder: "My repository"
rename: "Rename repository"
modal_copy:
title_html: "Copy repository <em>%{name}</em>"
name: "New repository name"
name_placeholder: "My repository"
copy: "Copy repository"
modal_create:
title: "Create new repository"
name_label: "Repository name"

View file

@ -134,6 +134,8 @@ Rails.application.routes.draw do
defaults: { format: 'json' }
get 'copy_modal', to: 'repositories#copy_modal',
defaults: { format: 'json' }
post 'copy', to: 'repositories#copy',
defaults: { format: 'json' }
end
resources :samples, only: [:new, :create]
resources :sample_types, except: [:show, :new] do