From 71c523c406a8c3ee975ad9669f4896c4824d0d1a Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Thu, 8 Jun 2017 11:44:24 +0200 Subject: [PATCH 1/5] load tabs with javascript --- app/assets/javascripts/repositories/index.js | 32 ++++++++++++ app/controllers/repositories_controller.rb | 13 +++++ app/views/repositories/_repository.html.erb | 6 +-- .../_repository_tab_content.html.erb | 35 +++++++++++++ app/views/repositories/index.html.erb | 51 ++----------------- config/routes.rb | 2 + 6 files changed, 89 insertions(+), 50 deletions(-) create mode 100644 app/views/repositories/_repository_tab_content.html.erb diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index 1a7249509..914938e40 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -5,4 +5,36 @@ $('.rename-repo-option').initializeModal('#rename-repo-modal'); $('.copy-repo-option').initializeModal('#copy-repo-modal'); $('.create-repository').initializeModal('#create-repo-modal'); + + loadRepositoryTab(); + })(); + +function loadRepositoryTab() { + $('#repository-tabs a').on("click", function(e) { + e.preventDefault(); + var pane = $(this); + + $.ajax({ + url: $(this).attr("data-url"), + type: "GET", + dataType: "json", + success: function (data) { + var tabBody = $(pane.context.hash).find(".tab-content-body"); + tabBody.html(data.html); + pane.tab('show'); + }, + error: function (error) { + // TODO + } + }); + }); + + // load first tab content + $('#repository-tabs a:first').click(); + + // clean tab content + $('a[data-toggle="tab"]').on('hide.bs.tab', function (e) { + $(".tab-content-body").html(""); + }) +} diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 66a4410ad..e5e8ecd6e 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -12,6 +12,19 @@ class RepositoriesController < ApplicationController render('repositories/index') end + def show_tab + @repository = Repository.find_by_id(params[:repository_id]) + respond_to do |format| + format.json do + render json: { + html: render_to_string( + partial: 'repositories/repository_tab_content.html.erb' + ) + } + end + end + end + def create_modal @repository = Repository.new respond_to do |format| diff --git a/app/views/repositories/_repository.html.erb b/app/views/repositories/_repository.html.erb index 3288a2ecb..3d26baaf2 100644 --- a/app/views/repositories/_repository.html.erb +++ b/app/views/repositories/_repository.html.erb @@ -1,5 +1,5 @@ -<%= render partial: "repositories/delete_record_modal" %> -<%= render partial: "repositories/delete_column_modal" %> +<%= render partial: "repositories/delete_record_modal.html.erb" %> +<%= render partial: "repositories/delete_column_modal.html.erb" %>
@@ -67,7 +67,7 @@ <% end %> -<%= render partial: "repository_table", +<%= render partial: "repositories/repository_table.html.erb", locals: { repository: repository, repository_index_link: repository_table_index_path(repository) diff --git a/app/views/repositories/_repository_tab_content.html.erb b/app/views/repositories/_repository_tab_content.html.erb new file mode 100644 index 000000000..7197a2330 --- /dev/null +++ b/app/views/repositories/_repository_tab_content.html.erb @@ -0,0 +1,35 @@ +
+ +
+ +<%= render partial: 'repositories/repository.html.erb', locals: { repository: @repository } %> \ No newline at end of file diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb index 498f78064..920fdc46a 100644 --- a/app/views/repositories/index.html.erb +++ b/app/views/repositories/index.html.erb @@ -8,15 +8,17 @@ <% active_repo = @repositories.first if !active_repo %> -