Added comments to clearify methods

This commit is contained in:
2020-03-28 20:16:54 -04:00
parent 983811af97
commit 016dca242c

View File

@@ -11,7 +11,7 @@
# This controller class will handle map management # This controller class will handle map management
class CustomersController < ApplicationController class CustomersController < ApplicationController
unloadable unloadable
include AuthHelper include AuthHelper
helper :issues helper :issues
helper :journals helper :journals
@@ -26,27 +26,33 @@ class CustomersController < ApplicationController
helper :sort helper :sort
include SortHelper include SortHelper
helper :timelog helper :timelog
before_filter :add_customer, :only => :new before_filter :add_customer, :only => :new
before_filter :view_customer, :except => :new before_filter :view_customer, :except => :new
skip_before_filter :verify_authenticity_token, :check_if_login_required, :only => [:view] skip_before_filter :verify_authenticity_token, :check_if_login_required, :only => [:view]
default_search_scope :names default_search_scope :names
autocomplete :customer, :name, :full => true, :extra_data => [:id] autocomplete :customer, :name, :full => true, :extra_data => [:id]
# getter method for a customer's vehicles
# TODO: move into customer model
def filter_vehicles_by_customer def filter_vehicles_by_customer
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer]) @filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])
end end
# getter method for a customer's invoices
# TODO: move into customer model
def filter_invoices_by_customer def filter_invoices_by_customer
@filtered_invoices = QboInvoice.all.where(customer_id: params[:selected_customer]) @filtered_invoices = QboInvoice.all.where(customer_id: params[:selected_customer])
end end
# getter method for a customer's estimates
# TODO: move into customer model
def filter_estimates_by_customer def filter_estimates_by_customer
@filtered_estimates = QboEstimate.all.where(customer_id: params[:selected_customer]) @filtered_estimates = QboEstimate.all.where(customer_id: params[:selected_customer])
end end
# display a list of all customers # display a list of all customers
def index def index
if params[:search] if params[:search]
@@ -56,22 +62,24 @@ class CustomersController < ApplicationController
end end
end end
end end
# initialize a new customer
def new def new
@customer = Customer.new @customer = Customer.new
end end
# create a new customer
def create def create
@customer = Customer.new(params[:customer]) @customer = Customer.new(params[:customer])
if @customer.save if @customer.save
flash[:notice] = "New Customer Created" flash[:notice] = "New Customer Created"
redirect_to @customer redirect_to @customer
else else
flash[:error] = @customer.errors.full_messages.to_sentence flash[:error] = @customer.errors.full_messages.to_sentence
redirect_to new_customer_path redirect_to new_customer_path
end end
end end
# display a specific customer # display a specific customer
def show def show
begin begin
@@ -82,7 +90,7 @@ class CustomersController < ApplicationController
render_404 render_404
end end
end end
# return an HTML form for editing a customer # return an HTML form for editing a customer
def edit def edit
begin begin
@@ -91,7 +99,7 @@ class CustomersController < ApplicationController
render_404 render_404
end end
end end
# update a specific customer # update a specific customer
def update def update
begin begin
@@ -107,7 +115,8 @@ class CustomersController < ApplicationController
render_404 render_404
end end
end end
# delete a customer
def destroy def destroy
begin begin
Customer.find_by_id(params[:id]).destroy Customer.find_by_id(params[:id]).destroy
@@ -117,12 +126,12 @@ class CustomersController < ApplicationController
render_404 render_404
end end
end end
# Customer view for an issue # displays an issue for a customer with a provided security CustomerToken
def view def view
User.current = User.find_by lastname: 'Anonymous' User.current = User.find_by lastname: 'Anonymous'
@token = CustomerToken.where("token = ? and expires_at > ?", params[:token], Time.now) @token = CustomerToken.where("token = ? and expires_at > ?", params[:token], Time.now)
@token = @token.first @token = @token.first
if @token if @token
@@ -137,10 +146,10 @@ class CustomersController < ApplicationController
Journal.preload_journals_details_custom_fields(@journals) Journal.preload_journals_details_custom_fields(@journals)
@journals.select! {|journal| journal.notes? || journal.visible_details.any?} @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
@journals.reverse! if User.current.wants_comments_in_reverse_order? @journals.reverse! if User.current.wants_comments_in_reverse_order?
@changesets = @issue.changesets.visible.preload(:repository, :user).to_a @changesets = @issue.changesets.visible.preload(:repository, :user).to_a
@changesets.reverse! if User.current.wants_comments_in_reverse_order? @changesets.reverse! if User.current.wants_comments_in_reverse_order?
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
@allowed_statuses = @issue.new_statuses_allowed_to(User.current) @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@priorities = IssuePriority.active @priorities = IssuePriority.active
@@ -150,17 +159,21 @@ class CustomersController < ApplicationController
render_403 render_403
end end
end end
private private
# redmine permission - add customers
def add_customer def add_customer
global_check_permission(:add_customers) global_check_permission(:add_customers)
end end
# redmine permission - view customers
def view_customer def view_customer
global_check_permission(:view_customers) global_check_permission(:view_customers)
end end
# checks to see if there is only one item in an array
# @return true if array only has one item
def only_one_non_zero?( array ) def only_one_non_zero?( array )
found_non_zero = false found_non_zero = false
array.each do |val| array.each do |val|