ticket_overviews_controller.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. require 'ticket/overviews'
  3. class TicketOverviewsController < ApplicationController
  4. before_filter :authentication_check
  5. # GET /api/v1/ticket_overviews
  6. def show
  7. # get navbar overview data
  8. if !params[:view]
  9. result = Ticket::Overviews.list(
  10. :current_user => current_user,
  11. )
  12. render :json => result
  13. return
  14. end
  15. # get real overview data
  16. if params[:array]
  17. overview = Ticket::Overviews.list(
  18. :view => params[:view],
  19. :current_user => current_user,
  20. :array => true,
  21. )
  22. tickets = []
  23. overview[:tickets].each {|ticket_id|
  24. data = { :id => ticket_id }
  25. tickets.push data
  26. }
  27. # return result
  28. render :json => {
  29. :overview => overview[:overview],
  30. :tickets => tickets,
  31. :tickets_count => overview[:tickets_count],
  32. }
  33. return
  34. end
  35. overview = Ticket::Overviews.list(
  36. :view => params[:view],
  37. :current_user => current_user,
  38. :array => true,
  39. )
  40. if !overview
  41. render :json => { :error => "No such view #{ params[:view] }!" }, :status => :unprocessable_entity
  42. return
  43. end
  44. # get related users
  45. assets = {}
  46. overview[:ticket_ids].each {|ticket_id|
  47. ticket = Ticket.lookup( :id => ticket_id )
  48. assets = ticket.assets(assets)
  49. }
  50. # get groups
  51. group_ids = []
  52. Group.where( :active => true ).each { |group|
  53. group_ids.push group.id
  54. }
  55. agents = {}
  56. Ticket::ScreenOptions.agents.each { |user|
  57. agents[ user.id ] = 1
  58. }
  59. groups_users = {}
  60. group_ids.each {|group_id|
  61. groups_users[ group_id ] = []
  62. Group.find(group_id).users.each {|user|
  63. next if !agents[ user.id ]
  64. groups_users[ group_id ].push user.id
  65. assets = user.assets( assets )
  66. }
  67. }
  68. # return result
  69. render :json => {
  70. :overview => overview[:overview],
  71. :ticket_ids => overview[:ticket_ids],
  72. :tickets_count => overview[:tickets_count],
  73. :bulk => {
  74. :group_id__owner_id => groups_users,
  75. },
  76. :assets => assets,
  77. }
  78. end
  79. end