Class: Helpdesk::Admin::TicketsController

Inherits:
BaseController show all
Defined in:
app/controllers/helpdesk/admin/tickets_controller.rb

Instance Method Summary collapse

Methods inherited from Helpdesk::ApplicationController

#default_url_options, #ensure_user

Instance Method Details

#assignObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 20

def assign
  @ticket = Helpdesk::Ticket.find(params[:id])
  if @ticket.update_column(:assignee_id, helpdesk_user)
    redirect_to admin_ticket_path,
      notice: t('helpdesk.tickets.is_now_assigned',subject: @ticket.subject)
  else
    redirect_to admin_ticket_path
  end
end

#createObject



45
46
47
48
49
50
51
52
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 45

def create
  @ticket = Helpdesk::Ticket.new(params[:ticket])
  if @ticket.save
    redirect_to admin_ticket_path(@ticket)
  else
    render action: "new"
  end
end

#editObject



35
36
37
38
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 35

def edit
  @ticket = Helpdesk::Ticket.find(params[:id])

end

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 3

def index
  if params[:tickets] == 'unassigned'
    @tickets = Helpdesk::Ticket.unassigned.scoped
  elsif params[:tickets] == 'closed'
    @tickets = Helpdesk::Ticket.closed.scoped
  elsif params[:tickets] == 'active'
    @tickets = Helpdesk::Ticket.active.scoped
  elsif params[:tickets] == 'all'
    @tickets = Helpdesk::Ticket.all.scoped
  else
    @tickets = my_tickets.active.scoped
  end
  @tickets = @tickets.page(params[:page])

  render 'list'
end

#newObject



30
31
32
33
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 30

def new
  @ticket = Helpdesk::Ticket.new
  @ticket.status = Helpdesk::Ticket::STATUSES[0][0]
end

#showObject



40
41
42
43
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 40

def show
  @ticket = Helpdesk::Ticket.find(params[:id])

end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 54

def update
  @ticket = Helpdesk::Ticket.find(params[:id])
  if @ticket.update_attributes(params[:ticket])
    unless @ticket.assignee
      @ticket.update_column(:assignee_id, helpdesk_user)
    end
    redirect_to admin_ticket_path
  else
    render action: "new"
  end
end