mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-01 02:05:41 +08:00
Added rename logic and improved remove logic. [SCI-1269]
This commit is contained in:
parent
cdaac6a01b
commit
21a72da84f
7 changed files with 143 additions and 11 deletions
|
@ -2,7 +2,11 @@
|
|||
'use strict';
|
||||
|
||||
// Show modal for repository deletion
|
||||
$(document).on('click', '#delete-repo-option', function() {
|
||||
$(document).on('click', '#delete-repo-option', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
var url = $(this).attr('href');
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
|
@ -15,5 +19,59 @@
|
|||
keyboard: false
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Show modal for repository renaming
|
||||
$(document).on('click', '#rename-repo-option', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
var url = $(this).attr('href');
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
}).done(function(xhr, settings, data) {
|
||||
$('body').append($.parseHTML(data.responseJSON.html));
|
||||
$('#rename-repo-modal').modal('show', {
|
||||
backdrop: true,
|
||||
keyboard: false
|
||||
});
|
||||
validateRenameForm($('#rename-repo-modal'));
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* Reload after successfully updated experiment
|
||||
* @param {object} $modal Modal object
|
||||
*/
|
||||
function validateRenameForm($modal) {
|
||||
if ($modal) {
|
||||
var form = $modal.find('form');
|
||||
form
|
||||
.on('ajax:success', function() {
|
||||
animateSpinner(form, true);
|
||||
location.reload();
|
||||
})
|
||||
.on('ajax:error', function(e, error) {
|
||||
var msg = JSON.parse(error.responseText);
|
||||
if ('name' in msg) {
|
||||
renderFormError(e,
|
||||
$modal.find('#repository_name'),
|
||||
msg.name.toString(),
|
||||
true);
|
||||
} else {
|
||||
renderFormError(e,
|
||||
$modal.find('#experiment-name'),
|
||||
error.statusText,
|
||||
true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -21,10 +21,39 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
def destroy
|
||||
@repo = Repository.find(params[:id])
|
||||
@repo.destroy if @repo
|
||||
flash[:success] = t('repositories.index.delete_flash', name: @repo.name)
|
||||
@repo.destroy
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
def rename_modal
|
||||
@repository = Repository.find(params[:repository_id])
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'rename_repository_modal.html.erb'
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@repo = Repository.find(params[:id])
|
||||
old_name = @repo.name
|
||||
@repo.update_attributes(repository_params)
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render inline: 'location.reload();' }
|
||||
format.json do
|
||||
if @repo.save
|
||||
flash[:success] = t('repositories.index.rename_flash',
|
||||
old_name: old_name, new_name: @repo.name)
|
||||
render json: {}, status: :ok
|
||||
else
|
||||
render json: @repo.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,4 +68,8 @@ class RepositoriesController < ApplicationController
|
|||
def check_view_all_permissions
|
||||
render_403 unless can_view_team_repositories(@team)
|
||||
end
|
||||
|
||||
def repository_params
|
||||
params.require(:repository).permit(:name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
team_repository_path(id: @repository),
|
||||
id: "confirm-repo-delete",
|
||||
method: :delete,
|
||||
remote: true,
|
||||
type: 'button',
|
||||
class: 'btn btn-primary' %>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel")%></button>
|
||||
|
|
33
app/views/repositories/_rename_repository_modal.html.erb
Normal file
33
app/views/repositories/_rename_repository_modal.html.erb
Normal file
|
@ -0,0 +1,33 @@
|
|||
<div class="modal"
|
||||
id="rename-repo-modal"
|
||||
tabindex="-1"
|
||||
role="dialog">
|
||||
<%= bootstrap_form_for @repository,
|
||||
url: team_repository_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">×</span></button>
|
||||
<h4 class="modal-title"><%= t("repositories.index.modal_rename.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_rename.name"),
|
||||
autofocus: true,
|
||||
placeholder: t("repositories.index.modal_rename.name_placeholder") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<%= f.submit t("repositories.index.modal_rename.copy"), class: "btn btn-primary" %>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t "general.cancel" %></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
|
@ -37,9 +37,9 @@
|
|||
<%= t("repositories.index.options_dropdown.header") %>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">
|
||||
<%= t("repositories.index.options_dropdown.rename") %>
|
||||
</a>
|
||||
<%= link_to t('repositories.index.options_dropdown.rename'),
|
||||
team_repository_rename_modal_path(repository_id: repo),
|
||||
id: "rename-repo-option" %>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">
|
||||
|
@ -50,8 +50,7 @@
|
|||
<li>
|
||||
<%= link_to t('repositories.index.modal_delete.delete'),
|
||||
team_repository_destroy_modal_path(repository_id: repo),
|
||||
id: "delete-repo-option",
|
||||
remote: true %>
|
||||
id: "delete-repo-option" %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -153,6 +153,8 @@ en:
|
|||
head_title: "Repositories"
|
||||
title: "Repositories"
|
||||
no_repositories: "No repositories"
|
||||
delete_flash: "\"%{name}\" repository was successfully deleted!"
|
||||
rename_flash: "\"%{old_name}\" repository was successfully renamed to \"%{new_name}\"!"
|
||||
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."
|
||||
|
@ -168,6 +170,11 @@ en:
|
|||
alert_line_1: "all data inside the repository will be lost;"
|
||||
alert_line_2: "all references to repository items will be rendered as invalid."
|
||||
delete: "Delete repository"
|
||||
modal_rename:
|
||||
title_html: "Rename repository <em>%{name}</em>"
|
||||
name: "New repository name"
|
||||
name_placeholder: "My repository"
|
||||
copy: "Copy repository"
|
||||
nav:
|
||||
breadcrumbs:
|
||||
repositories: "Repositories"
|
||||
|
|
|
@ -123,8 +123,11 @@ Rails.application.routes.draw do
|
|||
as: 'file_expired'
|
||||
|
||||
resources :teams do
|
||||
resources :repositories, only: [:index, :destroy] do
|
||||
get 'destroy_modal', to: 'repositories#destroy_modal'
|
||||
resources :repositories, only: [:index, :destroy, :update] do
|
||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||
defaults: { format: 'json' }
|
||||
get 'rename_modal', to: 'repositories#rename_modal',
|
||||
defaults: { format: 'json' }
|
||||
end
|
||||
resources :samples, only: [:new, :create]
|
||||
resources :sample_types, except: [:show, :new] do
|
||||
|
|
Loading…
Reference in a new issue