From 993a8da518a0558f19bab0caa06bd14b516f19ec Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 5 Jan 2024 18:58:12 +0100 Subject: [PATCH] Migrate inventory tables [SCI-9804] --- app/controllers/repositories_controller.rb | 42 ++- .../packs/vue/repositories_table.js | 10 + .../notifications/notifications_flyout.vue | 2 +- .../vue/repositories/modals/duplicate.vue | 68 ++++ .../vue/repositories/modals/edit.vue | 66 ++++ .../vue/repositories/modals/new.vue | 69 ++++ .../vue/repositories/modals/share.vue | 118 +++++++ app/javascript/vue/repositories/table.vue | 299 ++++++++++++++++++ .../vue/shared/datatable/modals/columns.vue | 9 +- .../lists/repository_serializer.rb | 80 +++++ app/serializers/shareable_team_serializer.rb | 21 ++ app/services/lists/repositories_service.rb | 54 ++++ app/services/toolbars/repositories_service.rb | 46 ++- .../repositories/_view_archived_btn.html.erb | 10 - app/views/repositories/index.html.erb | 81 ++--- config/database.yml | 1 + config/routes.rb | 3 + config/webpack/webpack.config.js | 3 +- 18 files changed, 856 insertions(+), 126 deletions(-) create mode 100644 app/javascript/packs/vue/repositories_table.js create mode 100644 app/javascript/vue/repositories/modals/duplicate.vue create mode 100644 app/javascript/vue/repositories/modals/edit.vue create mode 100644 app/javascript/vue/repositories/modals/new.vue create mode 100644 app/javascript/vue/repositories/modals/share.vue create mode 100644 app/javascript/vue/repositories/table.vue create mode 100644 app/serializers/lists/repository_serializer.rb create mode 100644 app/serializers/shareable_team_serializer.rb create mode 100644 app/services/lists/repositories_service.rb delete mode 100644 app/views/repositories/_view_archived_btn.html.erb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index eb29de025..f9418500d 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -11,7 +11,7 @@ class RepositoriesController < ApplicationController before_action :load_repository, except: %i(index create create_modal sidebar archive restore actions_toolbar export_modal export_repositories) - before_action :load_repositories, only: %i(index show sidebar) + before_action :load_repositories, only: :index before_action :load_repositories_for_archiving, only: :archive before_action :load_repositories_for_restoring, only: :restore before_action :check_view_all_permissions, only: %i(index sidebar) @@ -35,7 +35,9 @@ class RepositoriesController < ApplicationController render 'index' end format.json do - render json: prepare_repositories_datatable(@repositories, current_team, params) + repositories = Lists::RepositoriesService.new(@repositories, params).call + render json: repositories, each_serializer: Lists::RepositorySerializer, user: current_user, + meta: pagination_dict(repositories) end end end @@ -93,6 +95,11 @@ class RepositoriesController < ApplicationController render json: { html: render_to_string(partial: 'share_repository_modal', formats: :html) } end + def shareable_teams + teams = current_user.teams - [@repository.team] + render json: teams, each_serializer: ShareableTeamSerializer, repository: @repository + end + def hide_reminders # synchronously hide currently visible reminders if params[:visible_reminder_repository_row_ids].present? @@ -122,12 +129,9 @@ class RepositoriesController < ApplicationController if @repository.save log_activity(:create_inventory) - - flash[:success] = t('repositories.index.modal_create.success_flash_html', name: @repository.name) - render json: { url: repository_path(@repository) } + render json: { message: t('repositories.index.modal_create.success_flash_html', name: @repository.name) } else - render json: @repository.errors, - status: :unprocessable_entity + render json: @repository.errors, status: :unprocessable_entity end end @@ -163,14 +167,14 @@ class RepositoriesController < ApplicationController end def destroy - flash[:success] = t('repositories.index.delete_flash', - name: @repository.name) - log_activity(:delete_inventory) # Log before delete id @repository.discard @repository.destroy_discarded(current_user.id) - redirect_to team_repositories_path(archived: true) + + render json: { + message: t('repositories.index.delete_flash', name: @repository.name) + } end def rename_modal @@ -240,13 +244,8 @@ class RepositoriesController < ApplicationController if !copied_repository render json: { name: ['Server error'] }, status: :unprocessable_entity else - flash[:success] = t( - 'repositories.index.copy_flash', - old: @repository.name, - new: copied_repository.name - ) render json: { - url: repository_path(copied_repository) + message: t('repositories.index.copy_flash', old: @repository.name, new: copied_repository.name) } end end @@ -425,7 +424,7 @@ class RepositoriesController < ApplicationController Toolbars::RepositoriesService.new( current_user, current_team, - repository_ids: params[:repository_ids].split(',') + repository_ids: JSON.parse(params[:items]).map { |i| i['id'] } ).actions } end @@ -449,12 +448,7 @@ class RepositoriesController < ApplicationController end def load_repositories - @repositories = Repository.accessible_by_teams(current_team).order('repositories.created_at ASC') - @repositories = if params[:archived] == 'true' || @repository&.archived? - @repositories.archived - else - @repositories.active - end + @repositories = Repository.accessible_by_teams(current_team) end def load_repositories_for_archiving diff --git a/app/javascript/packs/vue/repositories_table.js b/app/javascript/packs/vue/repositories_table.js new file mode 100644 index 000000000..bf5548d09 --- /dev/null +++ b/app/javascript/packs/vue/repositories_table.js @@ -0,0 +1,10 @@ +import { createApp } from 'vue/dist/vue.esm-bundler.js'; +import PerfectScrollbar from 'vue3-perfect-scrollbar'; +import RepositoriesTable from '../../vue/repositories/table.vue'; +import { mountWithTurbolinks } from './helpers/turbolinks.js'; + +const app = createApp(); +app.component('RepositoriesTable', RepositoriesTable); +app.config.globalProperties.i18n = window.I18n; +app.use(PerfectScrollbar); +mountWithTurbolinks(app, '#repositoriesTable'); diff --git a/app/javascript/vue/navigation/notifications/notifications_flyout.vue b/app/javascript/vue/navigation/notifications/notifications_flyout.vue index 75ec2213b..36f632c85 100644 --- a/app/javascript/vue/navigation/notifications/notifications_flyout.vue +++ b/app/javascript/vue/navigation/notifications/notifications_flyout.vue @@ -59,7 +59,7 @@ export default { }) }, beforeUnmount() { - document.body.style.overflow = 'scroll'; + document.body.style.overflow = 'auto'; }, computed: { filteredNotifications() { diff --git a/app/javascript/vue/repositories/modals/duplicate.vue b/app/javascript/vue/repositories/modals/duplicate.vue new file mode 100644 index 000000000..acaa1327c --- /dev/null +++ b/app/javascript/vue/repositories/modals/duplicate.vue @@ -0,0 +1,68 @@ + + + diff --git a/app/javascript/vue/repositories/modals/edit.vue b/app/javascript/vue/repositories/modals/edit.vue new file mode 100644 index 000000000..e159cf3e3 --- /dev/null +++ b/app/javascript/vue/repositories/modals/edit.vue @@ -0,0 +1,66 @@ + + + diff --git a/app/javascript/vue/repositories/modals/new.vue b/app/javascript/vue/repositories/modals/new.vue new file mode 100644 index 000000000..d7e11b033 --- /dev/null +++ b/app/javascript/vue/repositories/modals/new.vue @@ -0,0 +1,69 @@ + + + diff --git a/app/javascript/vue/repositories/modals/share.vue b/app/javascript/vue/repositories/modals/share.vue new file mode 100644 index 000000000..f2086b615 --- /dev/null +++ b/app/javascript/vue/repositories/modals/share.vue @@ -0,0 +1,118 @@ + + + diff --git a/app/javascript/vue/repositories/table.vue b/app/javascript/vue/repositories/table.vue new file mode 100644 index 000000000..2eefad0ea --- /dev/null +++ b/app/javascript/vue/repositories/table.vue @@ -0,0 +1,299 @@ + + + diff --git a/app/javascript/vue/shared/datatable/modals/columns.vue b/app/javascript/vue/shared/datatable/modals/columns.vue index fed046c4e..a7bc1e72e 100644 --- a/app/javascript/vue/shared/datatable/modals/columns.vue +++ b/app/javascript/vue/shared/datatable/modals/columns.vue @@ -19,8 +19,11 @@ v-for="column in columnDefs" :key="column.field" @click="toggleColumn(column, columnVisbile(column))" - class="flex items-center gap-4 py-2.5 px-3 cursor-pointer" - :class="{'hover:bg-sn-super-light-grey': column.field !== 'name'}" + class="flex items-center gap-4 py-2.5 px-3" + :class="{ + 'cursor-pointer': column.field !== 'name', + 'hover:bg-sn-super-light-grey': column.field !== 'name' + }" >