Improved recent viewed object feature (like online notification is implemented).

This commit is contained in:
Martin Edenhofer 2014-08-27 15:06:09 +02:00
parent 14f77344c5
commit e9bceeeb8a
10 changed files with 59 additions and 40 deletions

View file

@ -382,7 +382,7 @@ class App.Controller extends Spine.Controller
App.Ajax.request( App.Ajax.request(
id: "recent_view_#{object}_#{o_id}" id: "recent_view_#{object}_#{o_id}"
type: 'POST' type: 'POST'
url: @Config.get('api_path') + '/recent_viewed' url: @Config.get('api_path') + '/recent_view'
data: JSON.stringify(params) data: JSON.stringify(params)
processData: true processData: true
) )

View file

@ -6,9 +6,9 @@ class App.DashboardRecentViewed extends App.Controller
# get data # get data
@ajax( @ajax(
id: 'dashboard_recent_viewed', id: 'dashboard_recent_view',
type: 'GET', type: 'GET',
url: @apiPath + '/recent_viewed', url: @apiPath + '/recent_view',
data: { data: {
limit: 5, limit: 5,
} }

View file

@ -21,16 +21,15 @@ class App.Navigation extends App.Controller
@bind 'auth', (user) => @bind 'auth', (user) =>
@log 'Navigation', 'notice', 'navbar rebuild', user @log 'Navigation', 'notice', 'navbar rebuild', user
if !_.isEmpty( user )
cache = App.Store.get( 'update_recent_viewed' )
@recent_viewed_build( cache ) if cache
@render() @render()
# rebuild recent viewed data # fetch new recent viewed after collection change
@bind 'update_recent_viewed', (data) => @bind 'RecentView::changed', =>
@recent_viewed_build(data) @delay(
@renderPersonal() => @fetchRecentView()
1000
'recent-view-changed'
)
# bell on / bell off # bell on / bell off
@bind 'bell', (data) => @bind 'bell', (data) =>
@ -67,6 +66,7 @@ class App.Navigation extends App.Controller
) )
renderPersonal: => renderPersonal: =>
@recentViewNavbarItemsRebuild()
items = @getItems( navbar: @Config.get( 'NavBarRight' ) ) items = @getItems( navbar: @Config.get( 'NavBarRight' ) )
# get open tabs to repopen on rerender # get open tabs to repopen on rerender
@ -332,6 +332,16 @@ class App.Navigation extends App.Controller
inordervalue = [] inordervalue = []
for num in inorder for num in inorder
inordervalue.push newlist[ num ] inordervalue.push newlist[ num ]
# add differ to after recent viewed item
found = false
for value in inordervalue
if value.type is 'recentViewed'
found = true
if found && value.type isnt 'recentViewed'
value.divider = true
found = false
return inordervalue return inordervalue
sortit: (a,b) -> sortit: (a,b) ->
@ -347,12 +357,7 @@ class App.Navigation extends App.Controller
@el.find('li').removeClass('active') @el.find('li').removeClass('active')
@el.find("[href=\"#{url}\"]").parents('li').addClass('active') @el.find("[href=\"#{url}\"]").parents('li').addClass('active')
recent_viewed_build: (data) => recentViewNavbarItemsRebuild: =>
App.Store.write( 'update_recent_viewed', data )
# load assets
App.Collection.loadAssets( data.assets )
# remove old views # remove old views
NavBarRight = @Config.get( 'NavBarRight' ) || {} NavBarRight = @Config.get( 'NavBarRight' ) || {}
@ -363,13 +368,13 @@ class App.Navigation extends App.Controller
delete NavBarRight[key] delete NavBarRight[key]
# add new views # add new views
items = data.recent_viewed || [] items = App.RecentView.search(sortBy: 'created_at', order: 'DESC' )
items = @prepareForObjectList(items) items = @prepareForObjectList(items)
prio = 8000 prio = 80
for item in items for item in items
divider = false divider = false
navheader = false navheader = false
if prio is 8000 if prio is 80
divider = true divider = true
navheader = 'Recent Viewed' navheader = 'Recent Viewed'
@ -381,8 +386,15 @@ class App.Navigation extends App.Controller
target: item.link target: item.link
divider: divider divider: divider
navheader: navheader navheader: navheader
type: 'recentViewed'
} }
@Config.set( 'NavBarRight', NavBarRight ) @Config.set( 'NavBarRight', NavBarRight )
fetchRecentView: =>
load = (items) =>
App.RecentView.refresh( items, { clear: true } )
@renderPersonal()
App.RecentView.fetchFull(load)
App.Config.set( 'navigation', App.Navigation, 'Navigations' ) App.Config.set( 'navigation', App.Navigation, 'Navigations' )

View file

@ -3,7 +3,11 @@ class App.OnlineNotificationWidget extends App.Controller
super super
@bind 'OnlineNotification::changed', => @bind 'OnlineNotification::changed', =>
@fetch() @delay(
=> @fetch()
1000
'online-notification-changed'
)
# rebuild widget on auth # rebuild widget on auth
@bind 'auth', (user) => @bind 'auth', (user) =>
@ -23,7 +27,7 @@ class App.OnlineNotificationWidget extends App.Controller
release: => release: =>
@stop() @stop()
App.Model.unsubscribe( @subscribeId ) App.OnlineNotification.unsubscribe( @subscribeId )
access: -> access: ->
return false if _.isEmpty( @Session.all() ) return false if _.isEmpty( @Session.all() )
@ -77,7 +81,6 @@ class App.OnlineNotificationWidget extends App.Controller
@frontendTimeUpdate() @frontendTimeUpdate()
) )
fetch: => fetch: =>
load = (items) => load = (items) =>
App.OnlineNotification.refresh( items, { clear: true } ) App.OnlineNotification.refresh( items, { clear: true } )

View file

@ -0,0 +1,4 @@
class App.RecentView extends App.Model
@configure 'RecentView', 'name'
@extend Spine.Model.Ajax
@url: @apiPath + '/recent_view'

View file

@ -1,6 +1,6 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class RecentViewedController < ApplicationController class RecentViewController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
=begin =begin
@ -14,7 +14,7 @@ Response:
} }
Test: Test:
curl http://localhost/api/v1/recent_viewed -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
=end =end
@ -40,7 +40,7 @@ Response:
{} {}
Test: 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}' curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}'
=end =end

View file

@ -133,11 +133,12 @@ returns:
end end
def notify_clients_after_change def notify_clients_after_change
Sessions.send_to(
puts "#{ self.class.name } changed " + self.created_at.to_s self.user_id,
Sessions.broadcast( {
:event => 'OnlineNotification::changed', :event => 'OnlineNotification::changed',
:data => {} :data => {}
}
) )
end end

View file

@ -60,12 +60,11 @@ class RecentView < ApplicationModel
end end
def notify_clients def notify_clients
data = RecentView.list_full( User.find(self.created_by_id), 10 )
Sessions.send_to( Sessions.send_to(
self.created_by_id, self.created_by_id,
{ {
:event => 'update_recent_viewed', :event => 'RecentView::changed',
:data => data, :data => {}
} }
) )
end end

View file

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

View file

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