diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index a180860fb..b4e24c027 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -382,7 +382,7 @@ class App.Controller extends Spine.Controller App.Ajax.request( id: "recent_view_#{object}_#{o_id}" type: 'POST' - url: @Config.get('api_path') + '/recent_viewed' + url: @Config.get('api_path') + '/recent_view' data: JSON.stringify(params) processData: true ) diff --git a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee index cbea2a62d..7a1a097b6 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -6,9 +6,9 @@ class App.DashboardRecentViewed extends App.Controller # get data @ajax( - id: 'dashboard_recent_viewed', + id: 'dashboard_recent_view', type: 'GET', - url: @apiPath + '/recent_viewed', + url: @apiPath + '/recent_view', data: { limit: 5, } diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index a119fabf3..736af3ee5 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -21,16 +21,15 @@ class App.Navigation extends App.Controller @bind 'auth', (user) => @log 'Navigation', 'notice', 'navbar rebuild', user - if !_.isEmpty( user ) - cache = App.Store.get( 'update_recent_viewed' ) - @recent_viewed_build( cache ) if cache - @render() - # rebuild recent viewed data - @bind 'update_recent_viewed', (data) => - @recent_viewed_build(data) - @renderPersonal() + # fetch new recent viewed after collection change + @bind 'RecentView::changed', => + @delay( + => @fetchRecentView() + 1000 + 'recent-view-changed' + ) # bell on / bell off @bind 'bell', (data) => @@ -67,6 +66,7 @@ class App.Navigation extends App.Controller ) renderPersonal: => + @recentViewNavbarItemsRebuild() items = @getItems( navbar: @Config.get( 'NavBarRight' ) ) # get open tabs to repopen on rerender @@ -332,6 +332,16 @@ class App.Navigation extends App.Controller inordervalue = [] for num in inorder 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 sortit: (a,b) -> @@ -347,12 +357,7 @@ class App.Navigation extends App.Controller @el.find('li').removeClass('active') @el.find("[href=\"#{url}\"]").parents('li').addClass('active') - recent_viewed_build: (data) => - - App.Store.write( 'update_recent_viewed', data ) - - # load assets - App.Collection.loadAssets( data.assets ) + recentViewNavbarItemsRebuild: => # remove old views NavBarRight = @Config.get( 'NavBarRight' ) || {} @@ -363,13 +368,13 @@ class App.Navigation extends App.Controller delete NavBarRight[key] # add new views - items = data.recent_viewed || [] + items = App.RecentView.search(sortBy: 'created_at', order: 'DESC' ) items = @prepareForObjectList(items) - prio = 8000 + prio = 80 for item in items divider = false navheader = false - if prio is 8000 + if prio is 80 divider = true navheader = 'Recent Viewed' @@ -381,8 +386,15 @@ class App.Navigation extends App.Controller target: item.link divider: divider navheader: navheader + type: 'recentViewed' } @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' ) diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee index 902dec6c5..f280e11e7 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee @@ -3,7 +3,11 @@ class App.OnlineNotificationWidget extends App.Controller super @bind 'OnlineNotification::changed', => - @fetch() + @delay( + => @fetch() + 1000 + 'online-notification-changed' + ) # rebuild widget on auth @bind 'auth', (user) => @@ -23,7 +27,7 @@ class App.OnlineNotificationWidget extends App.Controller release: => @stop() - App.Model.unsubscribe( @subscribeId ) + App.OnlineNotification.unsubscribe( @subscribeId ) access: -> return false if _.isEmpty( @Session.all() ) @@ -77,7 +81,6 @@ class App.OnlineNotificationWidget extends App.Controller @frontendTimeUpdate() ) - fetch: => load = (items) => App.OnlineNotification.refresh( items, { clear: true } ) diff --git a/app/assets/javascripts/app/models/recent_view.js.coffee b/app/assets/javascripts/app/models/recent_view.js.coffee new file mode 100644 index 000000000..c94c96b0c --- /dev/null +++ b/app/assets/javascripts/app/models/recent_view.js.coffee @@ -0,0 +1,4 @@ +class App.RecentView extends App.Model + @configure 'RecentView', 'name' + @extend Spine.Model.Ajax + @url: @apiPath + '/recent_view' diff --git a/app/controllers/recent_viewed_controller.rb b/app/controllers/recent_view_controller.rb similarity index 65% rename from app/controllers/recent_viewed_controller.rb rename to app/controllers/recent_view_controller.rb index 0f58a9fee..01a75ffa8 100644 --- a/app/controllers/recent_viewed_controller.rb +++ b/app/controllers/recent_view_controller.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -class RecentViewedController < ApplicationController +class RecentViewController < ApplicationController before_filter :authentication_check =begin @@ -14,7 +14,7 @@ Response: } 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 @@ -40,7 +40,7 @@ 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}' +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 diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 10b7610b4..dadbf5588 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -133,11 +133,12 @@ returns: end def notify_clients_after_change - - puts "#{ self.class.name } changed " + self.created_at.to_s - Sessions.broadcast( - :event => 'OnlineNotification::changed', - :data => {} + Sessions.send_to( + self.user_id, + { + :event => 'OnlineNotification::changed', + :data => {} + } ) end diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 201274f6d..f7d4d88e5 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -60,12 +60,11 @@ class RecentView < ApplicationModel end def notify_clients - data = RecentView.list_full( User.find(self.created_by_id), 10 ) Sessions.send_to( self.created_by_id, { - :event => 'update_recent_viewed', - :data => data, + :event => 'RecentView::changed', + :data => {} } ) end diff --git a/config/routes/recent_view.rb b/config/routes/recent_view.rb new file mode 100644 index 000000000..3b959f82f --- /dev/null +++ b/config/routes/recent_view.rb @@ -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 \ No newline at end of file diff --git a/config/routes/recent_viewed.rb b/config/routes/recent_viewed.rb deleted file mode 100644 index 7b584d5a4..000000000 --- a/config/routes/recent_viewed.rb +++ /dev/null @@ -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 \ No newline at end of file