|
| 1 | +import Ember from 'ember'; |
| 2 | + |
| 3 | +const { computed } = Ember; |
| 4 | + |
| 5 | +function flattenBuildInfo(buildOrdering, builds) { |
| 6 | + if (!buildOrdering || !builds) { |
| 7 | + return []; |
| 8 | + } |
| 9 | + |
| 10 | + return buildOrdering.map(version => { |
| 11 | + const thisVersion = builds[version]; |
| 12 | + |
| 13 | + return { |
| 14 | + version, |
| 15 | + 'x86_64-apple-darwin': thisVersion['x86_64-apple-darwin'], |
| 16 | + 'x86_64-pc-windows-gnu': thisVersion['x86_64-pc-windows-gnu'], |
| 17 | + 'x86_64-pc-windows-msvc': thisVersion['x86_64-pc-windows-msvc'], |
| 18 | + 'x86_64-unknown-linux-gnu': thisVersion['x86_64-unknown-linux-gnu'], |
| 19 | + }; |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +export default Ember.Controller.extend({ |
| 24 | + id: computed.alias('model.crate.id'), |
| 25 | + name: computed.alias('model.crate.name'), |
| 26 | + version: computed.alias('model.num'), |
| 27 | + build_info: computed.alias('model.build_info'), |
| 28 | + stable_build: computed('build_info.ordering.stable', 'build_info.stable', function() { |
| 29 | + const ordering = this.get('build_info.ordering.stable'); |
| 30 | + const stable = this.get('build_info.stable'); |
| 31 | + |
| 32 | + return flattenBuildInfo(ordering, stable); |
| 33 | + }), |
| 34 | + beta_build: computed('build_info.ordering.beta', 'build_info.beta', function() { |
| 35 | + const ordering = this.get('build_info.ordering.beta'); |
| 36 | + const beta = this.get('build_info.beta'); |
| 37 | + |
| 38 | + return flattenBuildInfo(ordering, beta); |
| 39 | + }), |
| 40 | + nightly_build: computed('build_info.ordering.nightly', 'build_info.nightly', function() { |
| 41 | + const ordering = this.get('build_info.ordering.nightly'); |
| 42 | + const nightly = this.get('build_info.nightly'); |
| 43 | + |
| 44 | + return flattenBuildInfo(ordering, nightly); |
| 45 | + }), |
| 46 | + has_stable_builds: computed.gt('stable_build.length', 0), |
| 47 | + has_beta_builds: computed.gt('beta_build.length', 0), |
| 48 | + has_nightly_builds: computed.gt('nightly_build.length', 0), |
| 49 | +}); |
0 commit comments