WIP quick repo switch

This commit is contained in:
Piotr Sarnacki 2016-03-21 10:42:54 +01:00
parent ae8092ddc0
commit ff6fad4d88
9 changed files with 157 additions and 4 deletions

View File

@ -13,7 +13,8 @@
"Log",
"moment",
"Pusher",
"md5"
"md5",
"key"
],
"browser": true,
"boss": true,

View File

@ -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 === '<' ? '<strong style="font-weight: 1000; color: #a80000">' : '</strong>' ) ).join('<br/>');
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);
}
}
}
}
}
});

13
app/services/keyboard.js Normal file
View File

@ -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;

View File

@ -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";

View File

@ -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;
}
}

View File

@ -1,3 +1,5 @@
{{#popup-click-handler}}
{{outlet}}
{{/popup-click-handler}}
{{travis-cmd}}

View File

@ -0,0 +1,15 @@
<div class="content">
{{#if loading}}
{{loading-indicator}}
{{else}}
<input type="text" class="input" value={{filterString}}
oninput={{action "filterChanged" value="target.value"}}
onkeydown={{action "keypress"}} />
<div class="matches">
{{{matches}}}
</div>
{{/if}}
</div>

View File

@ -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",

View File

@ -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();
};