2017-06-06 23:35:29 +08:00
|
|
|
class RepositoryRowsController < ApplicationController
|
|
|
|
include InputSanitizeHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ApplicationHelper
|
2020-05-08 17:56:29 +08:00
|
|
|
include MyModulesHelper
|
2023-10-26 18:59:11 +08:00
|
|
|
include RepositoryDatatableHelper
|
2017-06-06 23:35:29 +08:00
|
|
|
|
2024-01-09 16:37:50 +08:00
|
|
|
before_action :load_repository, except: %i(show print rows_to_print print_zpl validate_label_template_columns)
|
|
|
|
before_action :load_repository_or_snapshot, only: %i(show print rows_to_print print_zpl
|
|
|
|
validate_label_template_columns)
|
|
|
|
before_action :load_repository_row, only: %i(show update update_cell assigned_task_list
|
2023-11-23 18:08:42 +08:00
|
|
|
active_reminder_repository_cells relationships)
|
2024-01-09 16:37:50 +08:00
|
|
|
before_action :load_repository_rows, only: %i(print rows_to_print print_zpl validate_label_template_columns)
|
|
|
|
|
|
|
|
before_action :check_read_permissions, except: %i(create update update_cell delete_records
|
|
|
|
copy_records archive_records restore_records)
|
2020-05-15 23:46:59 +08:00
|
|
|
before_action :check_snapshotting_status, only: %i(create update delete_records copy_records)
|
2017-06-06 23:35:29 +08:00
|
|
|
before_action :check_create_permissions, only: :create
|
2020-06-10 01:18:30 +08:00
|
|
|
before_action :check_delete_permissions, only: %i(delete_records archive_records restore_records)
|
2023-10-16 23:43:53 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(update update_cell copy_records)
|
2017-06-06 23:35:29 +08:00
|
|
|
|
2018-03-06 23:32:39 +08:00
|
|
|
def index
|
|
|
|
@draw = params[:draw].to_i
|
|
|
|
per_page = params[:length] == '-1' ? 100 : params[:length].to_i
|
|
|
|
page = (params[:start].to_i / per_page) + 1
|
2020-01-13 23:09:07 +08:00
|
|
|
datatable_service = RepositoryDatatableService.new(@repository, params, current_user)
|
|
|
|
|
|
|
|
@all_rows_count = datatable_service.all_count
|
|
|
|
@columns_mappings = datatable_service.mappings
|
|
|
|
@repository_rows = datatable_service.repository_rows
|
2020-01-13 23:31:42 +08:00
|
|
|
.preload(:repository_columns,
|
|
|
|
:created_by,
|
2022-06-08 19:23:39 +08:00
|
|
|
:archived_by,
|
2021-07-07 23:43:51 +08:00
|
|
|
repository_cells: { value: @repository.cell_preload_includes })
|
2020-01-13 23:09:07 +08:00
|
|
|
.page(page)
|
|
|
|
.per(per_page)
|
2020-06-24 17:22:28 +08:00
|
|
|
|
|
|
|
@repository_rows = @repository_rows.where(archived: params[:archived]) unless @repository.archived?
|
2022-02-11 17:24:29 +08:00
|
|
|
rescue RepositoryFilters::ColumnNotFoundException
|
2022-02-15 21:37:26 +08:00
|
|
|
render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.column_not_found') }
|
2022-02-11 17:24:29 +08:00
|
|
|
rescue RepositoryFilters::ValueNotFoundException
|
2022-02-15 21:37:26 +08:00
|
|
|
render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.value_not_found') }
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
|
2023-09-18 22:24:07 +08:00
|
|
|
def show
|
2023-11-14 16:48:29 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
redirect_to repository_path(@repository)
|
|
|
|
end
|
2023-09-18 22:24:07 +08:00
|
|
|
|
2023-11-14 16:48:29 +08:00
|
|
|
format.json do
|
|
|
|
@my_module = if params[:my_module_id].present?
|
|
|
|
MyModule.repository_row_assignable_by_user(current_user).find_by(id: params[:my_module_id])
|
|
|
|
end
|
|
|
|
return render_403 if @my_module && !can_read_my_module?(@my_module)
|
|
|
|
|
|
|
|
if @my_module
|
|
|
|
@my_module_assign_error = if !can_assign_my_module_repository_rows?(@my_module)
|
|
|
|
I18n.t('repository_row.modal_info.assign_to_task_error.no_access')
|
|
|
|
elsif @repository_row.my_modules.where(id: @my_module.id).any?
|
|
|
|
I18n.t('repository_row.modal_info.assign_to_task_error.already_assigned')
|
|
|
|
end
|
|
|
|
end
|
2023-09-18 22:24:07 +08:00
|
|
|
|
2023-11-14 16:48:29 +08:00
|
|
|
@assigned_modules = @repository_row.my_modules
|
|
|
|
.joins(experiment: :project)
|
|
|
|
.joins(:my_module_repository_rows)
|
|
|
|
.select('my_module_repository_rows.created_at, my_modules.*')
|
|
|
|
.order('my_module_repository_rows.created_at': :desc)
|
|
|
|
.distinct
|
|
|
|
@viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams)
|
|
|
|
@reminders_present = @repository_row.repository_cells.with_active_reminder(@current_user).any?
|
|
|
|
end
|
|
|
|
end
|
2023-09-18 22:24:07 +08:00
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def create
|
2019-12-10 15:43:26 +08:00
|
|
|
service = RepositoryRows::CreateRepositoryRowService
|
|
|
|
.call(repository: @repository, user: current_user, params: update_params)
|
2017-06-22 23:26:11 +08:00
|
|
|
|
2019-12-10 15:43:26 +08:00
|
|
|
if service.succeed?
|
2020-03-24 01:45:36 +08:00
|
|
|
repository_row = service.repository_row
|
2023-10-24 22:22:10 +08:00
|
|
|
log_activity(:create_item_inventory, repository_row, { repository_row: repository_row.id,
|
|
|
|
repository: @repository.id })
|
2020-03-24 01:45:36 +08:00
|
|
|
repository_row.repository_cells.where(value_type: 'RepositoryTextValue').each do |repository_cell|
|
|
|
|
record_annotation_notification(repository_row, repository_cell)
|
|
|
|
end
|
2019-12-10 15:43:26 +08:00
|
|
|
|
|
|
|
render json: { id: service.repository_row.id, flash: t('repositories.create.success_flash',
|
2020-03-24 01:45:36 +08:00
|
|
|
record: escape_input(repository_row.name),
|
2019-12-10 15:43:26 +08:00
|
|
|
repository: escape_input(@repository.name)) },
|
|
|
|
status: :ok
|
|
|
|
else
|
|
|
|
render json: service.errors, status: :bad_request
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-22 21:06:36 +08:00
|
|
|
def validate_label_template_columns
|
2022-09-27 21:46:48 +08:00
|
|
|
label_template = LabelTemplate.where(team_id: current_team.id).find(params[:label_template_id])
|
|
|
|
|
2024-01-09 16:37:50 +08:00
|
|
|
label_code = LabelTemplates::RepositoryRowService.new(label_template, @repository_rows.first).render
|
2022-10-19 19:18:33 +08:00
|
|
|
if label_code[:error].empty?
|
|
|
|
render json: { label_code: label_code[:label] }
|
|
|
|
else
|
|
|
|
render json: { error: label_code[:error].first, label_code: label_code[:label] }, status: :unprocessable_entity
|
|
|
|
end
|
2022-09-22 21:06:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def print_zpl
|
|
|
|
label_template = LabelTemplate.find_by(id: params[:label_template_id])
|
2024-01-09 16:37:50 +08:00
|
|
|
labels = @repository_rows.flat_map do |repository_row|
|
2022-09-22 21:06:36 +08:00
|
|
|
LabelTemplates::RepositoryRowService.new(label_template,
|
2022-10-19 19:18:33 +08:00
|
|
|
repository_row).render[:label]
|
2022-09-22 21:06:36 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
render(
|
|
|
|
json: {
|
|
|
|
html:
|
|
|
|
render_to_string(
|
|
|
|
partial: 'label_printers/print_zebra_progress_modal'
|
|
|
|
),
|
|
|
|
labels: labels
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-09-22 17:07:08 +08:00
|
|
|
def rows_to_print
|
2024-01-09 16:37:50 +08:00
|
|
|
render json: @repository_rows, each_serializer: RepositoryRowSerializer, user: current_user
|
2022-09-22 17:07:08 +08:00
|
|
|
end
|
|
|
|
|
2021-08-02 17:11:11 +08:00
|
|
|
def print
|
2021-08-12 22:57:25 +08:00
|
|
|
# reset all potential error states for printers and discard all jobs
|
|
|
|
|
|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
|
|
|
LabelPrinter.update_all(status: :ready, current_print_job_ids: [])
|
|
|
|
# rubocop:enable Rails/SkipsModelValidations
|
2021-08-02 21:33:51 +08:00
|
|
|
|
2021-08-12 22:57:25 +08:00
|
|
|
label_printer = LabelPrinter.find(params[:label_printer_id])
|
2022-09-22 21:06:36 +08:00
|
|
|
label_template = LabelTemplate.find_by(id: params[:label_template_id])
|
2021-08-02 17:11:11 +08:00
|
|
|
|
2024-01-09 16:37:50 +08:00
|
|
|
job_ids = @repository_rows.flat_map do |repository_row|
|
2021-08-12 22:57:25 +08:00
|
|
|
LabelPrinters::PrintJob.perform_later(
|
|
|
|
label_printer,
|
2022-09-22 21:06:36 +08:00
|
|
|
LabelTemplates::RepositoryRowService.new(label_template,
|
2022-10-19 19:18:33 +08:00
|
|
|
repository_row).render[:label],
|
2021-08-12 22:57:25 +08:00
|
|
|
params[:copies].to_i
|
|
|
|
).job_id
|
2021-08-02 17:11:11 +08:00
|
|
|
end
|
|
|
|
|
2021-08-12 22:57:25 +08:00
|
|
|
label_printer.update!(current_print_job_ids: job_ids * params[:copies].to_i)
|
2021-08-02 17:11:11 +08:00
|
|
|
|
2021-09-07 18:28:11 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'label_printers/print_progress_modal',
|
2021-09-07 18:28:11 +08:00
|
|
|
locals: { starting_item_count: label_printer.current_print_job_ids.length,
|
|
|
|
label_printer: label_printer }
|
|
|
|
)
|
|
|
|
}
|
2021-08-02 17:11:11 +08:00
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def update
|
2019-12-10 15:43:26 +08:00
|
|
|
row_update = RepositoryRows::UpdateRepositoryRowService
|
2020-05-15 23:46:59 +08:00
|
|
|
.call(repository_row: @repository_row, user: current_user, params: update_params)
|
2017-06-06 23:35:29 +08:00
|
|
|
|
2019-12-10 15:43:26 +08:00
|
|
|
if row_update.succeed?
|
2020-03-24 01:45:36 +08:00
|
|
|
if row_update.record_updated
|
2023-10-24 22:22:10 +08:00
|
|
|
log_activity(:edit_item_inventory, @repository_row, { repository_row: @repository_row.id,
|
|
|
|
repository: @repository.id })
|
2020-05-15 23:46:59 +08:00
|
|
|
@repository_row.repository_cells.where(value_type: 'RepositoryTextValue').each do |repository_cell|
|
|
|
|
record_annotation_notification(@repository_row, repository_cell)
|
2020-03-24 01:45:36 +08:00
|
|
|
end
|
|
|
|
end
|
2018-07-03 21:25:37 +08:00
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
render json: {
|
|
|
|
id: @repository_row.id,
|
|
|
|
flash: t(
|
|
|
|
'repositories.update.success_flash',
|
|
|
|
record: escape_input(@repository_row.name),
|
|
|
|
repository: escape_input(@repository.name)
|
|
|
|
)
|
|
|
|
}, status: :ok
|
2018-04-16 20:10:49 +08:00
|
|
|
else
|
2019-12-10 15:43:26 +08:00
|
|
|
render json: row_update.errors, status: :bad_request
|
2018-04-16 20:10:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-16 23:43:53 +08:00
|
|
|
def update_cell
|
|
|
|
return render_422(t('.invalid_params')) if
|
|
|
|
update_params['repository_row'].present? && update_params['repository_cells'].present?
|
|
|
|
return render_422(t('.invalid_params')) if
|
|
|
|
update_params['repository_cells'] && update_params['repository_cells'].size != 1
|
|
|
|
|
|
|
|
row_cell_update =
|
|
|
|
RepositoryRows::UpdateRepositoryRowService.call(
|
|
|
|
repository_row: @repository_row, user: current_user, params: update_params
|
|
|
|
)
|
|
|
|
|
|
|
|
if row_cell_update.succeed?
|
2023-10-24 22:22:10 +08:00
|
|
|
if row_cell_update.record_updated
|
|
|
|
log_activity(:edit_item_field_inventory, @repository_row,
|
|
|
|
{ repository_row: @repository_row.id,
|
|
|
|
repository_column: update_params['repository_cells']&.keys&.first ||
|
|
|
|
I18n.t('repositories.table.row_name') })
|
|
|
|
end
|
2023-11-10 20:25:46 +08:00
|
|
|
@reminders_present = @repository_row.repository_cells.with_active_reminder(@current_user).any?
|
2023-10-26 18:59:11 +08:00
|
|
|
|
2023-11-20 22:26:01 +08:00
|
|
|
return render json: { name: @repository_row.name } if update_params['repository_row'].present?
|
|
|
|
|
|
|
|
column = row_cell_update.column
|
2023-11-29 21:54:30 +08:00
|
|
|
cell = row_cell_update.cell&.reload || row_cell_update.cell
|
2023-11-20 22:26:01 +08:00
|
|
|
data = { value_type: column.data_type, id: column.id, value: nil }
|
|
|
|
|
|
|
|
return render json: data if cell.blank?
|
|
|
|
|
|
|
|
data['hasActiveReminders'] = @reminders_present
|
|
|
|
data.merge! serialize_repository_cell_value(cell,
|
|
|
|
@repository.team,
|
|
|
|
@repository,
|
|
|
|
reminders_enabled: @reminders_present)
|
|
|
|
render json: data
|
2023-10-16 23:43:53 +08:00
|
|
|
else
|
2023-11-20 22:26:01 +08:00
|
|
|
render json: row_cell_update.errors, status: :bad_request
|
2023-10-16 23:43:53 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def delete_records
|
|
|
|
deleted_count = 0
|
2017-12-20 00:53:45 +08:00
|
|
|
if selected_params
|
|
|
|
selected_params.each do |row_id|
|
2020-05-15 23:46:59 +08:00
|
|
|
row = @repository.repository_rows.find_by(id: row_id)
|
2019-07-12 22:43:54 +08:00
|
|
|
next unless row && can_manage_repository_rows?(@repository)
|
2019-03-07 14:38:34 +08:00
|
|
|
|
2023-10-24 22:22:10 +08:00
|
|
|
log_activity(:delete_item_inventory, row, { repository_row: row.id, repository: @repository.id })
|
2019-07-12 22:43:54 +08:00
|
|
|
row.destroy && deleted_count += 1
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
if deleted_count.zero?
|
2017-06-16 23:12:04 +08:00
|
|
|
flash = t('repositories.destroy.no_deleted_records_flash',
|
2017-12-20 00:53:45 +08:00
|
|
|
other_records_number: selected_params.count)
|
|
|
|
elsif deleted_count != selected_params.count
|
|
|
|
not_deleted_count = selected_params.count - deleted_count
|
2017-06-06 23:35:29 +08:00
|
|
|
flash = t('repositories.destroy.contains_other_records_flash',
|
|
|
|
records_number: deleted_count,
|
|
|
|
other_records_number: not_deleted_count)
|
|
|
|
else
|
|
|
|
flash = t('repositories.destroy.success_flash',
|
|
|
|
records_number: deleted_count)
|
|
|
|
end
|
2023-07-18 19:36:41 +08:00
|
|
|
color = deleted_count.zero? ? 'info' : 'success'
|
|
|
|
render json: { flash: flash, color: color }, status: :ok
|
2017-06-06 23:35:29 +08:00
|
|
|
else
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
flash: t('repositories.destroy.no_records_selected_flash')
|
|
|
|
}, status: :bad_request
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-11 23:17:19 +08:00
|
|
|
def copy_records
|
2018-04-13 17:47:33 +08:00
|
|
|
duplicate_service = RepositoryActions::DuplicateRows.new(
|
2020-06-11 22:11:23 +08:00
|
|
|
current_user, @repository, selected_rows_in_repo_params
|
2018-04-13 17:47:33 +08:00
|
|
|
)
|
2018-04-11 23:17:19 +08:00
|
|
|
duplicate_service.call
|
|
|
|
render json: {
|
|
|
|
flash: t('repositories.copy_records_report',
|
|
|
|
number: duplicate_service.number_of_duplicated_items)
|
|
|
|
}, status: :ok
|
|
|
|
end
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
def available_rows
|
2021-07-23 17:56:28 +08:00
|
|
|
if @repository.repository_rows.active.blank?
|
2018-05-16 15:31:19 +08:00
|
|
|
no_items_string =
|
|
|
|
"#{t('projects.reports.new.save_PDF_to_inventory_modal.no_items')} " \
|
|
|
|
"#{link_to(t('projects.reports.new.save_PDF_to_inventory_modal.here'),
|
|
|
|
repository_path(@repository),
|
|
|
|
data: { 'no-turbolink' => true })}"
|
2024-01-11 02:56:01 +08:00
|
|
|
render json: { no_items: no_items_string }, status: :unprocessable_entity
|
2018-05-16 15:31:19 +08:00
|
|
|
else
|
2024-01-11 02:56:01 +08:00
|
|
|
render json: { results: load_available_rows }, status: :ok
|
2018-05-16 15:31:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-24 21:43:10 +08:00
|
|
|
def assigned_task_list
|
2020-05-20 23:23:48 +08:00
|
|
|
assigned_modules = @repository_row.my_modules.joins(experiment: :project)
|
2020-05-28 21:35:19 +08:00
|
|
|
.where_attributes_like(
|
|
|
|
['my_modules.name', 'experiments.name', 'projects.name'],
|
|
|
|
params[:query],
|
|
|
|
whole_phrase: true
|
|
|
|
)
|
2022-01-27 19:59:52 +08:00
|
|
|
viewable_modules = assigned_modules.viewable_by_user(current_user, current_user.teams)
|
2022-01-04 17:18:08 +08:00
|
|
|
private_modules_number = assigned_modules.where.not(id: viewable_modules).count
|
2020-04-28 18:41:59 +08:00
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string(partial: 'shared/my_modules_list_partial', locals: {
|
2020-05-20 23:23:48 +08:00
|
|
|
my_modules: viewable_modules,
|
2022-01-04 17:18:08 +08:00
|
|
|
private_modules_number: private_modules_number
|
2020-05-07 18:51:18 +08:00
|
|
|
})
|
2020-04-28 18:41:59 +08:00
|
|
|
}
|
2020-04-24 21:43:10 +08:00
|
|
|
end
|
|
|
|
|
2022-03-09 21:13:48 +08:00
|
|
|
def reminder_repository_cells
|
2022-03-15 17:24:35 +08:00
|
|
|
render json: @repository_row.repository_cells.with_active_reminder(current_user)
|
2022-03-09 21:13:48 +08:00
|
|
|
end
|
|
|
|
|
2020-06-10 01:18:30 +08:00
|
|
|
def archive_records
|
|
|
|
service = RepositoryActions::ArchiveRowsService.call(repository: @repository,
|
2020-06-11 22:11:23 +08:00
|
|
|
repository_rows: selected_rows_in_repo_params,
|
2020-06-10 01:18:30 +08:00
|
|
|
user: current_user,
|
|
|
|
team: current_team)
|
|
|
|
|
|
|
|
if service.succeed?
|
2023-03-15 22:56:47 +08:00
|
|
|
render json: { flash: t('repositories.archive_records.success_flash', repository: escape_input(@repository.name)) }
|
2020-06-10 01:18:30 +08:00
|
|
|
else
|
2020-06-10 04:16:55 +08:00
|
|
|
render json: { error: service.error_message }, status: :unprocessable_entity
|
2020-06-10 01:18:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def restore_records
|
|
|
|
service = RepositoryActions::RestoreRowsService.call(repository: @repository,
|
2020-06-11 22:11:23 +08:00
|
|
|
repository_rows: selected_rows_in_repo_params,
|
2020-06-10 01:18:30 +08:00
|
|
|
user: current_user,
|
|
|
|
team: current_team)
|
|
|
|
|
|
|
|
if service.succeed?
|
2023-03-15 22:56:47 +08:00
|
|
|
render json: { flash: t('repositories.restore_records.success_flash', repository: escape_input(@repository.name)) }
|
2020-06-10 01:18:30 +08:00
|
|
|
else
|
2020-06-10 04:16:55 +08:00
|
|
|
render json: { error: service.error_message }, status: :unprocessable_entity
|
2020-06-10 01:18:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-15 17:24:35 +08:00
|
|
|
def active_reminder_repository_cells
|
|
|
|
reminder_cells = @repository_row.repository_cells.with_active_reminder(current_user).distinct
|
|
|
|
render json: {
|
2024-08-08 17:52:22 +08:00
|
|
|
html: render_to_string(partial: 'shared/repository_row_reminder', formats: :html, locals: {
|
2022-03-15 17:24:35 +08:00
|
|
|
reminders: reminder_cells
|
|
|
|
})
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-05-17 17:27:55 +08:00
|
|
|
def actions_toolbar
|
|
|
|
render json: {
|
|
|
|
actions:
|
|
|
|
Toolbars::RepositoryRowsService.new(
|
|
|
|
current_user,
|
|
|
|
repository_row_ids: params[:repository_row_ids].split(',')
|
|
|
|
).actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-10-02 22:11:32 +08:00
|
|
|
def relationships
|
|
|
|
render json: {
|
|
|
|
repository_row: RepositoryRowSerializer.new(@repository_row),
|
|
|
|
parents: @repository_row.parent_repository_rows.map { |r| RepositoryRowSerializer.new(r) },
|
|
|
|
children: @repository_row.child_repository_rows.map { |r| RepositoryRowSerializer.new(r) }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
private
|
|
|
|
|
2018-05-16 15:31:19 +08:00
|
|
|
include StringUtility
|
|
|
|
AvailableRepositoryRow = Struct.new(:id, :name, :has_file_attached)
|
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def load_repository
|
2024-08-09 21:56:59 +08:00
|
|
|
@repository = Repository.viewable_by_user(current_user)
|
2019-08-12 16:55:30 +08:00
|
|
|
.eager_load(:repository_columns)
|
2020-05-15 23:46:59 +08:00
|
|
|
.find_by(id: params[:repository_id])
|
|
|
|
render_404 unless @repository
|
2022-01-04 21:12:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_repository_or_snapshot
|
2024-08-09 21:56:59 +08:00
|
|
|
@repository = Repository.viewable_by_user(current_user).find_by(id: params[:repository_id]) ||
|
2024-01-09 16:37:50 +08:00
|
|
|
RepositorySnapshot.find_by(id: params[:repository_id])
|
2023-11-22 21:53:08 +08:00
|
|
|
return render_404 unless @repository
|
|
|
|
end
|
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def load_repository_row
|
|
|
|
@repository_row = @repository.repository_rows.eager_load(:repository_columns).find_by(id: params[:id])
|
|
|
|
render_404 unless @repository_row
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2024-01-09 16:37:50 +08:00
|
|
|
def load_repository_rows
|
|
|
|
@repository_rows = @repository.repository_rows.eager_load(:repository_columns).where(id: params[:row_ids])
|
|
|
|
|
|
|
|
render_404 if @repository_rows.blank?
|
|
|
|
end
|
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def check_read_permissions
|
2019-07-17 22:00:49 +08:00
|
|
|
render_403 unless can_read_repository?(@repository)
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
|
2020-05-15 23:46:59 +08:00
|
|
|
def check_snapshotting_status
|
|
|
|
return if @repository.repository_snapshots.provisioning.none?
|
|
|
|
|
2023-07-18 19:36:41 +08:00
|
|
|
render json: {
|
|
|
|
flash: t('repositories.index.snapshot_provisioning_in_progress')
|
|
|
|
}, status: :unprocessable_entity
|
2020-05-15 23:46:59 +08:00
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def check_create_permissions
|
2019-07-12 22:43:54 +08:00
|
|
|
render_403 unless can_create_repository_rows?(@repository)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
def check_manage_permissions
|
2019-07-12 22:43:54 +08:00
|
|
|
render_403 unless can_manage_repository_rows?(@repository)
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2019-11-22 20:23:02 +08:00
|
|
|
def check_delete_permissions
|
|
|
|
render_403 unless can_delete_repository_rows?(@repository)
|
|
|
|
end
|
|
|
|
|
2018-08-21 22:46:47 +08:00
|
|
|
def remove_file_columns_params
|
|
|
|
JSON.parse(params.fetch(:remove_file_columns) { '[]' })
|
|
|
|
end
|
|
|
|
|
2017-12-20 00:53:45 +08:00
|
|
|
def selected_params
|
|
|
|
params.permit(selected_rows: []).to_h[:selected_rows]
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|
|
|
|
|
2020-06-11 22:11:23 +08:00
|
|
|
# Selected rows in scope of current @repository
|
|
|
|
def selected_rows_in_repo_params
|
2020-01-14 23:55:10 +08:00
|
|
|
process_ids = params[:selected_rows].map(&:to_i).uniq
|
|
|
|
@repository.repository_rows.where(id: process_ids).pluck(:id)
|
|
|
|
end
|
|
|
|
|
2022-02-11 17:24:29 +08:00
|
|
|
def load_available_rows
|
2018-05-16 15:31:19 +08:00
|
|
|
@repository.repository_rows
|
2020-06-16 14:47:48 +08:00
|
|
|
.active
|
2018-05-16 15:31:19 +08:00
|
|
|
.includes(:repository_cells)
|
|
|
|
.name_like(search_params[:q])
|
|
|
|
.limit(Constants::SEARCH_LIMIT)
|
|
|
|
.select(:id, :name)
|
|
|
|
.collect do |row|
|
|
|
|
with_asset_cell = row.repository_cells.where(
|
|
|
|
'repository_cells.repository_column_id = ?',
|
|
|
|
search_params[:repository_column_id]
|
|
|
|
)
|
|
|
|
AvailableRepositoryRow.new(row.id,
|
2018-05-17 17:21:34 +08:00
|
|
|
ellipsize(row.name, 75, 50),
|
2018-05-16 15:31:19 +08:00
|
|
|
with_asset_cell.present?)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def search_params
|
|
|
|
params.permit(:q, :repository_id, :repository_column_id)
|
|
|
|
end
|
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
def record_annotation_notification(record, cell, old_text = nil)
|
|
|
|
smart_annotation_notification(
|
2020-03-24 01:45:36 +08:00
|
|
|
old_text: old_text,
|
2017-06-06 23:35:29 +08:00
|
|
|
new_text: cell.value.data,
|
2023-11-27 18:29:27 +08:00
|
|
|
subject: cell.repository_column.repository,
|
2017-06-06 23:35:29 +08:00
|
|
|
title: t('notifications.repository_annotation_title',
|
|
|
|
user: current_user.full_name,
|
|
|
|
column: cell.repository_column.name,
|
|
|
|
record: record.name,
|
2019-03-20 17:52:58 +08:00
|
|
|
repository: record.repository.name),
|
2017-06-06 23:35:29 +08:00
|
|
|
message: t('notifications.repository_annotation_message_html',
|
2020-03-24 01:45:36 +08:00
|
|
|
record: link_to(record.name, repository_url(@repository)),
|
|
|
|
column: link_to(cell.repository_column.name, repository_url(@repository)))
|
2017-06-06 23:35:29 +08:00
|
|
|
)
|
|
|
|
end
|
2018-03-15 22:43:16 +08:00
|
|
|
|
|
|
|
def fetch_list_items(cell)
|
|
|
|
return [] if cell.value_type != 'RepositoryListValue'
|
|
|
|
RepositoryListItem.where(repository: @repository)
|
|
|
|
.where(repository_column: cell.repository_column)
|
|
|
|
.limit(Constants::SEARCH_LIMIT)
|
|
|
|
.pluck(:id, :data)
|
2019-05-08 23:38:24 +08:00
|
|
|
.map { |li| [li[0], escape_input(li[1])] }
|
2018-03-15 22:43:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_columns_list_items
|
|
|
|
collection = []
|
|
|
|
@repository.repository_columns
|
|
|
|
.list_type
|
|
|
|
.preload(:repository_list_items)
|
|
|
|
.each do |column|
|
|
|
|
collection << {
|
|
|
|
column_id: column.id,
|
|
|
|
list_items: column.repository_list_items
|
|
|
|
.limit(Constants::SEARCH_LIMIT)
|
|
|
|
.pluck(:id, :data)
|
2019-05-08 23:38:24 +08:00
|
|
|
.map { |li| [li[0], escape_input(li[1])] }
|
2018-03-15 22:43:16 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
collection
|
|
|
|
end
|
2019-03-07 14:38:34 +08:00
|
|
|
|
2019-12-10 15:43:26 +08:00
|
|
|
def update_params
|
2023-10-16 23:43:53 +08:00
|
|
|
params.permit(repository_row: :name, repository_cells: {}).to_h
|
2019-12-10 15:43:26 +08:00
|
|
|
end
|
|
|
|
|
2023-10-24 22:22:10 +08:00
|
|
|
def log_activity(type_of, repository_row, message_items = {})
|
2019-03-07 14:38:34 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
2022-07-07 18:00:35 +08:00
|
|
|
subject: repository_row,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: @repository.team,
|
2023-10-24 22:22:10 +08:00
|
|
|
message_items: message_items)
|
2019-03-07 14:38:34 +08:00
|
|
|
end
|
2017-06-06 23:35:29 +08:00
|
|
|
end
|