Skip to content

Commit

Permalink
Integrate filtering and sorting methods into notes controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kcne committed Oct 9, 2024
1 parent b11bd8b commit ac8f859
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ class NotesController < ApplicationController
before_action :set_locale
around_action :web_timeout

##
# Display a list of notes by a specified user
### Display a list of notes by a specified user
def index
param! :page, Integer, :min => 1

@params = params.permit(:display_name)
@title = t ".title", :user => @user.display_name
@params = params.permit(:display_name, :from, :to, :status, :sort_by, :sort_order, :note_type)
@title = t(".title", :user => @user.display_name)
@page = (params[:page] || 1).to_i
@page_size = 10

@notes = @user.notes
@notes = @notes.visible unless current_user&.moderator?
@notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
.filter_hidden_notes(current_user)
.filter_by_status(params[:status])
.filter_by_note_type(params[:note_type], @user.id)
.filter_by_date_range(params[:from], params[:to])
.sort_by_params(params[:sort_by], params[:sort_order])
.distinct
.offset((@page - 1) * @page_size)
.limit(@page_size)
.preload(:comments => :author)

render :layout => "site"
end
Expand Down

0 comments on commit ac8f859

Please sign in to comment.