Improved memory management.

This commit is contained in:
Martin Edenhofer 2016-10-15 21:21:44 +02:00
parent f5de9086b7
commit d092db4cd8
11 changed files with 78 additions and 66 deletions

View file

@ -152,8 +152,9 @@ class App.ControllerTable extends App.Controller
# check if table is empty # check if table is empty
if _.isEmpty(@objects) if _.isEmpty(@objects)
table = App.view('generic/admin/empty') table = App.view('generic/admin/empty')(
explanation: @explanation explanation: @explanation
)
return $(table) return $(table)
# get header data # get header data
@ -234,7 +235,7 @@ class App.ControllerTable extends App.Controller
# if we need to sort a relation # if we need to sort a relation
if header.relation if header.relation
if item[header.name] if item[header.name]
App[header.relation].find(item[header.name]).displayName() App[header.relation].findNative(item[header.name]).displayName()
else else
'' ''
else else

View file

@ -8,36 +8,36 @@ class App.UiElement.ApplicationUiElement
return if !attribute.options return if !attribute.options
# arrays can only get ordered
if _.isArray(attribute.options) if _.isArray(attribute.options)
# reverse if we have to exit early, if configured
if attribute.order # reverse - we have to exit early
if attribute.order == 'DESC' if attribute.order && attribute.order == 'DESC'
attribute.options = attribute.options.reverse() attribute.options = attribute.options.reverse()
return return
options_by_name = [] # sort by name
for i in attribute.options optionsByName = []
options_by_name.push i['name'].toString().toLowerCase() optionsByNameWithValue = {}
options_by_name = options_by_name.sort() for i, value of attribute.options
valueTmp = value.toString().toLowerCase()
optionsByName.push valueTmp
optionsByNameWithValue[valueTmp] = i
optionsByName = optionsByName.sort()
options_new = [] # do a reverse, if needed
options_new_used = {} if attribute.order && attribute.order == 'DESC'
for i in options_by_name optionsByName = optionsByName.reverse()
for ii, vv in attribute.options
if !options_new_used[ ii['value'] ] && i.toString().toLowerCase() is ii['name'].toString().toLowerCase()
options_new_used[ ii['value'] ] = 1
options_new.push ii
attribute.options = options_new
# do a final reverse, if configured optionsNew = []
if attribute.order for i in optionsByName
if attribute.order == 'DESC' optionsNew.push optionsByNameWithValue[i]
attribute.options = attribute.options.reverse() attribute.options = optionsNew
@addNullOption: (attribute) -> @addNullOption: (attribute) ->
return if !attribute.options return if !attribute.options
return if !attribute.nulloption return if !attribute.nulloption
if _.isArray( attribute.options ) if _.isArray(attribute.options)
attribute.options.unshift({ name: '-', value: '' }) attribute.options.unshift({ name: '-', value: '' })
else else
attribute.options[''] = '-' attribute.options[''] = '-'
@ -64,6 +64,7 @@ class App.UiElement.ApplicationUiElement
name: name_new name: name_new
value: key value: key
} }
attribute.sortBy = null
@getRelationOptionList: (attribute, params) -> @getRelationOptionList: (attribute, params) ->
@ -154,19 +155,21 @@ class App.UiElement.ApplicationUiElement
# if active or if active doesn't exist # if active or if active doesn't exist
if item.active || !activeSupport || isSelected if item.active || !activeSupport || isSelected
name_new = '?' nameNew = '?'
if item.displayName if item.displayName
name_new = item.displayName() nameNew = item.displayName()
else if item.name else if item.name
name_new = item.name nameNew = item.name
if attribute.translate if attribute.translate
name_new = App.i18n.translateInline(name_new) nameNew = App.i18n.translateInline(nameNew)
attribute.options.push { attribute.options.push {
name: name_new, name: nameNew,
value: item.id, value: item.id,
note: item.note, note: item.note,
} }
attribute.sortBy = null
# execute filter # execute filter
@filterOption: (attribute) -> @filterOption: (attribute) ->
return if !attribute.filter return if !attribute.filter

View file

