1 import Ember from 'ember'; |
1 import Ember from 'ember'; |
2 import * as constants from 'corpus-common-addon/utils/constants'; |
2 import * as constants from 'corpus-common-addon/utils/constants'; |
3 import layout from '../templates/components/doc-subject'; |
3 import layout from '../templates/components/doc-subject'; |
4 |
4 |
5 export default Ember.Component.extend({ |
5 export default Ember.Component.extend({ |
6 layout: layout, |
6 layout: layout, |
7 tagName: "span", |
7 tagName: 'span', |
8 displayLabel: Ember.computed('label', 'resolvedLabel', function() { |
8 displayLabel: Ember.computed('label', 'resolvedLabel', function () { |
9 return this.get('label') || this.get('resolvedLabel'); |
9 return this.get('label') || this.get('resolvedLabel'); |
10 }), |
10 }), |
11 bnfResolver: Ember.inject.service(), |
11 bnfResolver: Ember.inject.service(), |
12 |
12 |
13 _resolveBnfIds: Ember.on('init', Ember.observer('url', 'label', function() { |
13 _resolveBnfIds: Ember.on('init', Ember.observer('url', 'label', function () { |
14 if(this.get('label')) { |
14 if (this.get('label')) { |
15 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
15 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
16 this.set('resolvedLabel', this.get('label')); |
16 this.set('resolvedLabel', this.get('label')); |
17 } |
|
18 return; |
|
19 } |
17 } |
20 this.get('bnfResolver').getLabel(this.get('url')).then(function(str) { |
|
21 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
|
22 this.set('resolvedLabel', str); |
|
23 } |
|
24 }.bind(this)); |
|
25 })), |
|
26 |
18 |
27 code: Ember.computed('url', function() { |
19 return; |
28 var rawSubject = this.get('url'); |
20 } |
29 if(rawSubject) { |
21 if (this.get('bnfResolver')) { |
30 if(rawSubject.startsWith(constants.BNF_BASE_URL)) { |
22 this.get('bnfResolver').getLabel(this.get('url')) |
31 return rawSubject.substr(constants.BNF_BASE_URL.length); |
23 .then(function (str) { |
32 } |
24 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
33 else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) { |
25 this.set('resolvedLabel', str); |
34 return rawSubject.substr(constants.BNF_ARK_BASE_URL.length); |
26 } |
35 } |
27 }.bind(this)); |
|
28 } |
|
29 })), |
|
30 |
|
31 code: Ember.computed('url', function () { |
|
32 const rawSubject = this.get('url'); |
|
33 |
|
34 if (rawSubject) { |
|
35 if (rawSubject.startsWith(constants.BNF_BASE_URL)) { |
|
36 return rawSubject.substr(constants.BNF_BASE_URL.length); |
|
37 } else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) { |
|
38 return rawSubject.substr(constants.BNF_ARK_BASE_URL.length); |
36 } |
39 } |
37 return rawSubject; |
40 } |
38 }), |
41 |
39 isSubjectLink: Ember.computed.match('url', /^http\:\/\//) |
42 return rawSubject; |
|
43 }), |
|
44 isSubjectLink: Ember.computed.match('url', /^http\:\/\//) |
40 |
45 |
41 }); |
46 }); |