From 500581da9af84bddb9d5f44287620775efcd653d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 21 Mar 2016 10:42:54 +0100 Subject: [PATCH] WIP quick repo switch --- .jshintrc | 3 +- app/components/travis-cmd.js | 82 +++++++++++++++++++++++++ app/services/keyboard.js | 13 ++++ app/styles/app.scss | 1 + app/styles/app/modules/travis-cmd.scss | 37 +++++++++++ app/templates/application.hbs | 2 + app/templates/components/travis-cmd.hbs | 15 +++++ bower.json | 3 +- ember-cli-build.js | 5 +- 9 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 app/components/travis-cmd.js create mode 100644 app/services/keyboard.js create mode 100644 app/styles/app/modules/travis-cmd.scss create mode 100644 app/templates/components/travis-cmd.hbs diff --git a/.jshintrc b/.jshintrc index 64e26f6b..b08ae3bd 100644 --- a/.jshintrc +++ b/.jshintrc @@ -13,7 +13,8 @@ "Log", "moment", "Pusher", - "md5" + "md5", + "key" ], "browser": true, "boss": true, diff --git a/app/components/travis-cmd.js b/app/components/travis-cmd.js new file mode 100644 index 00000000..0ce85be2 --- /dev/null +++ b/app/components/travis-cmd.js @@ -0,0 +1,82 @@ +import Ember from 'ember'; +import config from 'travis/config/environment'; + +export default Ember.Component.extend({ + keyboard: Ember.inject.service(), + auth: Ember.inject.service(), + + classNameBindings: ['visible'], + classNames: ['travis-cmd'], + + didInsertElement() { + this.get('keyboard').bind('t', this.show.bind(this)); + this.get('keyboard').bind('esc', 'cmd', this.hide.bind(this)); + }, + + show() { + this.loadSlugs(); + this.set('visible', true); + this.get('keyboard').setScope('cmd'); + }, + + hide() { + this.set('visible', false); + this.get('keyboard').setScope(null); + this.set('matches', null); + this.set('filterString', null); + this.set('results', null); + }, + + loadSlugs() { + this.set('loading', true); + + $.ajax(config.apiEndpoint + '/repos/slugs', { + headers: { + Authorization: 'token ' + this.get('auth').token(), + Accept: 'application/json; version=2' + } + }).then((data) => { + this.set('loading', false); + this.set('repos', data.repositories); + this.onLoad(); + }); + }, + + onLoad() { + setTimeout( () => { + this.$('.input').focus(); + }, 10); + }, + + actions: { + filterChanged(value) { + let list = this.get('repos'); + + $.ajax("https://repos-filter-production.herokuapp.com/filter?phrase="+value, { + headers: { "Authorization": "token " + Travis.lookup('service:auth').token() + } }).then((response) => { + let repos = response.repositories; + repos = repos.sortBy('score').reverse(); + let matches = repos.slice(0, 10).mapBy('match').map( (match) => match.replace(new RegExp('<|>', 'g'), (match) => match === '<' ? '' : '' ) ).join('
'); + console.log(matches); + this.set('matches', matches); + }); + + this.set('filterString', value); + }, + + keypress(event) { + if(event.keyCode === 27) { + this.hide(); + } else if(event.keyCode === 13) { + let results; + if(results = this.get('results')) { + if(results[0]) { + let slug = results[0].original.slug; + console.log(slug); + } + } + } + } + } +}); diff --git a/app/services/keyboard.js b/app/services/keyboard.js new file mode 100644 index 00000000..e758606e --- /dev/null +++ b/app/services/keyboard.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +let KeyboardService = Ember.Service.extend({ + bind(keyName, scope, callback) { + key(...arguments); + }, + + setScope(scope) { + key.setScope(scope); + } +}); + +export default KeyboardService; diff --git a/app/styles/app.scss b/app/styles/app.scss index f848da8c..71327704 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -32,6 +32,7 @@ @import "app/modules/loading-indicator"; @import "app/modules/build-tile"; @import "app/modules/status-icon"; +@import "app/modules/travis-cmd"; @import "app/animation/tractor"; diff --git a/app/styles/app/modules/travis-cmd.scss b/app/styles/app/modules/travis-cmd.scss new file mode 100644 index 00000000..de1d3512 --- /dev/null +++ b/app/styles/app/modules/travis-cmd.scss @@ -0,0 +1,37 @@ +.travis-cmd { + opacity: 0.3; + background: #000; + width: 100%; + height: 100%; + z-index: 10; + top: 0; + left: 0; + top: 0; + left: 0; + position: fixed; + display: none; + + .content { + opacity: 1; + } + + &.visible { + display: block; + } + + .content { + width: 400px; + min-height: 60px; + background-color: white; + border-radius: 10px; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + } + + .content, .input { + color: black; + font-size: 20px; + } +} diff --git a/app/templates/application.hbs b/app/templates/application.hbs index 47326c47..c6a223df 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1,3 +1,5 @@ {{#popup-click-handler}} {{outlet}} {{/popup-click-handler}} + +{{travis-cmd}} diff --git a/app/templates/components/travis-cmd.hbs b/app/templates/components/travis-cmd.hbs new file mode 100644 index 00000000..95560083 --- /dev/null +++ b/app/templates/components/travis-cmd.hbs @@ -0,0 +1,15 @@ +
+ {{#if loading}} + {{loading-indicator}} + {{else}} + + + +
+ {{{matches}}} +
+ + {{/if}} +
diff --git a/bower.json b/bower.json index 42626fb9..ab03bfc4 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,8 @@ "pretender": "~0.12.0", "lodash": "~3.7.0", "Faker": "~3.0.0", - "ceibo": "1.0.0" + "ceibo": "1.0.0", + "keymaster": "~1.6.3" }, "resolutions": { "ember": "2.2.1", diff --git a/ember-cli-build.js b/ember-cli-build.js index 09529417..d473b646 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -15,9 +15,9 @@ module.exports = function(defaults) { if (assetsHost = process.env.ASSETS_HOST) { if (assetsHost.substr(-1) !== '/') { - assetsHost = assetsHost + '/' + assetsHost = assetsHost + '/'; } - fingerprint.prepend = assetsHost + fingerprint.prepend = assetsHost; } } @@ -40,6 +40,7 @@ module.exports = function(defaults) { app.import('vendor/log.js'); app.import('vendor/customerio.js'); app.import('bower_components/moment/moment.js'); + app.import('bower_components/keymaster/keymaster.js'); return app.toTree(); };