mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
moved to develop, fixed pagination style
This commit is contained in:
parent
cf6a901b67
commit
379ef7a9cc
6 changed files with 178 additions and 49 deletions
|
@ -7,6 +7,11 @@
|
|||
var CHECKBOX_SELECTOR;
|
||||
|
||||
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 row;
|
||||
$('#renameRepoBtn').attr('href', '#');
|
||||
|
@ -98,6 +103,9 @@
|
|||
}
|
||||
}],
|
||||
fnInitComplete: function(e) {
|
||||
initActionToolbar();
|
||||
actionToolbarComponent.setBottomOffset(75);
|
||||
|
||||
var dataTableWrapper = $(e.nTableWrapper);
|
||||
CHECKBOX_SELECTOR = new DataTableCheckboxes(dataTableWrapper, {
|
||||
checkboxSelector: '.repository-row-selector',
|
||||
|
@ -188,4 +196,4 @@
|
|||
if (notTurbolinksPreview()) {
|
||||
initRepositoriesDataTable('#repositoriesList', $('.repositories-index').hasClass('archived'));
|
||||
}
|
||||
}());
|
||||
}());
|
|
@ -133,3 +133,22 @@
|
|||
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 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_for_archiving, only: :archive
|
||||
before_action :load_repositories_for_restoring, only: :restore
|
||||
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_delete_permissions, only: %i(destroy destroy_modal)
|
||||
before_action :check_archive_permissions, only: %i(archive restore)
|
||||
|
@ -410,6 +411,17 @@ class RepositoriesController < ApplicationController
|
|||
end }
|
||||
end
|
||||
|
||||
def actions_toolbar
|
||||
render json: {
|
||||
actions:
|
||||
Toolbars::RepositoriesService.new(
|
||||
current_user,
|
||||
current_team,
|
||||
repository_ids: params[:repository_ids].split(',')
|
||||
).actions
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repostiory_import_actions
|
||||
|
|
115
app/services/toolbars/repositories_service.rb
Normal file
115
app/services/toolbars/repositories_service.rb
Normal file
|
@ -0,0 +1,115 @@
|
|||
# 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
|
||||
|
||||
return unless 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
|
||||
|
||||
return unless 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 -->
|
||||
<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) %>
|
||||
<a id="copyRepoBtn" class="btn btn-light disabled hidden" data-view-mode="active" href="#" data-action-mode="single" data-remote="true">
|
||||
<span class="fas fa-copy"></span>
|
||||
<%= t('libraries.index.buttons.duplicate') %>
|
||||
<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 %>
|
||||
<a id="archiveRepoBtn"
|
||||
class="btn btn-light disabled hidden"
|
||||
data-view-mode="active"
|
||||
data-action-mode="multiple"
|
||||
data-archive-repositories="<%= archive_team_repositories_path(current_team) %>">
|
||||
<span class="fas fa-archive"></span>
|
||||
<%= t('libraries.index.buttons.archive') %>
|
||||
</a>
|
||||
<a id="restoreRepoBtn"
|
||||
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>
|
||||
-->
|
||||
|
||||
<%= render partial: 'shared/state_view_switch', locals: {
|
||||
disabled: false,
|
||||
switchable: true,
|
||||
archived: params[:archived],
|
||||
active_url: repositories_path,
|
||||
archived_url: repositories_path(archived: true),
|
||||
} %>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div id="actionToolbar" data-behaviour="vue">
|
||||
<action-toolbar actions-url="<%= actions_toolbar_team_repositories_url(current_team) %>" />
|
||||
</div>
|
||||
|
||||
<%= javascript_include_tag "repositories/index" %>
|
||||
<%= stylesheet_link_tag 'datatables' %>
|
||||
<%= javascript_include_tag "vue_components_action_toolbar" %>
|
|
@ -196,6 +196,7 @@ Rails.application.routes.draw do
|
|||
defaults: { format: 'json' }
|
||||
get 'create_modal', to: 'repositories#create_modal',
|
||||
defaults: { format: 'json' }
|
||||
get 'actions_toolbar'
|
||||
end
|
||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||
defaults: { format: 'json' }
|
||||
|
|
Loading…
Reference in a new issue