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])
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()

View file

@ -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'

View file

@ -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) =>

View file

@ -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

View file

@ -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 =

View file

@ -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

View file

@ -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: ->

View file

@ -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}"
)