mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +08:00
Add toolbar to container table [SCI-10868]
This commit is contained in:
parent
7091c09aff
commit
50928f6948
5 changed files with 82 additions and 2 deletions
|
@ -56,7 +56,10 @@ class StorageLocationRepositoryRowsController < ApplicationController
|
|||
|
||||
def actions_toolbar
|
||||
render json: {
|
||||
actions: []
|
||||
actions: Toolbars::StorageLocationRepositoryRowsService.new(
|
||||
current_user,
|
||||
items_ids: JSON.parse(params[:items]).map { |i| i['id'] }
|
||||
).actions
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
<div v-if="withGrid">
|
||||
<div class="py-4">
|
||||
<div class="h-11">
|
||||
|
||||
<button class="btn btn-primary">
|
||||
<i class="sn-icon sn-icon-new-task"></i>
|
||||
{{ i18n.t('storage_locations.show.toolbar.assign') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<Grid :gridSize="gridSize" :assignedItems="assignedItems" />
|
||||
|
@ -99,6 +102,17 @@ export default {
|
|||
},
|
||||
toolbarActions() {
|
||||
const left = [];
|
||||
|
||||
if (!this.withGrid) {
|
||||
left.push({
|
||||
name: 'assign',
|
||||
icon: 'sn-icon sn-icon-new-task',
|
||||
label: this.i18n.t('storage_locations.show.toolbar.assign'),
|
||||
type: 'emit',
|
||||
buttonStyle: 'btn btn-primary'
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
left,
|
||||
right: []
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Toolbars
|
||||
class StorageLocationRepositoryRowsService
|
||||
attr_reader :current_user
|
||||
|
||||
include Canaid::Helpers::PermissionsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def initialize(current_user, items_ids: [])
|
||||
@current_user = current_user
|
||||
@assigned_rows = StorageLocationRepositoryRow.where(id: items_ids)
|
||||
@storage_location = @assigned_rows.first&.storage_location
|
||||
|
||||
@single = @assigned_rows.length == 1
|
||||
end
|
||||
|
||||
def actions
|
||||
return [] if @assigned_rows.none?
|
||||
|
||||
[
|
||||
unassign_action,
|
||||
move_action
|
||||
].compact
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unassign_action
|
||||
{
|
||||
name: 'edit',
|
||||
label: I18n.t('storage_locations.show.toolbar.unassign'),
|
||||
icon: 'sn-icon sn-icon-close',
|
||||
path: unassign_storage_location_storage_location_repository_rows_path(
|
||||
@storage_location, ids: @assigned_rows.pluck(:id)
|
||||
),
|
||||
type: :emit
|
||||
}
|
||||
end
|
||||
|
||||
def move_action
|
||||
return unless @single
|
||||
|
||||
{
|
||||
name: 'move',
|
||||
label: I18n.t('storage_locations.show.toolbar.move'),
|
||||
icon: 'sn-icon sn-icon-move',
|
||||
path: move_storage_location_storage_location_repository_row_path(
|
||||
@storage_location, @assigned_rows.first
|
||||
),
|
||||
type: :emit
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2680,6 +2680,10 @@ en:
|
|||
row_id: "Item ID"
|
||||
row_name: "Name"
|
||||
stock: "Stock"
|
||||
toolbar:
|
||||
assign: 'Assign item'
|
||||
unassign: 'Unassign'
|
||||
move: 'Move'
|
||||
index:
|
||||
head_title: "Locations"
|
||||
new_location: "New location"
|
||||
|
|
|
@ -819,6 +819,10 @@ Rails.application.routes.draw do
|
|||
resources :storage_location_repository_rows, only: %i(index create destroy update) do
|
||||
collection do
|
||||
get :actions_toolbar
|
||||
post :unassign
|
||||
end
|
||||
member do
|
||||
post :move
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue