Moved activity and recent view in own modules.

This commit is contained in:
Martin Edenhofer 2012-07-19 23:31:57 +02:00
parent 9715383b65
commit d649f2a53e
4 changed files with 101 additions and 85 deletions

View file

@ -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

View file

@ -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

View file

@ -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
@ -490,84 +486,7 @@ class TicketOverviewsController < ApplicationController
}
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

View file

@ -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