Class: ProblemsController

Inherits:
ApplicationController show all
Includes:
ProblemsSearcher
Defined in:
app/controllers/problems_controller.rb

Overview

Manage problems

List of actions available : MEMBER => :show, :edit, :update, :create, :destroy, :resolve, :unresolve, :create_issue, :unlink_issue COLLECTION => :index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search

Instance Method Summary collapse

Methods inherited from ApplicationController

#stored_location_for

Instance Method Details

#create_issueObject


58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/problems_controller.rb', line 58

def create_issue
  issue = Issue.new(problem: problem, user: current_user)
  issue.body = render_to_string(*issue.render_body_args)

  unless issue.save
    flash[:error] = issue.errors.full_messages.join(', ')
  end

  redirect_to app_problem_path(app, problem)
end

#destroy_allObject


121
122
123
124
125
126
127
# File 'app/controllers/problems_controller.rb', line 121

def destroy_all
  nb_problem_destroy = ProblemDestroy.execute(app.problems)
  flash[:success] = "#{I18n.t(:n_errs_have, :count => nb_problem_destroy)} been deleted."
  redirect_to :back
rescue ActionController::RedirectBackError
  redirect_to app_path(app)
end

#destroy_severalObject


115
116
117
118
119
# File 'app/controllers/problems_controller.rb', line 115

def destroy_several
  nb_problem_destroy = ProblemDestroy.execute(selected_problems)
  flash[:notice] = "#{I18n.t(:n_errs_have, :count => nb_problem_destroy)} been deleted."
  redirect_to :back
end

#indexObject


50
# File 'app/controllers/problems_controller.rb', line 50

def index; end

#merge_severalObject

Action to merge several Problem in One problem

Parameters:

  • :problems (Array<String>)

    the list of problem ids


99
100
101
102
103
104
105
106
107
# File 'app/controllers/problems_controller.rb', line 99

def merge_several
  if selected_problems.length < 2
    flash[:notice] = I18n.t('controllers.problems.flash.need_two_errors_merge')
  else
    ProblemMerge.new(selected_problems).merge
    flash[:notice] = I18n.t('controllers.problems.flash.merge_several.success', :nb => selected_problems.count)
  end
  redirect_to :back
end

#resolveObject


74
75
76
77
78
79
80
# File 'app/controllers/problems_controller.rb', line 74

def resolve
  problem.resolve!
  flash[:success] = 'Great news everyone! The error has been resolved.'
  redirect_to :back
rescue ActionController::RedirectBackError
  redirect_to app_path(app)
end

#resolve_severalObject


82
83
84
85
86
# File 'app/controllers/problems_controller.rb', line 82

def resolve_several
  selected_problems.each(&:resolve!)
  flash[:success] = "Great news everyone! #{I18n.t(:n_errs_have, :count => selected_problems.count)} been resolved."
  redirect_to :back
end

#searchObject


129
130
131
132
133
134
135
136
137
# File 'app/controllers/problems_controller.rb', line 129

def search
  ps = Problem.search(params[:search]).for_apps(app_scope).in_env(params[:environment]).all_else_unresolved(params[:all_errs]).ordered_by(params_sort, params_order)
  selected_problems = params[:problems] || []
  self.problems = ps.page(params[:page]).per(current_user.per_page)
  respond_to do |format|
    format.html { render :index }
    format.js
  end
end

#showObject


52
53
54
55
56
# File 'app/controllers/problems_controller.rb', line 52

def show
  @notices  = problem.notices.reverse_ordered.page(params[:notice]).per(1)
  @notice   = @notices.first
  @comment = Comment.new
end

69
70
71
72
# File 'app/controllers/problems_controller.rb', line 69

def unlink_issue
  problem.update_attribute :issue_link, nil
  redirect_to app_problem_path(app, problem)
end

#unmerge_severalObject


109
110
111
112
113
# File 'app/controllers/problems_controller.rb', line 109

def unmerge_several
  all = selected_problems.map(&:unmerge!).flatten
  flash[:success] = "#{I18n.t(:n_errs_have, :count => all.length)} been unmerged."
  redirect_to :back
end

#unresolve_severalObject


88
89
90
91
92
# File 'app/controllers/problems_controller.rb', line 88

def unresolve_several
  selected_problems.each(&:unresolve!)
  flash[:success] = "#{I18n.t(:n_errs_have, :count => selected_problems.count)} been unresolved."
  redirect_to :back
end