DEV: Plugin API to allow creation of directory columns with item query (#13402)

The first thing we needed here was an enum rather than a boolean to determine how a directory_column was created. Now we have `automatic`, `user_field` and `plugin` directory columns.

This plugin API is assuming that the plugin has added a migration to a column to the `directory_items` table.

This was created to be initially used by discourse-solved. PR with API usage - https://github.com/discourse/discourse-solved/pull/137/
This commit is contained in:
Mark VanLandingham
2021-06-17 09:06:18 -05:00
committed by GitHub
parent ea2833d0d8
commit 0c42a29dc4
25 changed files with 222 additions and 96 deletions

View File

@ -618,16 +618,18 @@ class ApplicationController < ActionController::Base
end
def directory_columns_json
types = DirectoryColumn.types
DirectoryColumn
.left_joins(:user_field)
.where(enabled: true)
.order(:position)
.pluck('directory_columns.name',
'directory_columns.automatic',
.pluck('directory_columns.id',
'directory_columns.name',
'directory_columns.type',
'directory_columns.icon',
'user_fields.id',
'user_fields.name')
.map { |column| { name: column[0] || column[4], automatic: column[1], icon: column[2], user_field_id: column[3] } }
.map { |column| { id: column[0], name: column[1] || column[5], type: types.key(column[2]), icon: column[3], user_field_id: column[4] } }
.to_json
end