Sha256: 4e89cbf53adb3c3508a1fb894fc001aa354b3d3f156258b845dbe32a85e45231

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 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 ||= begin
      raise('expected datatable poll_token attribute') unless attributes[:poll_token]
      Effective::Poll.deep_results.find(attributes[:poll_token])
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_polls-0.3.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.2.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.6 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.5 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.4 app/datatables/admin/effective_poll_results_datatable.rb