diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index ea0b5cfb..ca3d767f 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -15,9 +15,9 @@ def search_check(param) def sort_check(param) if param.present? sort_column = [] - sort_column << "state_priority DESC" << param + sort_column << "state.priority DESC" << param else - "state_priority DESC" + "state.priority DESC" end end @@ -25,16 +25,18 @@ def sort_check(param) def index if params[:q].nil? @q = Task.joins(:state).ransack(params[:q]) - @q.sorts = ["state_priority DESC", "due_at ASC"] + @q.sorts = ["state.priority DESC", "due_at ASC"] else @q = Task.joins(:state).ransack({combinator: 'and', groupings: search_check(params[:q][:content_or_assigner_screen_name_or_description_or_project_name_cont])}) @q.sorts = sort_check(params[:q][:s]) end - @tasks = @q.result.page(params[:page]).per(50).includes(:user, :state) + tasks_query = @q.result - return unless params[:only_todo] == '1' - - @tasks = @tasks.where(task_state_id: TaskState.find_by(name: 'todo').id) + if params[:only_todo] == '1' + tasks_query = tasks_query.merge(Task.active) + end + + @tasks = tasks_query.page(params[:page]).per(50).includes(:user, :state) end # GET /tasks/1 or /tasks/1.json diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb index fa431f55..f80d0a93 100644 --- a/app/views/tasks/index.html.erb +++ b/app/views/tasks/index.html.erb @@ -22,6 +22,7 @@ class: "form-control me-2", placeholder: '検索ワードを入力して下さい', style: "flex: 1;" %> + <%= hidden_field_tag :only_todo, params[:only_todo] if params[:only_todo].present? %> <%= f.submit "検索", class: "btn btn-primary" %> <% end %> @@ -30,10 +31,16 @@ <%= form_with url: request.path, method: :get, local: true, html: { class: "d-flex" } do %> - <%= check_box_tag :only_todo, "1", params[:only_todo] == "1", onchange: "this.form.submit()" %> -
- todoのみ -
+ <%= check_box_tag :only_todo, "1", params[:only_todo] == "1", onchange: "this.form.submit()" %> +
+ todoのみ +
+ + <% if params[:q].present? %> + <% params[:q].each do |key, value| %> + <%= hidden_field_tag "q[#{key}]", value %> + <% end %> + <% end %> <% end %> <%= render @tasks %>