2012-04-15 19:59:39 +02:00
|
|
|
# encoding: utf-8
|
2009-01-15 12:14:01 +01:00
|
|
|
class HomeController < ApplicationController
|
2011-05-19 19:49:37 +02:00
|
|
|
|
2009-01-15 12:14:01 +01:00
|
|
|
def index
|
|
|
|
# unaccepted tasks
|
2012-11-12 09:03:23 +01:00
|
|
|
@unaccepted_tasks = Task.unaccepted_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
# task in next week
|
2012-11-12 09:03:23 +01:00
|
|
|
@next_tasks = Task.next_assigned_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
# count tasks with no responsible person
|
|
|
|
# tasks for groups the current user is not a member are ignored
|
2012-11-12 09:03:23 +01:00
|
|
|
@unassigned_tasks = Task.unassigned_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def profile
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_profile
|
2012-11-12 09:03:23 +01:00
|
|
|
if @current_user.update_attributes(params[:user])
|
2013-02-04 02:12:24 +01:00
|
|
|
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
2012-11-12 09:03:23 +01:00
|
|
|
render :profile
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordergroup
|
|
|
|
@user = @current_user
|
2009-02-01 20:56:23 +01:00
|
|
|
@ordergroup = @user.ordergroup
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
unless @ordergroup.nil?
|
|
|
|
|
|
|
|
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
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
|
|
|
sort = "created_on DESC"
|
|
|
|
end
|
|
|
|
|
2012-11-12 09:03:23 +01:00
|
|
|
@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?
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
else
|
2013-02-04 02:12:24 +01:00
|
|
|
redirect_to root_path, :alert => I18n.t('home.no_ordergroups')
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
# cancel personal memberships direct from the myProfile-page
|
2009-01-15 12:14:01 +01:00
|
|
|
def cancel_membership
|
|
|
|
membership = Membership.find(params[:membership_id])
|
|
|
|
if membership.user == current_user
|
|
|
|
membership.destroy
|
2013-02-04 02:12:24 +01:00
|
|
|
flash[:notice] = I18n.t('home.ordergroup_cancelled', :group => membership.group.name)
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
2013-02-04 02:12:24 +01:00
|
|
|
flash[:error] = I18n.t('errors.general')
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
redirect_to my_profile_path
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|