Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save filters across sessions #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def change_page_num(name, total_item)
@page_num = [[1,@page_num].max,max_page_num].min
session["#{name}_page_num"] = @page_num.to_s
end

def app_owner(app_id)
current_user.app_ids.include? app_id unless current_user.student?
end
Expand All @@ -85,7 +85,7 @@ def get_pending_iteration_feedbacks
end
@pending_iterations = Iteration.where(id: pending_iteration_ids)
end

def get_reviewed_apps
reviewed_app_ids = []
@apps.each do |app|
Expand All @@ -97,4 +97,4 @@ def get_reviewed_apps
end
@reviewed_apps = App.where(id: reviewed_app_ids)
end
end
end
52 changes: 52 additions & 0 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,58 @@ def index
page_default_and_update("app", total_app)
change_page_num("app", total_app)

# Check to see if params already has deployment statuses
contains_at_least_one_status = false
App.getAllDeploymentStatuses.each do |status|
if params.key? status
contains_at_least_one_status = true
break
end
end

# Add deployment statuses to params if not already existing
@deployment_statuses = Hash.new
if not contains_at_least_one_status
# First time: add all statuses to params
App.getAllDeploymentStatuses.each do |status|
params[status] = 1
@deployment_statuses = params
end
else
App.getAllDeploymentStatuses.each do |status|
# Get existing statuses from params
if params.key? status
@deployment_statuses = params
end
end
end

# Repeat for Vetting STATUSES
contains_at_least_one_v_status = false
App.getAllVettingStatuses.each do |status|
if params.key? status
contains_at_least_one_v_status = true
break
end
end

@vetting_statuses = Hash.new
if not contains_at_least_one_v_status
App.getAllVettingStatuses.each do |status|
params[status] = 1
@vetting_statuses = params
end
else
App.getAllVettingStatuses.each do |status|
if params.key? status
@vetting_statuses = params
end
end
end

puts "CURRENT DEPLOYMENT STATUSES IN PARAMS"
puts params

@apps = App.limit(@each_page).offset(@each_page*(@page_num-1))
respond_to do |format|
format.json { render :json => @apps.featured }
Expand Down
95 changes: 54 additions & 41 deletions app/views/apps/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,64 @@
= link_to 'New App', new_app_path, :class => 'btn btn-success pull-right'
.help-block Click an App name to see more information

- $filters = ""
#filters
%label.checkbox-inline
%div#deploy
%strong Deployment Status:
%em #{" (" + @total_deploy.to_s + ")"}
%br
- App.getAllDeploymentStatuses.each do |status|
= check_box_tag status, 1, true, :class => 'filter'
%span{:class => status}= status.to_s.humanize
%em (#{@deployment_map[status.to_s].to_i})
= form_tag "/", :method => :get do
%label.checkbox-inline
%div#deploy
%strong Deployment Status:
%em #{" (" + @total_deploy.to_s + ")"}
%br

%label.checkbox-inline
%div#vetting
%strong Vetting Status:
%em #{" (" + @total_vet.to_s + ")"}
%br
- App.getAllVettingStatuses.each do |status|
= check_box_tag status, 1, true, :class => 'filter'
%span{:class => status}= status.to_s.humanize
%em (#{@vetting_map[status.to_s].to_i})
- App.getAllDeploymentStatuses.each do |status|
- if @deployment_statuses.key? status
- $filters = $filters + "&" + status.to_s + "=1"
= check_box_tag status, 1, true, :class => 'filter'
- else
= check_box_tag status, 1, false, :class => 'no_filter'
%span{:class => status}= status.to_s.humanize
%em (#{@deployment_map[status.to_s].to_i})
%br

%label.checkbox-inline
%div#vetting
%strong Vetting Status:
%em #{" (" + @total_vet.to_s + ")"}
%br
- App.getAllVettingStatuses.each do |status|
- if @vetting_statuses.key? status
- $filters = $filters + "&" + status.to_s + "=1"
= check_box_tag status, 1, true, :class => 'filter'
- else
= check_box_tag status, 1, false, :class => 'no_filter'
%span{:class => status}= status.to_s.humanize
%em (#{@vetting_map[status.to_s].to_i})
%br
%br
= submit_tag 'Apply Filters'

:javascript
$('.filter').change(function() { var klass = $("#apps_table ."+$(this).attr('name')).toggle(); });
//$('.filter').change(function() {var klass = $("#apps_table ."+$(this).attr('name')).toggle();});

%ul{:class => 'pagination'}
%li{:class=>'each_page'}
%li{:class=>'each_page'}
%a{:class=>"page_link"} Apps per page
- ["10","50","100","All"].each do |num_per_page|
- if @each_page == @page_dict[num_per_page] then
%li{:class=>'each_page active'}
%a{:class=>"page-link", :href=>"?app_each_page=#{num_per_page}"}=num_per_page
%li{:class=>'each_page active'}
%a{:class=>"page-link", :href=>"?app_each_page=#{num_per_page}" + $filters}=num_per_page
- else
%li{:class=>'each_page'}
%a{:class=>"page-link", :href=>"?app_each_page=#{num_per_page}"}=num_per_page
%a{:class=>"page-link", :href=>"?app_each_page=#{num_per_page}" + $filters}=num_per_page

%ul{:class => 'pagination pull-right'}
- ["First","Previous","Current","Next","Last"].each do |action|
- if action != "Current" then
- if action != "Current" then
%li{:class=>'page_num'}
%a{:class=>"page-link", :href=>"?app_page_action=#{action}&prev=#{@page_num}"}=action
%a{:class=>"page-link", :href=>"?app_page_action=#{action}&prev=#{@page_num}" + $filters}=action
- else
%li{:class=>"page-num"}
%a{:class=>'page_link'} Page #{[1,@page_num].max}

%table.table.table-condensed#apps_table
%thead
%tr
Expand All @@ -59,18 +71,19 @@
%th
%tbody
- @apps.each do |app|
%tr{:class => [app.status.to_s]}
%td
= app.id
= link_to app.name, app
%td
= link_to app.org.name, app.org
%td
= sanitize app.description
%br
- app.engagements.each do |engagement|
%span #{engagement.id} (#{engagement.team_number}): #{engagement.student_names}
- if @deployment_statuses.key? app.status.to_sym
%tr{:class => [app.status.to_s]}
%td
= app.id
= link_to app.name, app
%td
= link_to app.org.name, app.org
%td
= sanitize app.description
%br
%td{style: 'white-space: nowrap'}
= link_to 'Edit', edit_app_path(app), :title => "Last update: #{app.updated_at.strftime('%c')}", :class => 'btn btn-primary'
= link_to 'Destroy', app, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-danger'
- app.engagements.each do |engagement|
%span #{engagement.id} (#{engagement.team_number}): #{engagement.student_names}
%br
%td{style: 'white-space: nowrap'}
= link_to 'Edit', edit_app_path(app), :title => "Last update: #{app.updated_at.strftime('%c')}", :class => 'btn btn-primary'
= link_to 'Destroy', app, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-danger'