From 0e5724ca0b73ef48f5444972ff1484b72f5494cd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 27 Aug 2016 11:43:15 +0200 Subject: [PATCH] Just rerender ticket stats if user change was pushed from server. --- .../_application_controller_generic.coffee | 2 +- .../controllers/organization_profile.coffee | 2 +- .../app/controllers/taskbar_widget.coffee | 2 +- .../app/controllers/user_profile.coffee | 4 ++-- .../app/controllers/widget/ticket_stats.coffee | 6 +++++- .../app/lib/app_post/collection.coffee | 12 ++++++------ .../javascripts/app/lib/spine/ajax.coffee | 2 +- .../app/models/_application_model.coffee | 18 ++++++++++++++---- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index 936c222b3..4c4b0d864 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -843,7 +843,7 @@ class App.CollectionController extends App.Controller @domRemove(param[1]) else if param[0] is 'change' @collectionSync(param[1]) - else if param[0] is 'remove' + else if param[0] is 'destroy' @collectionSync(param[1], 'destroy') else if param[0] is 'renderAll' @renderAll() diff --git a/app/assets/javascripts/app/controllers/organization_profile.coffee b/app/assets/javascripts/app/controllers/organization_profile.coffee index 4f313a166..84833f637 100644 --- a/app/assets/javascripts/app/controllers/organization_profile.coffee +++ b/app/assets/javascripts/app/controllers/organization_profile.coffee @@ -174,7 +174,7 @@ class Object extends App.ObserverController data = {} data[name] = value org.updateAttributes(data) - @log 'notice', 'update', name, value, org + @log 'debug', 'update', name, value, org class Member extends App.ObserverController model: 'User' diff --git a/app/assets/javascripts/app/controllers/taskbar_widget.coffee b/app/assets/javascripts/app/controllers/taskbar_widget.coffee index 6c4da6b14..3ad68a41d 100644 --- a/app/assets/javascripts/app/controllers/taskbar_widget.coffee +++ b/app/assets/javascripts/app/controllers/taskbar_widget.coffee @@ -42,7 +42,7 @@ class App.TaskbarWidget extends App.CollectionController @uIRunner() ) @bind('taskRemove', (tasks) => - @queue.push ['remove', tasks] + @queue.push ['destroy', tasks] @uIRunner() ) @bind('taskCollectionOrderSet', (task_keys) => diff --git a/app/assets/javascripts/app/controllers/user_profile.coffee b/app/assets/javascripts/app/controllers/user_profile.coffee index b509a665e..f13dbdd88 100644 --- a/app/assets/javascripts/app/controllers/user_profile.coffee +++ b/app/assets/javascripts/app/controllers/user_profile.coffee @@ -173,7 +173,7 @@ class Object extends App.ObserverController data = {} data[name] = value user.updateAttributes(data) - @log 'notice', 'update', name, value, user + @log 'debug', 'update', name, value, user class Organization extends App.ObserverController model: 'Organization' @@ -195,7 +195,7 @@ class Router extends App.ControllerPermanent user_id: params.user_id App.TaskManager.execute( - key: 'User-' + @user_id + key: "User-#{@user_id}" controller: 'UserProfile' params: clean_params show: true diff --git a/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee b/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee index 98752cd16..3e78ef825 100644 --- a/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee +++ b/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee @@ -29,7 +29,11 @@ class App.TicketStats extends App.Controller if @subscribeIdOrganization App.Organization.unsubscribe(@subscribeIdOrganization) - load: (object) => + load: (object, type) => + + # ignore rerender on local record changes + return if type is 'change' + if @organization ajaxKey = "org_#{@organization.id}" data = diff --git a/app/assets/javascripts/app/lib/app_post/collection.coffee b/app/assets/javascripts/app/lib/app_post/collection.coffee index 973d3c765..08859832b 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.coffee @@ -66,14 +66,14 @@ class _collectionSingleton extends Spine.Module loadAssets: (assets) -> @log 'debug', 'loadAssets', assets - # proess not existing assets / to avoid not exising ref errors + # process not existing assets first / to avoid not exising ref errors loadAssetsLater = [] for type, collections of assets later = @load(type: type, data: collections, later: true) if later loadAssetsLater[type] = later - # proess existing assets + # process existing assets for type, collections of loadAssetsLater App[type].refresh(collections) @@ -99,7 +99,7 @@ class _collectionSingleton extends Spine.Module listToRefreshLater = [] for key, object of params.data if !params.refresh && appObject - @log 'debug', 'refrest try', params.type, key + @log 'debug', 'refresh try', params.type, key # check if new object is newer, just load newer objects if object.updated_at && appObject.exists(key) @@ -108,10 +108,10 @@ class _collectionSingleton extends Spine.Module if exists.updated_at if exists.updated_at < object.updated_at objectToLoad = object - @log 'debug', 'refrest newser', params.type, key + @log 'debug', 'refresh newser', params.type, key else objectToLoad = object - @log 'debug', 'refrest try no updated_at', params.type, key + @log 'debug', 'refresh try no updated_at', params.type, key if objectToLoad if params.later listToRefreshLater.push objectToLoad @@ -119,7 +119,7 @@ class _collectionSingleton extends Spine.Module listToRefresh.push object else listToRefresh.push object - @log 'debug', 'refrest new', params.type, key + @log 'debug', 'refresh new', params.type, key return listToRefreshLater if _.isEmpty(listToRefresh) appObject.refresh(listToRefresh) listToRefreshLater diff --git a/app/assets/javascripts/app/lib/spine/ajax.coffee b/app/assets/javascripts/app/lib/spine/ajax.coffee index 1370780db..e4f5115d8 100644 --- a/app/assets/javascripts/app/lib/spine/ajax.coffee +++ b/app/assets/javascripts/app/lib/spine/ajax.coffee @@ -244,7 +244,7 @@ class Singleton extends Base if !_.isEmpty(detailsRaw) details = JSON.parse(detailsRaw) options.fail?.call(@record, settings, details) - @record.trigger('remove', @record) + @record.trigger('destroy', @record) # /add errors to calllback createFailed: -> diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index bb5d3a605..96900e20e 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -292,6 +292,11 @@ class App.Model extends Spine.Model methodWhichIsCalledAtLocalOrServerSiteChange = (changedItems) -> console.log("Collection has changed", changedItems, localOrServer) + # localOrServer can be: + # change -> has changed local + # destroy -> has beed removed local or remote + # refresh -> has been changed remote + params = initFetch: true # fetch initial collection @@ -376,6 +381,11 @@ class App.Model extends Spine.Model methodWhichIsCalledAtLocalOrServerSiteChange = (changedItem, localOrServer) -> console.log("Item has changed", changedItem, localOrServer) + # localOrServer can be: + # change -> has changed local + # destroy -> has been removed local or remote + # refresh -> has been changed remote + model = App.Model.find(1) @subscribeId = model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange) @@ -407,17 +417,17 @@ class App.Model extends Spine.Model callback(item, 'change') ) @bind( - 'remove' + 'destroy' (items) => # check if result is array or singel item if !_.isArray(items) items = [items] - App.Log.debug('Model', "local remove #{@className}", items) + App.Log.debug('Model', "local destroy #{@className}", items) for item in items for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] item = App[ @className ]._fillUp(item) - callback(item, 'remove') + callback(item, 'destroy') ) @changeTable = {} @@ -466,7 +476,7 @@ class App.Model extends Spine.Model genericObject = App[ @className ].find(item.id) App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}") callback = -> - genericObject.trigger('remove', genericObject) + genericObject.trigger('destroy', genericObject) App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}") "Item::SubscribeDelete::#{@className}" )