From ee9bffe8cab35fdfbbdcdd8b1a42bc167f6fc50f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 12:21:31 +0200 Subject: [PATCH] Renamed Ticket::Overview to Ticket::Overviews. --- .../app/controllers/ticket_overview.js.coffee | 29 +++++++-------- .../ticket_overviews_controller.rb | 6 ++-- .../ticket/{overview.rb => overviews.rb} | 15 +++----- lib/session.rb | 35 ++++++++++--------- 4 files changed, 40 insertions(+), 45 deletions(-) rename app/models/ticket/{overview.rb => overviews.rb} (96%) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee index c9ebf5381..28f503f1b 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee @@ -55,22 +55,19 @@ class Index extends App.ControllerContent load: (data) => return if !data - return if !data.ticket_list + return if !data.ticket_ids return if !data.overview @overview = data.overview @tickets_count = data.tickets_count - @ticket_list = data.ticket_list + @ticket_ids = data.ticket_ids if data.ajax data.ajax = false App.Store.write( @key, data ) - # load user collection - App.Collection.load( type: 'User', data: data.collections.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.collections.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets # get meta data @overview = data.overview @@ -87,7 +84,7 @@ class Index extends App.ControllerContent @fetch() @ticket_list_show = [] - for ticket_id in @ticket_list + for ticket_id in @ticket_ids @ticket_list_show.push App.Ticket.retrieve( ticket_id ) # remeber bulk attributes @@ -497,7 +494,7 @@ class Router extends App.Controller cache = App.Store.get( @key ) if cache @tickets_count = cache.tickets_count - @ticket_list = cache.ticket_list + @ticket_ids = cache.ticket_ids @redirect() else @ajax( @@ -511,7 +508,7 @@ class Router extends App.Controller ) load: (data) => - @ticket_list = data.ticket_list + @ticket_ids = data.ticket_ids @tickets_count = data.tickets_count # App.Store.write( data ) @redirect() @@ -524,19 +521,19 @@ class Router extends App.Controller # redirect if @direction == 'next' - if @ticket_list[ @position ] && @ticket_list[ @position ] + if @ticket_ids[ @position ] && @ticket_ids[ @position ] position = @position + 1 @Config.set( 'LastOverviewPosition', position ) - @navigate 'ticket/zoom/' + @ticket_list[ @position ] + '/nav/true' + @navigate 'ticket/zoom/' + @ticket_ids[ @position ] + '/nav/true' else - @navigate 'ticket/zoom/' + @ticket_list[ @position - 1 ] + '/nav/true' + @navigate 'ticket/zoom/' + @ticket_ids[ @position - 1 ] + '/nav/true' else - if @ticket_list[ @position - 2 ] && @ticket_list[ @position - 2 ] + '/nav/true' + if @ticket_ids[ @position - 2 ] && @ticket_ids[ @position - 2 ] + '/nav/true' position = @position - 1 @Config.set( 'LastOverviewPosition', position ) - @navigate 'ticket/zoom/' + @ticket_list[ @position - 2 ] + '/nav/true' + @navigate 'ticket/zoom/' + @ticket_ids[ @position - 2 ] + '/nav/true' else - @navigate 'ticket/zoom/' + @ticket_list[ @position - 1 ] + '/nav/true' + @navigate 'ticket/zoom/' + @ticket_ids[ @position - 1 ] + '/nav/true' App.Config.set( 'ticket_view/:view', Index, 'Routes' ) App.Config.set( 'ticket_view/:view/:position/:direction', Router, 'Routes' ) diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index b985a23eb..c0f38de75 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -8,7 +8,7 @@ class TicketOverviewsController < ApplicationController # get navbar overview data if !params[:view] - result = Ticket::Overview.list( + result = Ticket::Overviews.list( :current_user => current_user, ) render :json => result @@ -17,7 +17,7 @@ class TicketOverviewsController < ApplicationController # get real overview data if params[:array] - overview = Ticket::Overview.list( + overview = Ticket::Overviews.list( :view => params[:view], :current_user => current_user, :array => true, @@ -36,7 +36,7 @@ class TicketOverviewsController < ApplicationController } return end - overview = Ticket::Overview.list( + overview = Ticket::Overviews.list( :view => params[:view], :current_user => current_user, :array => true, diff --git a/app/models/ticket/overview.rb b/app/models/ticket/overviews.rb similarity index 96% rename from app/models/ticket/overview.rb rename to app/models/ticket/overviews.rb index d707a38da..13a9f7a9c 100644 --- a/app/models/ticket/overview.rb +++ b/app/models/ticket/overviews.rb @@ -1,14 +1,12 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ -require 'overview' - -class Ticket::Overview +module Ticket::Overviews =begin all overview by user - result = Ticket::Overview.all( + result = Ticket::Overviews.all( :current_user => User.find(123), ) @@ -28,20 +26,19 @@ returns else overviews = Overview.where( :role_id => role.id, :organization_shared => false, :active => true ) end - return overviews + overviews end # get agent overviews role = data[:current_user].is_role( 'Agent' ) - overviews = Overview.where( :role_id => role.id, :active => true ) - return overviews + Overview.where( :role_id => role.id, :active => true ) end =begin selected overview by user - result = Ticket::Overview.list( + result = Ticket::Overviews.list( :current_user => User.find(123), :view => 'some_view_url', ) @@ -187,7 +184,6 @@ returns :tickets_count => tickets_count, :overview => overview_selected_raw, } - end private @@ -249,5 +245,4 @@ returns bind[0] = sql return bind end - end \ No newline at end of file diff --git a/lib/session.rb b/lib/session.rb index aefc416c8..2b2f8b2f2 100644 --- a/lib/session.rb +++ b/lib/session.rb @@ -395,7 +395,7 @@ class UserState # overview cache_key = @cache_key + '_overview' if CacheIn.expired(cache_key) - overview = Ticket::Overview.list( + overview = Ticket::Overviews.list( :current_user => user, ) overview_cache = CacheIn.get( cache_key, { :re_expire => true } ) @@ -410,13 +410,13 @@ class UserState end # overview lists - overviews = Ticket::Overview.all( + overviews = Ticket::Overviews.all( :current_user => user, ) overviews.each { |overview| cache_key = @cache_key + '_overview_data_' + overview.link if CacheIn.expired(cache_key) - overview_data = Ticket::Overview.list( + overview_data = Ticket::Overviews.list( :view => overview.link, :current_user => user, :array => true, @@ -597,14 +597,14 @@ class ClientState if !CacheIn.get( 'pushed_tickets' + @client_id.to_s ) CacheIn.set( 'pushed_tickets' + @client_id.to_s , true, { :expires_in => 20.seconds } ) if @pushed[:tickets] - tickets = [] + tickets = {} users = {} @pushed[:tickets].each {|ticket_id, ticket_data| self.ticket( ticket_id, tickets, users ) } if !tickets.empty? - tickets.each {|ticket| - self.log 'notify', "push update of already pushed ticket id #{ticket['id']}" + tickets.each {|id, ticket| + self.log 'notify', "push update of already pushed ticket id #{id}" } # send update to browser self.send({ @@ -637,7 +637,7 @@ class ClientState end # overview_data - overviews = Ticket::Overview.all( + overviews = Ticket::Overviews.all( :current_user => user, ) overviews.each { |overview| @@ -649,8 +649,8 @@ class ClientState overview_data = CacheIn.get( cache_key, { :ignore_expire => true } ) self.log 'notify', "push overview_data #{overview.link} for user #{user.id}" users = {} - tickets = [] - overview_data[:ticket_list].each {|ticket_id| + tickets = {} + overview_data[:ticket_ids].each {|ticket_id| self.ticket( ticket_id, tickets, users ) } @@ -677,21 +677,24 @@ class ClientState } # send update to browser + self.send({ + :data => { + :users => users, + :tickets => tickets, + }, + :event => [ 'loadAssets' ] + }) self.send({ :data => { :overview => overview_data[:overview], - :ticket_list => overview_data[:ticket_list], + :ticket_ids => overview_data[:ticket_ids], :tickets_count => overview_data[:tickets_count], - :collections => { - :User => users, - :Ticket => tickets, - }, :bulk => { :group_id__owner_id => groups_users, :owner_id => [], }, }, - :event => [ 'loadCollection', 'ticket_overview_rebuild' ], + :event => [ 'ticket_overview_rebuild' ], :collection => 'ticket_overview_' + overview.link.to_s, }) end @@ -816,7 +819,7 @@ class ClientState ticket = Ticket.lookup( :id => ticket_id ) if @pushed[:tickets][ticket_id] != ticket['updated_at'] @pushed[:tickets][ticket_id] = ticket['updated_at'] - tickets.push ticket + tickets[ticket_id] = ticket end # add users if needed