common/corpus-common-addon/addon/components/doc-subject.js
author Chloe Laisne <chloe.laisne@gmail.com>
Mon, 26 Sep 2016 20:17:26 +0200
changeset 297 50c80dda4fb8
parent 134 c06d08c8a1b8
child 394 48458e099b05
permissions -rw-r--r--
Hide filter-component if empty

import Ember from 'ember';
import * as constants from 'corpus-common-addon/utils/constants';
import layout from '../templates/components/doc-subject';

export default Ember.Component.extend({
    layout: layout,
    tagName: "span",

    bnfResolver: Ember.inject.service(),

    _resolveBnfIds: Ember.on('init', Ember.observer('url', function() {
      this.get('bnfResolver').getLabel(this.get('url')).then(function(str) {
          this.set('resolvedLabel', str);
      }.bind(this));
    })),

    code: Ember.computed('url', function() {
      var rawSubject = this.get('url');
      if(rawSubject) {
        if(rawSubject.startsWith(constants.BNF_BASE_URL)) {
          return rawSubject.substr(constants.BNF_BASE_URL.length);
        }
        else if (rawSubject.startsWith(constants.BNF_ARK_BASE_URL)) {
          return rawSubject.substr(constants.BNF_ARK_BASE_URL.length);
        }
      }
      return rawSubject;
    }),
    isSubjectLink: Ember.computed.match('url', /^http\:\/\//)

});