From ddc99ca4069d0f9e88c8fd72e70309b6f5be74b7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 08:29:49 +0200 Subject: [PATCH 01/14] First stage of migration to object assets for frontend. --- .../_dashboard/activity_stream.js.coffee | 47 ++---- .../_dashboard/recent_viewed.js.coffee | 26 +-- .../controllers/_dashboard/ticket.js.coffee | 15 +- .../controllers/agent_ticket_create.js.coffee | 45 +++-- .../agent_ticket_history.js.coffee | 21 +-- .../customer_ticket_create.js.coffee | 33 +--- .../app/controllers/dashboard.js.coffee | 6 +- .../controllers/link_info_widget.js.coffee | 7 +- .../app/controllers/ticket_zoom.js.coffee | 46 ++--- .../app/lib/app_post/collection.js.coffee | 22 +++ .../app/models/organization.js.coffee | 11 ++ .../views/dashboard/activity_stream.jst.eco | 4 +- .../app/views/dashboard/recent_viewed.jst.eco | 2 +- app/controllers/links_controller.rb | 22 +-- app/controllers/search_controller.rb | 23 +-- .../ticket_overviews_controller.rb | 34 ++-- app/controllers/tickets_controller.rb | 159 ++++++------------ app/models/history.rb | 42 ++--- app/models/history/assets.rb | 46 +++++ app/models/organization.rb | 35 +--- app/models/organization/assets.rb | 43 +++++ app/models/organization/search.rb | 62 +++++++ app/models/recent_view.rb | 23 +-- app/models/ticket.rb | 1 + app/models/ticket/article.rb | 2 + app/models/ticket/article/assets.rb | 48 ++++++ app/models/ticket/assets.rb | 51 ++++++ app/models/ticket/overview.rb | 2 +- app/models/user.rb | 39 +---- app/models/user/assets.rb | 34 ++++ app/models/user/search.rb | 57 +++++++ db/migrate/20130817000001_update_auth.rb | 52 ++++++ 32 files changed, 614 insertions(+), 446 deletions(-) create mode 100644 app/models/history/assets.rb create mode 100644 app/models/organization/assets.rb create mode 100644 app/models/organization/search.rb create mode 100644 app/models/ticket/article/assets.rb create mode 100644 app/models/ticket/assets.rb create mode 100644 app/models/user/assets.rb create mode 100644 app/models/user/search.rb create mode 100644 db/migrate/20130817000001_update_auth.rb diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index 70a74d844..c495ca7d2 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -1,10 +1,6 @@ class App.DashboardActivityStream extends App.Controller - events: - 'click [data-type=edit]': 'zoom' - constructor: -> super - @items = [] @fetch() @@ -36,34 +32,29 @@ class App.DashboardActivityStream extends App.Controller load: (data) => items = data.activity_stream - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) - - # load article collection - App.Collection.load( type: 'TicketArticle', data: data.articles ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render(items) render: (items) -> - # load user data for item in items - item.created_by = App.User.find( item.created_by_id ) - - # load ticket data - for item in items - item.data = {} if item.history_object is 'Ticket' - item.data.title = App.Ticket.find( item.o_id ).title - if item.history_object is 'Ticket::Article' + ticket = App.Ticket.find( item.o_id ) + item.link = '#ticket_zoom/' + ticket.id + item.title = ticket.title + item.type = item.history_object + item.updated_by_id = ticket.updated_by_id + item.updated_by = App.User.find( ticket.updated_by_id ) + else if item.history_object is 'Ticket::Article' article = App.TicketArticle.find( item.o_id ) - item.history_object = 'Article' - item.sub_o_id = article.id - item.o_id = article.ticket_id - item.data.title = article.subject + ticket = App.Ticket.find( article.ticket_id ) + item.link = '#ticket_zoom/' + ticket.id + '/' + article.od + item.title = article.subject || ticket.title + item.type = item.history_object + item.updated_by_id = article.updated_by_id + item.updated_by = App.User.find( article.updated_by_id ) html = App.view('dashboard/activity_stream')( head: 'Activity Stream', @@ -76,11 +67,3 @@ class App.DashboardActivityStream extends App.Controller # start user popups @userPopups('left') - zoom: (e) => - e.preventDefault() - id = $(e.target).parents('[data-id]').data('id') - subid = $(e.target).parents('[data-subid]').data('subid') - if subid - @navigate 'ticket/zoom/' + id + '/' + subid - else - @navigate 'ticket/zoom/' + id 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 56cbde3e5..23496b794 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -1,7 +1,4 @@ class App.DashboardRecentViewed extends App.Controller - events: - 'click [data-type=edit]': 'zoom' - constructor: -> super @@ -16,28 +13,21 @@ class App.DashboardRecentViewed extends App.Controller limit: 5, } processData: true, -# data: JSON.stringify( view: @view ), success: (data, status, xhr) => @items = data.recent_viewed - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render() ) render: -> - # load user data for item in @items - item.created_by = App.User.find( item.created_by_id ) - - # load ticket data - for item in @items - item.ticket = App.User.find( item.o_id ) + item.link = '#ticket_zoom/' + item.o_id + item.title = App.Ticket.find( item.o_id ).title + item.type = item.recent_view_object html = App.view('dashboard/recent_viewed')( head: 'Recent Viewed', @@ -49,9 +39,3 @@ class App.DashboardRecentViewed extends App.Controller # start user popups @userPopups('left') - - zoom: (e) => - e.preventDefault() - id = $(e.target).parents('[data-id]').data('id') - - @navigate 'ticket/zoom/' + id diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index 03678756a..9a37a27a4 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -48,11 +48,8 @@ class App.DashboardTicket extends App.Controller 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 App.Overview.refresh( data.overview, options: { clear: true } ) @@ -71,12 +68,12 @@ class App.DashboardTicket extends App.Controller render: (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 # FIXME 10 pages_total = parseInt( ( @tickets_count / 10 ) + 0.99999 ) || 1 html = App.view('dashboard/ticket')( @@ -94,8 +91,8 @@ class App.DashboardTicket extends App.Controller i = start while i < end i = i + 1 - if @ticket_list[ i - 1 ] - @tickets_in_table.push App.Ticket.retrieve( @ticket_list[ i - 1 ] ) + if @ticket_ids[ i - 1 ] + @tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] ) shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d ) new App.ControllerTable( diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index a8cd95db7..1acc0b452 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -35,12 +35,18 @@ class App.TicketCreate extends App.Controller title: 'Email' @article_attributes = article_sender_type_map[@type] + # remember split info if exists + split = '' + if @ticket_id && @article_id + split = "/#{@ticket_id}/#{@article_id}" + # if no map entry exists, route to default if !@article_attributes - @navigate '#ticket_create/' + default_type + @navigate '#ticket_create/' + default_type + split + return # update navbar highlighting - @navupdate '#ticket_create/' + @type + '/id/' + @id + @navupdate '#ticket_create/' + @type + '/id/' + @id + split @fetch(params) @@ -97,8 +103,8 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = cache.edit_form - # load user collection - App.Collection.load( type: 'User', data: cache.users ) + # load collections + App.Event.trigger 'loadAssets', cache.assets @render() else @@ -118,17 +124,11 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = data.edit_form - # load user collection - App.Collection.load( type: 'User', data: data.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - # load ticket collection - if data.ticket && data.articles - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) - - # render page + # split ticket + if data.split && data.split.ticket_id && data.split.article_id t = App.Ticket.find( params.ticket_id ).attributes() a = App.TicketArticle.find( params.article_id ) @@ -137,6 +137,8 @@ class App.TicketCreate extends App.Controller t.customer_id_autocompletion = a.from t.subject = a.subject || t.title t.body = a.body + + # render page @render( options: t ) ) @@ -386,8 +388,13 @@ class TicketCreateRouter extends App.ControllerPermanent # create new uniq form id if !params['id'] + # remember split info if exists + split = '' + if params['ticket_id'] && params['article_id'] + split = "/#{params['ticket_id']}/#{params['article_id']}" + id = Math.floor( Math.random() * 99999 ) - @navigate "#ticket_create/#{params['type']}/id/#{id}" + @navigate "#ticket_create/#{params['type']}/id/#{id}#{split}" return # cleanup params @@ -399,14 +406,16 @@ class TicketCreateRouter extends App.ControllerPermanent App.TaskManager.add( 'TicketCreateScreen-' + params['type'] + '-' + params['id'], 'TicketCreate', clean_params ) -# split ticket -App.Config.set( 'ticket_create/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) - # create new ticket routs/controller App.Config.set( 'ticket_create', TicketCreateRouter, 'Routes' ) App.Config.set( 'ticket_create/:type', TicketCreateRouter, 'Routes' ) App.Config.set( 'ticket_create/:type/id/:id', TicketCreateRouter, 'Routes' ) + +# split ticket +App.Config.set( 'ticket_create/:type/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) +App.Config.set( 'ticket_create/:type/id/:id/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) + # set new task actions App.Config.set( 'TicketNewCallOutbound', { prio: 8001, name: 'Call Outbound', target: '#ticket_create/call_outbound', role: ['Agent'] }, 'TaskActions' ) App.Config.set( 'TicketNewCallInbound', { prio: 8002, name: 'Call Inbound', target: '#ticket_create/call_inbound', role: ['Agent'] }, 'TaskActions' ) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee index 2c89a6ad8..6309a5e92 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -15,23 +15,9 @@ class App.TicketHistory extends App.ControllerModal type: 'GET', url: @apiPath + '/ticket_history/' + ticket_id, success: (data, status, xhr) => - # remember ticket - @ticket = data.ticket - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load history_type collections - App.Collection.load( type: 'HistoryType', data: data.history_types ) - - # load history_object collections - App.Collection.load( type: 'HistoryObject', data: data.history_objects ) - - # load history_attributes collections - App.Collection.load( type: 'HistoryAttribute', data: data.history_attributes ) + # load collections + App.Event.trigger 'loadAssets', data.assets # load history collections App.History.deleteAll() @@ -53,7 +39,7 @@ class App.TicketHistory extends App.ControllerModal @userPopups() # show frontend times - @delay( @frontendTimeUpdate, 200, 'ui-time-update' ) + @delay( @frontendTimeUpdate, 300, 'ui-time-update' ) sortorder: (e) -> e.preventDefault() @@ -72,7 +58,6 @@ class App.TicketHistory extends App.ControllerModal state: @sortstate ) - @modalShow() # enable user popups diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee index a3af61b45..01e4e40d8 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee @@ -24,13 +24,13 @@ class Index extends App.ControllerContent # use cache cache = App.Store.get( 'ticket_create_attributes' ) - if cache && !params.ticket_id && !params.article_id + if cache # get edit form attributes @edit_form = cache.edit_form - # load user collection - App.Collection.load( type: 'User', data: cache.users ) + # load collections + App.Event.trigger 'loadAssets', cache.assets @render() else @@ -38,10 +38,6 @@ class Index extends App.ControllerContent id: 'ticket_create', type: 'GET', url: @apiPath + '/ticket_create', - data: { - ticket_id: params.ticket_id, - article_id: params.article_id, - }, processData: true, success: (data, status, xhr) => @@ -51,27 +47,10 @@ class Index extends App.ControllerContent # get edit form attributes @edit_form = data.edit_form - # load user collection - App.Collection.load( type: 'User', data: data.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - # load ticket collection - if data.ticket && data.articles - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) - - # render page - t = App.Ticket.find( params.ticket_id ).attributes() - a = App.TicketArticle.find( params.article_id ) - - # reset owner - t.owner_id = 0 - t.customer_id_autocompletion = a.from - t.subject = a.subject || t.title - t.body = a.body - @log 'CustomerTicketCreate', 'notice', 'created', t - @render( options: t ) + @render() ) render: (template = {}) -> diff --git a/app/assets/javascripts/app/controllers/dashboard.js.coffee b/app/assets/javascripts/app/controllers/dashboard.js.coffee index abd74d4b3..f797d232e 100644 --- a/app/assets/javascripts/app/controllers/dashboard.js.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.js.coffee @@ -53,9 +53,9 @@ class Index extends App.ControllerContent # }, # }, -# recent_viewed: { -# controller: App.DashboardRecentViewed, -# } + recent_viewed: { + controller: App.DashboardRecentViewed, + } } } diff --git a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee index 9bf17db04..1a07420b6 100644 --- a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee @@ -23,11 +23,8 @@ class App.LinkInfo extends App.Controller success: (data, status, xhr) => @links = data.links - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render() ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index eea3c67da..745ebfe70 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -82,7 +82,7 @@ class App.TicketZoom extends App.Controller @log 'diff', diff # notify if ticket changed not by my self - if !_.isEmpty(diff) && data.ticket.updated_by_id isnt @Session.all().id + if !_.isEmpty(diff) && data.asset.ticket[0].updated_by_id isnt @Session.all().id App.TaskManager.notify( @task_key ) # rerender edit box @@ -112,20 +112,19 @@ class App.TicketZoom extends App.Controller # reset old indexes @ticket = undefined + + # remember article ids + @ticket_article_ids = data.ticket_article_ids + + # get edit form attributes @edit_form = data.edit_form # get signature @signature = data.signature - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles ) + # load collections + App.Event.trigger 'loadAssets', data.assets # render page @render(force) @@ -196,9 +195,10 @@ class App.TicketZoom extends App.Controller ArticleView: => # show article new ArticleView( - ticket: @ticket - el: @el.find('.article-view') - ui: @ + ticket: @ticket + ticket_article_ids: @ticket_article_ids + el: @el.find('.article-view') + ui: @ ) Edit: => @@ -570,7 +570,7 @@ class ArticleView extends App.Controller # get all articles @articles = [] - for article_id in @ticket.article_ids + for article_id in @ticket_article_ids article = App.TicketArticle.retrieve( article_id ) @articles.push article @@ -620,16 +620,16 @@ class ArticleView extends App.Controller checkIfSignatureIsNeeded: (article_type) => - # add signature - if @ui.signature && @ui.signature.body && article_type.name is 'email' - body = @ui.el.find('[name="body"]').val() || '' - regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i') - if !body.match(regexp) - body = body + "\n" + @ui.signature.body - @ui.el.find('[name="body"]').val( body ) + # add signature + if @ui.signature && @ui.signature.body && article_type.name is 'email' + body = @ui.el.find('[name="body"]').val() || '' + regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i') + if !body.match(regexp) + body = body + "\n" + @ui.signature.body + @ui.el.find('[name="body"]').val( body ) - # update textarea size - @ui.el.find('[name="body"]').trigger('change') + # update textarea size + @ui.el.find('[name="body"]').trigger('change') reply: (e) => e.preventDefault() @@ -774,7 +774,7 @@ class Article extends App.Controller actions.push { name: 'split' type: 'split' - href: '#ticket_create/' + @article.ticket_id + '/' + @article.id + href: '#ticket_create/call_inbound/' + @article.ticket_id + '/' + @article.id } @article.actions = actions diff --git a/app/assets/javascripts/app/lib/app_post/collection.js.coffee b/app/assets/javascripts/app/lib/app_post/collection.js.coffee index 63476a2cc..df2c55413 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.js.coffee @@ -19,6 +19,28 @@ class _collectionSingleton extends Spine.Module constructor: (@args) -> + # add trigger - bind new events + App.Event.bind 'loadAssets', (data) => + if data + for type, collections of data + if type is 'users' + type = 'User' + if type is 'tickets' + type = 'Ticket' + if type is 'ticket_article' + type = 'TicketArticle' + if type is 'organization' + type = 'Organization' + if type is 'history_object' + type = 'HistoryObject' + if type is 'history_type' + type = 'HistoryType' + if type is 'history_attribute' + type = 'HistoryAttribute' + + @log 'debug', 'loadCollection:trigger', type, collections + @load( localStorage: data.localStorage, type: type, data: collections ) + # add trigger - bind new events App.Event.bind 'loadCollection', (data) => diff --git a/app/assets/javascripts/app/models/organization.js.coffee b/app/assets/javascripts/app/models/organization.js.coffee index 3dbae098f..0f4e15bd5 100644 --- a/app/assets/javascripts/app/models/organization.js.coffee +++ b/app/assets/javascripts/app/models/organization.js.coffee @@ -13,3 +13,14 @@ class App.Organization extends App.Model 'name', 'shared', ] + + @_fillUp: (data) -> + + # addd users of organization + if data['user_ids'] + data['user_ids'] = [] + for user_id in data['user_ids'] + if App.User.exists( user_id ) + user = App.User.find( user_id ) + data['user_ids'].push user + data \ No newline at end of file diff --git a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco index 53c4bf10f..2f7134571 100644 --- a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco +++ b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco @@ -3,8 +3,8 @@

