mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
Merge pull request #7729 from artoscinote/ma_SCI_10859
Implement sub-location count column [SCI-10859]
This commit is contained in:
commit
d470a3a5ac
4 changed files with 19 additions and 5 deletions
|
|
@ -101,8 +101,9 @@ export default {
|
||||||
sortable: true
|
sortable: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'sub_locations',
|
field: 'sub_location_count',
|
||||||
headerName: this.i18n.t('storage_locations.index.table.sub_locations'),
|
headerName: this.i18n.t('storage_locations.index.table.sub_locations'),
|
||||||
|
width: 250,
|
||||||
sortable: true
|
sortable: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ class StorageLocation < ApplicationRecord
|
||||||
belongs_to :parent, class_name: 'StorageLocation', optional: true
|
belongs_to :parent, class_name: 'StorageLocation', optional: true
|
||||||
belongs_to :created_by, class_name: 'User'
|
belongs_to :created_by, class_name: 'User'
|
||||||
|
|
||||||
has_many :storage_location_repository_rows, inverse_of: :storage_location
|
has_many :storage_location_repository_rows, inverse_of: :storage_location, dependent: :destroy
|
||||||
has_many :storage_locations, foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent
|
has_many :storage_locations, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||||
has_many :repository_rows, through: :storage_location_repository_row
|
has_many :repository_rows, through: :storage_location_repository_row
|
||||||
|
|
||||||
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module Lists
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
|
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
|
||||||
:created_on, :urls, :metadata, :file_name
|
:created_on, :urls, :metadata, :file_name, :sub_location_count
|
||||||
|
|
||||||
def owned_by
|
def owned_by
|
||||||
object.team.name
|
object.team.name
|
||||||
|
|
@ -30,6 +30,14 @@ module Lists
|
||||||
I18n.l(object.created_at, format: :full)
|
I18n.l(object.created_at, format: :full)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sub_location_count
|
||||||
|
if object.respond_to?(:sub_location_count)
|
||||||
|
object.sub_location_count
|
||||||
|
else
|
||||||
|
StorageLocation.where(parent_id: object.id).count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def urls
|
def urls
|
||||||
show_url = if @object.container
|
show_url = if @object.container
|
||||||
storage_location_path(@object)
|
storage_location_path(@object)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,12 @@ module Lists
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_records
|
def fetch_records
|
||||||
@records = @team.storage_locations
|
@records =
|
||||||
|
StorageLocation.joins('LEFT JOIN storage_locations AS sub_locations ' \
|
||||||
|
'ON storage_locations.id = sub_locations.parent_id')
|
||||||
|
.select('storage_locations.*, COUNT(sub_locations.id) AS sub_location_count')
|
||||||
|
.where(team: @team)
|
||||||
|
.group(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_records
|
def filter_records
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue