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

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').length, 1)
equal(el.find('.js-pager').first().find('.js-page.is-selected').text(), '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') var el = $('#table-new7')
App.TicketPriority.refresh([ 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(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') 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')
}) })