|
1 | 1 | import Component from '@ember/component'; |
2 | 2 | import { inject as service } from '@ember/service'; |
3 | 3 | import layout from './template'; |
4 | | -import { sort } from '@ember/object/computed'; |
5 | 4 | import { reads } from '@ember/object/computed'; |
6 | | -import config from 'dummy/config/environment'; |
7 | | - |
8 | | -const { latestVersionName, primaryBranch } = config['ember-cli-addon-docs']; |
| 5 | +// import config from 'dummy/config/environment'; |
| 6 | +import { computed } from '@ember/object'; |
| 7 | +import { A } from '@ember/array'; |
| 8 | +import { getOwner } from '@ember/application'; |
9 | 9 |
|
| 10 | +// const { latestVersionName, primaryBranch } = config['ember-cli-addon-docs']; |
| 11 | +// |
10 | 12 | export default Component.extend({ |
11 | 13 | layout, |
12 | 14 |
|
13 | | - latestVersionName, |
14 | | - primaryBranch, |
| 15 | + latestVersionName: computed(function() { |
| 16 | + let config = getOwner(this).resolveRegistration('config:environment')['ember-cli-addon-docs']; |
| 17 | + |
| 18 | + return config.latestVersionName; |
| 19 | + }), |
| 20 | + |
| 21 | + primaryBranch: computed(function() { |
| 22 | + let config = getOwner(this).resolveRegistration('config:environment')['ember-cli-addon-docs']; |
| 23 | + |
| 24 | + return config.primaryBranch; |
| 25 | + }), |
15 | 26 |
|
16 | 27 | projectVersion: service(), |
17 | 28 | 'on-close'() {}, |
18 | 29 |
|
19 | 30 | currentVersion: reads('projectVersion.currentVersion'), |
20 | 31 |
|
21 | | - sortedVersions: sort('projectVersion.versions', function(a, b) { |
22 | | - if ([latestVersionName, primaryBranch].includes(a.key) || [latestVersionName, primaryBranch].includes(b.key) ) { |
23 | | - return a.key > b.key; |
24 | | - } else { |
25 | | - return a.key < b.key; |
26 | | - } |
| 32 | + sortedVersions: computed('projectVersion.versions', 'latestVersionName', 'primaryBranch', function() { |
| 33 | + let latestVersionName = this.get('latestVersionName'); |
| 34 | + let primaryBranch = this.get('primaryBranch'); |
| 35 | + let versions = A(this.get('projectVersion.versions')); |
| 36 | + let latest = versions.findBy('key', latestVersionName); |
| 37 | + let primary = versions.findBy('key', primaryBranch); |
| 38 | + |
| 39 | + return [ |
| 40 | + latest, |
| 41 | + primary, |
| 42 | + ...versions.removeObjects([ latest, primary ]).sortBy('key') |
| 43 | + ].filter(Boolean); |
27 | 44 | }), |
28 | 45 |
|
29 | 46 | actions: { |
|
0 commit comments