Moved to support generic objects for recent viewed.

This commit is contained in:
Martin Edenhofer 2014-08-24 01:56:45 +02:00
parent 1a8d503a4e
commit bafd51e0c8
11 changed files with 65 additions and 25 deletions

View file

@ -446,6 +446,18 @@ class App.Controller extends Spine.Controller
else
fetch(params)
recentView: (object, o_id) =>
params =
object: object
o_id: o_id
App.Ajax.request(
id: "recent_view_#{object}_#{o_id}"
type: 'POST'
url: @Config.get('api_path') + '/recent_viewed'
data: JSON.stringify(params)
processData: true
)
ws_send: (data) ->
App.Event.trigger( 'ws:send', JSON.stringify(data) )

View file

@ -34,6 +34,10 @@ class App.OrganizationZoom extends App.Controller
render: (organization) =>
if !@doNotLog
@doNotLog = 1
@recentView( 'Organization', @organization_id )
@html App.view('organization_zoom')(
organization: organization
)

View file

@ -11,7 +11,6 @@ class App.TicketZoom extends App.Controller
@ticket_id = params.ticket_id
@article_id = params.article_id
@signature = undefined
@doNotLog = params['doNotLog'] || 0
@key = 'ticket::' + @ticket_id
cache = App.Store.get( @key )
@ -66,7 +65,7 @@ class App.TicketZoom extends App.Controller
@ajax(
id: 'ticket_zoom_' + ticket_id
type: 'GET'
url: @apiPath + '/ticket_full/' + ticket_id + '?do_not_log=' + @doNotLog
url: @apiPath + '/ticket_full/' + ticket_id
processData: true
success: (data, status, xhr) =>
@ -101,7 +100,10 @@ class App.TicketZoom extends App.Controller
# remove task
App.TaskManager.remove( @task_key )
)
@doNotLog = 1
if !@doNotLog
@doNotLog = 1
@recentView( 'Ticket', ticket_id )
load: (data, force) =>

View file

@ -34,6 +34,9 @@ class App.UserZoom extends App.Controller
render: (user) =>
if !@doNotLog
@doNotLog = 1
@recentView( 'User', @user_id )
@html App.view('user_zoom')(
user: user

View file

@ -223,10 +223,6 @@ class ApplicationController < ActionController::Base
return false
end
def log_view (object)
RecentView.log( object, current_user )
end
def config_frontend
# config

View file

@ -14,15 +14,42 @@ Response:
}
Test:
curl http://localhost/api/v1/recent_viewed.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
curl http://localhost/api/v1/recent_viewed -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
=end
def recent_viewed
def index
recent_viewed = RecentView.list_fulldata( current_user, 10 )
# return result
render :json => recent_viewed
end
end
=begin
Resource:
POST /api/v1/recent_viewed
Payload:
{
"object": "Ticket",
"o_id": 123,
}
Response:
{}
Test:
curl http://localhost/api/v1/recent_viewed -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}'
=end
def create
RecentView.log( params[:object], params[:o_id], current_user )
# return result
render :json => { :message => 'ok' }
end
end

View file

@ -239,11 +239,6 @@ class TicketsController < ApplicationController
ticket = Ticket.find( params[:id] )
return if !ticket_permission( ticket )
# log object as viewed
if !params[:do_not_log] || params[:do_not_log].to_i == 0
log_view( ticket )
end
# get signature
signature = {}
if ticket.group.signature

View file

@ -3,14 +3,14 @@
class RecentView < ApplicationModel
belongs_to :object_lookup, :class_name => 'ObjectLookup'
def self.log( object, user )
def self.log( object, o_id, user )
# lookups
object_lookup_id = ObjectLookup.by_name( object.class.to_s )
object_lookup_id = ObjectLookup.by_name( object )
# create entry
record = {
:o_id => object.id,
:o_id => o_id,
:object_lookup_id => object_lookup_id.to_i,
:created_by_id => user.id,
}

View file

@ -1,5 +1,6 @@
Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path
match api_path + '/recent_viewed', :to => 'recent_viewed#recent_viewed', :via => :get
match api_path + '/recent_viewed', :to => 'recent_viewed#index', :via => :get
match api_path + '/recent_viewed', :to => 'recent_viewed#create', :via => :post
end

View file

@ -29,13 +29,13 @@ class RecentViewTest < ActiveSupport::TestCase
RecentView.user_log_destroy(user1)
RecentView.log( ticket1, user1 )
RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
sleep 1
RecentView.log( ticket2, user1 )
RecentView.log( ticket2.class.to_s, ticket2.id,, user1 )
sleep 1
RecentView.log( ticket1, user1 )
RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
sleep 1
RecentView.log( ticket1, user1 )
RecentView.log( ticket1.class.to_s, ticket1.id, user1 )
list = RecentView.list( user1 )
assert( list[0]['o_id'], ticket1.id )

View file

@ -261,7 +261,7 @@ class SessionBasicTest < ActiveSupport::TestCase
user = User.lookup(:id => 1)
ticket = Ticket.all.last
RecentView.log( ticket, user )
RecentView.log( ticket.class.to_s, ticket.id user )
recent_viewed_client1 = Sessions::Backend::RecentViewed.new(user, false, '123-1')
# get as stream
@ -278,7 +278,7 @@ class SessionBasicTest < ActiveSupport::TestCase
result1 = recent_viewed_client1.push
assert( !result1, "check recent_viewed - recall 2" )
RecentView.log( ticket, user )
RecentView.log( ticket.class.to_s, ticket.id, user )
sleep 20