mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-18 22:58:53 +08:00
create new repository
This commit is contained in:
parent
876fcfc979
commit
13bf4ad229
9 changed files with 207 additions and 61 deletions
|
|
@ -4,3 +4,54 @@
|
||||||
$('.delete-repo-option').initializeModal('#delete-repo-modal');
|
$('.delete-repo-option').initializeModal('#delete-repo-modal');
|
||||||
$('.rename-repo-option').initializeModal('#rename-repo-modal');
|
$('.rename-repo-option').initializeModal('#rename-repo-modal');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// create new
|
||||||
|
function init() {
|
||||||
|
initCreateNewModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initCreateNewModal() {
|
||||||
|
var link = $("[data-action='create-new-repository']");
|
||||||
|
var modal = $("#create-new-modal");
|
||||||
|
var submitBtn = modal.find(".modal-footer [data-action='submit']");
|
||||||
|
|
||||||
|
link.on("click", function() {
|
||||||
|
$.ajax({
|
||||||
|
url: link.attr("data-url"),
|
||||||
|
type: "GET",
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
var modalBody = modal.find(".modal-body");
|
||||||
|
modalBody.html(data.html);
|
||||||
|
|
||||||
|
modalBody.find("form")
|
||||||
|
.on("ajax:success", function(ev2, data2, status2) {
|
||||||
|
// Redirect to index page
|
||||||
|
$(location).attr("href", data2.url);
|
||||||
|
})
|
||||||
|
.on("ajax:error", function(ev2, data2, status2) {
|
||||||
|
// Display errors if needed
|
||||||
|
$(this).renderFormErrors("repository", data2.responseJSON);
|
||||||
|
});
|
||||||
|
|
||||||
|
modal.modal("show");
|
||||||
|
modalBody.find("input[type='text']").focus();
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
submitBtn.on("click", function() {
|
||||||
|
// Submit the form inside modal
|
||||||
|
$(this).closest(".modal").find(".modal-body form").submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
modal.on("hidden.bs.modal", function(e) {
|
||||||
|
modal.find(".modal-body form").off("ajax:success ajax:error");
|
||||||
|
modal.find(".modal-body").html("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,51 @@ class RepositoriesController < ApplicationController
|
||||||
before_action :check_view_all_permissions, only: :index
|
before_action :check_view_all_permissions, only: :index
|
||||||
before_action :check_edit_and_destroy_permissions, only:
|
before_action :check_edit_and_destroy_permissions, only:
|
||||||
%(destroy destroy_modal rename_modal update)
|
%(destroy destroy_modal rename_modal update)
|
||||||
|
before_action :check_create_permissions, only: [
|
||||||
|
:create_new_modal,
|
||||||
|
:create
|
||||||
|
]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render('repositories/index')
|
render('repositories/index')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_new_modal
|
||||||
|
@new_repository = Repository.new
|
||||||
|
respond_to do |format|
|
||||||
|
format.json {
|
||||||
|
render json: {
|
||||||
|
html: render_to_string({
|
||||||
|
partial: "repositories/index/create_new_modal_body.html.erb"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@repository = Repository.new(
|
||||||
|
team: @team,
|
||||||
|
created_by: current_user
|
||||||
|
)
|
||||||
|
@repository.assign_attributes(repository_params)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @repository.save
|
||||||
|
flash[:success] = t("repositories.create.success_flash", name: @repository.name)
|
||||||
|
format.json {
|
||||||
|
render json: { url: team_repositories_path(@team, create_action: true) },
|
||||||
|
status: :ok
|
||||||
|
}
|
||||||
|
else
|
||||||
|
format.json {
|
||||||
|
render json: @repository.errors,
|
||||||
|
status: :unprocessable_entity
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_modal
|
def destroy_modal
|
||||||
@repository = Repository.find(params[:repository_id])
|
@repository = Repository.find(params[:repository_id])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
@ -74,6 +114,11 @@ class RepositoriesController < ApplicationController
|
||||||
render_403 unless can_view_team_repositories(@team)
|
render_403 unless can_view_team_repositories(@team)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_create_permissions
|
||||||
|
render_403 unless can_create_new_repository(@team) &&
|
||||||
|
@repositories.count < Constants::REPOSITORIES_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
def check_edit_and_destroy_permissions
|
def check_edit_and_destroy_permissions
|
||||||
render_403 unless can_edit_and_destroy_repository(@repository)
|
render_403 unless can_edit_and_destroy_repository(@repository)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1053,6 +1053,10 @@ module PermissionHelper
|
||||||
is_member_of_team(team)
|
is_member_of_team(team)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_create_new_repository(team)
|
||||||
|
is_admin_of_team(team)
|
||||||
|
end
|
||||||
|
|
||||||
def can_view_repositories(team)
|
def can_view_repositories(team)
|
||||||
is_normal_user_or_admin_of_team(team)
|
is_normal_user_or_admin_of_team(team)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,68 +4,80 @@
|
||||||
<%= render partial: "repositories/breadcrumbs.html.erb",
|
<%= render partial: "repositories/breadcrumbs.html.erb",
|
||||||
locals: { teams: @teams, current_team: current_team, type: @type } %>
|
locals: { teams: @teams, current_team: current_team, type: @type } %>
|
||||||
|
|
||||||
|
<% active_repo = @repositories.find_by_id(params[:repository]) %>
|
||||||
|
<% active_repo = @repositories.first if !active_repo %>
|
||||||
|
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<% if @repositories.present? %>
|
<ul class="nav nav-tabs nav-settings" role="tablist" id="tabs">
|
||||||
<% active_repo = @repositories.find_by_id(params[:repository]) %>
|
<% @repositories.each do |repo| %>
|
||||||
<% active_repo = @repositories.first if !active_repo %>
|
<li role="presentation" class="<%= 'active' if repo == active_repo %>">
|
||||||
|
<a href="#custom_repo_<%= repo.id %>"
|
||||||
|
data-toggle="tab"
|
||||||
|
aria-controls="custom_repo_<%= repo.id %>"
|
||||||
|
title="<%=repo.name%>"><%= truncate(repo.name, length: Constants::NAME_TRUNCATION_LENGTH) %></a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
<!-- Add new repository tab -->
|
||||||
|
<li role="presentation"
|
||||||
|
<% unless can_create_new_repository(current_team) &&
|
||||||
|
@repositories.count < Constants::REPOSITORIES_LIMIT %>
|
||||||
|
class="disabled"
|
||||||
|
<% end %>>
|
||||||
|
<a href='#'
|
||||||
|
data-url="<%= create_new_modal_team_repositories_path %>"
|
||||||
|
<% if can_create_new_repository(current_team) &&
|
||||||
|
@repositories.count < Constants::REPOSITORIES_LIMIT %>
|
||||||
|
data-action='create-new-repository'
|
||||||
|
<% end %>>
|
||||||
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
|
<span class="hidden-xs"> <%= t('repositories.index.add_new_repository_tab') %></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<ul class="nav nav-tabs nav-settings" role="tablist" id="tabs">
|
<!-- Tab panes -->
|
||||||
<% @repositories.each do |repo| %>
|
<div class="tab-content">
|
||||||
<li role="presentation" class="<%= 'active' if repo == active_repo %>">
|
<% @repositories.each do |repo| %>
|
||||||
<a class="repository-nav-tab"
|
<div class="tab-pane tab-pane-settings <%= 'active' if repo == active_repo %>" id="custom_repo_<%= repo.id %>">
|
||||||
href="#custom_repo_<%= repo.id %>"
|
|
||||||
data-toggle="tab"
|
|
||||||
aria-controls="custom_repo_<%= repo.id %>"
|
|
||||||
title="<%=repo.name%>"><%= truncate(repo.name, length: Constants::NAME_TRUNCATION_LENGTH) %></a>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
<!-- Tab panes -->
|
|
||||||
<div class="tab-content">
|
|
||||||
<% @repositories.each do |repo| %>
|
|
||||||
<div class="tab-pane tab-pane-settings <%= 'active' if repo == active_repo %>" id="custom_repo_<%= repo.id %>">
|
|
||||||
<!-- Tab Content -->
|
|
||||||
|
|
||||||
<div id="repository-toolbar">
|
<!-- Tab Content -->
|
||||||
<div class="dropdown text-right">
|
<div id="repository-toolbar">
|
||||||
<div class="btn btn-default btn-xs"
|
<div class="dropdown text-right">
|
||||||
type="button"
|
<div class="btn btn-default btn-xs"
|
||||||
data-toggle="dropdown"
|
type="button"
|
||||||
aria-haspopup="true"
|
data-toggle="dropdown"
|
||||||
aria-expanded="true"
|
aria-haspopup="true"
|
||||||
<%= "disabled='disabled'" if !can_edit_and_destroy_repository repo %>>
|
aria-expanded="true"
|
||||||
<span class="glyphicon glyphicon-cog"></span>
|
<%= "disabled='disabled'" if !can_edit_and_destroy_repository repo %>>
|
||||||
<span class="caret"></span>
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
</div>
|
<span class="caret"></span>
|
||||||
<% if can_edit_and_destroy_repository repo %>
|
|
||||||
<ul class="dropdown-menu pull-right">
|
|
||||||
<li class="dropdown-header">
|
|
||||||
<%= t("repositories.index.options_dropdown.header") %>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<%= link_to t('repositories.index.options_dropdown.rename'),
|
|
||||||
team_repository_rename_modal_path(repository_id: repo),
|
|
||||||
class: "rename-repo-option",
|
|
||||||
remote: true %>
|
|
||||||
</li>
|
|
||||||
<li role="separator" class="divider"></li>
|
|
||||||
<li>
|
|
||||||
<%= link_to t('repositories.index.modal_delete.delete'),
|
|
||||||
team_repository_destroy_modal_path(repository_id: repo),
|
|
||||||
class: "delete-repo-option",
|
|
||||||
remote: true %>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
<% if can_edit_and_destroy_repository repo %>
|
||||||
|
<ul class="dropdown-menu pull-right">
|
||||||
|
<li class="dropdown-header">
|
||||||
|
<%= t("repositories.index.options_dropdown.header") %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<%= link_to t('repositories.index.options_dropdown.rename'),
|
||||||
|
team_repository_rename_modal_path(repository_id: repo),
|
||||||
|
class: "rename-repo-option",
|
||||||
|
remote: true %>
|
||||||
|
</li>
|
||||||
|
<li role="separator" class="divider"></li>
|
||||||
|
<li>
|
||||||
|
<%= link_to t('repositories.index.modal_delete.delete'),
|
||||||
|
team_repository_destroy_modal_path(repository_id: repo),
|
||||||
|
class: "delete-repo-option",
|
||||||
|
remote: true %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% end %>
|
||||||
<p><em><%=t 'repositories.index.no_repositories' %></em></p>
|
</div>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<!-- If member of no teams -->
|
<!-- If member of no teams -->
|
||||||
|
|
@ -76,3 +88,4 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= javascript_include_tag "repositories/index", "data-turbolinks-track" => true %>
|
<%= javascript_include_tag "repositories/index", "data-turbolinks-track" => true %>
|
||||||
|
<%= render partial: "repositories/index/create_new_modal.html.erb" %>
|
||||||
|
|
|
||||||
17
app/views/repositories/index/_create_new_modal.html.erb
Normal file
17
app/views/repositories/index/_create_new_modal.html.erb
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<div class="modal" id="create-new-modal" tabindex="-1" role="dialog" aria-labelledby="create-new-modal-label">
|
||||||
|
<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" id="create-new-modal-label">
|
||||||
|
<%= t("repositories.create.title") %>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body"></div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" data-action="submit"><%= t("repositories.create.submit") %></button>
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel") %></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<%= bootstrap_form_for [@team, @new_repository], remote: :true do |f| %>
|
||||||
|
<%= f.text_field :name, label: t("repositories.create.name_label"), placeholder: t("repositories.create.name_placeholder") %>
|
||||||
|
<% end %>
|
||||||
|
|
@ -51,6 +51,9 @@ class Constants
|
||||||
# Maximum nr. of search results for atwho (smart annotations)
|
# Maximum nr. of search results for atwho (smart annotations)
|
||||||
ATWHO_SEARCH_LIMIT = 5
|
ATWHO_SEARCH_LIMIT = 5
|
||||||
|
|
||||||
|
# Maximum number of repositories allowed
|
||||||
|
REPOSITORIES_LIMIT = 5
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# File and data memory size
|
# File and data memory size
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
|
|
|
||||||
|
|
@ -149,10 +149,13 @@ en:
|
||||||
result: "Result comment"
|
result: "Result comment"
|
||||||
|
|
||||||
repositories:
|
repositories:
|
||||||
|
nav:
|
||||||
|
breadcrumbs:
|
||||||
|
repositories: "Repositories"
|
||||||
index:
|
index:
|
||||||
head_title: "Repositories"
|
head_title: "Repositories"
|
||||||
title: "Repositories"
|
title: "Repositories"
|
||||||
no_repositories: "No repositories"
|
add_new_repository_tab: "Create new repository"
|
||||||
delete_flash: "\"%{name}\" repository was successfully deleted!"
|
delete_flash: "\"%{name}\" repository was successfully deleted!"
|
||||||
rename_flash: "\"%{old_name}\" repository was successfully renamed to \"%{new_name}\"!"
|
rename_flash: "\"%{old_name}\" repository was successfully renamed to \"%{new_name}\"!"
|
||||||
no_teams:
|
no_teams:
|
||||||
|
|
@ -174,9 +177,12 @@ en:
|
||||||
name: "New repository name"
|
name: "New repository name"
|
||||||
name_placeholder: "My repository"
|
name_placeholder: "My repository"
|
||||||
rename: "Rename repository"
|
rename: "Rename repository"
|
||||||
nav:
|
create:
|
||||||
breadcrumbs:
|
title: "Create new repository"
|
||||||
repositories: "Repositories"
|
name_label: "Repository name"
|
||||||
|
name_placeholder: "My repository"
|
||||||
|
submit: "Create repository"
|
||||||
|
success_flash: "Repository <strong>%{name}</strong> successfully created."
|
||||||
|
|
||||||
comments:
|
comments:
|
||||||
options_dropdown:
|
options_dropdown:
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,11 @@ Rails.application.routes.draw do
|
||||||
as: 'file_expired'
|
as: 'file_expired'
|
||||||
|
|
||||||
resources :teams do
|
resources :teams do
|
||||||
resources :repositories, only: %i(index destroy update) do
|
resources :repositories, only: %i(index create destroy update) do
|
||||||
|
collection do
|
||||||
|
get 'create_new_modal', to: 'repositories#create_new_modal',
|
||||||
|
defaults: { format: 'json' }
|
||||||
|
end
|
||||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
get 'rename_modal', to: 'repositories#rename_modal',
|
get 'rename_modal', to: 'repositories#rename_modal',
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue