Sha256: 45440c7b2f7a88be562703a9710cdc6bf749d3375fe39d6aacfb9ae4f5d0a46c

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 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)

    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

6 entries across 6 versions & 1 rubygems

Version Path
effective_polls-0.1.3 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.2 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.1 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.1.0 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.0.2 app/datatables/admin/effective_poll_results_datatable.rb
effective_polls-0.0.1 app/datatables/admin/effective_poll_results_datatable.rb