Skip to content

Commit

Permalink
Stilted table generation into separate eco files. Improved mem usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Mar 18, 2017
1 parent d2070f4 commit 21d575d
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class App.ControllerTable extends App.Controller
console.log('new header is', headers)
headers
callbackAttributes = (value, object, attribute, header, refObject) ->
console.log('data of item col', value, object, attribute, header, refObject)
callbackAttributes = (value, object, attribute, header) ->
console.log('data of item col', value, object, attribute, header)
value = 'New Data To Show'
value
Expand Down Expand Up @@ -288,19 +288,44 @@ class App.ControllerTable extends App.Controller
if @tableId
@calculateHeaderWidths()

# get content
# generate content
position = 0
columnsLength = @headers.length
if @checkbox || @radio
columnsLength++
groupLast = ''
tableBody = ''
for object in @objects
if @groupBy
groupByName = App.viewPrint(object, @groupBy, attributes)
if groupLast isnt groupByName
groupLast = groupByName
tableBody += App.view('generic/table_row_group_by')(
position: position
groupByName: groupByName
columnsLength: columnsLength
)
position++
tableBody += App.view('generic/table_row')(
headers: @headers
attributes: attributes
checkbox: @checkbox
radio: @radio
callbacks: @callbackAttributes
sortable: @dndCallback
position: position
object: object
)

# generate full table
table = App.view('generic/table')(
tableId: @tableId
header: @headers
attributes: attributes
objects: @objects
headers: @headers
checkbox: @checkbox
radio: @radio
groupBy: @groupBy
class: @class
destroy: destroy
callbacks: @callbackAttributes
sortable: @dndCallback
tableBody: tableBody
)

# convert to jquery object
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/app/controllers/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class Index extends App.ControllerSubContent
headers.splice(4, 0, attribute)
headers

callbackViewAttributes = (value, object, attribute, header, refObject) ->
callbackViewAttributes = (value, object, attribute, header) ->
value = 'X'
value

callbackTokenAttributes = (value, object, attribute, header, refObject) ->
callbackTokenAttributes = (value, object, attribute, header) ->
value = 'X'
value

Expand Down
67 changes: 16 additions & 51 deletions app/assets/javascripts/app/controllers/ticket_overview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -608,48 +608,6 @@ class App.TicketOverview extends App.Controller
valid_user_ids.push user_id
group.valid_user_ids = valid_user_ids

###
users = [
App.User.find(2),
App.User.find(2),
App.User.find(2),
]
macros = [
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close Beispiel für eine besonders'
},
{
name: 'Close & Tag as Spam'
},
{
name: 'Close & Reply we\'re on Holidays'
},
{
name: 'Escalate to 2nd level'
},
{
name: '1st Close'
},
]
###
@batchAssignInner.html $(App.view('ticket_overview/batch_overlay_user_group')(
users: users
groups: groups
Expand Down Expand Up @@ -1036,23 +994,30 @@ class Table extends App.Controller
show: true
)
@navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) ->
callbackTicketTitleAdd = (value, object, attribute, attributes) ->
attribute.title = object.title
value
callbackLinkToTicket = (value, object, attribute, attributes, refObject) ->
callbackLinkToTicket = (value, object, attribute, attributes) ->
attribute.link = object.uiUrl()
value
callbackUserPopover = (value, object, attribute, attributes, refObject) ->
return value if !refObject
callbackUserPopover = (value, object, attribute, attributes) ->
return value if !object
refObjectId = undefined
if attribute.name is 'customer_id'
refObjectId = object.customer_id
if attribute.name is 'owner_id'
refObjectId = object.owner_id
return value if !refObjectId
attribute.class = 'user-popover'
attribute.data =
id: refObject.id
id: refObjectId
value
callbackOrganizationPopover = (value, object, attribute, attributes, refObject) ->
return value if !refObject
callbackOrganizationPopover = (value, object, attribute, attributes) ->
return value if !object
return value if !object.organization_id
attribute.class = 'organization-popover'
attribute.data =
id: refObject.id
id: object.organization_id
value
callbackCheckbox = (id, checked, e) =>
if @$('table').find('input[name="bulk"]:checked').length == 0
Expand Down Expand Up @@ -1089,7 +1054,7 @@ class Table extends App.Controller
headers.unshift(0)
headers[0] = attribute
headers
callbackIcon = (value, object, attribute, header, refObject) ->
callbackIcon = (value, object, attribute, header) ->
value = ' '
attribute.class = object.iconClass()
attribute.link = ''
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/controllers/users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Index extends App.ControllerSubContent
header.push attribute
header

