common/corpus-common-addon/addon/components/doc-subject.js
author ymh <ymh.work@gmail.com>
Wed, 08 Feb 2017 15:25:24 +0100
changeset 502 74fba571487e
parent 492 acecbffac2c4
permissions -rw-r--r--
Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
     6
  layout: layout,
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
     7
  tagName: 'span',
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
     8
  displayLabel: Ember.computed('label', 'resolvedLabel', function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
     9
    return this.get('label') || this.get('resolvedLabel');
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    10
  }),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    14
  _resolveBnfIds: Ember.on('init', Ember.observer('url', 'label', function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    15
    if (this.get('label')) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    16
      if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    19
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    20
      return;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    21
    }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    22
    if (this.get('bnfResolver')) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    23
      this.get('bnfResolver').getLabel(this.get('url'))
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    24
        .then(function (str) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    25
          if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    26
            this.set('resolvedLabel', str);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    27
          }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    28
        }.bind(this));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    29
    }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    30
  })),
134
c06d08c8a1b8 add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    32
  code: Ember.computed('url', function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    33
    const rawSubject = this.get('url');
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    34
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    35
    if (rawSubject) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    36
      if (rawSubject.startsWith(constants.BNF_BASE_URL)) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    37
        return rawSubject.substr(constants.BNF_BASE_URL.length);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    38
      } else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    41
    }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    42
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    43
    return rawSubject;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    44
  }),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    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
});