common/corpus-common-addon/addon/components/doc-subject.js
author ymh <ymh.work@gmail.com>
Fri, 16 Dec 2016 17:43:07 +0100
changeset 474 245b4df137d3
parent 447 38d5789e30d0
child 492 acecbffac2c4
permissions -rw-r--r--
Correct themes visualisation
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(),
134
c06d08c8a1b8 add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    13
  _resolveBnfIds: Ember.on('init', Ember.observer('url', 'label', function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    14
    if (this.get('label')) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    15
      if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    16
        this.set('resolvedLabel', this.get('label'));
447
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    17
      }
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    18
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    19
      return;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    20
    }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    21
    if (this.get('bnfResolver')) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    22
      this.get('bnfResolver').getLabel(this.get('url'))
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    23
        .then(function (str) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    24
          if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    25
            this.set('resolvedLabel', str);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    26
          }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    27
        }.bind(this));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    28
    }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    29
  })),
134
c06d08c8a1b8 add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    31
  code: Ember.computed('url', function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    32
    const rawSubject = this.get('url');
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    33
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    34
    if (rawSubject) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    35
      if (rawSubject.startsWith(constants.BNF_BASE_URL)) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    36
        return rawSubject.substr(constants.BNF_BASE_URL.length);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    37
      } else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    38
        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
    39
      }
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    40
    }
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
    return rawSubject;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    43
  }),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    44
  isSubjectLink: Ember.computed.match('url', /^http\:\/\//)
134
c06d08c8a1b8 add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
c06d08c8a1b8 add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
});