diff --git a/app/components/status-images.js b/app/components/status-images.js index 7ced75f0..24d95ae5 100644 --- a/app/components/status-images.js +++ b/app/components/status-images.js @@ -1,14 +1,51 @@ import Ember from 'ember'; import { format as formatStatusImage } from 'travis/utils/status-image-formats'; +import Config from 'travis/config/environment'; export default Ember.Component.extend({ popup: Ember.inject.service(), + auth: Ember.inject.service(), + popupNameBinding: 'popup.popupName', id: 'status-images', attributeBindings: ['id'], classNames: ['popup', 'status-images'], formats: ['Image URL', 'Markdown', 'Textile', 'Rdoc', 'AsciiDoc', 'RST', 'Pod', 'CCTray'], + branches: function() { + let repoId = this.get('repo.id'), + popupName = this.get('popupName'); + + if(popupName === 'status-images') { + let array = Ember.ArrayProxy.create({ content: [] }), + apiEndpoint = Config.apiEndpoint, + options = {}; + + array.set('isLoaded', false); + + if (this.get('auth.signedIn')) { + options.headers = { + Authorization: "token " + (this.auth.token()) + }; + } + + $.ajax(apiEndpoint + "/v3/repo/" + repoId + "/branches?limit=100", options).then(function(response) { + if(response.branches.length) { + array.pushObjects(response.branches.map((branch) => { return branch.name; })); + } else { + array.pushObject('master'); + } + + array.set('isLoaded', true); + }); + + return array; + } else { + // if status images popup is not open, don't fetch any branches + return []; + } + }.property('popupName', 'repo'), + actions: { close() { return this.get('popup').close(); diff --git a/app/services/popup.js b/app/services/popup.js index 2a866c97..c91f38c9 100644 --- a/app/services/popup.js +++ b/app/services/popup.js @@ -5,10 +5,12 @@ export default Ember.Service.extend({ var ref; this.close(); name = (typeof event !== "undefined" && event !== null ? (ref = event.target) != null ? ref.name : void 0 : void 0) || name; - return $("#" + name).toggleClass('display'); + this.set('popupName', name); + $("#" + name).toggleClass('display'); }, close() { - return $('.popup').removeClass('display'); + this.set('popupName', null); + $('.popup').removeClass('display'); } }); diff --git a/app/templates/components/status-images.hbs b/app/templates/components/status-images.hbs index 24bcf4cd..16c06c80 100644 --- a/app/templates/components/status-images.hbs +++ b/app/templates/components/status-images.hbs @@ -4,7 +4,7 @@ {{#if branches.isLoaded}} {{#x-select value=branch}} {{#each branches as |branch|}} - {{#x-option value=branch.commit.branch}}{{branch.commit.branch}}{{/x-option}} + {{#x-option value=branch}}{{branch}}{{/x-option}} {{/each}} {{/x-select}} {{else}} diff --git a/app/templates/repo.hbs b/app/templates/repo.hbs index 4190b84a..1e4aaa17 100644 --- a/app/templates/repo.hbs +++ b/app/templates/repo.hbs @@ -42,4 +42,4 @@ {{/if}} {{/repo-wrapper}} -{{status-images repo=repo branches=repo.branches}} +{{status-images repo=repo}}