Skip to content

Commit

Permalink
format ruby with prettier-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
eins78 committed Feb 9, 2019
1 parent fc38cc0 commit 818678a
Show file tree
Hide file tree
Showing 395 changed files with 12,215 additions and 13,232 deletions.
7 changes: 2 additions & 5 deletions app/controllers/attachments_controller.rb
Expand Up @@ -2,11 +2,8 @@ class AttachmentsController < ApplicationController
def show
attachment = Attachment.find(id_param)
if attachment and attachment.content
send_data \
Base64.decode64(attachment.content),
filename: attachment.filename,
type: attachment.content_type,
disposition: 'inline'
send_data Base64.decode64(attachment.content),
filename: attachment.filename, type: attachment.content_type, disposition: 'inline'
else
head :not_found and return
end
Expand Down
39 changes: 19 additions & 20 deletions app/controllers/borrow/application_controller.rb
@@ -1,5 +1,4 @@
class Borrow::ApplicationController < ApplicationController

layout 'borrow'

before_action :check_maintenance_mode, except: :maintenance
Expand All @@ -8,23 +7,21 @@ class Borrow::ApplicationController < ApplicationController
def root
current_user_categories = current_user.all_categories
@categories = (current_user_categories & Category.roots).sort
@child_categories = \
@categories.map { |c| (current_user_categories & c.children).sort }
@child_categories = @categories.map { |c| (current_user_categories & c.children).sort }
@any_template = current_user.templates.any?
end

def refresh_timeout
# ok, refreshed
respond_to do |format|
format.html { head :ok }
date = if current_user.reservations.unsubmitted.empty?
Time.zone.now
else
current_user.reservations.unsubmitted.first.updated_at
end
format.json do
render json: { date: date }
end
date =
if current_user.reservations.unsubmitted.empty?
Time.zone.now
else
current_user.reservations.unsubmitted.first.updated_at
end
format.json { render json: { date: date } }
end
end

Expand All @@ -39,14 +36,17 @@ def require_customer
end

def redirect_if_order_timed_out
return if request.format == :json or
[borrow_order_timed_out_path,
borrow_order_delete_unavailables_path,
borrow_order_remove_path,
borrow_order_remove_reservations_path,
borrow_change_time_range_path].include? request.path
if current_user.timeout? \
and current_user.reservations.unsubmitted.any? { |l| not l.available? }
if request.format == :json or
[
borrow_order_timed_out_path,
borrow_order_delete_unavailables_path,
borrow_order_remove_path,
borrow_order_remove_reservations_path,
borrow_change_time_range_path
].include? request.path
return
end
if current_user.timeout? and current_user.reservations.unsubmitted.any? { |l| nl.available? }
redirect_to borrow_order_timed_out_path
else
current_user.reservations.unsubmitted.each &:touch
Expand All @@ -56,5 +56,4 @@ def redirect_if_order_timed_out
def init_breadcrumbs
@bread_crumbs = BreadCrumbs.new params.delete('_bc')
end

end
50 changes: 20 additions & 30 deletions app/controllers/borrow/availability_controller.rb
@@ -1,53 +1,43 @@
class Borrow::AvailabilityController < Borrow::ApplicationController

def show
model = current_user.models.borrowable.find params[:model_id]
inventory_pool = current_user.inventory_pools.find params[:inventory_pool_id]
@availability =
{
id: "#{model.id}-#{current_user.id}-#{inventory_pool.id}",
changes: \
model.availability_in(inventory_pool).available_total_quantities,
total_borrowable: \
@availability = {
id: "#{model.id}-#{current_user.id}-#{inventory_pool.id}",
changes: model.availability_in(inventory_pool).available_total_quantities,
total_borrowable:
model.total_borrowable_items_for_user_and_pool(
current_user,
inventory_pool,
ensure_non_negative_general: true
current_user, inventory_pool, ensure_non_negative_general: true
),
inventory_pool_id: inventory_pool.id,
model_id: model.id
}
inventory_pool_id: inventory_pool.id,
model_id: model.id
}
end

def booking_calendar_availability
model = Model.find(model_id_param)
ip = InventoryPool.find(inventory_pool_id_param)
user = User.find(user_id_param)
reservations = Reservation.find(reservation_ids_param)
presenter = Borrow::BookingCalendar.new(ip,
model,
user,
start_date_param,
end_date_param,
reservations)
presenter =
Borrow::BookingCalendar.new(ip, model, user, start_date_param, end_date_param, reservations)

respond_with_presenter(presenter)
end

def total_borrowable_quantities
model = Model.find(model_id_param)
inventory_pools = InventoryPool.find(inventory_pool_ids_param)
result = inventory_pools.map do |inventory_pool|
{
inventory_pool_id: inventory_pool.id,
total_borrowable: \
model.total_borrowable_items_for_user_and_pool(
current_user,
inventory_pool,
ensure_non_negative_general: true
)
}
end
result =
inventory_pools.map do |inventory_pool|
{
inventory_pool_id: inventory_pool.id,
total_borrowable:
model.total_borrowable_items_for_user_and_pool(
current_user, inventory_pool, ensure_non_negative_general: true
)
}
end

render(json: result) and return
end
Expand Down
11 changes: 2 additions & 9 deletions app/controllers/borrow/categories_controller.rb
@@ -1,16 +1,9 @@
class Borrow::CategoriesController < Borrow::ApplicationController

def index(category_id = params[:category_id])
categories = \
(current_user.all_categories & Category.find(category_id).children)
.sort
categories = (current_user.all_categories & Category.find(category_id).children).sort

output = categories.map do |category|
{ id: category.id,
name: category.label(category_id) }
end
output = categories.map { |category| { id: category.id, name: category.label(category_id) } }

