-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline the ember-data-table components
This copies over the ember-data-table .js code so we no longer need the addon itself. We were already overriding all the templates. This will make things easier to maintain and improve in the future. Linting errors are silenced with inline ignore comments. They will be fixed once we convert the code to .gts.
- Loading branch information
Showing
13 changed files
with
1,159 additions
and
2,360 deletions.
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 |
---|---|---|
@@ -1,3 +1,47 @@ | ||
import DataTableContentBody from 'ember-data-table/components/data-table-content-body'; | ||
/* eslint-disable ember/no-actions-hash, ember/no-classic-classes, ember/no-classic-components, ember/no-get, ember/require-tagless-components */ | ||
import { set } from '@ember/object'; | ||
import { computed } from '@ember/object'; | ||
import Component from '@ember/component'; | ||
|
||
export default DataTableContentBody.extend({}); | ||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/data-table-content-body.js | ||
export default Component.extend({ | ||
tagName: 'tbody', | ||
init() { | ||
this._super(...arguments); | ||
if (!this['data-table']) this.set('data-table', {}); | ||
if (!this['content']) this.set('content', []); | ||
}, | ||
offset: computed('data-table.{page,size}', function () { | ||
var offset = 1; //to avoid having 0. row | ||
var page = this.get('data-table.page'); | ||
var size = this.get('data-table.size'); | ||
if (page && size) { | ||
offset += page * size; | ||
} | ||
return offset; | ||
}), | ||
wrappedItems: computed( | ||
'content', | ||
'content.[]', | ||
'data-table.selection.[]', | ||
function () { | ||
const selection = this.get('data-table.selection') || []; | ||
const content = this.content || []; | ||
return content.map(function (item) { | ||
return { item: item, isSelected: selection.includes(item) }; | ||
}); | ||
}, | ||
), | ||
actions: { | ||
updateSelection(selectedWrapper, event) { | ||
set(selectedWrapper, 'isSelected', event.target.checked); | ||
this.wrappedItems.forEach((wrapper) => { | ||
if (wrapper.isSelected) { | ||
this.get('data-table').addItemToSelection(wrapper.item); | ||
} else { | ||
this.get('data-table').removeItemFromSelection(wrapper.item); | ||
} | ||
}); | ||
}, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import DataTableContentHeader from 'ember-data-table/components/data-table-content-header'; | ||
/* eslint-disable ember/no-classic-classes, ember/no-classic-components, ember/require-tagless-components */ | ||
import { oneWay } from '@ember/object/computed'; | ||
import { alias } from '@ember/object/computed'; | ||
import Component from '@ember/component'; | ||
|
||
export default DataTableContentHeader.extend({}); | ||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/data-table-content-header.js | ||
export default Component.extend({ | ||
tagName: 'thead', | ||
sort: alias('data-table.sort'), | ||
fields: oneWay('data-table.parsedFields'), | ||
}); |
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
48 changes: 46 additions & 2 deletions
48
addon/components/au-data-table/default-data-table-content-body.js
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 |
---|---|---|
@@ -1,3 +1,47 @@ | ||
import DefaultDataTableContentBody from 'ember-data-table/components/default-data-table-content-body'; | ||
/* eslint-disable ember/no-actions-hash, ember/no-classic-classes, ember/no-classic-components, ember/no-get, ember/require-tagless-components */ | ||
import { set } from '@ember/object'; | ||
import { computed } from '@ember/object'; | ||
import Component from '@ember/component'; | ||
|
||
export default DefaultDataTableContentBody.extend({}); | ||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/default-data-table-content-body.js | ||
export default Component.extend({ | ||
tagName: 'tbody', | ||
init() { | ||
this._super(...arguments); | ||
if (!this['data-table']) this.set('data-table', {}); | ||
if (!this['content']) this.set('content', []); | ||
}, | ||
offset: computed('data-table.{page,size}', function () { | ||
var offset = 1; //to avoid having 0. row | ||
var page = this.get('data-table.page'); | ||
var size = this.get('data-table.size'); | ||
if (page && size) { | ||
offset += page * size; | ||
} | ||
return offset; | ||
}), | ||
wrappedItems: computed( | ||
'content', | ||
'content.[]', | ||
'data-table.selection.[]', | ||
function () { | ||
const selection = this.get('data-table.selection') || []; | ||
const content = this.content || []; | ||
return content.map(function (item) { | ||
return { item: item, isSelected: selection.includes(item) }; | ||
}); | ||
}, | ||
), | ||
actions: { | ||
updateSelection(selectedWrapper, event) { | ||
set(selectedWrapper, 'isSelected', event.target.checked); | ||
this.wrappedItems.forEach((wrapper) => { | ||
if (wrapper.isSelected) { | ||
this.get('data-table').addItemToSelection(wrapper.item); | ||
} else { | ||
this.get('data-table').removeItemFromSelection(wrapper.item); | ||
} | ||
}); | ||
}, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import DataTableMenuGeneral from 'ember-data-table/components/data-table-menu-general'; | ||
/* eslint-disable ember/no-classic-classes, ember/no-classic-components, ember/require-tagless-components */ | ||
import Component from '@ember/component'; | ||
|
||
export default DataTableMenuGeneral.extend({}); | ||
export default Component.extend({}); |
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 |
---|---|---|
@@ -1,3 +1,17 @@ | ||
import DataTableMenuSelected from 'ember-data-table/components/data-table-menu-selected'; | ||
/* eslint-disable ember/no-actions-hash, ember/no-classic-classes, ember/no-classic-components, ember/no-get, ember/require-tagless-components */ | ||
import { reads } from '@ember/object/computed'; | ||
import Component from '@ember/component'; | ||
|
||
export default DataTableMenuSelected.extend({}); | ||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/data-table-menu-selected.js | ||
export default Component.extend({ | ||
init: function () { | ||
this._super(...arguments); | ||
this.set('data-table.enableSelection', true); | ||
}, | ||
selectionCount: reads('data-table.selection.length'), | ||
actions: { | ||
clearSelection() { | ||
this.get('data-table').clearSelection(); | ||
}, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import DataTableMenu from 'ember-data-table/components/data-table-menu'; | ||
/* eslint-disable ember/no-classic-classes, ember/no-classic-components, ember/require-tagless-components */ | ||
import Component from '@ember/component'; | ||
|
||
export default DataTableMenu.extend({}); | ||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/data-table-menu.js | ||
export default Component.extend({ | ||
classNames: ['data-table-menu'], | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,46 @@ | ||
import TextSearch from 'ember-data-table/components/text-search'; | ||
/* eslint-disable ember/no-classic-classes, ember/no-classic-components, ember/no-observers, ember/require-tagless-components */ | ||
import { isEqual } from '@ember/utils'; | ||
import { cancel, debounce } from '@ember/runloop'; | ||
import { observer } from '@ember/object'; | ||
import { oneWay } from '@ember/object/computed'; | ||
import Component from '@ember/component'; | ||
import { SearchIcon } from '../icons/search'; | ||
|
||
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/text-search.js | ||
const TextSearch = Component.extend({ | ||
filter: '', | ||
classNames: ['data-table-search'], | ||
internalValue: oneWay('filter'), | ||
auto: true, | ||
placeholder: 'Search', | ||
init() { | ||
this._super(...arguments); | ||
this.set('value', this.filter); | ||
}, | ||
onValueChange: observer('value', function () { | ||
this._valuePid = debounce(this, this._setFilter, this.wait); | ||
}), | ||
onFilterChange: observer('filter', function () { | ||
// update value if filter is update manually outsite this component | ||
if ( | ||
!this.isDestroying && | ||
!this.isDestroyed && | ||
!isEqual(this.filter, this.value) | ||
) { | ||
this.set('value', this.filter); | ||
} | ||
}), | ||
_setFilter() { | ||
if (!this.isDestroying && !this.isDestroyed) { | ||
this.set('filter', this.value); | ||
} | ||
}, | ||
willDestroy() { | ||
this._super(...arguments); | ||
cancel(this._valuePid); | ||
}, | ||
}); | ||
|
||
export default TextSearch.extend({ | ||
SearchIcon, | ||
}); |
Oops, something went wrong.