1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- class SelectorsController < ApplicationController
- prepend_before_action :authenticate_and_authorize!
- before_action :ensure_object_klass_has_selector!
-
-
-
-
- def preview
- object_count, objects = object_klass.selectors(params[:condition], limit: 6, execution_time: true)
- assets = {}
- object_ids = []
- objects&.each do |object|
- object_ids.push object.id
- assets = object.assets(assets)
- end
-
- render json: {
- object_ids: object_ids,
- object_count: object_count || 0,
- assets: assets,
- }
- end
- private
- def object_klass
- @object_klass ||= case params[:object]
- when 'organizations'
- Organization
- when 'tickets'
- Ticket
- when 'users'
- User
- end
- end
- def ensure_object_klass_has_selector!
- return if object_klass.present?
- raise Exceptions::UnprocessableEntity, __('Given object does not support selector')
- end
- end
|