callbackAttributes = (value, object, attribute, header, refObject) ->
callbackAttributes = (value, object, attribute, header) ->
text = App.i18n.translateInline('View from user\'s perspective')
value = ' '
attribute.raw = ' <span class="btn btn--primary btn--table switchView" title="' + text + '">' + App.Utils.icon('switchView') + text + '</span>'
Expand Down
26 changes: 17 additions & 9 deletions app/assets/javascripts/app/controllers/widget/ticket_list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ class App.TicketList extends App.Controller
openTicket = (id,e) =>
ticket = App.Ticket.findNative(id)
@navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) ->
callbackTicketTitleAdd = (value, object, attribute, attributes) ->
attribute.title = object.title
value
callbackLinkToTicket = (value, object, attribute, attributes, refObject) ->
callbackLinkToTicket = (value, object, attribute, attributes) ->
attribute.link = object.uiUrl()
value
callbackUserPopover = (value, object, attribute, attributes, refObject) ->
return value if !refObject
callbackUserPopover = (value, object, attribute, attributes) ->
return value if !object
refObjectId = undefined
if attribute.name is 'customer_id'
refObjectId = object.customer_id
if attribute.name is 'owner_id'
refObjectId = object.owner_id
return value if !refObjectId
attribute.class = 'user-popover'
attribute.data =
id: refObject.id
id: refObjectId
value
callbackOrganizationPopover = (value, object, attribute, attributes, refObject) ->
return value if !refObject
callbackOrganizationPopover = (value, object, attribute, attributes) ->
return value if !object
return value if !object.organization_id
attribute.class = 'organization-popover'
attribute.data =
id: refObject.id
id: object.organization_id
value

callbackIconHeader = (headers) ->
Expand All @@ -39,7 +46,8 @@ class App.TicketList extends App.Controller
headers.unshift(0)
headers[0] = attribute
headers
callbackIcon = (value, object, attribute, header, refObject) ->

callbackIcon = (value, object, attribute, header) ->
value = ' '
attribute.class = object.iconClass()
attribute.link = ''
Expand Down
77 changes: 38 additions & 39 deletions app/assets/javascripts/app/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,57 @@
#= require_tree ./lib/app_post

class App extends Spine.Controller
@viewPrint: (object, attribute_name, attributes) ->
@viewPrint: (object, attributeName, attributes) ->
if !attributes
attributes = {}
if object.constructor.attributesGet
attributes = object.constructor.attributesGet()
attribute_config = attributes[attribute_name]
value = object[attribute_name]
valueRef = undefined
attributeConfig = attributes[attributeName]
value = object[attributeName]
valueRef = undefined

# check if relation is requested
if !attribute_config
attribute_name_new = "#{attribute_name}_id"
attribute_config = attributes[attribute_name_new]
if attribute_config
attribute_name = attribute_name_new
if object[attribute_name]
if !attributeConfig
attributeNameNew = "#{attributeName}_id"
attributeConfig = attributes[attributeNameNew]
if attributeConfig
attributeName = attributeNameNew
if object[attributeName]
valueRef = value
value = object[attribute_name]
value = object[attributeName]

# in case of :: key, get the sub value
if !value
parts = attribute_name.split('::')
parts = attributeName.split('::')
if parts[0] && parts[1] && object[ parts[0] ]
value = object[ parts[0] ][ parts[1] ]

# if we have no config, get output this way
if !attribute_config
if !attributeConfig
return @viewPrintItem(value)

