Improved recent viewed object feature (like online notification is implemented).
This commit is contained in:
parent
14f77344c5
commit
e9bceeeb8a
10 changed files with 59 additions and 40 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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' )
|
||||
|
|
|
@ -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 } )
|
||||
|
|
4
app/assets/javascripts/app/models/recent_view.js.coffee
Normal file
4
app/assets/javascripts/app/models/recent_view.js.coffee
Normal file
|
@ -0,0 +1,4 @@
|
|||
class App.RecentView extends App.Model
|
||||
@configure 'RecentView', 'name'
|
||||
@extend Spine.Model.Ajax
|
||||
@url: @apiPath + '/recent_view'
|
|
@ -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
|
||||
|
|
@ -133,11 +133,12 @@ returns:
|
|||
end
|
||||
|
||||
def notify_clients_after_change
|
||||
|
||||
puts "#{ self.class.name } changed " + self.created_at.to_s
|
||||
Sessions.broadcast(
|
||||
Sessions.send_to(
|
||||
self.user_id,
|
||||
{
|
||||
:event => 'OnlineNotification::changed',
|
||||
:data => {}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
6
config/routes/recent_view.rb
Normal file
6
config/routes/recent_view.rb
Normal 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
|
|
@ -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
|
Loading…
Reference in a new issue