mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
38 lines
1,002 B
Ruby
38 lines
1,002 B
Ruby
# frozen_string_literal: true
|
|
|
|
class VisitsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :set_visit, only: %i[update]
|
|
|
|
def index
|
|
order_by = params[:order_by] || 'asc'
|
|
|
|
visits = current_user
|
|
.visits
|
|
.where(status: :pending)
|
|
.or(current_user.visits.where(status: :confirmed))
|
|
.order(started_at: order_by)
|
|
.group_by { |visit| visit.started_at.to_date }
|
|
.map { |k, v| { date: k, visits: v } }
|
|
|
|
@visits = Kaminari.paginate_array(visits).page(params[:page]).per(10)
|
|
end
|
|
|
|
def update
|
|
if @visit.update(visit_params)
|
|
redirect_to visits_url, notice: 'Visit was successfully updated.', status: :see_other
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_visit
|
|
@visit = current_user.visits.find(params[:id])
|
|
end
|
|
|
|
def visit_params
|
|
params.require(:visit).permit(:name, :started_at, :ended_at, :status)
|
|
end
|
|
end
|