# check if valueRef already exists, no lookup needed later
if !valueRef
attribute_name_without_ref = attribute_name.substr(attribute_name.length-3, attribute_name.length)
if attribute_name_without_ref is '_id'
attribute_name_without_ref = attribute_name.substr(0, attribute_name.length-3)
if object[attribute_name_without_ref]
valueRef = object[attribute_name_without_ref]
if attributeName.substr(attributeName.length-3, attributeName.length) is '_id'
attributeNameWithoutRef = attributeName.substr(0, attributeName.length-3)
if object[attributeNameWithoutRef]
valueRef = object[attributeNameWithoutRef]

@viewPrintItem(value, attribute_config, valueRef)
@viewPrintItem(value, attributeConfig, valueRef)

# define print name helper
@viewPrintItem: (item, attribute_config = {}, valueRef) ->
@viewPrintItem: (item, attributeConfig = {}, valueRef) ->
return '-' if item is undefined
return '-' if item is ''
return item if item is null
result = item

# lookup relation
if attribute_config.relation || valueRef
if attributeConfig.relation || valueRef
if valueRef
item = valueRef
else
item = App[attribute_config.relation].find(item)
item = App[attributeConfig.relation].find(item)

# if date is a object, get name of the object
isObject = false
Expand All @@ -74,57 +73,57 @@ class App extends Spine.Controller
result = item.name

# execute callback on content
if attribute_config.callback
result = attribute_config.callback(result, attribute_config)
if attributeConfig.callback
result = attributeConfig.callback(result, attributeConfig)

# text2html in textarea view
isHtmlEscape = false
if attribute_config.tag is 'textarea'
if attributeConfig.tag is 'textarea'
isHtmlEscape = true
result = App.Utils.text2html(result)

# remember, html snippets are already escaped
else if attribute_config.tag is 'richtext'
else if attributeConfig.tag is 'richtext'
isHtmlEscape = true

# fillup options
if !_.isEmpty(attribute_config.options)
if attribute_config.options[result]
result = attribute_config.options[result]
if !_.isEmpty(attributeConfig.options)
if attributeConfig.options[result]
result = attributeConfig.options[result]

# transform boolean
if attribute_config.tag is 'boolean'
if attributeConfig.tag is 'boolean'
if result is true
result = 'yes'
else if result is false
result = 'no'

# translate content
if attribute_config.translate || (isObject && item.translate && item.translate())
if attributeConfig.translate || (isObject && item.translate && item.translate())
isHtmlEscape = true
result = App.i18n.translateContent(result)

# transform date
if attribute_config.tag is 'date'
if attributeConfig.tag is 'date'
isHtmlEscape = true
result = App.i18n.translateDate(result)

# transform input tel|url to make it clickable
if attribute_config.tag is 'input'
if attribute_config.type is 'tel'
if attributeConfig.tag is 'input'
if attributeConfig.type is 'tel'
result = "<a href=\"#{App.Utils.phoneify(result)}\">#{App.Utils.htmlEscape(result)}</a>"
else if attribute_config.type is 'url'
else if attributeConfig.type is 'url'
result = App.Utils.linkify(result)
else
result = App.Utils.htmlEscape(result)
isHtmlEscape = true

# use pretty time for datetime
else if attribute_config.tag is 'datetime'
else if attributeConfig.tag is 'datetime'
isHtmlEscape = true
timestamp = App.i18n.translateTimestamp(result)
escalation = false
cssClass = attribute_config.class || ''
cssClass = attributeConfig.class || ''
if cssClass.match 'escalation'
escalation = true
humanTime = App.PrettyDate.humanTime(result, escalation)
Expand All @@ -139,8 +138,8 @@ class App extends Spine.Controller
template = (params = {}) ->

# define print name helper
params.P = (object, attribute_name, attributes) ->
App.viewPrint(object, attribute_name, attributes)
params.P = (object, attributeName, attributes) ->
App.viewPrint(object, attributeName, attributes)

# define date format helper
params.date = (time) ->
Expand Down
Loading

0 comments on commit 21d575d

Please sign in to comment.