@@ -7,23 +7,30 @@ class Admin::Certification::ShipsController < Admin::Certification::ApplicationC
77 def index
88 authorize ::Certification ::Ship
99
10- @status = params [ :status ] . presence_in ( %w[ pending approved returned all ] ) || "pending"
11- @sort = params [ :sort ] == "newest" ? "newest" : "oldest"
12- @search = params [ :search ] . to_s . strip
13- @from = parse_date ( params [ :from ] )
14- @to = parse_date ( params [ :to ] )
10+ @status = params [ :status ] . presence_in ( %w[ pending approved returned all ] ) || "pending"
11+ @sort = params [ :sort ] == "newest" ? "newest" : "oldest"
12+ @search = params [ :search ] . to_s . strip
13+ @from = parse_date ( params [ :from ] )
14+ @to = parse_date ( params [ :to ] )
15+ @project_type = params [ :project_type ] . presence
1516
1617 scope = policy_scope ( ::Certification ::Ship )
17- . includes ( :reviewer , :returned_by , project : { memberships : :user } )
1818 scope = scope . where ( status : @status ) unless @status == "all"
1919 scope = scope . where ( "certification_ship_reviews.created_at >= ?" , @from . beginning_of_day ) if @from
2020 scope = scope . where ( "certification_ship_reviews.created_at <= ?" , @to . end_of_day ) if @to
2121 scope = apply_search ( scope ) if @search . present?
2222
23+ @type_counts = scope . joins ( :project ) . group ( "projects.project_type" ) . count
24+
25+ scope = scope . by_project_type ( @project_type ) if @project_type . present?
26+
2327 @pagy , @ships = pagy ( :offset ,
24- scope . order ( created_at : @sort == "newest" ? :desc : :asc ) ,
28+ scope . includes ( :reviewer , :returned_by , project : { memberships : :user } )
29+ . order ( created_at : @sort == "newest" ? :desc : :asc ) ,
2530 limit : 25 )
2631
32+ @own_project_ids = current_user . memberships . pluck ( :project_id ) . to_set
33+
2734 @stats = ::Certification ::Ship . dashboard_stats
2835 @lb_period = params [ :lb ] . presence_in ( %w[ daily weekly alltime ] ) || "daily"
2936 @leaderboards = {
0 commit comments