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 %> -
-
- -
+
+ <%= render partial: "sidebar_list", locals: { repositories: repositories, archived: false} %>
<% end %> diff --git a/app/views/repositories/_sidebar_list.html.erb b/app/views/repositories/_sidebar_list.html.erb new file mode 100644 index 000000000..5378f1073 --- /dev/null +++ b/app/views/repositories/_sidebar_list.html.erb @@ -0,0 +1,27 @@ +
+ +
diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb index 500d13cee..c6ef599df 100644 --- a/app/views/repositories/index.html.erb +++ b/app/views/repositories/index.html.erb @@ -3,46 +3,109 @@ <% if current_team %> <%= render partial: "sidebar", locals: { repositories: @repositories } %> -
+
-

<%= t('libraries.index.head_title') %>

+

<%= t('libraries.index.head_title') %>

+

<%= t('libraries.index.head_title_archived') %>

+ <%= render layout: "shared/view_switch" do %> +
  • + + <%= t('libraries.index.switch_view.archived') %> +
  • +
  • + + <%= t('libraries.index.switch_view.active') %> +
  • + <% end %>
    - -
    <% end %> + + + + + + + + + + <%= javascript_include_tag "repositories/index" %> <%= stylesheet_link_tag 'datatables' %> diff --git a/app/views/shared/_view_switch.html.erb b/app/views/shared/_view_switch.html.erb new file mode 100644 index 000000000..e8d3a4ea5 --- /dev/null +++ b/app/views/shared/_view_switch.html.erb @@ -0,0 +1,9 @@ + diff --git a/config/locales/en.yml b/config/locales/en.yml index d8612ecfe..ad4747a8c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1312,6 +1312,7 @@ en: error_flash: "Something went wrong! Please try again later." index: head_title: "Inventories" + head_title_archived: "Archived Inventories" table: name: "Name" number_of_items: "No. of items" @@ -1319,6 +1320,17 @@ en: ownership: "Ownership" added_on: "Added on" added_by: "Added by" + archived_on: "Archived on" + archived_by: "Archived by" + switch_view: + active: Show active inventories + archived: Show archived inventories + buttons: + edit: "Edit" + duplicate: "Duplicate" + archive: "Archive" + restore: "Restore" + delete: "Delete" no_libraries: create_new_button: "New Inventory" show: @@ -2234,6 +2246,7 @@ en: other: "tasks" public: "public" private: "private" + view: "View" search: "Search" file: choose: "Choose File" diff --git a/config/routes.rb b/config/routes.rb index 70d951786..ff41159e3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -643,6 +643,7 @@ Rails.application.routes.draw do end collection do + get :sidebar post 'available_rows', to: 'repository_rows#available_rows', defaults: { format: 'json' } end diff --git a/db/structure.sql b/db/structure.sql index 83a289b67..5efaff92b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -7235,3 +7235,4 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200604210943'); + diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index d02e19cd8..f4082bb29 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -19,7 +19,7 @@ describe RepositoriesController, type: :controller do action parsed_response = JSON.parse(response.body) expect(parsed_response[0].keys).to contain_exactly( - 'DT_RepositoryId', '1', '2', '3', '4', '5', '6', 'repositoryUrl' + 'DT_RepositoryId', '1', '2', '3', '4', '5', '6', '7', '8', 'repositoryUrl' ) end end