Class: PlanMyStuff::IssuesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plan_my_stuff/issues_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /issues



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 32

def create
  @issue = PlanMyStuff::Issue.create!(
    title: issue_params[:title],
    body: issue_params[:body],
    labels: parse_labels(issue_params[:labels]),
    user: pms_current_user,
  )

  yield(@issue) if block_given?
  return if performed?

  flash[:success] = 'Issue was successfully created.'
  redirect_to(plan_my_stuff.issue_path(@issue))
rescue PlanMyStuff::ValidationError => e
  pms_handle_rescue(e)
  @issue = PlanMyStuff::Issue.new(title: issue_params[:title], body: issue_params[:body])
  flash.now[:error] = e.message
  render(:new, status: PlanMyStuff.unprocessable_status)
end

#edit {|@issue| ... } ⇒ Object

GET /issues/:id/edit

Yields:

  • (@issue)


65
66
67
68
69
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 65

def edit
  @issue = PlanMyStuff::Issue.find(params[:id])

  yield(@issue) if block_given?
end

#index {|@issues| ... } ⇒ Object

GET /issues

Yields:

  • (@issues)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 6

def index
  @page = (params[:page] || 1).to_i
  @per_page = (params[:per_page] || 25).to_i
  @state = (params[:state] || 'open').to_sym
  @labels = params[:labels].present? ? Array.wrap(params[:labels]) : []
  @repo = params[:repo]

  @issues = PlanMyStuff::Issue.list(
    repo: @repo,
    state: @state,
    labels: @labels,
    page: @page,
    per_page: @per_page,
  )

  yield(@issues) if block_given?
end

#new {|@issue| ... } ⇒ Object

GET /issues/new

Yields:

  • (@issue)


25
26
27
28
29
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 25

def new
  @issue = PlanMyStuff::Issue.new

  yield(@issue) if block_given?
end

#show {|@issue| ... } ⇒ Object

GET /issues/:id

Yields:

  • (@issue)


53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 53

def show
  @issue = PlanMyStuff::Issue.find(params[:id])
  @comments = filter_visible_comments(@issue.comments)
  @current_user_id = pms_current_user.present? ? PlanMyStuff::UserResolver.user_id(pms_current_user) : nil
  @current_user_login = PlanMyStuff.configuration.[@current_user_id]
  @pipeline_enabled = PlanMyStuff.configuration.pipeline_enabled
  @pipeline_item = load_pipeline_item(@issue.number) if @pipeline_enabled

  yield(@issue) if block_given?
end

#updateObject

PATCH/PUT /issues/:id



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/plan_my_stuff/issues_controller.rb', line 72

def update
  @issue = PlanMyStuff::Issue.find(params[:id])

  @issue.update!(
    title: issue_params[:title],
    body: issue_params[:body],
    labels: parse_labels(issue_params[:labels]),
  )

  yield(@issue) if block_given?
  return if performed?

  flash[:success] = 'Issue was successfully updated.'
  redirect_to(plan_my_stuff.issue_path(@issue))
rescue PlanMyStuff::StaleObjectError => e
  pms_handle_rescue(e)
  flash.now[:error] = 'Issue was modified by someone else. Please review the latest changes and try again.'
  render(:edit, status: PlanMyStuff.unprocessable_status)
rescue PlanMyStuff::ValidationError => e
  pms_handle_rescue(e)
  flash.now[:error] = e.message
  render(:edit, status: PlanMyStuff.unprocessable_status)
end