ticket_overviews_controller.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (C) 2012-2013 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 = { :users => {} }
  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. if !assets[:users][user.id]
  66. assets[:users][user.id] = User.user_data_full(user.id)
  67. end
  68. }
  69. }
  70. # return result
  71. render :json => {
  72. :overview => overview[:overview],
  73. :ticket_ids => overview[:ticket_ids],
  74. :tickets_count => overview[:tickets_count],
  75. :bulk => {
  76. :group_id__owner_id => groups_users,
  77. },
  78. :assets => assets,
  79. }
  80. end
  81. end