From 6b21e155e9ec91fcadc9ab40c76f22217fffcd00 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 29 Sep 2013 18:40:42 +0200 Subject: [PATCH] Moved to new history api. --- .../agent_ticket_history.js.coffee | 62 ++++--- .../javascripts/app/models/history.js.coffee | 20 --- .../app/models/history_attributes.js.coffee | 4 - .../app/models/history_object.js.coffee | 4 - .../app/models/history_type.js.coffee | 4 - .../app/views/agent_ticket_history.jst.eco | 40 ++--- app/controllers/tickets_controller.rb | 46 +---- app/models/application_model.rb | 151 ++++++++++++++++- .../application_model/history_log_base.rb | 25 ++- app/models/group.rb | 2 + app/models/history.rb | 52 +++++- app/models/observer/history.rb | 159 ------------------ app/models/organization.rb | 2 + app/models/ticket.rb | 5 +- app/models/ticket/article.rb | 1 + app/models/ticket/article/history_log.rb | 38 +---- app/models/ticket/history_log.rb | 23 ++- app/models/user.rb | 1 + config/application.rb | 1 - test/unit/history_test.rb | 29 ++-- 20 files changed, 316 insertions(+), 353 deletions(-) delete mode 100644 app/assets/javascripts/app/models/history.js.coffee delete mode 100644 app/assets/javascripts/app/models/history_attributes.js.coffee delete mode 100644 app/assets/javascripts/app/models/history_object.js.coffee delete mode 100644 app/assets/javascripts/app/models/history_type.js.coffee delete mode 100644 app/models/observer/history.rb 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 6309a5e92..37fa9545e 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -9,6 +9,7 @@ class App.TicketHistory extends App.ControllerModal @fetch(@ticket_id) fetch: (@ticket_id) -> + # get data @ajax( id: 'ticket_history', @@ -19,18 +20,43 @@ class App.TicketHistory extends App.ControllerModal # load collections App.Event.trigger 'loadAssets', data.assets - # load history collections - App.History.deleteAll() - App.Collection.load( type: 'History', data: data.history ) # render page - @render() + @render(data.history) ) - render: -> + render: ( items, orderClass = '' ) -> + + for item in items + if item.object is 'Ticket' + ticket = App.Ticket.find( item.o_id ) + item.link = '#ticket/zoom/' + ticket.id + item.title = ticket.title + item.object = 'Ticket' + + else if item.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.id + item.title = article.subject || ticket.title + item.object = 'Article' + + else if item.object is 'User' + user = App.User.find( item.o_id ) + item.link = '#user/zoom/' + item.o_id + item.title = user.displayName() + item.object = 'User' + + item.created_by = App.User.find( item.created_by_id ) + + # set cache + @historyListCache = items @html App.view('agent_ticket_history')( - objects: App.History.search() + items: items + orderClass: orderClass + + @historyListCache ) @modalShow() @@ -43,25 +69,9 @@ class App.TicketHistory extends App.ControllerModal sortorder: (e) -> e.preventDefault() - isSorted = @el.find('.sorted') + idDown = @el.find('[data-type="sortorder"]').hasClass('down') - if isSorted.length - @sortstate = 'notsorted' - @html App.view('agent_ticket_history')( - objects: App.History.search() - state: @sortstate - ) + if idDown + @render( @historyListCache, 'up' ) else - @sortstate = 'sorted' - @html App.view('agent_ticket_history')( - objects: App.History.search().reverse() - state: @sortstate - ) - - @modalShow() - - # enable user popups - @userPopups() - - # show frontend times - @delay( @frontendTimeUpdate, 200, 'ui-time-update' ) + @render( @historyListCache.reverse(), 'down' ) diff --git a/app/assets/javascripts/app/models/history.js.coffee b/app/assets/javascripts/app/models/history.js.coffee deleted file mode 100644 index 9b82b5699..000000000 --- a/app/assets/javascripts/app/models/history.js.coffee +++ /dev/null @@ -1,20 +0,0 @@ -class App.History extends App.Model - @configure 'History', 'name' - @extend Spine.Model.Ajax - @url: @apiPath + '/histories' - - @_fillUp: (data) -> - - # add user - data.created_by = App.User.find( data.created_by_id ) - - # add possible actions - if data.history_attribute_id - data.attribute = App.HistoryAttribute.find( data.history_attribute_id ) - if data.history_type_id - data.type = App.HistoryType.find( data.history_type_id ) - if data.history_object_id - data.object = App.HistoryObject.find( data.history_object_id ) - - return data - diff --git a/app/assets/javascripts/app/models/history_attributes.js.coffee b/app/assets/javascripts/app/models/history_attributes.js.coffee deleted file mode 100644 index 8c314c1dd..000000000 --- a/app/assets/javascripts/app/models/history_attributes.js.coffee +++ /dev/null @@ -1,4 +0,0 @@ -class App.HistoryAttribute extends App.Model - @configure 'HistoryAttribute', 'name' - @extend Spine.Model.Ajax - @url: @apiPath + '/history_attributes' diff --git a/app/assets/javascripts/app/models/history_object.js.coffee b/app/assets/javascripts/app/models/history_object.js.coffee deleted file mode 100644 index 9d03058d0..000000000 --- a/app/assets/javascripts/app/models/history_object.js.coffee +++ /dev/null @@ -1,4 +0,0 @@ -class App.HistoryObject extends App.Model - @configure 'HistoryObject', 'name' - @extend Spine.Model.Ajax - @url: @apiPath + '/history_objects' diff --git a/app/assets/javascripts/app/models/history_type.js.coffee b/app/assets/javascripts/app/models/history_type.js.coffee deleted file mode 100644 index 0865e9e23..000000000 --- a/app/assets/javascripts/app/models/history_type.js.coffee +++ /dev/null @@ -1,4 +0,0 @@ -class App.HistoryType extends App.Model - @configure 'HistoryType', 'name' - @extend Spine.Model.Ajax - @url: @apiPath + '/history_types' diff --git a/app/assets/javascripts/app/views/agent_ticket_history.jst.eco b/app/assets/javascripts/app/views/agent_ticket_history.jst.eco index e7348868d..81c807bd8 100644 --- a/app/assets/javascripts/app/views/agent_ticket_history.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_history.jst.eco @@ -3,44 +3,40 @@