<%- @T( @head ) %>

<% for item in @items: %> -
"<%= item.created_by.displayName() %>"
-
<%- @T( item.history_type ) %> <%= item.history_object %><% if item.data.title: %> (<%= item.data.title %>)<% end %>.
+
"<%= item.updated_by.displayName() %>"
+
<%- @T( item.history_type ) %> <%= item.type %><% if item.title: %> (<%= item.title %>)<% end %>.
<% end %>
diff --git a/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco b/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco index ff161319f..bf342e815 100644 --- a/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco +++ b/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco @@ -3,7 +3,7 @@

<%- @T( @head ) %>

diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 001c0d7f2..b73a8fc61 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -10,32 +10,20 @@ class LinksController < ApplicationController :link_object_value => params[:link_object_value], ) - # - tickets = [] - users = {} + assets = {} link_list = [] links.each { |item| link_list.push item if item['link_object'] == 'Ticket' - data = Ticket.lookup( :id => item['link_object_value'] ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end + ticket = Ticket.lookup( :id => item['link_object_value'] ) + assets = ticket.assets(assets) end } # return result render :json => { - :links => link_list, - :tickets => tickets, - :users => users, + :links => link_list, + :assets => assets, } end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 31ca3133b..cec5dcc40 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -12,13 +12,11 @@ class SearchController < ApplicationController :query => params[:term], :current_user => current_user, ) - users_data = {} + assets = {} ticket_result = [] tickets.each do |ticket| + assets = ticket.assets(assets) ticket_result.push ticket.id - users_data[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - users_data[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - users_data[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) end # do query @@ -30,7 +28,7 @@ class SearchController < ApplicationController user_result = [] users.each do |user| user_result.push user.id - users_data[ user.id ] = User.user_data_full( user.id ) + assets = user.assets(assets) end organizations = Organization.search( @@ -39,17 +37,10 @@ class SearchController < ApplicationController :current_user => current_user, ) - organizations_data = {} organization_result = [] organizations.each do |organization| organization_result.push organization.id - organizations_data[ organization.id ] = Organization.find( organization.id ).attributes - organizations_data[ organization.id ][:user_ids] = [] - users = User.where( :organization_id => organization.id ).limit(10) - users.each {|user| - users_data[ user.id ] = User.user_data_full( user.id ) - organizations_data[ organization.id ][:user_ids].push user.id - } + assets = organization.assets(assets) end result = [] @@ -77,11 +68,7 @@ class SearchController < ApplicationController # return result render :json => { - :load => { - :tickets => tickets, - :users => users_data, - :organizations => organizations_data, - }, + :load => assets, :result => result, } end diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index 63b2e1c77..b985a23eb 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -3,7 +3,7 @@ class TicketOverviewsController < ApplicationController before_filter :authentication_check - # GET /api/v1/tickets + # GET /api/v1/ticket_overviews def show # get navbar overview data @@ -38,8 +38,7 @@ class TicketOverviewsController < ApplicationController end overview = Ticket::Overview.list( :view => params[:view], - # :view_mode => params[:view_mode], - :current_user => User.find( current_user.id ), + :current_user => current_user, :array => true, ) if !overview @@ -48,20 +47,10 @@ class TicketOverviewsController < ApplicationController end # get related users - users = {} - tickets = [] - overview[:ticket_list].each {|ticket_id| - data = Ticket.lookup( :id => ticket_id ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end + assets = { :users => {} } + overview[:ticket_ids].each {|ticket_id| + ticket = Ticket.lookup( :id => ticket_id ) + assets = ticket.assets(assets) } # get groups @@ -79,8 +68,8 @@ class TicketOverviewsController < ApplicationController Group.find(group_id).users.each {|user| next if !agents[ user.id ] groups_users[ group_id ].push user.id - if !users[user.id] - users[user.id] = User.user_data_full(user.id) + if !assets[:users][user.id] + assets[:users][user.id] = User.user_data_full(user.id) end } } @@ -88,15 +77,12 @@ class TicketOverviewsController < ApplicationController # return result render :json => { :overview => overview[:overview], - :ticket_list => overview[:ticket_list], + :ticket_ids => overview[:ticket_ids], :tickets_count => overview[:tickets_count], :bulk => { :group_id__owner_id => groups_users, }, - :collections => { - :users => users, - :tickets => tickets, - }, + :assets => assets, } end diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 860579b1a..d8f991ee4 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -132,14 +132,13 @@ class TicketsController < ApplicationController # get history of ticket history = History.list( 'Ticket', params[:id], 'Ticket::Article' ) - # get related users - users = {} - users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) - users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) + # get related assets + assets = ticket.assets({}) history_list = [] history.each do |item| - users[ item[:created_by_id] ] = User.user_data_full( item[:created_by_id] ) + assets = item.assets(assets) + item_tmp = item.attributes if item['history_object'] == 'Ticket::Article' item_temp['type'] = 'Article ' + item['type'].to_s @@ -171,22 +170,12 @@ class TicketsController < ApplicationController item_tmp.delete( 'related_o_id' ) end history_list.push item_tmp - end - # fetch meta relations - history_objects = History::Object.all() - history_types = History::Type.all() - history_attributes = History::Attribute.all() - # return result render :json => { - :ticket => ticket, - :users => users, - :history => history_list, - :history_objects => history_objects, - :history_types => history_types, - :history_attributes => history_attributes + :assets => assets, + :history => history_list, } end @@ -203,34 +192,18 @@ class TicketsController < ApplicationController .limit(6) # get related users - users = {} - tickets = [] + assets = {} ticket_list.each {|ticket| - data = Ticket.lookup( :id => ticket.id ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end - if !users[ data['updated_by_id'] ] - users[ data['updated_by_id'] ] = User.user_data_full( data['updated_by_id'] ) - end + ticket = Ticket.lookup( :id => ticket.id ) + assets = ticket.assets(assets) } recent_viewed = RecentView.list_fulldata( current_user, 8 ) # return result render :json => { - :customer => { - :tickets => tickets, - :users => users, - }, - :recent => recent_viewed + :customer => assets, + :recent => recent_viewed } end @@ -295,18 +268,6 @@ class TicketsController < ApplicationController ticket = Ticket.find( params[:id] ) return if !ticket_permission( ticket ) - # get related users - users = {} - if !users[ticket.owner_id] - users[ticket.owner_id] = User.user_data_full( ticket.owner_id ) - end - if !users[ticket.customer_id] - users[ticket.customer_id] = User.user_data_full( ticket.customer_id ) - end - if !users[ticket.created_by_id] - users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id ) - end - # log object as viewed if !params[:do_not_log] || params[:do_not_log].to_i == 0 log_view( ticket ) @@ -328,58 +289,52 @@ class TicketsController < ApplicationController ) end + # get related users + assets = {} + assets[:users] = {} + assets = ticket.assets(assets) + # get attributes to update attributes_to_change = Ticket::ScreenOptions.attributes_to_change( :user => current_user, :ticket => ticket ) attributes_to_change[:owner_id].each { |user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| user_ids.each {|user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } } # get related articles - ticket = ticket.attributes - ticket[:article_ids] = [] articles = Ticket::Article.where( :ticket_id => params[:id] ) # get related users - articles_used = [] + article_ids = [] articles.each {|article| # ignore internal article if customer is requesting next if article.internal == true && is_role('Customer') - article_tmp = article.attributes # load article ids - ticket[:article_ids].push article_tmp['id'] + article_ids.push article.id - # add attachment list to article - article_tmp['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => article.id ) - - # remember article - articles_used.push article_tmp - - # load users - if !users[article.created_by_id] - users[article.created_by_id] = User.user_data_full( article.created_by_id ) - end + # load assets + assets = article.assets(assets) } # return result render :json => { - :ticket => ticket, - :articles => articles_used, - :signature => signature, - :users => users, - :edit_form => attributes_to_change, + :ticket_id => ticket.id, + :ticket_article_ids => article_ids, + :signature => signature, + :assets => assets, + :edit_form => attributes_to_change, } end @@ -393,65 +348,47 @@ class TicketsController < ApplicationController # :article_id => params[:article_id] ) - users = {} + assets = {} + assets[:users] = {} attributes_to_change[:owner_id].each { |user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| user_ids.each {|user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } } # split data - ticket = nil - articles = nil + split = {} if params[:ticket_id] && params[:article_id] ticket = Ticket.find( params[:ticket_id] ) - - # get related users - if !users[ticket.owner_id] - users[ticket.owner_id] = User.user_data_full( ticket.owner_id ) - end - if !users[ticket.customer_id] - users[ticket.customer_id] = User.user_data_full( ticket.customer_id ) - end - if !users[ticket.created_by_id] - users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id ) - end + split[:ticket_id] = ticket.id + assets = ticket.assets(assets) owner_ids = [] ticket.agent_of_group.each { |user| owner_ids.push user.id - if !users[user.id] - users[user.id] = User.user_data_full( user.id ) + if !assets[:users][user.id] + assets[:users][user.id] = User.user_data_full( user.id ) end } # get related articles - ticket[:article_ids] = [ params[:article_id] ] - article = Ticket::Article.find( params[:article_id] ) - - # add attachment list to article - article['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => article.id ) - - # load users - if !users[article.created_by_id] - users[article.created_by_id] = User.user_data_full( article.created_by_id ) - end + split[:article_id] = article.id + assets = article.assets(assets) end # return result render :json => { - :ticket => ticket, - :articles => [ article ], - :users => users, + :split => split, + :assets => assets, :edit_form => attributes_to_change, } end @@ -465,19 +402,17 @@ class TicketsController < ApplicationController :query => params[:term], :current_user => current_user, ) - users_data = {} + assets = {} ticket_result = [] tickets.each do |ticket| ticket_result.push ticket.id - users_data[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - users_data[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - users_data[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) + assets = ticket.assets(assets) end # return result render :json => { :tickets => ticket_result, - :users => users_data, + :assets => assets, } end diff --git a/app/models/history.rb b/app/models/history.rb index 358c4a0e8..0ff89fe6d 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -1,6 +1,8 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class History < ApplicationModel + include History::Assets + self.table_name = 'histories' belongs_to :history_type, :class_name => 'History::Type' belongs_to :history_object, :class_name => 'History::Object' @@ -157,51 +159,27 @@ return all histoy entries of an object activity_stream = History.activity_stream( user, limit ) # get related users - users = {} - tickets = [] - articles = [] + assets = {} activity_stream.each {|item| # load article ids if item['history_object'] == 'Ticket' - ticket = Ticket.find( item['o_id'] ).attributes - tickets.push ticket - - # load users - if !users[ ticket['owner_id'] ] - users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - end - if !users[ ticket['customer_id'] ] - users[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - end + ticket = Ticket.find( item['o_id'] ) + assets = ticket.assets(assets) end if item['history_object'] == 'Ticket::Article' - article = Ticket::Article.find( item['o_id'] ).attributes - if !article['subject'] || article['subject'] == '' - article['subject'] = Ticket.find( article['ticket_id'] ).title - end - articles.push article - - # load users - if !users[ article['created_by_id'] ] - users[ article['created_by_id'] ] = User.user_data_full( article['created_by_id'] ) - end + article = Ticket::Article.find( item['o_id'] ) + assets = article.assets(assets) end if item['history_object'] == 'User' - users[ item['o_id'] ] = User.user_data_full( item['o_id'] ) - end - - # load users - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) + user = User.find( item['o_id'] ) + assets = user.assets(assets) end } return { :activity_stream => activity_stream, - :tickets => tickets, - :articles => articles, - :users => users, + :assets => assets, } end diff --git a/app/models/history/assets.rb b/app/models/history/assets.rb new file mode 100644 index 000000000..b81d94ef4 --- /dev/null +++ b/app/models/history/assets.rb @@ -0,0 +1,46 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module History::Assets + +=begin + +get all assets / related models for this history entry + + history = History.find(123) + result = history.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + } + +=end + + def assets (data) + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + + # fetch meta relations + if !data[:history_object] + data[:history_object] = History::Object.all() + end + if !data[:history_type] + data[:history_type] = History::Type.all() + end + if !data[:history_attribute] + data[:history_attribute] = History::Attribute.all() + end + + data + end + +end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index 615e2ef4c..4fba65cc5 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,37 +1,10 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class Organization < ApplicationModel + include Organization::Assets + extend Organization::Search + has_and_belongs_to_many :users validates :name, :presence => true - def self.search(params) - - # get params - query = params[:query] - limit = params[:limit] || 10 - current_user = params[:current_user] - - # enable search only for agents and admins - return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') - - # do query - organizations = Organization.find( - :all, - :limit => limit, - :conditions => ['name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"], - :order => 'name' - ) - - # if only a few organizations are found, search for names of users - if organizations.length <= 3 - organizations = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').find( - :all, - :limit => limit, - :conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"], - :order => 'organizations.name' - ) - end - return organizations - end - -end +end \ No newline at end of file diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb new file mode 100644 index 000000000..c3818915c --- /dev/null +++ b/app/models/organization/assets.rb @@ -0,0 +1,43 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Organization::Assets + +=begin + +get all assets / related models for this organization + + organization = Organization.find(123) + result = organization.assets( assets_if_exists ) + +returns + + result = { + :organizations => { + 123 => organization_model_123, + 1234 => organization_model_1234, + } + } + +=end + + def assets (data) + + if !data[:organizations] + data[:organizations] = {} + end + if !data[:users] + data[:users] = {} + end + if !data[:organizations][ self.id ] + data[:organizations][ self.id ] = self.attributes + data[:organizations][ self.id ][:user_ids] = [] + users = User.where( :organization_id => self.id ).limit(10) + users.each {|user| + data[:users][ user.id ] = User.user_data_full( user.id ) + data[:organizations][ self.id ][:user_ids].push user.id + } + end + data + end + +end \ No newline at end of file diff --git a/app/models/organization/search.rb b/app/models/organization/search.rb new file mode 100644 index 000000000..9d048bb0d --- /dev/null +++ b/app/models/organization/search.rb @@ -0,0 +1,62 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Organization::Search + +=begin + +search organizations + + result = Organization.search( + :current_user => User.find(123), + :query => 'search something', + :limit => 15, + ) + +returns + + result = [organization_model1, organization_model2] + +=end + + def search(params) + + # get params + query = params[:query] + limit = params[:limit] || 10 + current_user = params[:current_user] + + # enable search only for agents and admins + return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') + + # do query + organizations = Organization.find( + :all, + :limit => limit, + :conditions => ['name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"], + :order => 'name' + ) + + # if only a few organizations are found, search for names of users + if organizations.length <= 3 + organizations_by_user = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').find( + :all, + :limit => limit, + :conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"], + :order => 'organizations.name' + ) + organizations_by_user.each {|organization_by_user| + puts 'OOO ' + organization_by_user.inspect + organization_exists = false + organizations.each {|organization| + if organization.id == organization_by_user.id + organization_exists = true + end + } + if !organization_exists + organizations.push organization + end + } + end + organizations + end +end \ No newline at end of file diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 614f2ee4f..7ac9ed16e 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -44,14 +44,14 @@ class RecentView < ApplicationModel recent_viewed = self.list( user, limit ) # get related users - users = {} - tickets = [] + assets = {} + ticket_ids = [] recent_viewed.each {|item| # load article ids # if item.recent_view_object == 'Ticket' - ticket = Ticket.find( item['o_id'] ).attributes - tickets.push ticket + ticket = Ticket.find( item['o_id'] ) + ticket_ids.push ticket.id # end # if item.recent_view_object 'Ticket::Article' # tickets.push Ticket::Article.find(item.o_id) @@ -60,21 +60,12 @@ class RecentView < ApplicationModel # tickets.push User.find(item.o_id) # end - # load users - if !users[ ticket['owner_id'] ] - users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - end - if !users[ ticket['created_by_id'] ] - users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) - end - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) - end + assets = ticket.assets(assets) } return { :recent_viewed => recent_viewed, - :tickets => tickets, - :users => users, + :ticket_ids => ticket_ids, + :assets => assets, } end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 84c01b645..3669c13ac 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -25,6 +25,7 @@ class Ticket < ApplicationModel include Ticket::Escalation include Ticket::Subject include Ticket::Permission + include Ticket::Assets extend Ticket::Search attr_accessor :callback_loop diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index dd4c97855..c1bf19b4a 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -1,6 +1,8 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class Ticket::Article < ApplicationModel + include Ticket::Article::Assets + after_create :attachment_check belongs_to :ticket belongs_to :ticket_article_type, :class_name => 'Ticket::Article::Type' diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb new file mode 100644 index 000000000..6b8d0e117 --- /dev/null +++ b/app/models/ticket/article/assets.rb @@ -0,0 +1,48 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Ticket::Article::Assets + +=begin + +get all assets / related models for this article + + article = Ticket::Article.find(123) + result = article.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + :article => [ article_model1 ], + } + +=end + + def assets (data) + + if !data[:ticket_article] + data[:ticket_article] = {} + end + if !data[:ticket_article][ self.id ] + data[:ticket_article][ self.id ] = self.attributes + + # add attachment list to article + data[:ticket_article][ self.id ]['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => self.id ) + end + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + if !data[:users][ self['updated_by_id'] ] + data[:users][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb new file mode 100644 index 000000000..7b96346ec --- /dev/null +++ b/app/models/ticket/assets.rb @@ -0,0 +1,51 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Ticket::Assets + +=begin + +get all assets / related models for this ticket + + ticket = Ticket.find(123) + result = ticket.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + :tickets => [ ticket_model1 ] + } + +=end + + def assets (data) + + if !data[:tickets] + data[:tickets] = {} + end + if !data[:tickets][ self.id ] + data[:tickets][ self.id ] = self.attributes + end + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['owner_id'] ] + data[:users][ self['owner_id'] ] = User.user_data_full( self['owner_id'] ) + end + if !data[:users][ self['customer_id'] ] + data[:users][ self['customer_id'] ] = User.user_data_full( self['customer_id'] ) + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + if !data[:users][ self['updated_by_id'] ] + data[:users][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/ticket/overview.rb b/app/models/ticket/overview.rb index 6a900a464..d707a38da 100644 --- a/app/models/ticket/overview.rb +++ b/app/models/ticket/overview.rb @@ -164,7 +164,7 @@ returns count() return { - :ticket_list => ticket_ids, + :ticket_ids => ticket_ids, :tickets_count => tickets_count, :overview => overview_selected_raw, } diff --git a/app/models/user.rb b/app/models/user.rb index 4f4fcf8a8..5fa2bfb92 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,9 @@ require 'digest/sha2' require 'organization' class User < ApplicationModel + include User::Assets + extend User::Search + before_create :check_name, :check_email, :check_login, :check_image, :check_password before_update :check_password, :check_image, :check_email, :check_login_update after_create :notify_clients_after_create @@ -283,42 +286,6 @@ returns return user end -=begin - -search user - - result = User.search( - :query => 'some search term' - :limit => 15, - :current_user => user_model, - ) - -returns - - result = [user_model1, user_model2, ...] - -=end - - def self.search(params) - - # get params - query = params[:query] - limit = params[:limit] || 10 - current_user = params[:current_user] - - # enable search only for agents and admins - return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') - - # do query - users = User.find( - :all, - :limit => limit, - :conditions => ['(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%"], - :order => 'firstname' - ) - return users - end - def self.find_fulldata(user_id) cache = self.cache_get(user_id, true) diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb new file mode 100644 index 000000000..202303355 --- /dev/null +++ b/app/models/user/assets.rb @@ -0,0 +1,34 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module User::Assets + +=begin + +get all assets / related models for this user + + user = User.find(123) + result = user.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + } + +=end + + def assets (data) + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self.id ] + data[:users][ self.id ] = User.user_data_full( self.id ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/user/search.rb b/app/models/user/search.rb new file mode 100644 index 000000000..705b0cee5 --- /dev/null +++ b/app/models/user/search.rb @@ -0,0 +1,57 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module User::Search + +=begin + +search tickets + + result = Ticket.search( + :current_user => User.find(123), + :query => 'search something', + :limit => 15, + ) + +returns + + result = [ticket_model1, ticket_model2] + +=end + +=begin + +search user + + result = User.search( + :query => 'some search term' + :limit => 15, + :current_user => user_model, + ) + +returns + + result = [user_model1, user_model2, ...] + +=end + + def search(params) + + # get params + query = params[:query] + limit = params[:limit] || 10 + current_user = params[:current_user] + + # enable search only for agents and admins + return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') + + # do query + users = User.find( + :all, + :limit => limit, + :conditions => ['(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%"], + :order => 'firstname' + ) + return users + end + +end \ No newline at end of file diff --git a/db/migrate/20130817000001_update_auth.rb b/db/migrate/20130817000001_update_auth.rb new file mode 100644 index 000000000..449334f11 --- /dev/null +++ b/db/migrate/20130817000001_update_auth.rb @@ -0,0 +1,52 @@ +class UpdateAuth < ActiveRecord::Migration + def up + Setting.create_or_update( + :title => 'Authentication via OTRS', + :name => 'auth_otrs', + :area => 'Security::Authentication', + :description => 'Enables user authentication via OTRS.', + :state => { + :adapter => 'Auth::Otrs', + :required_group_ro => 'stats', + :group_rw_role_map => { + 'admin' => 'Admin', + 'stats' => 'Report', + }, + :group_ro_role_map => { + 'stats' => 'Report', + }, + :always_role => { + 'Agent' => true, + }, + }, + :frontend => false + ) + Setting.create_or_update( + :title => 'Authentication via LDAP', + :name => 'auth_ldap', + :area => 'Security::Authentication', + :description => 'Enables user authentication via LDAP.', + :state => { + :adapter => 'Auth::Ldap', + :host => 'localhost', + :port => 389, + :bind_dn => 'cn=Manager,dc=example,dc=org', + :bind_pw => 'example', + :uid => 'mail', + :base => 'dc=example,dc=org', + :always_filter => '', + :always_roles => ['Admin', 'Agent'], + :always_groups => ['Users'], + :sync_params => { + :firstname => 'sn', + :lastname => 'givenName', + :email => 'mail', + :login => 'mail', + }, + }, + :frontend => false + ) + end + def down + end +end \ No newline at end of file From d6b498a20acc398cbad65de2d4a99aa6ea669bb0 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 08:35:24 +0200 Subject: [PATCH 02/14] Fixed url and object name. --- .../app/controllers/_dashboard/activity_stream.js.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index c495ca7d2..167e149b0 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -42,17 +42,17 @@ class App.DashboardActivityStream extends App.Controller for item in items if item.history_object is 'Ticket' ticket = App.Ticket.find( item.o_id ) - item.link = '#ticket_zoom/' + ticket.id + item.link = '#ticket/zoom/' + ticket.id item.title = ticket.title - item.type = item.history_object + item.type = 'Ticket' item.updated_by_id = ticket.updated_by_id item.updated_by = App.User.find( ticket.updated_by_id ) else if item.history_object is 'Ticket::Article' article = App.TicketArticle.find( item.o_id ) ticket = App.Ticket.find( article.ticket_id ) - item.link = '#ticket_zoom/' + ticket.id + '/' + article.od + item.link = '#ticket/zoom/' + ticket.id + '/' + article.id item.title = article.subject || ticket.title - item.type = item.history_object + item.type = 'Article' item.updated_by_id = article.updated_by_id item.updated_by = App.User.find( article.updated_by_id ) From 4115f1691d6a94330d66095f2bd37131a852f99a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 10:21:52 +0200 Subject: [PATCH 03/14] Moved ticket merge to new assets feature. --- .../controllers/agent_ticket_merge.js.coffee | 26 +++++++++--------- app/controllers/tickets_controller.rb | 27 ++++++++++++++----- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index 6daae0830..8c5c4fee7 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -16,25 +16,23 @@ class App.TicketMerge extends App.ControllerModal processData: true, success: (data, status, xhr) => - if data.customer - App.Collection.load( type: 'Ticket', data: data.customer.tickets ) - App.Collection.load( type: 'User', data: data.customer.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - if data.recent - App.Collection.load( type: 'Ticket', data: data.recent.tickets ) - App.Collection.load( type: 'User', data: data.recent.users ) + @ticket_ids_by_customer = data.ticket_ids_by_customer + @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed - @render( data ) + @render() ) - render: (data) -> + render: -> @html App.view('agent_ticket_merge')() list = [] - for t in data.customer.tickets - if t.id isnt @ticket_id - ticketItem = App.Ticket.retrieve( t.id ) + for ticket_id in @ticket_ids_by_customer + if ticket_id isnt @ticket_id + ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-customer-tickets'), @@ -59,9 +57,9 @@ class App.TicketMerge extends App.ControllerModal ) list = [] - for t in data.recent.tickets - if t.id isnt @ticket_id - ticketItem = App.Ticket.retrieve( t.id ) + for ticket_id in @ticket_ids_recent_viewed + if ticket_id isnt @ticket_id + ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-recent-tickets'), diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index d8f991ee4..ecd5a144f 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -182,7 +182,10 @@ class TicketsController < ApplicationController # GET /api/v1/ticket_merge_list/1 def ticket_merge_list - ticket = Ticket.find( params[:ticket_id] ) + ticket = Ticket.find( params[:ticket_id] ) + assets = ticket.assets({}) + + # open tickets by customer ticket_list = Ticket.where( :customer_id => ticket.customer_id, :ticket_state_id => Ticket::State.by_category( 'open' ) @@ -191,19 +194,29 @@ class TicketsController < ApplicationController .order('created_at DESC') .limit(6) - # get related users - assets = {} + # get related assets + ticket_ids_by_customer = [] ticket_list.each {|ticket| - ticket = Ticket.lookup( :id => ticket.id ) + ticket_ids_by_customer.push ticket.id assets = ticket.assets(assets) } - recent_viewed = RecentView.list_fulldata( current_user, 8 ) + + ticket_ids_recent_viewed = [] + ticket_recent_view = RecentView.list( current_user, 8 ) + ticket_recent_view.each {|item| + if item['recent_view_object'] == 'Ticket' + ticket_ids_recent_viewed.push item['o_id'] + ticket = Ticket.find( item['o_id'] ) + assets = ticket.assets(assets) + end + } # return result render :json => { - :customer => assets, - :recent => recent_viewed + :assets => assets, + :ticket_ids_by_customer => ticket_ids_by_customer, + :ticket_ids_recent_viewed => ticket_ids_recent_viewed, } end From d5f8b7247267b5ac672f5df03622873a0562dabf Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 10:22:31 +0200 Subject: [PATCH 04/14] Fixed sso call. --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 5fa2bfb92..71418fc9f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -129,7 +129,7 @@ returns def self.sso(params) # try to login against configure auth backends - user_auth = Sso.check( params, user ) + user_auth = Sso.check( params ) return if !user_auth return user_auth From 63dc1bf7f8f22ac7533a1da4df420b8c8fb0e56e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 10:22:47 +0200 Subject: [PATCH 05/14] Fixed doc. --- lib/sso.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sso.rb b/lib/sso.rb index 4715723e9..9f04e1498 100644 --- a/lib/sso.rb +++ b/lib/sso.rb @@ -6,7 +6,7 @@ class Sso < ApplicationLib authenticate user via username and password - result = Sso.check( params, config_item ) + result = Sso.check( params ) returns From 66396b702958d47e6c79d1bcf74a71f1da34c3af Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 10:23:05 +0200 Subject: [PATCH 06/14] Removed not needed lines. --- app/models/ticket/search.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/ticket/search.rb b/app/models/ticket/search.rb index c51158d70..810a23ab7 100644 --- a/app/models/ticket/search.rb +++ b/app/models/ticket/search.rb @@ -50,13 +50,11 @@ returns # build result list tickets = [] - users = {} tickets_all.each do |ticket| - ticket_tmp = Ticket.lookup( :id => ticket.id ) - tickets.push ticket_tmp + tickets.push Ticket.lookup( :id => ticket.id ) end - return tickets + tickets end end \ No newline at end of file From ddbac79251ac97e7548dc22d4711175634a7a49c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 12:20:11 +0200 Subject: [PATCH 07/14] Moved to App.Model. --- app/assets/javascripts/app/models/overview.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/models/overview.js.coffee b/app/assets/javascripts/app/models/overview.js.coffee index 93ecc35d9..90da9c1af 100644 --- a/app/assets/javascripts/app/models/overview.js.coffee +++ b/app/assets/javascripts/app/models/overview.js.coffee @@ -1,4 +1,4 @@ -class App.Overview extends Spine.Model +class App.Overview extends App.Model @configure 'Overview', 'name', 'link', 'prio', 'condition', 'order', 'group_by', 'view', 'user_id', 'organization_shared', 'role_id', 'order', 'group_by', 'active', 'updated_at' @extend Spine.Model.Ajax @url: @apiPath + '/overviews' From f8f68836a65f5a310b4dd1d05446d47a0fcaf15f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 12:20:26 +0200 Subject: [PATCH 08/14] Fixed search. --- app/controllers/search_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index cec5dcc40..1b4413a5d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -68,7 +68,7 @@ class SearchController < ApplicationController # return result render :json => { - :load => assets, + :assets => assets, :result => result, } end From ee9bffe8cab35fdfbbdcdd8b1a42bc167f6fc50f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 12:21:31 +0200 Subject: [PATCH 09/14] 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 From 6509d89318d2fe222827895435f66d29e327f368 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 12:26:30 +0200 Subject: [PATCH 10/14] Moved to new asset feature. --- .../app/controllers/navigation.js.coffee | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 11e5d7a2c..7d3bb6d7e 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -92,24 +92,8 @@ class App.Navigation extends App.Controller processData: true, success: (data, status, xhr) => - # load user collection - if data.load.users - App.Collection.load( type: 'User', data: data.load.users ) - - # load user collection - if data.load.organizations - for organization_id, organization of data.load.organizations - if organization.user_ids - organization.users = [] - for user_id in organization.user_ids - user = App.User.find( user_id ) - organization.users.push user - App.Collection.load( type: 'Organization', data: data.load.organizations ) - - - # load ticket collection - if data.load.tickets - App.Collection.load( type: 'Ticket', data: data.load.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets @result = data.result for area in @result From 05e2288528b485a888a8ed37e786ff0e1c793619 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 14:04:34 +0200 Subject: [PATCH 11/14] Added missing return. --- app/models/ticket/overviews.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index 13a9f7a9c..d08bee701 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -26,7 +26,7 @@ returns else overviews = Overview.where( :role_id => role.id, :organization_shared => false, :active => true ) end - overviews + return overviews end # get agent overviews From 8a92f300ff180cab1f15b7c714c36396f4a38c9a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 14:05:07 +0200 Subject: [PATCH 12/14] Fixed reload of content. --- .../app/controllers/ticket_zoom.js.coffee | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 745ebfe70..3b7b8aae5 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -27,7 +27,7 @@ class App.TicketZoom extends App.Controller (data) => update = => if data.id.toString() is @ticket_id.toString() - ticket = App.Ticket.retrieve( @ticket_id ) + ticket = App.Ticket.find( @ticket_id ) @log 'notice', 'TRY', data.updated_at, ticket.updated_at if data.updated_at isnt ticket.updated_at @fetch( @ticket_id, false ) @@ -68,28 +68,25 @@ class App.TicketZoom extends App.Controller id: 'ticket_zoom_' + ticket_id type: 'GET' url: @apiPath + '/ticket_full/' + ticket_id + '?do_not_log=' + @doNotLog - data: - view: @view processData: true success: (data, status, xhr) => - if @dataLastCall && !force + + # check if ticket has changed + newTicketRaw = data.assets.tickets[ticket_id] + if @ticketUpdatedAtLastCall && !force # return if ticket hasnt changed - return if _.isEqual( @dataLastCall.ticket, data.ticket ) - - # trigger task notify - diff = difference( @dataLastCall.ticket, data.ticket ) - @log 'diff', diff + return if @ticketUpdatedAtLastCall is newTicketRaw.updated_at # notify if ticket changed not by my self - if !_.isEmpty(diff) && data.asset.ticket[0].updated_by_id isnt @Session.all().id + if newTicketRaw.updated_by_id isnt @Session.all().id App.TaskManager.notify( @task_key ) # rerender edit box @editDone = false # remember current data - @dataLastCall = data + @ticketUpdatedAtLastCall = newTicketRaw.updated_at @load(data, force) App.Store.write( @key, data ) @@ -112,11 +109,9 @@ class App.TicketZoom extends App.Controller # reset old indexes @ticket = undefined - # remember article ids @ticket_article_ids = data.ticket_article_ids - # get edit form attributes @edit_form = data.edit_form From 5a30476bc064618e2f8676d212105db36b9b420a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 15:15:49 +0200 Subject: [PATCH 13/14] Fixed text module in zoom view, added browser tests. --- .../controllers/agent_ticket_create.js.coffee | 5 +- .../controllers/text_module_widget.js.coffee | 7 ++- test/browser/text_module_test.rb | 62 +++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index 1acc0b452..93498db1a 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -211,9 +211,8 @@ class App.TicketCreate extends App.Controller # update text module UI callback = (user) => @textModule.reload( - data: - ticket: - customer: user + ticket: + customer: user ) @userInfo( diff --git a/app/assets/javascripts/app/controllers/text_module_widget.js.coffee b/app/assets/javascripts/app/controllers/text_module_widget.js.coffee index 4af73778a..fdd23daf0 100644 --- a/app/assets/javascripts/app/controllers/text_module_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/text_module_widget.js.coffee @@ -2,6 +2,7 @@ class App.TextModuleUI extends App.Controller constructor: -> super + @lastData = {} customItemTemplate = "
 
