# Displays available cpd_cycles that the current_user may complete class EffectiveCpdAvailableCyclesDatatable < Effective::Datatable datatable do order :start_at col :start_at, visible: false col(:title, label: cpd_cycle_label) col :available_date col :target_score, label: "Required #{cpd_credits_label}" do |cpd_cycle| cpd_score(current_user.cpd_target_score(cpd_cycle: cpd_cycle)) end actions_col(actions: []) do |cpd_cycle| statement = cpd_cycle.cpd_statements.where(user: current_user).first if statement.blank? dropdown_link_to('Start', effective_cpd.cpd_cycle_cpd_statement_build_path(cpd_cycle, :new, :start)) else dropdown_link_to('Continue', effective_cpd.cpd_cycle_cpd_statement_build_path(cpd_cycle, statement, statement.next_step)) end end end collection do raise('expected a current_user') unless current_user.present? completed = EffectiveCpd.CpdStatement.completed.where(user: current_user) Effective::CpdCycle.available.where.not(id: completed.select('cpd_cycle_id as id')) end end