diff --git a/app/assets/javascripts/repositories/my_module_repository.js b/app/assets/javascripts/repositories/my_module_repository.js deleted file mode 100644 index 55ac5c44b..000000000 --- a/app/assets/javascripts/repositories/my_module_repository.js +++ /dev/null @@ -1,13 +0,0 @@ -(function() { - 'use strict'; - - function initTable() { - RepositoryDatatable.destroy() - RepositoryDatatable.init($('#content').attr('data-repo-id')); - RepositoryDatatable.redrawTableOnSidebarToggle(); - onClickToggleAssignedRecords(); - } - - // initialze repository datatable - initTable(); -}()); diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index 3d0318299..269a12a8d 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -65,8 +65,8 @@ var RepositoryDatatable = (function(global) { $('#copyRepositoryRecords').prop('disabled', true); $('#editRepositoryRecord').prop('disabled', true); $('#archiveRepositoryRecordsButton').prop('disabled', true); - $('#assignRepositoryRecords').prop('disabled', true); - $('#unassignRepositoryRecords').prop('disabled', true); + $('#restoreRepositoryRecords').prop('disabled', true); + $('#deleteRepositoryRecords').prop('disabled', true); $('#editDeleteCopy').hide(); } else { if (rowsSelected.length === 1) { @@ -77,8 +77,8 @@ var RepositoryDatatable = (function(global) { $('#exportRepositoriesButton').removeClass('disabled'); $('#archiveRepositoryRecordsButton').prop('disabled', false); $('#copyRepositoryRecords').prop('disabled', false); - $('#assignRepositoryRecords').prop('disabled', false); - $('#unassignRepositoryRecords').prop('disabled', false); + $('#restoreRepositoryRecords').prop('disabled', false); + $('#deleteRepositoryRecords').prop('disabled', false); if (rowsSelected.some(r=> rowsLocked.indexOf(r) >= 0)) { // Some selected rows is rowsLocked $('#editRepositoryRecord').prop('disabled', true); @@ -437,6 +437,7 @@ var RepositoryDatatable = (function(global) { url: $(TABLE_ID).data('source'), data: function(d) { d.assigned = viewAssigned; + d.archived = $('.repository-show').hasClass('archived'); }, global: false, type: 'POST' @@ -467,7 +468,7 @@ var RepositoryDatatable = (function(global) { if (!row.recordEditable) { icon = ``; } else if (EDITABLE) { - icon = ''; + icon = ''; } else { icon = ''; } @@ -538,6 +539,7 @@ var RepositoryDatatable = (function(global) { // Show number of selected rows near pages info $('#repository-table_info').append(''); $('#selected_info').html(' (' + rowsSelected.length + ' entries selected)'); + checkArchivedColumnsState(); }, preDrawCallback: function() { animateSpinner(this); @@ -551,8 +553,9 @@ var RepositoryDatatable = (function(global) { dataType: 'json', type: 'POST', success: function(json) { - json.state.columns[6].visible = false; // Here must be switcher depend on active/archive view - json.state.columns[7].visible = false; + var archived = $('.repository-show').hasClass('archived'); + if (json.state.columns[6]) json.state.columns[6].visible = archived; + if (json.state.columns[7]) json.state.columns[7].visible = archived; callback(json.state); } }); @@ -638,53 +641,6 @@ var RepositoryDatatable = (function(global) { return TABLE; } - global.onClickAddRecord = function() { - checkAvailableColumns(); - RepositoryDatatableRowEditor.addNewRow(TABLE); - changeToEditMode(); - }; - - global.onClickToggleAssignedRecords = function() { - $('.repository-assign-group > .btn').click(function() { - $('.btn-group > .btn').removeClass('active'); - $(this).addClass('active'); - }); - - $('#assigned-repo-records').on('click', function() { - viewAssigned = 'assigned'; - return new Promise(function(resolve) { - resolve(TABLE.ajax.reload()); - }); - }); - $('#all-repo-records').on('click', function() { - viewAssigned = 'all'; - return new Promise(function(resolve) { - resolve(TABLE.ajax.reload()); - }); - }); - }; - - global.hideAssignUnasignModal = function(id) { - $(id).modal('hide').promise().done( - function() { - $(id).remove(); - } - ); - }; - - global.openUnassignRecordsModal = function() { - $.post( - $('#unassignRepositoryRecords').data('unassign-url'), - { selected_rows: rowsSelected } - ).done( - function(data) { - $(data.html).appendTo('body').promise().done(function() { - $('#unassignRepositoryRecordModal').modal('show'); - }); - } - ); - }; - global.onClickDeleteRecord = function() { animateSpinner(); $.ajax({ @@ -705,105 +661,105 @@ var RepositoryDatatable = (function(global) { } } }); - } + }; - global.onClickCopyRepositoryRecords = function() { - animateSpinner(); - $.ajax({ - url: $('table' + TABLE_ID).data('copy-records'), - type: 'POST', - dataType: 'json', - data: { selected_rows: rowsSelected }, - success: function(data) { - HelperModule.flashAlertMsg(data.flash, 'success'); - rowsSelected = []; - resetTableView(); - }, - error: function(ev) { - if (ev.status === 403) { - HelperModule.flashAlertMsg( - I18n.t('repositories.js.permission_error'), ev.responseJSON.style - ); + $('.repository-show') + .on('click', '#addRepositoryRecord', function() { + checkAvailableColumns(); + RepositoryDatatableRowEditor.addNewRow(TABLE); + changeToEditMode(); + }) + .on('click', '#copyRepositoryRecords', function() { + animateSpinner(); + $.ajax({ + url: $('table' + TABLE_ID).data('copy-records'), + type: 'POST', + dataType: 'json', + data: { selected_rows: rowsSelected }, + success: function(data) { + HelperModule.flashAlertMsg(data.flash, 'success'); + rowsSelected = []; + resetTableView(); + }, + error: function(ev) { + if (ev.status === 403) { + HelperModule.flashAlertMsg( + I18n.t('repositories.js.permission_error'), ev.responseJSON.style + ); + } } - } - }); - }; - - global.onClickArchiveRepositoryRecords = function() { - animateSpinner(); - $.ajax({ - url: $('table' + TABLE_ID).data('archive-records'), - type: 'POST', - dataType: 'json', - data: { selected_rows: rowsSelected }, - success: function(data) { - HelperModule.flashAlertMsg(data.flash, 'success'); - rowsSelected = []; - resetTableView(); - }, - error: function(ev) { - if (ev.status === 403) { - HelperModule.flashAlertMsg( - I18n.t('repositories.js.permission_error'), ev.responseJSON.style - ); - } else if (ev.status === 422) { - HelperModule.flashAlertMsg( - ev.responseJSON.error, 'danger' - ); - animateSpinner(null, false); + }); + }) + .on('click', '#archiveRepositoryRecordsButton', function() { + animateSpinner(); + $.ajax({ + url: $('table' + TABLE_ID).data('archive-records'), + type: 'POST', + dataType: 'json', + data: { selected_rows: rowsSelected }, + success: function(data) { + HelperModule.flashAlertMsg(data.flash, 'success'); + rowsSelected = []; + resetTableView(); + }, + error: function(ev) { + if (ev.status === 403) { + HelperModule.flashAlertMsg( + I18n.t('repositories.js.permission_error'), ev.responseJSON.style + ); + } else if (ev.status === 422) { + HelperModule.flashAlertMsg( + ev.responseJSON.error, 'danger' + ); + animateSpinner(null, false); + } } - } - }); - }; - - global.onClickRestoreRepositoryRecords = function() { - animateSpinner(); - $.ajax({ - url: $('table' + TABLE_ID).data('restore-records'), - type: 'POST', - dataType: 'json', - data: { selected_rows: rowsSelected }, - success: function(data) { - HelperModule.flashAlertMsg(data.flash, 'success'); - rowsSelected = []; - resetTableView(); - }, - error: function(ev) { - if (ev.status === 403) { - HelperModule.flashAlertMsg( - I18n.t('repositories.js.permission_error'), ev.responseJSON.style - ); - } else if (ev.status === 422) { - HelperModule.flashAlertMsg( - ev.responseJSON.error, 'danger' - ); - animateSpinner(null, false); + }); + }) + .on('click', '#restoreRepositoryRecords', function() { + animateSpinner(); + $.ajax({ + url: $('table' + TABLE_ID).data('restore-records'), + type: 'POST', + dataType: 'json', + data: { selected_rows: rowsSelected }, + success: function(data) { + HelperModule.flashAlertMsg(data.flash, 'success'); + rowsSelected = []; + resetTableView(); + }, + error: function(ev) { + if (ev.status === 403) { + HelperModule.flashAlertMsg( + I18n.t('repositories.js.permission_error'), ev.responseJSON.style + ); + } else if (ev.status === 422) { + HelperModule.flashAlertMsg( + ev.responseJSON.error, 'danger' + ); + animateSpinner(null, false); + } } + }); + }) + .on('click', '#editRepositoryRecord', function() { + checkAvailableColumns(); + + if (rowsSelected.length !== 1) { + return; } + + let row = TABLE.row('#' + rowsSelected[0]); + + $(TABLE_ID).find('.repository-row-edit-icon').remove(); + + RepositoryDatatableRowEditor.switchRowToEditMode(row); + changeToEditMode(); + adjustTableHeader(); + }) + .on('click', '#deleteRepositoryRecords', function() { + $('#deleteRepositoryRecord').modal('show'); }); - }; - - // Edit record - global.onClickEdit = function() { - checkAvailableColumns(); - - if (rowsSelected.length !== 1) { - return; - } - - let row = TABLE.row('#' + rowsSelected[0]); - - $(TABLE_ID).find('.repository-row-edit-icon').remove(); - - RepositoryDatatableRowEditor.switchRowToEditMode(row); - changeToEditMode(); - adjustTableHeader(); - }; - - // Delete record - global.onClickDelete = function() { - $('#deleteRepositoryRecord').modal('show'); - }; // Handle enter key $(document).off('keypress').keypress(function(event) { @@ -869,9 +825,19 @@ var RepositoryDatatable = (function(global) { }); } + function checkArchivedColumnsState() { + var archived = $('.repository-show').hasClass('archived'); + TABLE.column(6).visible(archived); + TABLE.column(7).visible(archived); + } + return Object.freeze({ init: init, destroy: destroy, + reload: function() { + TABLE.ajax.reload(); + clearRowSelection(); + }, redrawTableOnSidebarToggle: redrawTableOnSidebarToggle, checkAvailableColumns: checkAvailableColumns }); diff --git a/app/assets/javascripts/repositories/show.js b/app/assets/javascripts/repositories/show.js index f1f206721..ffbf8d0a6 100644 --- a/app/assets/javascripts/repositories/show.js +++ b/app/assets/javascripts/repositories/show.js @@ -1,7 +1,7 @@ //= require repositories/import/records_importer.js /* - global animateSpinner repositoryRecordsImporter + global animateSpinner repositoryRecordsImporter I18n RepositoryDatatable PerfectScrollbar HelperModule */ @@ -147,6 +147,25 @@ }); } + function initRepositoryViewSwitcher() { + var viewSwitch = $('.view-switch'); + viewSwitch.on('click', '.view-switch-archived', function() { + $('.repository-show').toggleClass('archived active'); + RepositoryDatatable.reload(); + }); + viewSwitch.on('click', '.view-switch-active', function() { + $('.repository-show').toggleClass('archived active'); + RepositoryDatatable.reload(); + }); + } + + $('.repository-title-name .inline-editing-container').on('inlineEditing::updated', function(e, value, viewValue) { + $('.repository-archived-title-name') + .text(I18n.t('repositories.show.archived_inventory', { repository_name: viewValue })); + $('#toolbarButtonsDatatable .archived-label') + .text(I18n.t('repositories.show.archived_view_label.active', { repository_name: viewValue })); + }); + $('#shareRepoBtn').on('ajax:success', function() { initShareModal(); }); @@ -154,4 +173,5 @@ $('.create-new-repository').initializeModal('#create-repo-modal'); initImportRecordsModal(); initTable(); + initRepositoryViewSwitcher(); }(window)); diff --git a/app/assets/javascripts/shared/inline_editing.js b/app/assets/javascripts/shared/inline_editing.js index c1b7b7cd9..6a7035fbf 100644 --- a/app/assets/javascripts/shared/inline_editing.js +++ b/app/assets/javascripts/shared/inline_editing.js @@ -94,6 +94,8 @@ var inlineEditing = (function() { .attr('value', inputField(container).val()); appendAfterLabel(container); + container.trigger('inlineEditing::updated', [inputField(container).val(), viewData]) + if (SIDEBAR_ITEM_TYPES.includes(paramsGroup)) { updateSideBarNav(paramsGroup, itemId, viewData); } diff --git a/app/assets/stylesheets/repositories.scss b/app/assets/stylesheets/repositories.scss index 478e9e526..d223b54a8 100644 --- a/app/assets/stylesheets/repositories.scss +++ b/app/assets/stylesheets/repositories.scss @@ -8,23 +8,35 @@ } .repository-show { - height: calc(100vh - 66px); + height: calc(100vh - var(--navbar-height)); left: var(--repository-sidebar-margin); margin: 0; - padding: 0 32px; + padding: 0 2em; position: absolute; - top: 51px; + top: var(--navbar-height); transition: .4s $timing-function-sharp; width: calc(100vw - var(--repository-sidebar-margin)); + &.active { + [data-view-mode="archived"] { + display: none !important; + } + } + + &.archived { + [data-view-mode="active"] { + display: none !important; + } + } + #repository-toolbar { align-items: center; background-color: $color-white; + border: 0; display: flex; - height: 75px; left: var(--repository-sidebar-margin); - padding: 35px 32px 20px; + padding: 0 2em; position: fixed; transition: .4s $timing-function-sharp; width: calc(100% - var(--repository-sidebar-margin)); @@ -34,7 +46,7 @@ border-bottom: $border-tertiary; bottom: 0; position: absolute; - width: calc(100% - 64px); + width: calc(100% - 4em); } .repository-share-icon { @@ -47,10 +59,10 @@ } .repository-title-name { + @include font-h2; display: flex; flex-direction: column; flex-grow: 1; - font-size: 18px; line-height: 32px; margin-right: 20px; overflow: hidden; @@ -79,6 +91,14 @@ } } + .repository-archived-title-name { + @include font-h2; + flex-grow: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + .repository-subtitle { color: $color-silver-chalice; font-size: 12px; @@ -92,6 +112,10 @@ .manage-repo-column-index { margin-left: 4px; } + + .view-switch { + margin-left: 4px; + } } } @@ -100,17 +124,19 @@ background-color: $color-white; display: flex; flex-grow: 1; - height: 68px; + flex-wrap: nowrap; + height: 5em; left: var(--repository-sidebar-margin); - padding: 0 32px; + overflow: hidden; + padding: 0 2em; position: fixed; - top: 126px; + top: calc(5em + var(--navbar-height)); transition: .4s $timing-function-sharp; width: calc(100% - var(--repository-sidebar-margin)); z-index: 90; .filter-container { - flex-grow: 1; + flex-shrink: 0; .toolbar-filter-buttons { float: right; @@ -120,16 +146,44 @@ .repository-provisioning-notice { color: $brand-info; } + + #editDeleteCopy { + flex-shrink: 0; + } + + .archived-label { + color: $color-silver-chalice; + display: inline-block; + margin: 0 auto; + max-width: 400px; + padding: 0 1em; + + table { + tr { + td { + padding: 0 .5em; + + &:nth-child(1) { + text-align: right; + } + + &:nth-child(2) { + color: $color-black; + } + } + } + } + } } .dataTables_scroll { - padding-bottom: 68px; - padding-top: 123px; + padding-bottom: 5em; + padding-top: 10em; .dataTables_scrollHead { position: -webkit-sticky !important; position: sticky !important; - top: 194px; + top: calc(10em + var(--navbar-height)); z-index: 90; .table.dataTable { @@ -154,9 +208,9 @@ background-color: $color-white; bottom: 0; display: flex; - height: 68px; + height: 5em; left: var(--repository-sidebar-margin); - padding: 0 142px 0 32px; + padding: 0 10em 0 2em; position: fixed; transition: .4s $timing-function-sharp; width: calc(100% - var(--repository-sidebar-margin)); @@ -355,6 +409,9 @@ } #toolbarButtonsDatatable { + align-items: center; + display: flex; + .view-only-label { opacity: .6; } diff --git a/app/assets/stylesheets/repository/repository_table.scss b/app/assets/stylesheets/repository/repository_table.scss index 4247e003c..734ce0bf0 100644 --- a/app/assets/stylesheets/repository/repository_table.scss +++ b/app/assets/stylesheets/repository/repository_table.scss @@ -4,8 +4,6 @@ @import "constants"; .repository-table { - margin-top: 20px; - .dataTables_filter { float: right; } @@ -211,42 +209,45 @@ } // Actions + .dataTable { + tbody { + tr:hover { + background-color: $color-concrete; - tbody { - tr:hover { - background-color: $color-concrete; - - .assigned-column { - .repository-row-edit-icon { - display: inline-block; + .assigned-column { + .repository-row-edit-icon { + display: inline-block; + } } } - } - .editing { - border: 1px solid; + .editing { + border: 1px solid; + } } } &.editing { - tbody { - tr.blocked { - opacity: .4; - pointer-events: none; - } + .dataTable { + tbody { + tr.blocked { + opacity: .4; + pointer-events: none; + } - tr:hover { - .assigned-column { - .repository-row-edit-icon { - display: none; - } + tr:hover { + .assigned-column { + .repository-row-edit-icon { + display: none; + } - .assign-counter-container { - background-color: transparent; - } + .assign-counter-container { + background-color: transparent; + } - .circle-icon { - margin-left: 30px; + .circle-icon { + margin-left: 30px; + } } } } diff --git a/app/assets/stylesheets/shared/datatable.scss b/app/assets/stylesheets/shared/datatable.scss index 13eb58be2..9ff35e26b 100644 --- a/app/assets/stylesheets/shared/datatable.scss +++ b/app/assets/stylesheets/shared/datatable.scss @@ -4,6 +4,7 @@ .dataTables_wrapper { .main-actions { + align-items: center; display: flex; flex-wrap: wrap; padding: 1em 0; diff --git a/app/assets/stylesheets/themes/main_navigation.scss b/app/assets/stylesheets/themes/main_navigation.scss index b1eaaf331..f3c406d97 100644 --- a/app/assets/stylesheets/themes/main_navigation.scss +++ b/app/assets/stylesheets/themes/main_navigation.scss @@ -1,6 +1,10 @@ @import 'constants'; @import "mixins"; +:root { + --navbar-height: 51px; +} + #main-nav { box-shadow: $flyout-shadow; margin-bottom: 0; diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 277e06d9f..a030fdafa 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -351,7 +351,7 @@ class RepositoriesController < ApplicationController def load_repositories @repositories = Repository.accessible_by_teams(current_team).order('repositories.created_at ASC') - @repositories = @repositories.archived if params[:archived] + @repositories = @repositories.archived if params[:archived] || @repository&.archived? end def set_inline_name_editing diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 493f8d062..b4025aee9 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -21,7 +21,7 @@ class RepositoryRowsController < ApplicationController @all_rows_count = datatable_service.all_count @columns_mappings = datatable_service.mappings @repository_rows = datatable_service.repository_rows - .active + .where(archived: (params[:archived] || false)) .preload(:repository_columns, :created_by, repository_cells: @repository.cell_preload_includes) diff --git a/app/models/repository.rb b/app/models/repository.rb index 030f57b82..c70655072 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,6 +4,7 @@ class Repository < RepositoryBase include SearchableModel include SearchableByNameModel include RepositoryImportParser + include ArchivableModel enum permission_level: Extends::SHARED_INVENTORIES_PERMISSION_LEVELS diff --git a/app/views/my_modules/repository.html.erb b/app/views/my_modules/repository.html.erb index f1bfdb29c..633e1161d 100644 --- a/app/views/my_modules/repository.html.erb +++ b/app/views/my_modules/repository.html.erb @@ -29,13 +29,13 @@ <% if module_page? && can_assign_repository_rows_to_module?(@my_module) %> diff --git a/app/views/repositories/_sidebar.html.erb b/app/views/repositories/_sidebar.html.erb index 4c33fff81..b1e3ffb4f 100644 --- a/app/views/repositories/_sidebar.html.erb +++ b/app/views/repositories/_sidebar.html.erb @@ -1,6 +1,6 @@ <%= content_for :sidebar do %>