Skip to content

Commit

Permalink
Merge c7507da into f2e9543
Browse files Browse the repository at this point in the history
  • Loading branch information
shingara committed Jul 18, 2013
2 parents f2e9543 + c7507da commit 3732bdd
Show file tree
Hide file tree
Showing 34 changed files with 471 additions and 322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ bin
bundle
coverage
*#
.ruby-version
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ gem 'htmlentities'
gem 'rack-ssl', :require => 'rack/ssl' # force SSL

gem 'useragent'
gem 'inherited_resources'
gem 'decent_exposure'
gem 'strong_parameters'
gem 'SystemTimer', :platform => :ruby_18
Expand Down
8 changes: 1 addition & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ GEM
multipart-post (~> 1.1)
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
ffi (1.9.0)
flowdock (0.3.1)
httparty (~> 0.7)
multi_json
Expand All @@ -133,7 +134,6 @@ GEM
tilt
happymapper (0.4.0)
libxml-ruby (~> 2.0)
has_scope (0.5.1)
hashie (1.2.0)
highline (1.6.19)
hike (1.2.3)
Expand All @@ -151,9 +151,6 @@ GEM
multi_xml (>= 0.5.2)
httpauth (0.2.0)
i18n (0.6.1)
inherited_resources (1.4.0)
has_scope (~> 0.5.0)
responders (~> 0.9)
journey (1.0.4)
jquery-rails (2.1.4)
railties (>= 3.0, < 5.0)
Expand Down Expand Up @@ -288,8 +285,6 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
responders (0.9.3)
railties (~> 3.1)
rest-client (1.6.7)
mime-types (>= 1.16)
ri_cal (0.8.8)
Expand Down Expand Up @@ -412,7 +407,6 @@ DEPENDENCIES
hoptoad_notifier (~> 2.4)
htmlentities
httparty
inherited_resources
jquery-rails (~> 2.1.4)
kaminari (>= 0.14.1)
launchy
Expand Down
104 changes: 60 additions & 44 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,92 @@
class AppsController < InheritedResources::Base
class AppsController < ApplicationController

include ProblemsSearcher

before_filter :require_admin!, :except => [:index, :show]
before_filter :parse_email_at_notices_or_set_default, :only => [:create, :update]
before_filter :parse_notice_at_notices_or_set_default, :only => [:create, :update]
respond_to :html

def show
respond_to do |format|
format.html do
@all_errs = !!params[:all_errs]
expose(:app_scope) {
(current_user.admin? ? App : current_user.apps)
}

expose(:apps) {
app_scope.all.sort
}

expose(:app, :ancestor => :app_scope)

expose(:all_errs) {
!!params[:all_errs]
}
expose(:problems) {
if request.format == :atom
app.problems.unresolved.ordered
else
pr = app.problems
pr = pr.unresolved unless all_errs
pr.in_env(
params[:environment]
).ordered_by(params_sort, params_order).page(params[:page]).per(current_user.per_page)
end
}

@sort = params[:sort]
@order = params[:order]
@sort = "last_notice_at" unless %w{message app last_deploy_at last_notice_at count}.member?(@sort)
@order = "desc" unless %w{asc desc}.member?(@order)
expose(:deploys) {
app.deploys.order_by(:created_at.desc).limit(5)
}

@problems = resource.problems
@problems = @problems.unresolved unless @all_errs
@problems = @problems.in_env(params[:environment]).ordered_by(@sort, @order).page(params[:page]).per(current_user.per_page)
def index; end
def show
app
end

@selected_problems = params[:problems] || []
@deploys = @app.deploys.order_by(:created_at.desc).limit(5)
end
format.atom do
@problems = resource.problems.unresolved.ordered
end
end
def new
plug_params(app)
end

def create
@app = App.new(params[:app])
initialize_subclassed_issue_tracker
initialize_subclassed_notification_service
create!
if app.save
redirect_to app_url(app), :flash => { :success => I18n.t('controllers.apps.flash.create.success') }
else
flash[:error] = I18n.t('controllers.apps.flash.create.error')
render :new
end
end

def update
@app = resource
initialize_subclassed_issue_tracker
initialize_subclassed_notification_service
update!
if app.save
redirect_to app_url(app), :flash => { :success => I18n.t('controllers.apps.flash.update.success') }
else
flash[:error] = I18n.t('controllers.apps.flash.update.error')
render :edit
end
end

def new
plug_params(build_resource)
new!
def edit
plug_params(app)
end

def edit
plug_params(resource)
edit!
def destroy
if app.destroy
redirect_to apps_url, :flash => { :success => I18n.t('controllers.apps.flash.destroy.success') }
else
flash[:error] = I18n.t('controllers.apps.flash.destroy.error')
render :show
end
end

protected
def collection
@apps ||= end_of_association_chain.all.sort
end

def initialize_subclassed_issue_tracker
# set the app's issue tracker
if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type]
if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type)
@app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes])
app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes])
end
end
end
Expand All @@ -69,21 +95,11 @@ def initialize_subclassed_notification_service
# set the app's notification service
if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type]
if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type)
@app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes])
app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes])
end
end
end

def begin_of_association_chain
# Filter the @apps collection to apps watched by the current user, unless user is an admin.
# If user is an admin, then no filter is applied, and all apps are shown.
current_user unless current_user.admin?
end

def interpolation_options
{:app_name => resource.name}
end

def plug_params app
app.watchers.build if app.watchers.none?
app.issue_tracker = IssueTracker.new unless app.issue_tracker_configured?
Expand Down

0 comments on commit 3732bdd

Please sign in to comment.