@ -174,9 +174,6 @@ class App.Navigation extends App.ControllerWidgetPermanent
render: -> render: ->
# reset result cache
@searchResultCache = {}
user = App.Session.get() user = App.Session.get()
@html App.view('navigation')( @html App.view('navigation')(
user: user user: user

View file

@ -338,12 +338,12 @@ class Table extends App.Controller
tickets = data.tickets tickets = data.tickets
# get ticket list # get ticket list
ticket_list_show = [] ticketListShow = []
for ticket in tickets for ticket in tickets
ticket_list_show.push App.Ticket.fullLocal(ticket.id) ticketListShow.push App.Ticket.fullLocal(ticket.id)
# if customer and no ticket exists, show the following message only # if customer and no ticket exists, show the following message only
if !ticket_list_show[0] && @permissionCheck('ticket.customer') if !ticketListShow[0] && @permissionCheck('ticket.customer')
@html App.view('customer_not_ticket_exists')() @html App.view('customer_not_ticket_exists')()
return return
@ -388,7 +388,7 @@ class Table extends App.Controller
if @view_mode is 'm' if @view_mode is 'm'
table = App.view('agent_ticket_view/detail')( table = App.view('agent_ticket_view/detail')(
overview: @overview overview: @overview
objects: ticket_list_show objects: ticketListShow
checkbox: checkbox checkbox: checkbox
) )
table = $(table) table = $(table)
@ -403,9 +403,9 @@ class Table extends App.Controller
openTicket = (id,e) => openTicket = (id,e) =>
# open ticket via task manager to provide task with overview info # open ticket via task manager to provide task with overview info
ticket = App.Ticket.fullLocal(id) ticket = App.Ticket.findNative(id)
App.TaskManager.execute( App.TaskManager.execute(
key: 'Ticket-' + ticket.id key: "Ticket-#{ticket.id}"
controller: 'TicketZoom' controller: 'TicketZoom'
params: params:
ticket_id: ticket.id ticket_id: ticket.id
@ -457,7 +457,7 @@ class Table extends App.Controller
overview: @overview.view.s overview: @overview.view.s
el: @$('.table-overview') el: @$('.table-overview')
model: App.Ticket model: App.Ticket
objects: ticket_list_show objects: ticketListShow
checkbox: checkbox checkbox: checkbox
groupBy: @overview.group_by groupBy: @overview.group_by
orderBy: @overview.order.by orderBy: @overview.order.by
@ -524,16 +524,16 @@ class Table extends App.Controller
getSelected: -> getSelected: ->
@ticketIDs = [] @ticketIDs = []
@$('.table-overview').find('[name="bulk"]:checked').each( (index, element) => @$('.table-overview').find('[name="bulk"]:checked').each( (index, element) =>
ticket_id = $(element).val() ticketId = $(element).val()
@ticketIDs.push ticket_id @ticketIDs.push ticketId
) )
@ticketIDs @ticketIDs
setSelected: (ticketIDs) -> setSelected: (ticketIDs) ->
@$('.table-overview').find('[name="bulk"]').each( (index, element) -> @$('.table-overview').find('[name="bulk"]').each( (index, element) ->
ticket_id = $(element).val() ticketId = $(element).val()
for ticket_id_selected in ticketIDs for ticketIdSelected in ticketIDs
if ticket_id_selected is ticket_id if ticketIdSelected is ticketId
$(element).attr('checked', true) $(element).attr('checked', true)
) )

View file

@ -75,6 +75,9 @@ class App.TicketZoom extends App.Controller
fetch: (ignoreSame = false) => fetch: (ignoreSame = false) =>
return if !@Session.get() return if !@Session.get()
queue = false
if !@initFetched
queue = true
# get data # get data
@ajax( @ajax(
@ -82,7 +85,7 @@ class App.TicketZoom extends App.Controller
type: 'GET' type: 'GET'
url: "#{@apiPath}/tickets/#{@ticket_id}?all=true" url: "#{@apiPath}/tickets/#{@ticket_id}?all=true"
processData: true processData: true
queue: true queue: queue
success: (data, status, xhr) => success: (data, status, xhr) =>
@load(data, ignoreSame) @load(data, ignoreSame)
App.SessionStorage.set(@key, data) App.SessionStorage.set(@key, data)
@ -196,7 +199,7 @@ class App.TicketZoom extends App.Controller
# set icon and title based on ticket # set icon and title based on ticket
if @ticket_id && App.Ticket.exists(@ticket_id) if @ticket_id && App.Ticket.exists(@ticket_id)
ticket = App.Ticket.find(@ticket_id) ticket = App.Ticket.findNative(@ticket_id)
meta.head = ticket.title meta.head = ticket.title
meta.title = "##{ticket.number} - #{ticket.title}" meta.title = "##{ticket.number} - #{ticket.title}"
meta.class = "task-state-#{ ticket.getState() }" meta.class = "task-state-#{ ticket.getState() }"
@ -489,6 +492,7 @@ class App.TicketZoom extends App.Controller
if @article_id if @article_id
@pagePositionData = @article_id @pagePositionData = @article_id
@pagePosition(type: 'init') @pagePosition(type: 'init')
@positionPageHeaderStart()
@initDone = true @initDone = true
return return

View file

@ -7,7 +7,7 @@ class App.TicketList extends App.Controller
render: => render: =>
openTicket = (id,e) => openTicket = (id,e) =>
ticket = App.Ticket.fullLocal(id) ticket = App.Ticket.findNative(id)
@navigate ticket.uiUrl() @navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) -> callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) ->
attribute.title = object.title attribute.title = object.title

View file

@ -102,13 +102,13 @@ class _collectionSingleton extends Spine.Module
@log 'debug', 'refresh 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
exists = appObject.find(key) currentUpdatedAt = appObject.updatedAt(key)
objectToLoad = undefined objectToLoad = undefined
if exists.updated_at if currentUpdatedAt
if exists.updated_at < object.updated_at if currentUpdatedAt < object.updated_at
objectToLoad = object objectToLoad = object
@log 'debug', 'refresh newser', params.type, key @log 'debug', 'refresh newer', params.type, key
else else
objectToLoad = object objectToLoad = object
@log 'debug', 'refresh try no updated_at', params.type, key @log 'debug', 'refresh try no updated_at', params.type, key

View file

@ -588,7 +588,7 @@ class App.Model extends Spine.Model
# only if relation record exists in collection # only if relation record exists in collection
if App[ attribute.relation ].exists(data[attribute.name]) if App[ attribute.relation ].exists(data[attribute.name])
item = App[attribute.relation].find(data[attribute.name]) item = App[attribute.relation].findNative(data[attribute.name])
item = App[attribute.relation]._fillUp(item, classNames.concat(@className)) item = App[attribute.relation]._fillUp(item, classNames.concat(@className))
data[withoutId] = item data[withoutId] = item
else else
@ -630,11 +630,11 @@ class App.Model extends Spine.Model
all_complied = [] all_complied = []
if !params if !params
for item in all for item in all
item_new = @find(item.id) item_new = @findNative(item.id)
all_complied.push @_fillUp(item_new) all_complied.push @_fillUp(item_new)
return all_complied return all_complied
for item in all for item in all
item_new = @find(item.id) item_new = @findNative(item.id)
all_complied.push @_fillUp(item_new) all_complied.push @_fillUp(item_new)
# filter search # filter search
@ -693,7 +693,7 @@ class App.Model extends Spine.Model
collection collection
@_filterExtended: (collection, filters) -> @_filterExtended: (collection, filters) ->
collection = _.filter( collection, (item) -> collection = _.filter(collection, (item) ->
# check all filters # check all filters
for filter in filters for filter in filters
@ -704,7 +704,7 @@ class App.Model extends Spine.Model
if matchInner isnt false if matchInner isnt false
reg = new RegExp( value, 'i' ) reg = new RegExp( value, 'i' )
if item[ key ] isnt undefined && item[ key ] isnt null && item[ key ].match( reg ) if item[ key ] isnt undefined && item[ key ] isnt null && item[ key ].match(reg)
matchInner = true matchInner = true
else else
matchInner = false matchInner = false
@ -729,3 +729,10 @@ class App.Model extends Spine.Model
else if item.updated_at > updated_at else if item.updated_at > updated_at
updated_at = item.updated_at updated_at = item.updated_at
updated_at updated_at
@updatedAt: (id) ->
return if !@irecords[id]
@irecords[id].updated_at
@findNative: (id) ->
@irecords[id] or notFound?(id)

View file

@ -25,7 +25,7 @@ Mit **Organisationen** können Sie Kunden **gruppieren**. Dies hat u. a. zwei be
''' '''
uiUrl: -> uiUrl: ->
'#organization/profile/' + @id "#organization/profile/#{@id}"
icon: -> icon: ->
'organization' 'organization'
@ -37,7 +37,7 @@ Mit **Organisationen** können Sie Kunden **gruppieren**. Dies hat u. a. zwei be
data['members'] = [] data['members'] = []
for user_id in data['member_ids'] for user_id in data['member_ids']
if App.User.exists(user_id) if App.User.exists(user_id)
user = App.User.find(user_id) user = App.User.findNative(user_id)
data['members'].push user data['members'].push user
data data

View file

@ -30,7 +30,7 @@ class App.Role extends App.Model
data['permissions'] = [] data['permissions'] = []
for permission_id in data['permission_ids'] for permission_id in data['permission_ids']
if App.Permission.exists(permission_id) if App.Permission.exists(permission_id)
permission = App.Permission.find(permission_id) permission = App.Permission.findNative(permission_id)
data['permissions'].push permission data['permissions'].push permission
data data

View file

@ -120,20 +120,20 @@ class App.User extends App.Model
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid'] data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
if data.organization_id if data.organization_id
data.organization = App.Organization.find(data.organization_id) data.organization = App.Organization.findNative(data.organization_id)
if data['role_ids'] if data['role_ids']
data['roles'] = [] data['roles'] = []
for role_id in data['role_ids'] for role_id in data['role_ids']
if App.Role.exists(role_id) if App.Role.exists(role_id)
role = App.Role.find(role_id) role = App.Role.findNative(role_id)
data['roles'].push role data['roles'].push role
if data['group_ids'] if data['group_ids']
data['groups'] = [] data['groups'] = []
for group_id in data['group_ids'] for group_id in data['group_ids']
if App.Group.exists(group_id) if App.Group.exists(group_id)
group = App.Group.find(group_id) group = App.Group.findNative(group_id)
data['groups'].push group data['groups'].push group
data data
@ -191,10 +191,10 @@ class App.User extends App.Model
# get all permissions of user # get all permissions of user
permissions = {} permissions = {}
for role_id in @role_ids for role_id in @role_ids
role = App.Role.find(role_id) role = App.Role.findNative(role_id)
if role.active is true if role.active is true
for permission_id in role.permission_ids for permission_id in role.permission_ids
permission = App.Permission.find(permission_id) permission = App.Permission.findNative(permission_id)
permissions[permission.name] = true permissions[permission.name] = true
for localKey in keys for localKey in keys