" elementFactory = (element, e) -> template = $(customItemTemplate).find('span') @@ -23,7 +24,7 @@ class App.TextModuleUI extends App.Controller reload: (data = false) => if data - @lastData = data + @lastData['data'] = data @update() update: => @@ -35,10 +36,12 @@ class App.TextModuleUI extends App.Controller contentNew = item.content.replace( /<%=\s{0,2}(.+?)\s{0,2}%>/g, ( all, key ) -> key = key.replace( /@/g, 'ui.data.' ) varString = "#{key}" + '' +# console.log( "tag replacement env: ", ui.data) try +# console.log( "tag replacement: " + key, varString ) key = eval (varString) catch error - #console.log( "tag replacement: " + error ) +# console.log( "tag replacement error: " + error ) key = '' return key ) diff --git a/test/browser/text_module_test.rb b/test/browser/text_module_test.rb index 8bd889832..94264c9c9 100644 --- a/test/browser/text_module_test.rb +++ b/test/browser/text_module_test.rb @@ -361,6 +361,68 @@ class TextModuleTest < TestCase }, ], }, + { + :name => 'verify zoom', + :action => [ + + # create ticket + { + :where => :instance2, + :execute => 'create_ticket', + :group => 'Users', + :subject => 'some subject 123äöü', + :body => 'some body 123äöü', + }, + + # check ticket + { + :where => :instance2, + :execute => 'match', + :css => '.active div.article', + :value => 'some body 123äöü', + :match_result => true, + }, + + # check ticket zoom + { + :execute => 'wait', + :value => 4, + }, + { + :where => :instance2, + :execute => 'set', + :css => '.active textarea[name=body]', + :value => '::' + random, + }, + { + :execute => 'wait', + :value => 1, + }, + { + :where => :instance2, + :execute => 'match', + :css => 'body', + :value => random, + :match_result => true, + }, + { + :where => :instance2, + :execute => 'click', + :css => '.-sew-list-item.selected', + }, + { + :execute => 'wait', + :value => 1, + }, + { + :where => :instance2, + :execute => 'match', + :css => '.active textarea[name=body]', + :value => 'some content' + random, + :match_result => true, + }, + ], + }, ] browser_double_test(tests) end From 11e1cd471e925e614da2c6e7284e5ede1056024a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 17:26:44 +0200 Subject: [PATCH 14/14] Improved unit tests. --- test/browser/text_module_test.rb | 14 ++++++++++++-- test/browser_test_helper.rb | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/browser/text_module_test.rb b/test/browser/text_module_test.rb index 94264c9c9..2e62bd39e 100644 --- a/test/browser/text_module_test.rb +++ b/test/browser/text_module_test.rb @@ -263,7 +263,7 @@ class TextModuleTest < TestCase :action => [ { :execute => 'wait', - :value => 3, + :value => 4, }, { :where => :instance2, @@ -388,6 +388,16 @@ class TextModuleTest < TestCase :execute => 'wait', :value => 4, }, + { + :where => :instance2, + :execute => 'set', + :css => '.active textarea[name=body]', + :value => 'test', + }, + { + :execute => 'wait', + :value => 4, + }, { :where => :instance2, :execute => 'set', @@ -418,7 +428,7 @@ class TextModuleTest < TestCase :where => :instance2, :execute => 'match', :css => '.active textarea[name=body]', - :value => 'some content' + random, + :value => 'some content Braun' + random, :match_result => true, }, ], diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 69ddec753..903ae87cb 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -247,7 +247,7 @@ puts "NOTICE #{Time.now.to_s}: " + action.inspect sleep 4 element = instance.find_element( { :css => '.active .ticket_create input[name="customer_id_autocompletion"]' } ) element.clear - element.send_keys( 'ma' ) + element.send_keys( 'nico' ) sleep 4 element = instance.find_element( { :css => '.active .ticket_create input[name="customer_id_autocompletion"]' } ) element.send_keys( :arrow_down )