Class: HomeController
Instance Method Summary
collapse
current
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#cancel_membership ⇒ Object
cancel personal memberships direct from the myProfile-page
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/home_controller.rb', line 67
def cancel_membership
membership = if params[:membership_id]
@current_user.memberships.find(params[:membership_id])
else
@current_user.memberships.find_by_group_id!(params[:group_id])
end
membership.destroy
redirect_to my_profile_path, notice: I18n.t('home.ordergroup_cancelled', group: membership.group.name)
end
|
#index ⇒ Object
2
3
4
5
6
7
8
9
10
|
# File 'app/controllers/home_controller.rb', line 2
def index
@unaccepted_tasks = Task.order(:due_date).unaccepted_tasks_for(current_user)
@next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
@unassigned_tasks = Task.order(:due_date).next_unassigned_tasks_for(current_user)
end
|
#ordergroup ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/controllers/home_controller.rb', line 34
def ordergroup
@user = @current_user
@ordergroup = @user.ordergroup
if @ordergroup.nil?
redirect_to root_path, alert: I18n.t('home.no_ordergroups')
else
@ordergroup = Ordergroup.include_transaction_class_sum.find(@ordergroup.id)
sort = if params['sort']
case params['sort']
when 'date' then 'created_on'
when 'note' then 'note'
when 'amount' then 'amount'
when 'date_reverse' then 'created_on DESC'
when 'note_reverse' then 'note DESC'
when 'amount_reverse' then 'amount DESC'
end
else
'created_on DESC'
end
@financial_transactions = @ordergroup.financial_transactions.visible.page(params[:page]).per(@per_page).order(sort)
if params[:query].present?
@financial_transactions = @financial_transactions.where('financial_transactions.note LIKE ?',
"%#{params[:query]}%")
end
end
end
|
#ordergroup_params ⇒ Object
86
87
88
89
90
|
# File 'app/controllers/home_controller.rb', line 86
def ordergroup_params
return unless params[:user][:ordergroup]
params.require(:user).require(:ordergroup).permit(:contact_address)
end
|
#profile ⇒ Object
12
|
# File 'app/controllers/home_controller.rb', line 12
def profile; end
|
#reference_calculator ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/home_controller.rb', line 14
def reference_calculator
if current_user.ordergroup
@types = FinancialTransactionType.with_name_short.order(:name)
@bank_accounts = @types.includes(:bank_account).map(&:bank_account).uniq.compact
@bank_accounts = [BankAccount.last] if @bank_accounts.empty?
else
redirect_to root_url, alert: I18n.t('group_orders.errors.no_member')
end
end
|
#update_profile ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/home_controller.rb', line 24
def update_profile
if @current_user.update(user_params)
@current_user.ordergroup.update(ordergroup_params) if ordergroup_params
session[:locale] = @current_user.locale
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
else
render :profile
end
end
|
#user_params ⇒ Object
79
80
81
82
83
84
|
# File 'app/controllers/home_controller.rb', line 79
def user_params
params
.require(:user)
.permit(:first_name, :last_name, :email, :phone,
:password, :password_confirmation).merge(params[:user].slice(:settings_attributes))
end
|