Skip to content

Commit

Permalink
fix ordering of event segs in timegrid, for print preview. fixes #4432
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Mar 8, 2019
1 parent e03eb3f commit 333adc2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/timegrid/TimeGridEventRenderer.ts
Expand Up @@ -14,7 +14,7 @@ Does not own rendering. Use for low-level util methods by TimeGrid.
export default class TimeGridEventRenderer extends FgEventRenderer {

timeGrid: TimeGrid
segsByCol: any
segsByCol: any // within each col, events are ordered
fullTimeFormat: DateFormatter


Expand All @@ -34,8 +34,16 @@ export default class TimeGridEventRenderer extends FgEventRenderer {
// Given an array of foreground segments, render a DOM element for each, computes position,
// and attaches to the column inner-container elements.
attachSegs(segs: Seg[], mirrorInfo) {
this.segsByCol = this.timeGrid.groupSegsByCol(segs)
this.timeGrid.attachSegsByCol(this.segsByCol, this.timeGrid.fgContainerEls)
let segsByCol = this.timeGrid.groupSegsByCol(segs)

// order the segs within each column
// TODO: have groupSegsByCol do this?
for (let col = 0; col < segsByCol.length; col++) {
segsByCol[col] = this.sortEventSegs(segsByCol[col])
}

this.segsByCol = segsByCol
this.timeGrid.attachSegsByCol(segsByCol, this.timeGrid.fgContainerEls)
}


Expand Down Expand Up @@ -171,13 +179,13 @@ export default class TimeGridEventRenderer extends FgEventRenderer {


// Given an array of segments that are all in the same column, sets the backwardCoord and forwardCoord on each.
// Assumed the segs are already ordered.
// NOTE: Also reorders the given array by date!
computeSegHorizontals(segs: Seg[]) {
let levels
let level0
let i

segs = this.sortEventSegs(segs) // order by certain criteria
levels = buildSlotSegLevels(segs)
computeForwardSlotSegs(levels)

Expand Down
31 changes: 31 additions & 0 deletions tests/automated/event-render/print-preview.js
@@ -0,0 +1,31 @@

describe('print preview', function() {
pushOptions({
defaultDate: '2019-04-08',
scrollTime: '00:00',
events: [
{ id: '2', start: '2019-04-08T05:00:00' },
{ id: '1', start: '2019-04-08T01:00:00' }
],
eventRender: function(arg) {
arg.el.setAttribute('data-id', arg.event.id)
}
})

describeOptions('defaultView', {
'with timeGrid view': 'timeGridDay',
'with dayGrid view': 'dayGridDay'
}, function() {

it('orders events in DOM by start time', function() {
initCalendar()

let ids = $('.fc-event').map(function(i, el) {
return el.getAttribute('data-id')
}).get()

expect(ids).toEqual([ '1', '2' ])
})
})

})

0 comments on commit 333adc2

Please sign in to comment.