Skip to content

Creating Recapitulation Matrix

ralibi edited this page Dec 27, 2012 · 1 revision

Recapitulation matrix only has 3 parameters

  1. Recapitulation_model (string class name)
  2. Recapitulation_matrix (Array)
  3. Advanced_search_attributes (Array)

Recapitulation Matrix

Put the Model attribute name or Association model (belongs_to only) attribute name in an array so Recapitulation Matrix will know what attributes to be grouped.

Advanced Search

Rich Table Component build advanced-search form using simple_form by specifying Model attributes or Association Model attributes in an array. RTC guesses the attribute type. If a string, it render input, if integer or date it will render input range.

Model attributes

:name,
:birth_date, 
:birth_place, 

Association Model attributes

'user.email',
'department.faculty.name'

RTC can render combo_box using simple_form syntax as params

=# STUDENT_REGULARITY_CLASS = [['R', 'Reguler'], ['N', 'Non Reguler'], ['K', 'Kerjasama']]
{input: :regularity_class, params: {as: :select, label: 'regularity_class', collection: STUDENT_REGULARITY_CLASS.collect(&:reverse), prompt: :true}}

Step-by-Step

Create some helper method

** admin_students_advanced_search_attributes ** if needed

def admin_students_advanced_search_attributes
[ 
  :nim, 
  :name,
  {input: 'department_id', params: {as: :select, label: 'department', collection: Department.all, label_method: :to_s_code, value_method: :id, prompt: :true}},  
  {input: :regularity_class, params: {as: :select, label: 'regularity_class', collection: STUDENT_REGULARITY_CLASS.collect(&:reverse), prompt: :true}}, 
  {input: :active_status, params: {as: :select, label: 'active_status', collection: STUDENT_ACTIVE_STATUS.collect(&:reverse), prompt: :true}}, 
  {input: :admission_status, params: {as: :select, label: 'admission_status', collection: STUDENT_ADMISSION_STATUS.collect(&:reverse), prompt: :true}}, 
  {input: 'degree_id', params: {as: :select, label: 'degree', collection: Degree.all, label_method: :name, value_method: :id, prompt: :true}}, 
  :birth_date, 
  'user.email',
  :birth_place, 
  :admission_date, 
  {input: :gender, params: {as: :select, label: 'gender', collection: GENDER.collect(&:reverse), prompt: :true}}, 
  :final_credit, 
  :final_gpa, 
  :sk_number, 
  :sk_date, 
  :certificate_number
]
end

and admin_students_recapitulation

def admin_students_recapitulation
render_recapitulation(
  recapitulation_model: 'Student', 
  recapitulation_matrix: [ 
    'department', 
    {value: 'lecturer', label: 'advisor'}, 
    'degree',
    "gender__#{mapping_label(GENDER)}",
    'admission_year',
    'limit_studies',
    "regularity_class__#{mapping_label(STUDENT_REGULARITY_CLASS)}",
    "active_status__#{mapping_label(STUDENT_ACTIVE_STATUS)}",
    "admission_status__#{mapping_label(STUDENT_ADMISSION_STATUS)}",
    'birth_place',
    {value: 'birth_date__time.year.old.5', label: 'birth_date_old_5'}  
  ],
  advanced_search_attributes: admin_students_advanced_search_attributes
)
end

Within View

Just write this

= admin_students_recapitulation

Clone this wiki locally