diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index c135596e9..ececb0678 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -4,10 +4,11 @@ var REPOSITORIES_TABLE; - function initRepositoriesDataTable(tableContainer) { - if (REPOSITORIES_TABLE) REPOSITORIES_TABLE.destroy(); - $('.content-body').html($('#activeRepositoriesListTable').html()); - $.get($(tableContainer).data('source'), function(data) { + function initRepositoriesDataTable(tableContainer, archived = false) { + var tableTemplate = archived ? $('#archivedRepositoriesListTable').html() : $('#activeRepositoriesListTable').html(); + $.get($(tableTemplate).data('source'), function(data) { + if (REPOSITORIES_TABLE) REPOSITORIES_TABLE.destroy(); + $('.content-body').html(tableTemplate); REPOSITORIES_TABLE = $(tableContainer).DataTable({ aaData: data, dom: "R<'main-actions hidden'<'toolbar'><'filter-container'f>>t<'pagination-row hidden'<'pagination-info'li><'pagination-actions'p>>", @@ -39,7 +40,7 @@ var dataTableWrapper = $(tableContainer).closest('.dataTables_wrapper'); DataTableHelpers.initLengthApearance(dataTableWrapper); DataTableHelpers.initSearchField(dataTableWrapper); - $('.content-body .toolbar').html($('#activeRepositoriesListButtons').html()); + $('.content-body .toolbar').html($('#repositoriesListButtons').html()); dataTableWrapper.find('.main-actions, .pagination-row').removeClass('hidden'); $('.create-new-repository').initializeModal('#create-repo-modal'); } @@ -47,5 +48,29 @@ }); } + function reloadSidebar() { + var slidePanel = $('#slide-panel'); + var archived; + if ($('.repositories-index').hasClass('archived')) archived = true; + $.get(slidePanel.data('sidebar-url'), { archived: archived }, function(data) { + slidePanel.html(data.html); + }); + } + + function initRepositoryViewSwitcher() { + var viewSwitch = $('.view-switch'); + viewSwitch.on('click', '.view-switch-archived', function() { + $('.repositories-index').toggleClass('archived active'); + initRepositoriesDataTable('#repositoriesList', true); + reloadSidebar(); + }); + viewSwitch.on('click', '.view-switch-active', function() { + $('.repositories-index').toggleClass('archived active'); + initRepositoriesDataTable('#repositoriesList'); + reloadSidebar(); + }); + } + initRepositoriesDataTable('#repositoriesList'); + initRepositoryViewSwitcher(); }()); diff --git a/app/assets/stylesheets/repository/index.scss b/app/assets/stylesheets/repository/index.scss new file mode 100644 index 000000000..19f008d0c --- /dev/null +++ b/app/assets/stylesheets/repository/index.scss @@ -0,0 +1,13 @@ +.repositories-index { + &.active { + [data-view-mode="archived"] { + display: none + } + } + + &.archived { + [data-view-mode="active"] { + display: none + } + } +} diff --git a/app/assets/stylesheets/shared/content_pane.scss b/app/assets/stylesheets/shared/content_pane.scss index f90f7aee1..a5b339c70 100644 --- a/app/assets/stylesheets/shared/content_pane.scss +++ b/app/assets/stylesheets/shared/content_pane.scss @@ -17,6 +17,37 @@ h1 { margin: 0; } + + .view-switch { + margin-left: auto; + + .caret { + margin: 8px 0 8px 8px; + } + &.open { + .caret { + transform: rotateX(180deg) + } + } + + .dropdown-menu { + @include font-button; + min-width: 250px; + + li { + cursor: pointer; + padding: 1em; + + .button-icon { + margin-right: .5em; + } + + &:hover { + background: $color-concrete; + } + } + } + } } .content-body { diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9380ae2ac..f9704fd2e 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -9,10 +9,10 @@ class RepositoriesController < ApplicationController include RepositoriesDatatableHelper before_action :switch_team_with_param, only: :show - before_action :load_repository, except: %i(index create create_modal) - before_action :load_repositories, only: %i(index show) - before_action :check_view_all_permissions, only: :index - before_action :check_view_permissions, except: %i(index create_modal create update destroy parse_sheet import_records) + before_action :load_repository, except: %i(index create create_modal sidebar) + before_action :load_repositories, only: %i(index show sidebar) + before_action :check_view_all_permissions, only: %i(index sidebar) + before_action :check_view_permissions, except: %i(index create_modal create update destroy parse_sheet import_records sidebar) before_action :check_manage_permissions, only: %i(destroy destroy_modal rename_modal update) before_action :check_share_permissions, only: :share_modal before_action :check_create_permissions, only: %i(create_modal create) @@ -30,6 +30,15 @@ class RepositoriesController < ApplicationController end end + def sidebar + render json: { + html: render_to_string(partial: 'repositories/sidebar_list.html.erb', locals: { + repositories: @repositories, + archived: params[:archived] + }) + } + end + def show @display_edit_button = can_create_repository_rows?(@repository) @display_delete_button = can_delete_repository_rows?(@repository) @@ -342,6 +351,11 @@ class RepositoriesController < ApplicationController def load_repositories @repositories = Repository.accessible_by_teams(current_team).order('repositories.created_at ASC') + @repositories = if params[:archived] + @repositories.archived + else + @repositories.active + end end def set_inline_name_editing diff --git a/app/helpers/repositories_datatable_helper.rb b/app/helpers/repositories_datatable_helper.rb index b420d293d..616997266 100644 --- a/app/helpers/repositories_datatable_helper.rb +++ b/app/helpers/repositories_datatable_helper.rb @@ -5,7 +5,7 @@ module RepositoriesDatatableHelper def prepare_repositories_datatable(repositories, team, _config) result = [] - repositories = repositories.includes(:repository_rows, :team, :created_by) + repositories = repositories.includes(:repository_rows, :team, :created_by, :archived_by) repositories.each do |repository| result.push( 'DT_RepositoryId': repository.id, @@ -15,6 +15,8 @@ module RepositoriesDatatableHelper '4': escape_input(repository.team.name), '5': I18n.l(repository.created_at, format: :full), '6': escape_input(repository.created_by.full_name), + '7': (I18n.l(repository.archived_on, format: :full) if repository.archived_on), + '8': escape_input(repository.archived_by&.full_name), 'repositoryUrl': repository_path(repository) ) end diff --git a/app/models/repository_base.rb b/app/models/repository_base.rb index 730731356..1401fae6b 100644 --- a/app/models/repository_base.rb +++ b/app/models/repository_base.rb @@ -9,7 +9,7 @@ class RepositoryBase < ApplicationRecord belongs_to :team belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User' - belongs_to :archived_by, foreign_key: :archived_by_id, class_name: 'User', inverse_of: :repository, optional: true + belongs_to :archived_by, foreign_key: :archived_by_id, class_name: 'User', inverse_of: :archived_repositories, optional: true has_many :repository_columns, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy has_many :repository_rows, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy has_many :repository_table_states, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy diff --git a/app/views/repositories/_sidebar.html.erb b/app/views/repositories/_sidebar.html.erb index e9abdb98a..4c33fff81 100644 --- a/app/views/repositories/_sidebar.html.erb +++ b/app/views/repositories/_sidebar.html.erb @@ -1,32 +1,6 @@ <%= content_for :sidebar do %> -
-
-
-
-
- |
- <%= t('libraries.index.table.name') %> | -<%= t('libraries.index.table.number_of_items') %> | -<%= t('libraries.index.table.shared') %> | -<%= t('libraries.index.table.shared') %> | -Added on | -Added by | -
---|
+
+
+
+
+ |
+ <%= t('libraries.index.table.name') %> | +<%= t('libraries.index.table.number_of_items') %> | +<%= t('libraries.index.table.shared') %> | +<%= t('libraries.index.table.ownership') %> | +<%= t('libraries.index.table.added_on') %> | +<%= t('libraries.index.table.added_by') %> | +
---|
+
+
+
+
+ |
+ <%= t('libraries.index.table.name') %> | +<%= t('libraries.index.table.number_of_items') %> | +<%= t('libraries.index.table.shared') %> | +<%= t('libraries.index.table.ownership') %> | +<%= t('libraries.index.table.added_on') %> | +<%= t('libraries.index.table.added_by') %> | +<%= t('libraries.index.table.archived_on') %> | +<%= t('libraries.index.table.archived_by') %> | +
---|