put language node names in doc-language component
authorymh <ymh.work@gmail.com>
Sat, 19 Nov 2016 21:29:56 +0100
changeset 429 4a0fc5c5f420
parent 428 76a47f714766
child 430 46b4d1971fee
put language node names in doc-language component
cms/app-client/mirage/fixtures/lexvos.js
common/corpus-common-addon/addon/components/doc-language.js
common/corpus-common-addon/addon/templates/components/doc-language.hbs
common/corpus-common-addon/addon/utils/constants.js
--- a/cms/app-client/mirage/fixtures/lexvos.js	Fri Nov 18 14:48:49 2016 +0100
+++ b/cms/app-client/mirage/fixtures/lexvos.js	Sat Nov 19 21:29:56 2016 +0100
@@ -40,14 +40,4 @@
     { 'id': "http://lexvo.org/id/iso639-3/ita", 'name': "italien" },
     { 'id': "http://lexvo.org/id/iso639-3/kdk", 'name': "numee" },
     { 'id': "http://lexvo.org/id/iso639-3/nua", 'name': "yuaga" },
-    { 'id': "corpus-global", 'name': "global" },
-    { 'id': "corpus-regionals", 'name': "langues régionales" },
-    { 'id': "corpus-oil", 'name': "langues d'oïl" },
-    { 'id': "corpus-creoles", 'name': "les créoles" },
-    { 'id': "corpus-non-territorials", 'name': "langues non territoriales" },
-    { 'id': "corpus-guyane", 'name': "Guyane" },
-    { 'id': "corpus-mayotte", 'name': "Mayotte" },
-    { 'id': "corpus-polynesia", 'name': "Polynésie française" },
-    { 'id': "corpus-wallis-futuna", 'name': "Wallis et Futuna" },
-    { 'id': "corpus-new-caledonia", 'name': "Nouvelle-Calédonie" },
 ];
--- a/common/corpus-common-addon/addon/components/doc-language.js	Fri Nov 18 14:48:49 2016 +0100
+++ b/common/corpus-common-addon/addon/components/doc-language.js	Sat Nov 19 21:29:56 2016 +0100
@@ -3,26 +3,35 @@
 import layout from '../templates/components/doc-language';
 
 export default Ember.Component.extend({
-    layout: layout,
-    tagName: "span",
+  layout: layout,
+  tagName: 'span',
+
+  lexvoResolver: Ember.inject.service(),
 
-    lexvoResolver: Ember.inject.service(),
+  _resolveLexvoIds: Ember.on('init', Ember.observer('url', function () {
+    this.get('lexvoResolver').getName(this.get('url')).then(function (str) {
+      if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
+        this.set('resolvedName', str);
+      }
+    }.bind(this));
+  })),
 
-    _resolveLexvoIds: Ember.on('init', Ember.observer('url', function() {
-      this.get('lexvoResolver').getName(this.get('url')).then(function(str) {
-        if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
-          this.set('resolvedName', str);
-        }
-      }.bind(this));
-    })),
+  code: Ember.computed('url', function () {
+    const rawLanguage = this.get('url');
+
+    if (this.get('isLanguageNode')) {
+      return constants.LANGUAGES_NODES[rawLanguage];
+    }
 
-    code: Ember.computed('url', function() {
-      var rawLanguage = this.get('url');
-      if(rawLanguage && rawLanguage.startsWith(constants.LEXVO_BASE_URL) ) {
-        return rawLanguage.substr(constants.LEXVO_BASE_URL.length);
-      }
-      return rawLanguage;
-    }),
-    isLanguageLink: Ember.computed.match('url', /^http\:\/\//)
+    if (rawLanguage && rawLanguage.startsWith(constants.LEXVO_BASE_URL)) {
+      return rawLanguage.substr(constants.LEXVO_BASE_URL.length);
+    }
+
+    return rawLanguage;
+  }),
+  isLanguageLink: Ember.computed.match('url', /^http\:\/\//),
+  isLanguageNode: Ember.computed('url', function () {
+    return this.get('url') in constants.LANGUAGES_NODES;
+  })
 
 });
--- a/common/corpus-common-addon/addon/templates/components/doc-language.hbs	Fri Nov 18 14:48:49 2016 +0100
+++ b/common/corpus-common-addon/addon/templates/components/doc-language.hbs	Sat Nov 19 21:29:56 2016 +0100
@@ -1,4 +1,6 @@
-{{#if isLanguageLink}}
+{{#if isLanguageNode}}
+{{code}}
+{{else if isLanguageLink}}
 <a href="{{url}}" target="_blank" title={{url}} class="bo-doc-ref-link doc-link-lexvo">
   {{#if resolvedName}}{{resolvedName}}{{else}}{{code}}{{/if}}
 </a>
--- a/common/corpus-common-addon/addon/utils/constants.js	Fri Nov 18 14:48:49 2016 +0100
+++ b/common/corpus-common-addon/addon/utils/constants.js	Sat Nov 19 21:29:56 2016 +0100
@@ -2,6 +2,18 @@
 export const LEXVO_BASE_URL = 'http://lexvo.org/id/iso639-3/';
 
 export const LANGUAGES_NODE_PREFIX = 'corpus-';
+export const LANGUAGES_NODES = {
+  'corpus-global': 'global',
+  'corpus-regionals': 'langues régionales',
+  'corpus-oil': 'langues d\'oïl',
+  'corpus-creoles': 'les créoles',
+  'corpus-non-territorials': 'langues non territoriales',
+  'corpus-guyane': 'Guyane',
+  'corpus-mayotte': 'Mayotte',
+  'corpus-polynesia': 'Polynésie française',
+  'corpus-wallis-futuna': 'Wallis et Futuna',
+  'corpus-new-caledonia': 'Nouvelle-Calédonie'
+};
 
 export const VIAF_BASE_URL = 'http://viaf.org/viaf/';
 
@@ -44,7 +56,8 @@
   'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'
 ];
 export const NOID_CHARS_POS = {
-  '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
-  'b': 10, 'c': 11, 'd': 12, 'f': 13, 'g': 14, 'h': 15, 'j': 16, 'k': 17, 'm': 18, 'n': 19,
-  'p': 20, 'q': 21, 'r': 22, 's': 23, 't': 24, 'v': 25, 'w': 26, 'x': 27, 'z': 28
+  0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,
+  b: 10, c: 11, d: 12, f: 13, g: 14, h: 15, j: 16, k: 17, m: 18, n: 19,
+  p: 20, q: 21, r: 22, s: 23, t: 24, v: 25, w: 26, x: 27, z: 28
 };
+