mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-02 01:45:38 +08:00
Merge pull request #5416 from G-Chubinidze/gc_SCI_8299
Implement the bottom action toolbar - inventories [SCI-8299]
This commit is contained in:
commit
4a3520883b
6 changed files with 174 additions and 48 deletions
|
@ -7,6 +7,11 @@
|
||||||
var CHECKBOX_SELECTOR;
|
var CHECKBOX_SELECTOR;
|
||||||
|
|
||||||
function updateActionButtons() {
|
function updateActionButtons() {
|
||||||
|
if (window.actionToolbarComponent) {
|
||||||
|
window.actionToolbarComponent.fetchActions({ repository_ids: CHECKBOX_SELECTOR.selectedRows });
|
||||||
|
$('.dataTables_scrollBody').css('padding-bottom', `${CHECKBOX_SELECTOR.selectedRows.length > 0 ? 68 : 0}px`);
|
||||||
|
}
|
||||||
|
|
||||||
var rowsCount = CHECKBOX_SELECTOR.selectedRows.length;
|
var rowsCount = CHECKBOX_SELECTOR.selectedRows.length;
|
||||||
var row;
|
var row;
|
||||||
$('#renameRepoBtn').attr('href', '#');
|
$('#renameRepoBtn').attr('href', '#');
|
||||||
|
@ -98,6 +103,9 @@
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
fnInitComplete: function(e) {
|
fnInitComplete: function(e) {
|
||||||
|
initActionToolbar();
|
||||||
|
actionToolbarComponent.setBottomOffset(75);
|
||||||
|
|
||||||
var dataTableWrapper = $(e.nTableWrapper);
|
var dataTableWrapper = $(e.nTableWrapper);
|
||||||
CHECKBOX_SELECTOR = new DataTableCheckboxes(dataTableWrapper, {
|
CHECKBOX_SELECTOR = new DataTableCheckboxes(dataTableWrapper, {
|
||||||
checkboxSelector: '.repository-row-selector',
|
checkboxSelector: '.repository-row-selector',
|
||||||
|
|
|
@ -133,3 +133,23 @@
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content-body {
|
||||||
|
height: calc(100vh - var(--navbar-height) - 5em);
|
||||||
|
}
|
||||||
|
|
||||||
|
#repositoriesList_wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.dataTables_scroll {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-grow: 1;
|
||||||
|
height: calc(100% - var(--datatable-pagination-row) - 4em);
|
||||||
|
padding-bottom: 12px;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,12 +9,13 @@ class RepositoriesController < ApplicationController
|
||||||
include RepositoriesDatatableHelper
|
include RepositoriesDatatableHelper
|
||||||
include MyModulesHelper
|
include MyModulesHelper
|
||||||
|
|
||||||
before_action :load_repository, except: %i(index create create_modal sidebar archive restore)
|
before_action :load_repository, except: %i(index create create_modal sidebar archive restore actions_toolbar)
|
||||||
before_action :load_repositories, only: %i(index show sidebar)
|
before_action :load_repositories, only: %i(index show sidebar)
|
||||||
before_action :load_repositories_for_archiving, only: :archive
|
before_action :load_repositories_for_archiving, only: :archive
|
||||||
before_action :load_repositories_for_restoring, only: :restore
|
before_action :load_repositories_for_restoring, only: :restore
|
||||||
before_action :check_view_all_permissions, only: %i(index 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 archive restore)
|
before_action :check_view_permissions, except: %i(index create_modal create update destroy parse_sheet import_records
|
||||||
|
sidebar archive restore actions_toolbar)
|
||||||
before_action :check_manage_permissions, only: %i(rename_modal update)
|
before_action :check_manage_permissions, only: %i(rename_modal update)
|
||||||
before_action :check_delete_permissions, only: %i(destroy destroy_modal)
|
before_action :check_delete_permissions, only: %i(destroy destroy_modal)
|
||||||
before_action :check_archive_permissions, only: %i(archive restore)
|
before_action :check_archive_permissions, only: %i(archive restore)
|
||||||
|
@ -410,6 +411,17 @@ class RepositoriesController < ApplicationController
|
||||||
end }
|
end }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def actions_toolbar
|
||||||
|
render json: {
|
||||||
|
actions:
|
||||||
|
Toolbars::RepositoriesService.new(
|
||||||
|
current_user,
|
||||||
|
current_team,
|
||||||
|
repository_ids: params[:repository_ids].split(',')
|
||||||
|
).actions
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def repostiory_import_actions
|
def repostiory_import_actions
|
||||||
|
|
111
app/services/toolbars/repositories_service.rb
Normal file
111
app/services/toolbars/repositories_service.rb
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Toolbars
|
||||||
|
class RepositoriesService
|
||||||
|
attr_reader :current_user
|
||||||
|
|
||||||
|
include Canaid::Helpers::PermissionsHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
def initialize(current_user, current_team, repository_ids: [])
|
||||||
|
@current_user = current_user
|
||||||
|
@current_team = current_team
|
||||||
|
@repositories = Repository.readable_by_user(current_user)
|
||||||
|
.where(id: repository_ids)
|
||||||
|
@repository = @repositories.length == 1 ? @repositories.first : nil
|
||||||
|
@archived_state = @repositories.all.any?(&:archived?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def actions
|
||||||
|
return [] if @repositories.none?
|
||||||
|
|
||||||
|
if @archived_state
|
||||||
|
[restore_action, delete_action]
|
||||||
|
else
|
||||||
|
[rename_action, duplicate_action, archive_action, share_action]
|
||||||
|
end.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def rename_action
|
||||||
|
return unless @repository
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'rename',
|
||||||
|
label: I18n.t('libraries.index.buttons.edit'),
|
||||||
|
button_id: 'renameRepoBtn',
|
||||||
|
icon: 'fas fa-pencil-alt',
|
||||||
|
path: team_repository_rename_modal_path(@current_team, repository_id: @repository),
|
||||||
|
type: 'remote-modal'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def duplicate_action
|
||||||
|
return unless @repository && can_create_repositories?(@current_team)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'duplicate',
|
||||||
|
label: I18n.t('libraries.index.buttons.duplicate'),
|
||||||
|
button_id: 'copyRepoBtn',
|
||||||
|
icon: 'fas fa-copy',
|
||||||
|
path: team_repository_copy_modal_path(@current_team, repository_id: @repository),
|
||||||
|
type: 'remote-modal'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive_action
|
||||||
|
return unless @repositories.all? { |repository| can_archive_repository?(repository) }
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'archive',
|
||||||
|
label: I18n.t('libraries.index.buttons.archive'),
|
||||||
|
button_id: 'archiveRepoBtn',
|
||||||
|
icon: 'fas fa-archive',
|
||||||
|
path: archive_team_repositories_path(@current_team),
|
||||||
|
type: :request,
|
||||||
|
request_method: :post
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def share_action
|
||||||
|
return unless @repository && can_share_repository?(@repository)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'share',
|
||||||
|
label: I18n.t('repositories.index.share_inventory'),
|
||||||
|
icon: 'fas fa-user-plus',
|
||||||
|
button_class: 'share-repository-button',
|
||||||
|
path: team_repository_share_modal_path(@current_team, repository_id: @repository),
|
||||||
|
type: 'remote-modal'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def restore_action
|
||||||
|
return unless @repositories.all? { |repository| can_archive_repository?(repository) }
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'restore',
|
||||||
|
label: I18n.t('libraries.index.buttons.restore'),
|
||||||
|
icon: 'fas fa-undo',
|
||||||
|
button_id: 'restoreRepoBtn',
|
||||||
|
path: restore_team_repositories_path(@current_team),
|
||||||
|
type: :request,
|
||||||
|
request_method: :post
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_action
|
||||||
|
return unless @repository
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'delete',
|
||||||
|
label: I18n.t('libraries.index.buttons.delete'),
|
||||||
|
icon: 'fas fa-trash',
|
||||||
|
button_id: 'deleteRepoBtn',
|
||||||
|
path: team_repository_destroy_modal_path(@current_team, repository_id: @repository),
|
||||||
|
type: 'remote-modal'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -37,56 +37,30 @@
|
||||||
|
|
||||||
<!-- Repositories action buttons -->
|
<!-- Repositories action buttons -->
|
||||||
<template id="repositoriesListButtons">
|
<template id="repositoriesListButtons">
|
||||||
<% if can_create_repositories?(current_team) %>
|
|
||||||
<a id="createRepoBtn" class="btn btn-primary"
|
|
||||||
data-remote="true"
|
|
||||||
data-view-mode="active"
|
|
||||||
href="<%= create_modal_team_repositories_path(current_team) %>">
|
|
||||||
<span class="fas fa-plus"></span>
|
|
||||||
<span class="hidden-xs"><%= t('libraries.index.no_libraries.create_new_button') %></span>
|
|
||||||
</a>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render partial: 'shared/state_view_switch', locals: {
|
|
||||||
disabled: false,
|
|
||||||
switchable: true,
|
|
||||||
archived: params[:archived],
|
|
||||||
active_url: repositories_path,
|
|
||||||
archived_url: repositories_path(archived: true),
|
|
||||||
} %>
|
|
||||||
<!--
|
|
||||||
<a id="renameRepoBtn" class="btn btn-light disabled hidden" data-view-mode="active" href="#" data-action-mode="single" data-remote="true">
|
|
||||||
<span class="fas fa-pencil-alt"></span>
|
|
||||||
<%= t('libraries.index.buttons.edit') %>
|
|
||||||
</a>
|
|
||||||
<% if can_create_repositories?(current_team) %>
|
<% if can_create_repositories?(current_team) %>
|
||||||
<a id="copyRepoBtn" class="btn btn-light disabled hidden" data-view-mode="active" href="#" data-action-mode="single" data-remote="true">
|
<a id="createRepoBtn" class="btn btn-primary"
|
||||||
<span class="fas fa-copy"></span>
|
data-remote="true"
|
||||||
<%= t('libraries.index.buttons.duplicate') %>
|
data-view-mode="active"
|
||||||
|
href="<%= create_modal_team_repositories_path(current_team) %>">
|
||||||
|
<span class="fas fa-plus"></span>
|
||||||
|
<span class="hidden-xs"><%= t('libraries.index.no_libraries.create_new_button') %></span>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
<a id="archiveRepoBtn"
|
|
||||||
class="btn btn-light disabled hidden"
|
<%= render partial: 'shared/state_view_switch', locals: {
|
||||||
data-view-mode="active"
|
disabled: false,
|
||||||
data-action-mode="multiple"
|
switchable: true,
|
||||||
data-archive-repositories="<%= archive_team_repositories_path(current_team) %>">
|
archived: params[:archived],
|
||||||
<span class="fas fa-archive"></span>
|
active_url: repositories_path,
|
||||||
<%= t('libraries.index.buttons.archive') %>
|
archived_url: repositories_path(archived: true),
|
||||||
</a>
|
} %>
|
||||||
<a id="restoreRepoBtn"
|
</div>
|
||||||
class="btn btn-light disabled hidden"
|
|
||||||
data-view-mode="archived"
|
|
||||||
data-action-mode="multiple"
|
|
||||||
data-restore-repositories="<%= restore_team_repositories_path(current_team) %>">
|
|
||||||
<span class="fas fa-undo"></span>
|
|
||||||
<%= t('libraries.index.buttons.restore') %>
|
|
||||||
</a>
|
|
||||||
<a id="deleteRepoBtn" class="btn btn-light disabled hidden" data-view-mode="archived" href="#" data-action-mode="single" data-remote="true">
|
|
||||||
<span class="fas fa-trash"></span>
|
|
||||||
<%= t('libraries.index.buttons.delete') %>
|
|
||||||
</a>
|
|
||||||
-->
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<div id="actionToolbar" data-behaviour="vue">
|
||||||
|
<action-toolbar actions-url="<%= actions_toolbar_team_repositories_url(current_team) %>" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= javascript_include_tag "repositories/index" %>
|
<%= javascript_include_tag "repositories/index" %>
|
||||||
<%= stylesheet_link_tag 'datatables' %>
|
<%= stylesheet_link_tag 'datatables' %>
|
||||||
|
<%= javascript_include_tag "vue_components_action_toolbar" %>
|
|
@ -196,6 +196,7 @@ Rails.application.routes.draw do
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
get 'create_modal', to: 'repositories#create_modal',
|
get 'create_modal', to: 'repositories#create_modal',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
|
get 'actions_toolbar'
|
||||||
end
|
end
|
||||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
|
|
Loading…
Add table
Reference in a new issue