Class: HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/home_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Instance Method Details

#cancel_membershipObject

cancel personal memberships direct from the myProfile-page


57
58
59
60
61
62
63
64
65
# File 'app/controllers/home_controller.rb', line 57

def cancel_membership
  if params[:membership_id]
    membership = @current_user.memberships.find!(params[:membership_id])
  else
    membership = @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

#indexObject


4
5
6
7
8
9
10
11
12
# File 'app/controllers/home_controller.rb', line 4

def index
  # unaccepted tasks
  @unaccepted_tasks = Task.order(:due_date).unaccepted_tasks_for(current_user)
  # task in next week
  @next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
  # count tasks with no responsible person
  # tasks for groups the current user is not a member are ignored
  @unassigned_tasks = Task.order(:due_date).next_unassigned_tasks_for(current_user)
end

#ordergroupObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/home_controller.rb', line 27

def ordergroup
  @user = @current_user
  @ordergroup = @user.ordergroup

  unless @ordergroup.nil?

    @ordergroup = Ordergroup.include_transaction_class_sum.find(@ordergroup)

    if params['sort']
      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
      sort = "created_on DESC"
    end

    @financial_transactions = @ordergroup.financial_transactions.page(params[:page]).per(@per_page).order(sort)
    @financial_transactions = @financial_transactions.where("note LIKE ?", "%#{params[:query]}%") if params[:query].present?

  else
    redirect_to root_path, alert: I18n.t('home.no_ordergroups')
  end
end

#ordergroup_paramsObject (protected)


76
77
78
79
80
# File 'app/controllers/home_controller.rb', line 76

def ordergroup_params
  if params[:user][:ordergroup]
    params.require(:user).require(:ordergroup).permit(:contact_address)
  end
end

#profileObject


14
15
# File 'app/controllers/home_controller.rb', line 14

def profile
end

#update_profileObject


17
18
19
20
21
22
23
24
25
# File 'app/controllers/home_controller.rb', line 17

def update_profile
  if @current_user.update_attributes(user_params)
    @current_user.ordergroup.update_attributes(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_paramsObject (protected)


69
70
71
72
73
74
# File 'app/controllers/home_controller.rb', line 69

def user_params
  params
    .require(:user)
    .permit(:first_name, :last_name, :email, :phone,
            :password, :password_confirmation).merge(params[:user].slice(:settings_attributes))
end