Last active
August 3, 2018 16:09
-
-
Save onechiporenko/d0d21f6c374804d51186ce0cde736ff7 to your computer and use it in GitHub Desktop.
Keyboard navigation demo (2.6.0)
This file contains hidden or 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
import ModelsTableRow from 'ember-models-table/components/models-table/row'; | |
import {on} from '@ember/object/evented'; | |
import {get} from '@ember/object'; | |
import {EKOnFocusMixin, EKMixin, keyDown} from 'ember-keyboard'; | |
export default ModelsTableRow.extend(EKMixin, EKOnFocusMixin, { | |
doubleClick() { | |
this.send('editRow'); | |
this._super(...arguments); | |
}, | |
cancelEditKeyDown: on(keyDown('Escape'), function() { | |
this.send('cancelEditRow'); | |
get(this, 'record').rollbackAttributes(); | |
}) | |
}); |
This file contains hidden or 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
import {EKOnInitMixin,EKOnInsertMixin, EKMixin, keyDown, keyUp} from 'ember-keyboard'; | |
import ModelsTable from 'ember-models-table/components/models-table'; | |
import {on} from '@ember/object/evented'; | |
import {get} from '@ember/object'; | |
function getSortEventListener(num) { | |
return on(keyDown(`ctrl+shift+Digit${num}`), function () { | |
if (get(this, 'processedColumns.length') <= num) { | |
this.send('sort', get(this, 'processedColumns').objectAt(num - 1)); | |
} | |
}); | |
} | |
function getToggleVisibilityEventListener(num) { | |
return on(keyDown(`ctrl+shift+Numpad${num}`), function () { | |
if (get(this, 'processedColumns.length') <= num) { | |
this.send('toggleHidden', get(this, 'processedColumns').objectAt(num - 1)); | |
} | |
}); | |
} | |
const MixinWithExtraListeners = {}; | |
for(let i = 1; i <= 3; i++) { | |
MixinWithExtraListeners[`sortByColumn${i}`] = getSortEventListener(i); | |
MixinWithExtraListeners[`toggleColumn${i}`] = getToggleVisibilityEventListener(i); | |
} | |
export default ModelsTable.extend(EKMixin, EKOnInsertMixin, MixinWithExtraListeners, { | |
leftKeyDown: on(keyDown('ctrl+ArrowLeft'), function () { | |
const pageToMove = get(this, 'currentPageNumber') - 1; | |
if (pageToMove >= 1) { | |
this.send('gotoCustomPage', get(this, 'currentPageNumber') - 1); | |
} | |
}), | |
rightKeyDown: on(keyDown('ctrl+ArrowRight'), function () { | |
const pageToMove = get(this, 'currentPageNumber') + 1; | |
const pagesCount = get(this, 'pagesCount'); | |
if (pageToMove <= pagesCount) { | |
this.send('gotoCustomPage', get(this, 'currentPageNumber') + 1); | |
} | |
}), | |
clearFiltersKeyDown: on(keyDown('ctrl+KeyQ'), function () { | |
this.send('clearFilters'); | |
}), | |
showAllColumnsKeyDown: on(keyDown('ctrl+shift+NumpadAdd'), function () { | |
this.send('showAllColumns'); | |
}), | |
hideAllColumnsKeyDown: on(keyDown('ctrl+shift+NumpadSubtract'), function () { | |
this.send('hideAllColumns'); | |
}), | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Keyboard navigation demo', | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
columns: [ | |
{ | |
title: 'Tag', | |
propertyName: 'tagName' | |
}, | |
{ | |
propertyName: 'publishedAt', | |
simple: true | |
}, | |
{ | |
title: 'Author', | |
propertyName: 'author.login' | |
}, | |
{ | |
component: 'editRow', | |
editable: false | |
} | |
], | |
actions: { | |
onSaveRow(param) { | |
return param.record.save(); | |
}, | |
onCancelRow( { record } ) { | |
record.rollbackAttributes(); | |
return true; | |
} | |
} | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.get('store').query('github-release', { repo: 'emberjs/ember.js', per_page: 100 }); | |
} | |
}); |
This file contains hidden or 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
{ | |
"version": "0.14.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.18.2", | |
"ember-template-compiler": "2.18.2", | |
"ember-testing": "2.18.2", | |
"bs-css": "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", | |
"bs-js": "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" | |
}, | |
"addons": { | |
"ember-data": "2.18.2", | |
"ember-models-table": "2.6.0", | |
"ember-keyboard": "3.0.2", | |
"ember-data-github": "0.7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment