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



23
24
25
26
27
28
29
30
31
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 23

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



48
49
50
51
52
53
54
55
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 48

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

#editObject



38
39
40
41
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 38

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
19
20
21
# 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.scoped
  else
    @tickets = my_tickets.active
  end
  @tickets = @tickets.includes(:requester)
                      .includes(:assignee)
                      .includes(:ticket_type)
                      .page(params[:page])

  render 'list'
end

#newObject



33
34
35
36
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 33

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

#showObject



43
44
45
46
# File 'app/controllers/helpdesk/admin/tickets_controller.rb', line 43

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

end

#updateObject



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

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