-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
thead, th, and tr to classic components #680
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
98505c1
thead, th, and tr to classic components
nummi 4cdf2db
Fix some tests
RobbieTheWagner baf6790
Add missing attributeBindings
RobbieTheWagner 37159a7
Use defaultTo for sortFunction and compareFunction
RobbieTheWagner 6e9ccef
fix defaultTo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,7 @@ | |
import BaseTableCell from '../-private/base-table-cell'; | ||
import { next } from '@ember/runloop'; | ||
|
||
import { action } from '@ember-decorators/object'; | ||
import { readOnly } from '@ember-decorators/object/computed'; | ||
import { attribute, className, tagName } from '@ember-decorators/component'; | ||
import { argument } from '@ember-decorators/argument'; | ||
import { required } from '@ember-decorators/argument/validation'; | ||
import { type, optional } from '@ember-decorators/argument/type'; | ||
import { Action } from '@ember-decorators/argument/types'; | ||
|
||
import { readOnly } from '@ember/object/computed'; | ||
import { closest } from '../../-private/utils/element'; | ||
|
||
import layout from './template'; | ||
|
@@ -39,95 +32,85 @@ const COLUMN_REORDERING = 2; | |
@yield {object} columnValue - The column definition | ||
@yield {object} columnMeta - The meta object associated with this column | ||
*/ | ||
@tagName('th') | ||
export default class EmberTh extends BaseTableCell { | ||
layout = layout; | ||
|
||
export default BaseTableCell.extend({ | ||
layout, | ||
tagName: 'th', | ||
attributeBindings: ['columnSpan:colspan', 'rowSpan:rowspan'], | ||
classNameBindings: ['isSortable', 'isResizable', 'isReorderable'], | ||
|
||
/** | ||
The API object passed in by the table row | ||
@argument | ||
@required | ||
@type('object') | ||
*/ | ||
@argument | ||
@required | ||
@type('object') | ||
api; | ||
api: null, | ||
|
||
/** | ||
Action sent when the user clicks right this element | ||
@argument | ||
@type(optional(Action)) | ||
*/ | ||
@argument | ||
@type(optional(Action)) | ||
onContextMenu; | ||
onContextMenu: null, | ||
|
||
@readOnly('api.columnValue') | ||
columnValue; | ||
columnValue: readOnly('api.columnValue'), | ||
|
||
@readOnly('api.columnMeta') | ||
columnMeta; | ||
columnMeta: readOnly('api.columnMeta'), | ||
|
||
/** | ||
Any sorts applied to the table. | ||
*/ | ||
@readOnly('api.sorts') | ||
sorts; | ||
sorts: readOnly('api.sorts'), | ||
|
||
/** | ||
Whether or not the column is sortable. Is true IFF the column is a leaf node | ||
onUpdateSorts is set on the thead. | ||
*/ | ||
@className | ||
@readOnly('columnMeta.isSortable') | ||
isSortable; | ||
isSortable: readOnly('columnMeta.isSortable'), | ||
|
||
/** | ||
Indicates if this column can be resized. | ||
*/ | ||
@className | ||
@readOnly('columnMeta.isResizable') | ||
isResizable; | ||
isResizable: readOnly('columnMeta.isResizable'), | ||
|
||
/** | ||
Indicates if this column can be reordered. | ||
*/ | ||
@className | ||
@readOnly('columnMeta.isReorderable') | ||
isReorderable; | ||
isReorderable: readOnly('columnMeta.isReorderable'), | ||
|
||
@attribute('colspan') | ||
@readOnly('columnMeta.columnSpan') | ||
columnSpan; | ||
columnSpan: readOnly('columnMeta.columnSpan'), | ||
|
||
@attribute('rowspan') | ||
@readOnly('columnMeta.rowSpan') | ||
rowSpan; | ||
rowSpan: readOnly('columnMeta.rowSpan'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/** | ||
A variable used for column resizing & ordering. When user press mouse at a point that's close | ||
to column boundary (using some threshold), this variable set whether it's the left or right | ||
column. | ||
*/ | ||
_columnState = COLUMN_INACTIVE; | ||
_columnState: COLUMN_INACTIVE, | ||
|
||
/** | ||
An object that listens to touch/ press/ drag events. | ||
*/ | ||
_hammer = null; | ||
_hammer: null, | ||
|
||
didInsertElement() { | ||
super.didInsertElement(...arguments); | ||
this._super(...arguments); | ||
|
||
this.get('columnMeta').registerElement(this.element); | ||
|
||
let hammer = new Hammer(this.element); | ||
|
||
hammer.add(new Hammer.Press({ time: 0 })); | ||
|
||
hammer.on('press', this.pressHandler); | ||
hammer.on('panstart', this.panStartHandler); | ||
hammer.on('panmove', this.panMoveHandler); | ||
hammer.on('panend', this.panEndHandler); | ||
hammer.on('press', this.pressHandler.bind(this)); | ||
hammer.on('panstart', this.panStartHandler.bind(this)); | ||
hammer.on('panmove', this.panMoveHandler.bind(this)); | ||
hammer.on('panend', this.panEndHandler.bind(this)); | ||
|
||
this._hammer = hammer; | ||
} | ||
}, | ||
|
||
willDestroyElement() { | ||
let hammer = this._hammer; | ||
|
@@ -139,13 +122,14 @@ export default class EmberTh extends BaseTableCell { | |
|
||
hammer.destroy(); | ||
|
||
super.willDestroyElement(...arguments); | ||
} | ||
this._super(...arguments); | ||
}, | ||
|
||
@action | ||
sendDropdownAction(...args) { | ||
this.sendAction('onDropdownAction', ...args); | ||
} | ||
actions: { | ||
sendDropdownAction(...args) { | ||
this.sendAction('onDropdownAction', ...args); | ||
}, | ||
}, | ||
|
||
click(event) { | ||
let isSortable = this.get('isSortable'); | ||
|
@@ -156,12 +140,12 @@ export default class EmberTh extends BaseTableCell { | |
|
||
this.updateSort({ toggle }); | ||
} | ||
} | ||
}, | ||
|
||
contextMenu(event) { | ||
this.sendAction('onContextMenu', event); | ||
return false; | ||
} | ||
}, | ||
|
||
keyUp(event) { | ||
let isSortable = this.get('isSortable'); | ||
|
@@ -175,7 +159,7 @@ export default class EmberTh extends BaseTableCell { | |
) { | ||
this.updateSort(); | ||
} | ||
} | ||
}, | ||
|
||
updateSort({ toggle }) { | ||
let valuePath = this.get('columnValue.valuePath'); | ||
|
@@ -191,16 +175,16 @@ export default class EmberTh extends BaseTableCell { | |
} | ||
|
||
this.get('api').sendUpdateSort(newSortings); | ||
} | ||
}, | ||
|
||
pressHandler = event => { | ||
pressHandler(event) { | ||
let [{ clientX, target }] = event.pointers; | ||
|
||
this._originalClientX = clientX; | ||
this._originalTargetWasResize = target.classList.contains('et-header-resize-area'); | ||
}; | ||
}, | ||
|
||
panStartHandler = event => { | ||
panStartHandler(event) { | ||
let isResizable = this.get('isResizable'); | ||
let isReorderable = this.get('isReorderable'); | ||
|
||
|
@@ -215,9 +199,9 @@ export default class EmberTh extends BaseTableCell { | |
|
||
this.get('columnMeta').startReorder(clientX); | ||
} | ||
}; | ||
}, | ||
|
||
panMoveHandler = event => { | ||
panMoveHandler(event) { | ||
let [{ clientX }] = event.pointers; | ||
|
||
if (this._columnState === COLUMN_RESIZING) { | ||
|
@@ -227,15 +211,15 @@ export default class EmberTh extends BaseTableCell { | |
this.get('columnMeta').updateReorder(clientX); | ||
this._columnState = COLUMN_REORDERING; | ||
} | ||
}; | ||
}, | ||
|
||
panEndHandler = () => { | ||
panEndHandler() { | ||
if (this._columnState === COLUMN_RESIZING) { | ||
this.get('columnMeta').endResize(); | ||
} else if (this._columnState === COLUMN_REORDERING) { | ||
this.get('columnMeta').endReorder(); | ||
} | ||
|
||
next(() => (this._columnState = COLUMN_INACTIVE)); | ||
}; | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added to
attributeBindings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!