diff --git a/app/controllers/repository_columns_controller.rb b/app/controllers/repository_columns_controller.rb index aee0b4b7a..b9df94444 100644 --- a/app/controllers/repository_columns_controller.rb +++ b/app/controllers/repository_columns_controller.rb @@ -34,6 +34,18 @@ class RepositoryColumnsController < ApplicationController raise NotImplementedError end + def describe_all + response_json = @repository.repository_columns.map do |column| + { + id: column.id, + name: escape_input(column.name), + data_type: column.data_type, + items: column.items&.map { |item| { id: item.id, label: escape_input(item.data) } } + } + end + render json: { response: response_json } + end + def edit render json: { html: render_to_string( @@ -118,7 +130,8 @@ class RepositoryColumnsController < ApplicationController end def load_asset_type_columns - render_403 unless can_read_repository?(@repository) + render_403 && return unless can_read_repository?(@repository) + @asset_columns = load_asset_columns(search_params[:q]) end diff --git a/app/models/repository_column.rb b/app/models/repository_column.rb index 8d5f071a4..16b36d16f 100644 --- a/app/models/repository_column.rb +++ b/app/models/repository_column.rb @@ -100,6 +100,11 @@ class RepositoryColumn < ApplicationRecord Constants::REPOSITORY_LIST_ITEMS_DELIMITERS_MAP[metadata['delimiter']&.to_sym] || "\n" end + def items + items_method_name = "#{data_type.chomp('Value').underscore}_items" + __send__(items_method_name) if respond_to?(items_method_name, true) + end + private def repository_list_value_deep_dup(new_column) diff --git a/config/routes.rb b/config/routes.rb index 6ca4aa9e8..60706a24c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -584,7 +584,11 @@ Rails.application.routes.draw do get :table_toolbar get :status - resources :repository_columns, only: %i(index new edit destroy) + resources :repository_columns, only: %i(index new edit destroy) do + collection do + get :describe_all + end + end resources :repository_rows, only: %i(create show update) do collection do get :print_modal