Fixed issue #1595 - Unable to sort overview by priority.

This commit is contained in:
Martin Edenhofer 2017-10-30 09:55:03 +01:00
parent 0afcc33b14
commit 7bf73984c4
3 changed files with 244 additions and 18 deletions

View file

@ -235,9 +235,9 @@ class App.ControllerTable extends App.Controller
removedRows = _.difference(@currentRows, newRows)
addedRows = _.difference(newRows, @currentRows)
#console.log('newRows', newRows)
#console.log('removedRows', removedRows)
#console.log('addedRows', addedRows)
@log 'debug', 'table newRows', newRows
@log 'debug', 'table removedRows', removedRows
@log 'debug', 'table addedRows', addedRows
# if only rows are removed
if (!_.isEmpty(addedRows) || !_.isEmpty(removedRows)) && addedRows.length < 10 && removedRows.length < 15 && removedRows.length < newRows.length && !_.isEmpty(newRows)
@ -267,24 +267,24 @@ class App.ControllerTable extends App.Controller
else
@$("tbody > tr:nth-child(#{position})").after(newCurrentRows[position])
@currentRows = newCurrentRows
#console.log('fullRender.contentRemoved', removePositions, addPositions)
@log 'debug', 'table.fullRender.contentRemoved', removePositions, addPositions
@renderPager(@el, true)
return ['fullRender.contentRemoved', removePositions, addPositions]
if newRows.length isnt @currentRows.length
result = ['fullRender.lenghtChanged', @currentRows.length, newRows.length]
@renderTableFull(newRows)
#console.log('result', result)
@log 'debug', 'table.fullRender.lenghtChanged', result
return result
# compare rows
result = @_isSame(newRows, @currentRows)
if result isnt true
@renderTableFull(newRows)
#console.log('result', "fullRender.contentChanged|row(#{result})")
@log 'debug', "table.fullRender.contentChanged|row(#{result})"
return ['fullRender.contentChanged', result]
#console.log('result', 'noChanges')
@log 'debug', 'table.noChanges'
return ['noChanges']
renderEmptyList: =>
@ -293,7 +293,7 @@ class App.ControllerTable extends App.Controller
)
renderTableFull: (rows) =>
#console.log('renderTableFull', @orderBy, @orderDirection, @objects)
@log 'debug', 'table.renderTableFull', @orderBy, @orderDirection
@tableHeaders()
@sortList()
bulkIds = @getBulkSelected()
@ -499,9 +499,8 @@ class App.ControllerTable extends App.Controller
orderBy = @customOrderBy || @orderBy
orderDirection = @customOrderDirection || @orderDirection
#console.log('LLL', @lastOrderBy, @orderBy, @lastOrderDirection, @orderDirection, @overviewAttributes, @lastOverview)
if @headers && @lastOrderBy is orderBy && @lastOrderDirection is orderDirection && !@tableHeadersHasChanged()
#console.log('tableHeaders: same overviewAttributes just return headers', @headers)
@log 'debug', 'table.Headers: same overviewAttributes just return headers', @headers
return ['headers are the same', @headers]
@lastOverview = @overviewAttributes
@ -582,7 +581,7 @@ class App.ControllerTable extends App.Controller
@columnsLength = @headers.length
if @checkbox || @radio
@columnsLength++
#console.log('tableHeaders: new headers', @headers)
@log 'debug', 'table.Headers: new headers', @headers
['new headers', @headers]
setMaxPage: =>
@ -600,8 +599,8 @@ class App.ControllerTable extends App.Controller
orderBy = @customOrderBy || @orderBy
orderDirection = @customOrderDirection || @orderDirection
#console.log('order', @orderBy, @orderDirection)
#console.log('customOrder', @customOrderBy, @customOrderDirection)
@log 'debug', 'table.order', @orderBy, @orderDirection
@log 'debug', 'table.customOrder', @customOrderBy, @customOrderDirection
return if _.isEmpty(orderBy) && _.isEmpty(@groupBy)
@ -609,9 +608,10 @@ class App.ControllerTable extends App.Controller
@lastOrderDirection = orderDirection
@lastOrderBy = orderBy
localObjects is undefined
if orderBy
for header in @headers
if header.name is orderBy || "#{header.name}_id" is orderBy
if header.name is orderBy || "#{header.name}_id" is orderBy || header.name is "#{orderBy}_id"
localObjects = _.sortBy(
@objects
(item) ->
@ -649,7 +649,7 @@ class App.ControllerTable extends App.Controller
# in case order by is not in show column, use orderBy attribute
if !localObjects
for attributeName, attribute of @attributesList
if attributeName is orderBy || "#{attributeName}_id" is orderBy
if attributeName is orderBy || "#{attributeName}_id" is orderBy || attributeName is "#{orderBy}_id"
# order by
localObjects = _.sortBy(
@ -722,6 +722,7 @@ class App.ControllerTable extends App.Controller
localObjects = localObjects.concat groupObjects[group]
groupObjects[group] = [] # release old array
return if localObjects is undefined
@objects = localObjects
@lastSortedobjects = localObjects

View file

@ -196,7 +196,7 @@ set new attributes of model (remove already available attributes)
for attribute in attributes
App[@.className].attributes.push attribute.name
attributesNew.push attribute
App[ @.className ].configure_attributes = attributesNew
App[@.className].configure_attributes = attributesNew
###
@ -226,7 +226,7 @@ set new attributes of model (remove already available attributes)
@attributesGet: (screen = undefined, attributes = false, noDefaultAttributes = false) ->
if !attributes
attributes = clone(App[ @.className ].configure_attributes, true)
attributes = clone(App[@.className].configure_attributes, true)
else
attributes = clone(attributes, true)

View file

@ -1321,7 +1321,7 @@ test('table new - initial list', function() {
equal(el.find('.js-pager').first().find('.js-page.is-selected').length, 1)
equal(el.find('.js-pager').first().find('.js-page.is-selected').text(), '1')
$('#table').append('<hr><h1>table with data</h1><div id="table-new7"></div>')
$('#table').append('<hr><h1>table with data 7</h1><div id="table-new7"></div>')
var el = $('#table-new7')
App.TicketPriority.refresh([
@ -1421,4 +1421,229 @@ test('table new - initial list', function() {
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
$('#table').append('<hr><h1>table with data 8</h1><div id="table-new8"></div>')
var el = $('#table-new8')
App.TicketPriority.refresh([
{
id: 1,
name: '1 low',
note: 'some note',
active: true,
created_at: '2014-06-12T11:17:34.000Z',
},
{
id: 2,
name: '2 normal',
note: 'some note 2',
active: false,
created_at: '2014-06-10T10:17:34.000Z',
},
{
id: 3,
name: '3 high',
note: 'some note 3',
active: false,
created_at: '2014-06-10T10:17:38.000Z',
},
], {clear: true})
var table = new App.ControllerTable({
el: el,
overviewAttributes: ['name', 'created_at', 'active'],
model: App.TicketPriority,
objects: App.TicketPriority.all(),
checkbox: false,
radio: false,
orderBy: 'not_existing',
orderDirection: 'DESC',
})
equal(el.find('table > thead > tr').length, 1, 'row count')
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '12.06.2014', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '3 hoch', 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
result = table.update({sync: true, objects: App.TicketPriority.all(), orderBy: 'not_existing', orderDirection: 'ASC'})
equal(result[0], 'noChanges')
$('#table').append('<hr><h1>table with data 9</h1><div id="table-new9"></div>')
var el = $('#table-new9')
App.TicketPriority.refresh([
{
id: 1,
name: '1 low',
external_id: 3,
note: 'some note',
active: true,
created_at: '2014-06-12T11:17:34.000Z',
},
{
id: 2,
name: '2 normal',
external_id: 2,
note: 'some note 2',
active: false,
created_at: '2014-06-10T10:17:34.000Z',
},
{
id: 3,
name: '3 high',
external_id: 1,
note: 'some note 3',
active: false,
created_at: '2014-06-10T10:17:38.000Z',
},
], {clear: true})
App.TicketPriority.resetAttributes()
App.TicketPriority.updateAttributes([{
name: 'external_id',
display: 'External',
tag: 'input',
readonly: 1,
}])
var table = new App.ControllerTable({
el: el,
overviewAttributes: ['name', 'created_at', 'active'],
model: App.TicketPriority,
objects: App.TicketPriority.all(),
checkbox: false,
radio: false,
orderBy: 'external',
orderDirection: 'DESC',
})
equal(el.find('table > thead > tr').length, 1, 'row count')
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '12.06.2014', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '3 hoch', 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
result = table.update({sync: true, objects: App.TicketPriority.all(), orderBy: 'external', orderDirection: 'ASC'})
equal(result[0], 'fullRender.contentChanged')
equal(result[1], 0)
equal(el.find('table > thead > tr').length, 1, 'row count')
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 3')
equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '3 hoch', 'check row 3')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '1 niedrig', 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '12.06.2014', 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
$('#table').append('<hr><h1>table with data 10</h1><div id="table-new10"></div>')
var el = $('#table-new10')
App.TicketPriority.refresh([
{
id: 1,
name: '1 low',
external_id: 3,
note: 'some note',
active: true,
created_at: '2014-06-12T11:17:34.000Z',
},
{
id: 2,
name: '2 normal',
external_id: 2,
note: 'some note 2',
active: false,
created_at: '2014-06-10T10:17:34.000Z',
},
{
id: 3,
name: '3 high',
external_id: 1,
note: 'some note 3',
active: false,
created_at: '2014-06-10T10:17:38.000Z',
},
], {clear: true})
App.TicketPriority.resetAttributes()
App.TicketPriority.updateAttributes([{
name: 'external',
display: 'External',
tag: 'input',
readonly: 1,
}])
var table = new App.ControllerTable({
el: el,
overviewAttributes: ['name', 'created_at', 'active'],
model: App.TicketPriority,
objects: App.TicketPriority.all(),
checkbox: false,
radio: false,
orderBy: 'external',
orderDirection: 'ASC',
})
equal(el.find('table > thead > tr').length, 1, 'row count')
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '12.06.2014', 'check row 1')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '3 hoch', 'check row 3')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
result = table.update({sync: true, objects: App.TicketPriority.all(), orderBy: 'external', orderDirection: 'DESC'})
equal(result[0], 'fullRender.contentChanged')
equal(result[1], 0)
equal(el.find('table > thead > tr').length, 1, 'row count')
equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 3')
equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '3 hoch', 'check row 3')
equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 3')
equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
equal(el.find('tbody > tr:nth-child(3) > td').length, 3, 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:first').text().trim(), '1 niedrig', 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '12.06.2014', 'check row 1')
equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
equal(el.find('tbody > tr:nth-child(4) > td').length, 0, 'check row 3')
})