Moved activity and recent view in own modules.
This commit is contained in:
parent
9715383b65
commit
d649f2a53e
4 changed files with 101 additions and 85 deletions
58
app/controllers/activity_controller.rb
Normal file
58
app/controllers/activity_controller.rb
Normal 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
|
38
app/controllers/recent_viewed_controller.rb
Normal file
38
app/controllers/recent_viewed_controller.rb
Normal 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
|
|
@ -2,7 +2,6 @@ class TicketOverviewsController < ApplicationController
|
||||||
before_filter :authentication_check
|
before_filter :authentication_check
|
||||||
|
|
||||||
# GET /tickets
|
# GET /tickets
|
||||||
# GET /tickets.json
|
|
||||||
def show
|
def show
|
||||||
#sleep 2
|
#sleep 2
|
||||||
# build up attributes hash
|
# build up attributes hash
|
||||||
|
@ -130,8 +129,7 @@ class TicketOverviewsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# GET /ticket_create
|
# GET /ticket_create/1
|
||||||
# GET /ticket_create/1.json
|
|
||||||
def ticket_create
|
def ticket_create
|
||||||
|
|
||||||
# get related users
|
# get related users
|
||||||
|
@ -221,7 +219,6 @@ class TicketOverviewsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /ticket_full/1
|
# GET /ticket_full/1
|
||||||
# GET /ticket_full/1.json
|
|
||||||
def ticket_full
|
def ticket_full
|
||||||
ticket = Ticket.find(params[:id])
|
ticket = Ticket.find(params[:id])
|
||||||
|
|
||||||
|
@ -406,7 +403,6 @@ class TicketOverviewsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /ticket_history/1
|
# GET /ticket_history/1
|
||||||
# GET /tickets_history/1.json
|
|
||||||
def ticket_history
|
def ticket_history
|
||||||
|
|
||||||
# get ticket data
|
# get ticket data
|
||||||
|
@ -490,84 +486,7 @@ class TicketOverviewsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
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
|
||||||
# GET /user_search.json
|
|
||||||
def user_search
|
def user_search
|
||||||
|
|
||||||
# get params
|
# get params
|
||||||
|
|
|
@ -14,13 +14,14 @@ module ExtraRoutes
|
||||||
map.match '/ticket_history/:id', :to => 'ticket_overviews#ticket_history'
|
map.match '/ticket_history/:id', :to => 'ticket_overviews#ticket_history'
|
||||||
map.match '/ticket_customer', :to => 'ticket_overviews#ticket_customer'
|
map.match '/ticket_customer', :to => 'ticket_overviews#ticket_customer'
|
||||||
map.match '/ticket_overviews', :to => 'ticket_overviews#show'
|
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 '/ticket_create', :to => 'ticket_overviews#ticket_create'
|
||||||
map.match '/user_search', :to => 'ticket_overviews#user_search'
|
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 '/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
|
end
|
||||||
module_function :add
|
module_function :add
|
||||||
end
|
end
|
Loading…
Reference in a new issue