Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #93 from dragosmiron/constant-names
Browse files Browse the repository at this point in the history
Refactor constant names
  • Loading branch information
mezis committed May 20, 2013
2 parents 9d43a2c + 4bdf75a commit 931c321
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
40 changes: 20 additions & 20 deletions app/controllers/ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class IdeasController < ApplicationController
before_filter :map_no_category, only:[:create, :update]
before_filter :can_create_idea, only:[:new, :create]

ValidAngles = %w(discussable vettable votable pickable approvable signoffable buildable followed)
DefaultAngle = ValidAngles.last
VALID_ANGLES = %w(discussable vettable votable pickable approvable signoffable buildable followed)
DEFAULT_ANGLE = VALID_ANGLES.last

ValidOrders = %w(impact activity progress creation size)
DefaultOrder = ValidOrders.first
VALID_ORDERS = %w(impact activity progress creation size)
DEFAULT_ORDER = VALID_ORDERS.first

ValidFilters = %w(all authored commented vetted backed)
DefaultFilter = ValidFilters.first
VALID_FILTERS = %w(all authored commented vetted backed)
DEFAULT_FILTER = VALID_FILTERS.first

ValidViews = %w(cards board)
DefaultView = ValidViews.first
VALID_VIEWS = %w(cards board)
DEFAULT_VIEW = VALID_VIEWS.first

def index
@angle = set_angle_from_params
Expand Down Expand Up @@ -132,40 +132,40 @@ def cleanup_session
def set_angle_from_params
params[:angle] =
session[:ideas_angle] = begin
(ValidAngles.include?(params[:angle]) and params[:angle]) ||
(ValidAngles.include?(session[:ideas_angle]) and session[:ideas_angle]) ||
(VALID_ANGLES.include?(params[:angle]) and params[:angle]) ||
(VALID_ANGLES.include?(session[:ideas_angle]) and session[:ideas_angle]) ||
session[:ideas_angle] ||
DefaultAngle
DEFAULT_ANGLE
end
end

def set_view_from_params
params[:view] =
session[:ideas_view] = begin
(ValidViews.include?(params[:view]) and params[:view]) ||
(ValidViews.include?(session[:ideas_view]) and session[:ideas_view]) ||
(VALID_VIEWS.include?(params[:view]) and params[:view]) ||
(VALID_VIEWS.include?(session[:ideas_view]) and session[:ideas_view]) ||
session[:ideas_view] ||
DefaultView
DEFAULT_VIEW
end
end

def set_order_from_params_and_angle
session[:ideas_order] ||= {}
params[:order] =
session[:ideas_order][@angle] = begin
(ValidOrders.include?(params[:order]) and params[:order]) ||
(ValidOrders.include?(session[:ideas_order][@angle]) and session[:ideas_order][@angle]) ||
DefaultOrder
(VALID_ORDERS.include?(params[:order]) and params[:order]) ||
(VALID_ORDERS.include?(session[:ideas_order][@angle]) and session[:ideas_order][@angle]) ||
DEFAULT_ORDER
end
end

def set_filter_from_params_and_angle
session[:ideas_filter] ||= {}
params[:filter] =
session[:ideas_filter][@angle] = begin
(ValidFilters.include?(params[:filter]) and params[:filter]) ||
(ValidFilters.include?(session[:ideas_filter][@angle]) and session[:ideas_filter][@angle]) ||
DefaultFilter
(VALID_FILTERS.include?(params[:filter]) and params[:filter]) ||
(VALID_FILTERS.include?(session[:ideas_filter][@angle]) and session[:ideas_filter][@angle]) ||
DEFAULT_FILTER
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class NotificationsController < ApplicationController
include Traits::RequiresLogin

ValidAngles = %w(unread all)
DefaultAngle = ValidAngles.first
VALID_ANGLES = %w(unread all)
DEFAULT_ANGLE = VALID_ANGLES.first
PER_PAGE = 25

def index
Expand Down Expand Up @@ -49,7 +49,7 @@ def destroy
private

def get_angle_from_params
return params[:angle] if ValidAngles.include?(params[:angle])
session[:notifications_angle] || DefaultAngle
return params[:angle] if VALID_ANGLES.include?(params[:angle])
session[:notifications_angle] || DEFAULT_ANGLE
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _sign_in_from_hash(provider)
sign_in login
flash[:success] = _('Welcome, %{user}!') % { user: login.first_name }

redirect_to return_to || ideas_path(angle: IdeasController::DefaultAngle)
redirect_to return_to || ideas_path(angle: IdeasController::DEFAULT_ANGLE)
end

def _auth_hash
Expand Down
6 changes: 3 additions & 3 deletions app/views/ideas/_filters.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.container
%ul.nav.pull-right.pull-right-spaced
.btn-group
- IdeasController::ValidViews.each do |view|
- IdeasController::VALID_VIEWS.each do |view|
- is_current = (@view == view)
- classes = ['btn', is_current && 'active'].compact.join(' ')
= can_link_to ideas_path(params.merge(view:view)), class:classes, if:!is_current, title:ideas_view_tooltip(view) do
Expand Down Expand Up @@ -43,7 +43,7 @@
%i.icon-sort
%span.caret
%ul.dropdown-menu.filter-order
- IdeasController::ValidOrders.each do |order|
- IdeasController::VALID_ORDERS.each do |order|
- is_current = (@order == order)
%li{ class: (is_current && 'disabled')}
= can_link_to ideas_path(params.merge(order:order)), if:!is_current do
Expand All @@ -59,7 +59,7 @@
%i.icon-filter
%span.caret
%ul.dropdown-menu.filter-filter
- IdeasController::ValidFilters.each do |filter|
- IdeasController::VALID_FILTERS.each do |filter|
- is_current = (@filter == filter)
%li{ class: (is_current && 'disabled')}
= can_link_to ideas_path(params.merge(filter:filter)), if:!is_current do
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%p= _('The app that helps product teams build fantastic apps.')

- if current_user
= link_to ideas_path(angle: IdeasController::DefaultAngle), class: 'btn btn-primary' do
= link_to ideas_path(angle: IdeasController::DEFAULT_ANGLE), class: 'btn btn-primary' do
= _('Let\'s get cracking')
&nbsp;
%i.icon-caret-right
Expand Down

0 comments on commit 931c321

Please sign in to comment.