jshoe/coursequestionbank

View on GitHub
app/views/problems/_filter.html.haml

Summary

Maintainability
Test Coverage
= form_tag set_filters_path, :method => :post, :id => 'filter-form' do

  %div.form-group
    = label_tag :search, 'Search Keywords:'
    = text_field_tag :search, session[:filters][:search], class: 'form-control', placeholder: 'Search'

  %hr

  %div.form-group
    = label_tag :tags, 'Tags:'
    = text_field_tag :tags, session[:filters][:tags].join(', '), class: 'form-control', placeholder: 'e.g.: tag 1, tag 2'

  %hr

  %div.form-group
    = label_tag :sort_by, 'Sort by:'
    - Problem.sort_by_options.each do |option|
      %div.filter_option
        = radio_button_tag :sort_by, option, !!(session[:filters][:sort_by] == option), class: 'radio', id: "sort_by_#{option}"
        = label_tag "sort_by_#{option}", option

  %hr

  %div.form-group
    = label_tag :problem_type, 'Problem type:'
    - Problem.all_problem_types.each do |type, display_type|
      %div.filter_option
        = check_box_tag "problem_type[#{type}]", 1, !!(session[:filters][:problem_type].include? type), class: 'checkbox', id: "problem_type_#{type}"
        = label_tag "problem_type_#{type}", display_type

  %hr

  %div.form-group
    = label_tag :bloom_category, 'Bloom category:'
    - Problem.all_bloom_categories.each do |category|
      %div.filter_option
        = check_box_tag "bloom_category[#{category}]", 1, !!(session[:filters][:bloom_category].include? category), class: 'checkbox', id: "bloom_category_#{category}"
        = label_tag "bloom_category_#{category}", category

  %hr

  %div.form-group
    = label_tag :collections, 'Collections:'
    - @collections.each do |collection|
      %div.filter_option
        = check_box_tag "collections[#{collection.id}]", 1,  !!(session[:filters][:collections].include? collection.id), class: 'checkbox', id: "collections_#{collection.id}"
        = label_tag "collections_#{collection.id}", collection.name
    %div.filter_option
      = check_box_tag "collections[0]", 1, !!(session[:filters][:collections].include? 0), class: 'checkbox', id: 'collections_0'
      = label_tag 'collections_0', 'All Collections'

  %hr

  %div.form-group
    %div.filter_option
      = check_box_tag :show_obsolete, 1, !!session[:filters][:show_obsolete], class: 'checkbox'
      = label_tag :show_obsolete, 'Show obsolete'
    %br
    = submit_tag 'Search', :class => 'btn btn-primary'