Sha256: e8af563281b81438be1dac3914866abd63b334c1fde6b616b401fcfc03a7b1a7

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

class Admin::EffectivePollResultsDatatable < Effective::Datatable
  datatable do
    col :ballot, search: poll.completed_ballots.order(:token).pluck(:token)

    col :position, visible: false
    col :category, search: Effective::PollQuestion::CATEGORIES, visible: false

    col :question, search: poll.poll_questions.pluck(:title)
    col :responses
  end

  collection do
    ballot_responses = Effective::BallotResponse.completed.deep.where(poll: poll, poll_question: poll.poll_questions)

    ballot_responses.flat_map do |br|
      rows = if br.poll_question.poll_question_option?
        br.poll_question_options.map do |response|
          [
            br.ballot.token,
            br.poll_question.position,
            br.poll_question.category,
            br.poll_question.to_s,
            response.to_s
          ]
        end
      elsif br.response.present?
        [
          [
            br.ballot.token,
            br.poll_question.position,
            br.poll_question.category,
            br.poll_question.to_s,
            br.response.to_s
          ]
        ]
      else
        []
      end
    end

  end

  def poll
    @poll ||= Effective::Poll.deep_results.where(id: attributes[:poll_id]).first!
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
effective_polls-0.7.3 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.7.2 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.7.1 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.7.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.6.2 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.6.1 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.6.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.6 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.5 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.4 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.3 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.2 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.1 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.5.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.4.1 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.4.0 app/datatables/admin/effective_poll_results_datatable.rb