From d8f5bc310027844c31781e96e80e5e2a3484b55f Mon Sep 17 00:00:00 2001 From: Gokul Kathirvel Date: Mon, 2 Jul 2018 02:05:43 +0530 Subject: [PATCH] adds keyboard shortcuts for `run now` and `save` (#628) * adds keyboard shortcuts for `run now` and `save` * adds deps for unit test * using e-keyboard test helper * minor tweaks --- app/components/main-gist.js | 22 +++++++++++-- app/routes/gist.js | 5 ++- app/templates/components/gist-header.hbs | 2 +- app/templates/components/main-gist.hbs | 1 + .../components/saved-state-indicator.hbs | 4 ++- app/templates/gist.hbs | 2 ++ package.json | 1 + tests/acceptance/code-comment-test.js | 3 +- tests/acceptance/run-now-test.js | 32 +++++++++++++++---- tests/acceptance/save-test.js | 15 +++++++++ tests/helpers/start-app.js | 2 ++ tests/unit/components/main-gist-test.js | 3 +- yarn.lock | 6 ++++ 13 files changed, 82 insertions(+), 16 deletions(-) diff --git a/app/components/main-gist.js b/app/components/main-gist.js index a6d37967..74bf5212 100644 --- a/app/components/main-gist.js +++ b/app/components/main-gist.js @@ -4,10 +4,11 @@ import ColumnsMixin from "../mixins/columns"; import FilesMixin from "../mixins/files"; import TestFilesMixin from "../mixins/test-files"; import AppBuilderMixin from "../mixins/app-builder"; +import { keyDown, EKMixin } from 'ember-keyboard'; -const { inject, computed, run } = Ember; +const { inject, computed, run, on } = Ember; -export default Ember.Component.extend(AppBuilderMixin, ColumnsMixin, FilesMixin, TestFilesMixin, { +export default Ember.Component.extend(AppBuilderMixin, ColumnsMixin, FilesMixin, TestFilesMixin, EKMixin, { emberCli: inject.service(), dependencyResolver: inject.service(), notify: inject.service(), @@ -24,9 +25,24 @@ export default Ember.Component.extend(AppBuilderMixin, ColumnsMixin, FilesMixin, isFastBoot: this.get('fastboot.isFastBoot') })); this.createColumns(); - this.set('activeEditorCol', '1'); + this.setProperties({ + activeEditorCol: '1', + keyboardActivated: true + }); }, + // eslint-disable-next-line ember/no-on-calls-in-components + onReloadCommand: on(keyDown('Enter+cmd'), function () { + this.send('runNow'); + }), + + // eslint-disable-next-line ember/no-on-calls-in-components + onSaveCommand: on(keyDown('cmd+KeyS'), function (event) { + this.saveGist(this.get('model')); + this.send('runNow'); + event.preventDefault(); + }), + /** * Output from the build, sets the `code` attr on the component * @type {String} diff --git a/app/routes/gist.js b/app/routes/gist.js index 5ca33dea..e1ed94ad 100644 --- a/app/routes/gist.js +++ b/app/routes/gist.js @@ -49,10 +49,12 @@ export default Ember.Route.extend({ actions: { saveGist(gist) { var newGist = gist.get('isNew'); + let controller = this.get('controller'); if (!newGist && gist.get('ownerLogin') !== this.get('session.currentUser.login')) { this.send('fork', gist); return; } + controller.set('isGistSaving', true); gist.save().then(() => { this.get('notify').info(`Saved to Gist ${gist.get('id')} on Github`); this.send('setSaved'); @@ -60,7 +62,8 @@ export default Ember.Route.extend({ gist.set('gistId', gist.get('id')); this.transitionTo('gist.edit', gist); } - }).catch((this.catchSaveError.bind(this))); + }).catch((this.catchSaveError.bind(this))) + .finally(() => controller.set('isGistSaving', false)); }, deleteGist(gist) { diff --git a/app/templates/components/gist-header.hbs b/app/templates/components/gist-header.hbs index 4c8f8586..450e21c4 100644 --- a/app/templates/components/gist-header.hbs +++ b/app/templates/components/gist-header.hbs @@ -2,7 +2,7 @@
{{title-input value=model.description titleChanged=(action this.attrs.titleChanged)}} - {{saved-state-indicator model=model unsaved=unsaved}} + {{saved-state-indicator model=model unsaved=unsaved isGistSaving=isGistSaving}}