diff --git a/app/controllers/activity_controller.rb b/app/controllers/activity_controller.rb new file mode 100644 index 000000000..f94a8148f --- /dev/null +++ b/app/controllers/activity_controller.rb @@ -0,0 +1,58 @@ +class ActivityController < ApplicationController + before_filter :authentication_check + + # GET /activity_stream + def activity_stream + activity_stream = History.activity_stream(current_user, params[:limit]) + + # get related users + users = {} + tickets = [] + articles = [] + activity_stream.each {|item| + + # load article ids + if item['history_object'] == 'Ticket' + ticket = Ticket.find( item['o_id'] ).attributes + tickets.push ticket + + # load users + if !users[ ticket['owner_id'] ] + users[ ticket['owner_id'] ] = user_data_full( ticket['owner_id'] ) + end + if !users[ ticket['customer_id'] ] + users[ ticket['customer_id'] ] = user_data_full( ticket['customer_id'] ) + end + end + if item['history_object'] == 'Ticket::Article' + article = Ticket::Article.find( item['o_id'] ).attributes + if !article['subject'] || article['subject'] == '' + article['subject'] = Ticket.find( article['ticket_id'] ).title + end + articles.push article + + # load users + if !users[ article['created_by_id'] ] + users[ article['created_by_id'] ] = user_data_full( article['created_by_id'] ) + end + end + if item['history_object'] == 'User' + users[ item['o_id'] ] = user_data_full( item['o_id'] ) + end + + # load users + if !users[ item['created_by_id'] ] + users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) + end + } + + # return result + render :json => { + :activity_stream => activity_stream, + :tickets => tickets, + :articles => articles, + :users => users, + } + end + +end \ No newline at end of file diff --git a/app/controllers/recent_viewed_controller.rb b/app/controllers/recent_viewed_controller.rb new file mode 100644 index 000000000..8d2a944d2 --- /dev/null +++ b/app/controllers/recent_viewed_controller.rb @@ -0,0 +1,38 @@ +class RecentViewedController < ApplicationController + before_filter :authentication_check + + # GET /recent_viewed + def recent_viewed + recent_viewed = History.recent_viewed(current_user) + + # get related users + users = {} + tickets = [] + recent_viewed.each {|item| + + # load article ids +# if item.history_object == 'Ticket' + tickets.push Ticket.find( item['o_id'] ).attributes +# end +# if item.history_object 'Ticket::Article' +# tickets.push Ticket::Article.find(item.o_id) +# end +# if item.history_object 'User' +# tickets.push User.find(item.o_id) +# end + + # load users + if !users[ item['created_by_id'] ] + users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) + end + } + + # return result + render :json => { + :recent_viewed => recent_viewed, + :tickets => tickets, + :users => users, + } + end + +end \ No newline at end of file diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index 4b57b280d..427cbf607 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -2,7 +2,6 @@ class TicketOverviewsController < ApplicationController before_filter :authentication_check # GET /tickets - # GET /tickets.json def show #sleep 2 # build up attributes hash @@ -130,8 +129,7 @@ class TicketOverviewsController < ApplicationController end - # GET /ticket_create - # GET /ticket_create/1.json + # GET /ticket_create/1 def ticket_create # get related users @@ -221,7 +219,6 @@ class TicketOverviewsController < ApplicationController end # GET /ticket_full/1 - # GET /ticket_full/1.json def ticket_full ticket = Ticket.find(params[:id]) @@ -406,7 +403,6 @@ class TicketOverviewsController < ApplicationController end # GET /ticket_history/1 - # GET /tickets_history/1.json def ticket_history # get ticket data @@ -489,85 +485,8 @@ class TicketOverviewsController < ApplicationController :slave_ticket => ticket_slave.attributes, } end - - # GET /activity_stream - # GET /activity_stream.json - def activity_stream - activity_stream = History.activity_stream(current_user, params[:limit]) - - # get related users - users = {} - tickets = [] - articles = [] - activity_stream.each {|item| - - # load article ids - if item['history_object'] == 'Ticket' - tickets.push Ticket.find( item['o_id'] ).attributes - end - if item['history_object'] == 'Ticket::Article' - article = Ticket::Article.find( item['o_id'] ).attributes - if !article['subject'] || article['subject'] == '' - article['subject'] = Ticket.find( article['ticket_id'] ).title - end - articles.push article - end - if item['history_object'] == 'User' - users[ item['o_id'] ] = user_data_full( item['o_id'] ) - end - - # load users - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) - end - } - - # return result - render :json => { - :activity_stream => activity_stream, - :tickets => tickets, - :articles => articles, - :users => users, - } - end - - # GET /recent_viewed - # GET /recent_viewed.json - def recent_viewed - recent_viewed = History.recent_viewed(current_user) - - # get related users - users = {} - tickets = [] - recent_viewed.each {|item| - - # load article ids -# if item.history_object == 'Ticket' - tickets.push Ticket.find( item['o_id'] ).attributes -# end -# if item.history_object 'Ticket::Article' -# tickets.push Ticket::Article.find(item.o_id) -# end -# if item.history_object 'User' -# tickets.push User.find(item.o_id) -# end - - # load users - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) - end - } - - # return result - render :json => { - :recent_viewed => recent_viewed, - :tickets => tickets, - :users => users, - } - end - + # GET /user_search - # GET /user_search.json def user_search # get params diff --git a/config/routes/ticket.rb b/config/routes/ticket.rb index 3d753073c..98ba5fe85 100644 --- a/config/routes/ticket.rb +++ b/config/routes/ticket.rb @@ -14,13 +14,14 @@ module ExtraRoutes map.match '/ticket_history/:id', :to => 'ticket_overviews#ticket_history' map.match '/ticket_customer', :to => 'ticket_overviews#ticket_customer' map.match '/ticket_overviews', :to => 'ticket_overviews#show' - map.match '/activity_stream', :to => 'ticket_overviews#activity_stream' - map.match '/recent_viewed', :to => 'ticket_overviews#recent_viewed' map.match '/ticket_create', :to => 'ticket_overviews#ticket_create' map.match '/user_search', :to => 'ticket_overviews#user_search' map.match '/ticket_merge/:slave_ticket_id/:master_ticket_number', :to => 'ticket_overviews#ticket_merge' + map.match '/activity_stream', :to => 'activity#activity_stream' + map.match '/recent_viewed', :to => 'recent_viewed#recent_viewed' + end module_function :add end \ No newline at end of file