mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-07 20:40:26 +08:00
Merge pull request #7728 from aignatov-bio/ai-sci-10861-add-storage-locations-toolbar
Add toolbar for storage locations [SCI-10861]
This commit is contained in:
commit
60ce8aa425
5 changed files with 104 additions and 1 deletions
|
@ -52,7 +52,11 @@ class StorageLocationsController < ApplicationController
|
||||||
|
|
||||||
def actions_toolbar
|
def actions_toolbar
|
||||||
render json: {
|
render json: {
|
||||||
actions: [] # TODO: Add actions
|
actions:
|
||||||
|
Toolbars::StorageLocationsService.new(
|
||||||
|
current_user,
|
||||||
|
storage_location_ids: JSON.parse(params[:items]).map { |i| i['id'] }
|
||||||
|
).actions
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,10 @@ Canaid::Permissions.register_for(Team) do
|
||||||
true # TODO: Add permission check
|
true # TODO: Add permission check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
can :manage_storage_locations do |user, team|
|
||||||
|
true # TODO: Add permission check
|
||||||
|
end
|
||||||
|
|
||||||
can :create_reports do |user, team|
|
can :create_reports do |user, team|
|
||||||
team.permission_granted?(user, TeamPermissions::REPORTS_CREATE)
|
team.permission_granted?(user, TeamPermissions::REPORTS_CREATE)
|
||||||
end
|
end
|
||||||
|
|
86
app/services/toolbars/storage_locations_service.rb
Normal file
86
app/services/toolbars/storage_locations_service.rb
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Toolbars
|
||||||
|
class StorageLocationsService
|
||||||
|
attr_reader :current_user
|
||||||
|
|
||||||
|
include Canaid::Helpers::PermissionsHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
def initialize(current_user, storage_location_ids: [])
|
||||||
|
@current_user = current_user
|
||||||
|
@storage_locations = StorageLocation.where(id: storage_location_ids)
|
||||||
|
|
||||||
|
@single = @storage_locations.length == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def actions
|
||||||
|
return [] if @storage_locations.none?
|
||||||
|
|
||||||
|
[
|
||||||
|
edit_action,
|
||||||
|
move_action,
|
||||||
|
duplicate_action,
|
||||||
|
delete_action
|
||||||
|
].compact
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def edit_action
|
||||||
|
return unless @single
|
||||||
|
|
||||||
|
return unless can_manage_storage_locations?(current_user.current_team)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'edit',
|
||||||
|
label: I18n.t('storage_locations.index.toolbar.edit'),
|
||||||
|
icon: 'sn-icon sn-icon-edit',
|
||||||
|
path: storage_location_path(@storage_locations.first),
|
||||||
|
type: :emit
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_action
|
||||||
|
return unless @single
|
||||||
|
|
||||||
|
return unless can_manage_storage_locations?(current_user.current_team)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'set_as_default',
|
||||||
|
label: I18n.t("storage_locations.index.toolbar.move"),
|
||||||
|
icon: 'sn-icon sn-icon-move',
|
||||||
|
path: move_storage_location_path(@storage_locations.first),
|
||||||
|
type: :emit
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def duplicate_action
|
||||||
|
return unless @single
|
||||||
|
|
||||||
|
return unless can_manage_storage_locations?(current_user.current_team)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'duplicate',
|
||||||
|
label: I18n.t('storage_locations.index.toolbar.duplicate'),
|
||||||
|
icon: 'sn-icon sn-icon-duplicate',
|
||||||
|
path: copy_storage_location_path(@storage_locations.first),
|
||||||
|
type: :emit
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_action
|
||||||
|
return unless @single
|
||||||
|
|
||||||
|
return unless can_manage_storage_locations?(current_user.current_team)
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'delete',
|
||||||
|
label: I18n.t('storage_locations.index.toolbar.delete'),
|
||||||
|
icon: 'sn-icon sn-icon-delete',
|
||||||
|
path: storage_location_path(@storage_locations.first),
|
||||||
|
type: :emit
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2672,6 +2672,11 @@ en:
|
||||||
head_title: "Locations"
|
head_title: "Locations"
|
||||||
new_location: "New location"
|
new_location: "New location"
|
||||||
new_box: "New box"
|
new_box: "New box"
|
||||||
|
toolbar:
|
||||||
|
edit: 'Edit'
|
||||||
|
move: 'Move'
|
||||||
|
duplicate: 'Duplicate'
|
||||||
|
delete: 'Delete'
|
||||||
table:
|
table:
|
||||||
name: "Location name"
|
name: "Location name"
|
||||||
id: "ID"
|
id: "ID"
|
||||||
|
|
|
@ -811,6 +811,10 @@ Rails.application.routes.draw do
|
||||||
collection do
|
collection do
|
||||||
get :actions_toolbar
|
get :actions_toolbar
|
||||||
end
|
end
|
||||||
|
member do
|
||||||
|
post :move
|
||||||
|
post :copy
|
||||||
|
end
|
||||||
resources :storage_location_repository_rows, only: %i(index create destroy update)
|
resources :storage_location_repository_rows, only: %i(index create destroy update)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue