Browse Source

Moved to support generic objects for recent viewed.

Martin Edenhofer 10 years ago
parent
commit
bafd51e0c8

+ 12 - 0
app/assets/javascripts/app/controllers/_application_controller.js.coffee

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

+ 4 - 0
app/assets/javascripts/app/controllers/organization_zoom.js.coffee

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

+ 5 - 3
app/assets/javascripts/app/controllers/ticket_zoom.js.coffee

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

+ 3 - 0
app/assets/javascripts/app/controllers/user_zoom.js.coffee

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

+ 0 - 4
app/controllers/application_controller.rb

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

+ 30 - 3
app/controllers/recent_viewed_controller.rb

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

+ 0 - 5
app/controllers/tickets_controller.rb

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

+ 3 - 3
app/models/recent_view.rb

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

+ 2 - 1
config/routes/recent_viewed.rb

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

+ 4 - 4
test/unit/recent_view_test.rb

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

Some files were not shown because too many files changed in this diff