author | ymh <ymh.work@gmail.com> |
Mon, 06 Feb 2017 15:22:39 +0100 | |
changeset 500 | 4f507ba2bb4c |
parent 492 | acecbffac2c4 |
permissions | -rw-r--r-- |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
import * as constants from 'corpus-common-addon/utils/constants'; |
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import layout from '../templates/components/doc-subject'; |
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
export default Ember.Component.extend({ |
474 | 6 |
layout: layout, |
7 |
tagName: 'span', |
|
8 |
displayLabel: Ember.computed('label', 'resolvedLabel', function () { |
|
9 |
return this.get('label') || this.get('resolvedLabel'); |
|
10 |
}), |
|
11 |
bnfResolver: Ember.inject.service(), |
|
492
acecbffac2c4
on notice display add external link to subject, locations, and languages, correct #0025938
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
12 |
displayUrlLink: false, |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
474 | 14 |
_resolveBnfIds: Ember.on('init', Ember.observer('url', 'label', function () { |
15 |
if (this.get('label')) { |
|
16 |
if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
|
17 |
this.set('resolvedLabel', this.get('label')); |
|
447
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
394
diff
changeset
|
18 |
} |
474 | 19 |
|
20 |
return; |
|
21 |
} |
|
22 |
if (this.get('bnfResolver')) { |
|
23 |
this.get('bnfResolver').getLabel(this.get('url')) |
|
24 |
.then(function (str) { |
|
25 |
if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
|
26 |
this.set('resolvedLabel', str); |
|
27 |
} |
|
28 |
}.bind(this)); |
|
29 |
} |
|
30 |
})), |
|
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
|
474 | 32 |
code: Ember.computed('url', function () { |
33 |
const rawSubject = this.get('url'); |
|
34 |
||
35 |
if (rawSubject) { |
|
36 |
if (rawSubject.startsWith(constants.BNF_BASE_URL)) { |
|
37 |
return rawSubject.substr(constants.BNF_BASE_URL.length); |
|
38 |
} else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) { |
|
39 |
return rawSubject.substr(constants.BNF_ARK_BASE_URL.length); |
|
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
} |
474 | 41 |
} |
42 |
||
43 |
return rawSubject; |
|
44 |
}), |
|
45 |
isSubjectLink: Ember.computed.match('url', /^http\:\/\//) |
|
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
|
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
}); |