render json: output
end

end
32 changes: 12 additions & 20 deletions app/controllers/borrow/concerns/create_lines.rb
@@ -1,28 +1,20 @@
module Borrow
module Concerns
module CreateLines
def create_lines(model:,
status:,
quantity:,
inventory_pool:,
start_date: nil,
end_date: nil,
delegated_user_id: nil)
if end_date and start_date and end_date < start_date
end_date = start_date
end
def create_lines(model:, status:, quantity:, inventory_pool:, start_date: nil, end_date: nil, delegated_user_id: nil)
end_date = start_date if end_date and start_date and end_date < start_date

attrs = { inventory_pool: inventory_pool,
status: status,
quantity: 1,
model: model,
start_date: start_date || time_window_min,
end_date: end_date || next_open_date(time_window_max),
delegated_user_id: delegated_user_id }
attrs = {
inventory_pool: inventory_pool,
status: status,
quantity: 1,
model: model,
start_date: start_date || time_window_min,
end_date: end_date || next_open_date(time_window_max),
delegated_user_id: delegated_user_id
}

new_lines = Integer(quantity).times.map do
current_user.item_lines.create(attrs)
end
new_lines = Integer(quantity).times.map { current_user.item_lines.create(attrs) }

new_lines
end
Expand Down
63 changes: 33 additions & 30 deletions app/controllers/borrow/customer_orders_controller.rb
@@ -1,17 +1,15 @@
class Borrow::CustomerOrdersController < Borrow::ApplicationController

before_action only: [:current, :timed_out] do
@grouped_and_merged_lines = \
@grouped_and_merged_lines =
Contract.grouped_and_merged_lines(current_user.reservations.unsubmitted)
@models = current_user.reservations.unsubmitted.map(&:model).uniq
@inventory_pools = \
current_user.reservations.unsubmitted.map(&:inventory_pool).uniq
@inventory_pools = current_user.reservations.unsubmitted.map(&:inventory_pool).uniq
end

def index
respond_to do |format|
format.html do
@grouped_and_merged_lines = \
@grouped_and_merged_lines =
Contract.grouped_and_merged_lines current_user.reservations.submitted
end
end
Expand All @@ -24,36 +22,37 @@ def current
def submit
Order.transaction do
begin
current_user
.reservations
.unsubmitted
.group_by(&:inventory_pool_id)
current_user.reservations.unsubmitted.group_by(&:inventory_pool_id)
.each_pair do |inventory_pool_id, reservations|
inventory_pool = InventoryPool.find(inventory_pool_id)
order = Order.create!(user: current_user,
inventory_pool: inventory_pool,
purpose: purpose_param,
state: :submitted)
order =
Order.create!(
user: current_user,
inventory_pool: inventory_pool,
purpose: purpose_param,
state: :submitted
)

reservations.each do |reservation|
if reservation.user.delegation?
reservation.delegated_user = \
reservation.delegated_user =
reservation.user.delegated_users.find(user_session.user_id)
end
reservation.order = order
reservation.status = :submitted
unless reservation.approvable?
raise reservation.errors.full_messages.uniq.join(', ')
end
raise reservation.errors.full_messages.uniq.join(', ') unless reservation.approvable?
reservation.save!
end

order.reload
order.send_submitted_notification
order.send_received_notification
end
flash[:notice] = _('Your order has been successfully submitted, ' \
'but is NOT YET APPROVED.')
flash[:notice] =
_(
'Your order has been successfully submitted, ' \
'but is NOT YET APPROVED.'
)
redirect_to borrow_root_path
rescue => e
Rails.logger.warn e
Expand All @@ -76,35 +75,39 @@ def remove_reservations(line_ids = params[:line_ids])
end

def timed_out
flash[:error] = \
_('%d minutes passed. The items are not reserved for you any more!') \
% app_settings.timeout_minutes
flash[:error] =
_('%d minutes passed. The items are not reserved for you any more!') %
app_settings.timeout_minutes
@timed_out = true
@inventory_pools_for_calendar = inventory_pools_for_calendar(@inventory_pools)
render :current
end

def delete_unavailables
current_user.reservations.unsubmitted.each { |l| l.delete unless l.available? }
redirect_to \
borrow_current_order_path,
flash: { success: _('Your order has been modified. ' \
'All reservations are now available.') }
redirect_to borrow_current_order_path,
flash: {
success:
_(
'Your order has been modified. ' \
'All reservations are now available.'
)
}
end

private

def inventory_pools_for_calendar(inventory_pools)
inventory_pools.map do |ip|
{ inventory_pool: ip,
{
inventory_pool: ip,
workday: ip.workday,
holidays: \
ip.holidays.where('CURRENT_DATE <= end_date').order(:end_date) }
holidays: ip.holidays.where('CURRENT_DATE <= end_date').order(:end_date)
}
end
end

def purpose_param
params.require(:purpose)
end

end
1 change: 0 additions & 1 deletion app/controllers/borrow/groups_controller.rb
@@ -1,5 +1,4 @@
class Borrow::GroupsController < Borrow::ApplicationController

def index
@groups = current_user.entitlement_groups
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/borrow/holidays_controller.rb
@@ -1,5 +1,4 @@
class Borrow::HolidaysController < Borrow::ApplicationController

def index
@holidays = current_user.inventory_pools.map(&:holidays).flatten
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/borrow/inventory_pools_controller.rb
@@ -1,5 +1,4 @@
class Borrow::InventoryPoolsController < Borrow::ApplicationController

def index
@inventory_pools = current_user.inventory_pools.reorder(:name)
end
Expand Down

0 comments on commit 818678a

Please sign in to comment.