common/corpus-common-addon/addon/components/doc-location.js
author Chloe Laisne <chloe.laisne@gmail.com>
Tue, 18 Oct 2016 20:10:45 +0530
changeset 361 90cb51111854
parent 304 20071981ba2a
child 391 4f6118afabee
permissions -rw-r--r--
Merge

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

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

  geonamesResolver: Ember.inject.service(),

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

  code: Ember.computed('url', function() {
    var rawLocation = this.get('url');
    var m = rawLocation.match(constants.GEONAMES_BASE_URLS);

    if (m) {
      rawLocation = rawLocation.slice(m[0].length);
    }

    return rawLocation.replace(/\/+$/, '');
  }),
  isLocationLink: Ember.computed.match('url', /^http:\/\//)

});