Just rerender ticket stats if user change was pushed from server.

This commit is contained in:
Martin Edenhofer 2016-08-27 11:43:15 +02:00
parent 89fd6f9e90
commit 0e5724ca0b
8 changed files with 31 additions and 17 deletions

View file

@ -843,7 +843,7 @@ class App.CollectionController extends App.Controller
@domRemove(param[1]) @domRemove(param[1])
else if param[0] is 'change' else if param[0] is 'change'
@collectionSync(param[1]) @collectionSync(param[1])
else if param[0] is 'remove' else if param[0] is 'destroy'
@collectionSync(param[1], 'destroy') @collectionSync(param[1], 'destroy')
else if param[0] is 'renderAll' else if param[0] is 'renderAll'
@renderAll() @renderAll()

View file

@ -174,7 +174,7 @@ class Object extends App.ObserverController
data = {} data = {}
data[name] = value data[name] = value
org.updateAttributes(data) org.updateAttributes(data)
@log 'notice', 'update', name, value, org @log 'debug', 'update', name, value, org
class Member extends App.ObserverController class Member extends App.ObserverController
model: 'User' model: 'User'

View file

@ -42,7 +42,7 @@ class App.TaskbarWidget extends App.CollectionController
@uIRunner() @uIRunner()
) )
@bind('taskRemove', (tasks) => @bind('taskRemove', (tasks) =>
@queue.push ['remove', tasks] @queue.push ['destroy', tasks]
@uIRunner() @uIRunner()
) )
@bind('taskCollectionOrderSet', (task_keys) => @bind('taskCollectionOrderSet', (task_keys) =>

View file

@ -173,7 +173,7 @@ class Object extends App.ObserverController
data = {} data = {}
data[name] = value data[name] = value
user.updateAttributes(data) user.updateAttributes(data)
@log 'notice', 'update', name, value, user @log 'debug', 'update', name, value, user
class Organization extends App.ObserverController class Organization extends App.ObserverController
model: 'Organization' model: 'Organization'
@ -195,7 +195,7 @@ class Router extends App.ControllerPermanent
user_id: params.user_id user_id: params.user_id
App.TaskManager.execute( App.TaskManager.execute(
key: 'User-' + @user_id key: "User-#{@user_id}"
controller: 'UserProfile' controller: 'UserProfile'
params: clean_params params: clean_params
show: true show: true

View file

@ -29,7 +29,11 @@ class App.TicketStats extends App.Controller
if @subscribeIdOrganization if @subscribeIdOrganization
App.Organization.unsubscribe(@subscribeIdOrganization) App.Organization.unsubscribe(@subscribeIdOrganization)
load: (object) => load: (object, type) =>
# ignore rerender on local record changes
return if type is 'change'
if @organization if @organization
ajaxKey = "org_#{@organization.id}" ajaxKey = "org_#{@organization.id}"
data = data =

View file

@ -66,14 +66,14 @@ class _collectionSingleton extends Spine.Module
loadAssets: (assets) -> loadAssets: (assets) ->
@log 'debug', '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 = [] loadAssetsLater = []
for type, collections of assets for type, collections of assets
later = @load(type: type, data: collections, later: true) later = @load(type: type, data: collections, later: true)
if later if later
loadAssetsLater[type] = later loadAssetsLater[type] = later
# proess existing assets # process existing assets
for type, collections of loadAssetsLater for type, collections of loadAssetsLater
App[type].refresh(collections) App[type].refresh(collections)
@ -99,7 +99,7 @@ class _collectionSingleton extends Spine.Module
listToRefreshLater = [] listToRefreshLater = []
for key, object of params.data for key, object of params.data
if !params.refresh && appObject 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 # check if new object is newer, just load newer objects
if object.updated_at && appObject.exists(key) if object.updated_at && appObject.exists(key)
@ -108,10 +108,10 @@ class _collectionSingleton extends Spine.Module
if exists.updated_at if exists.updated_at
if exists.updated_at < object.updated_at if exists.updated_at < object.updated_at
objectToLoad = object objectToLoad = object
@log 'debug', 'refrest newser', params.type, key @log 'debug', 'refresh newser', params.type, key
else else
objectToLoad = object 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 objectToLoad
if params.later if params.later
listToRefreshLater.push objectToLoad listToRefreshLater.push objectToLoad
@ -119,7 +119,7 @@ class _collectionSingleton extends Spine.Module
listToRefresh.push object listToRefresh.push object
else else
listToRefresh.push object listToRefresh.push object
@log 'debug', 'refrest new', params.type, key @log 'debug', 'refresh new', params.type, key
return listToRefreshLater if _.isEmpty(listToRefresh) return listToRefreshLater if _.isEmpty(listToRefresh)
appObject.refresh(listToRefresh) appObject.refresh(listToRefresh)
listToRefreshLater listToRefreshLater

View file

@ -244,7 +244,7 @@ class Singleton extends Base
if !_.isEmpty(detailsRaw) if !_.isEmpty(detailsRaw)
details = JSON.parse(detailsRaw) details = JSON.parse(detailsRaw)
options.fail?.call(@record, settings, details) options.fail?.call(@record, settings, details)
@record.trigger('remove', @record) @record.trigger('destroy', @record)
# /add errors to calllback # /add errors to calllback
createFailed: -> createFailed: ->

View file

@ -292,6 +292,11 @@ class App.Model extends Spine.Model
methodWhichIsCalledAtLocalOrServerSiteChange = (changedItems) -> methodWhichIsCalledAtLocalOrServerSiteChange = (changedItems) ->
console.log("Collection has changed", changedItems, localOrServer) 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 = params =
initFetch: true # fetch initial collection initFetch: true # fetch initial collection
@ -376,6 +381,11 @@ class App.Model extends Spine.Model
methodWhichIsCalledAtLocalOrServerSiteChange = (changedItem, localOrServer) -> methodWhichIsCalledAtLocalOrServerSiteChange = (changedItem, localOrServer) ->
console.log("Item has changed", 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) model = App.Model.find(1)
@subscribeId = model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange) @subscribeId = model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange)
@ -407,17 +417,17 @@ class App.Model extends Spine.Model
callback(item, 'change') callback(item, 'change')
) )
@bind( @bind(
'remove' 'destroy'
(items) => (items) =>
# check if result is array or singel item # check if result is array or singel item
if !_.isArray(items) if !_.isArray(items)
items = [items] items = [items]
App.Log.debug('Model', "local remove #{@className}", items) App.Log.debug('Model', "local destroy #{@className}", items)
for item in items for item in items
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
item = App[ @className ]._fillUp(item) item = App[ @className ]._fillUp(item)
callback(item, 'remove') callback(item, 'destroy')
) )
@changeTable = {} @changeTable = {}
@ -466,7 +476,7 @@ class App.Model extends Spine.Model
genericObject = App[ @className ].find(item.id) genericObject = App[ @className ].find(item.id)
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}") App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
callback = -> callback = ->
genericObject.trigger('remove', genericObject) genericObject.trigger('destroy', genericObject)
App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}") App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}")
"Item::SubscribeDelete::#{@className}" "Item::SubscribeDelete::#{@className}"
) )