External OLAC links leads now to the OLAC documentation. Closes #0025936
authorymh <ymh.work@gmail.com>
Thu, 19 Jan 2017 13:53:17 +0100
changeset 490 76da86cf9696
parent 489 18613f052d56
child 491 e9e436a588b2
External OLAC links leads now to the OLAC documentation. Closes #0025936
cms/app-client/app/templates/components/doc-olac.hbs
common/corpus-common-addon/addon/components/doc-olac.js
common/corpus-common-addon/addon/helpers/get-link-type.js
common/corpus-common-addon/addon/templates/components/doc-olac.hbs
common/corpus-common-addon/addon/utils/constants.js
common/corpus-common-addon/addon/utils/utils.js
common/corpus-common-addon/app/components/doc-olac.js
common/corpus-common-addon/tests/integration/components/doc-olac-test.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cms/app-client/app/templates/components/doc-olac.hbs	Thu Jan 19 13:53:17 2017 +0100
@@ -0,0 +1,1 @@
+{{#if value}}{{value}}{{/if}}{{#if olacUrl}}<a href="{{olacUrl}}" target="_blank" class="fa fa-share-square-o">&nbsp;</a>{{else}}<a href="{{datatype}}#{{value}}" target="_blank" class="fa fa-share-square-o">&nbsp;</a>{{/if}}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/corpus-common-addon/addon/components/doc-olac.js	Thu Jan 19 13:53:17 2017 +0100
@@ -0,0 +1,20 @@
+import Ember from 'ember';
+import layout from '../templates/components/doc-olac';
+import DocLiteral from './doc-literal';
+import * as utils from 'corpus-common-addon/utils/utils';
+
+export default DocLiteral.extend({
+  layout,
+  olacUrl: Ember.computed('url', function () {
+    const url = this.get('url');
+    const value = this.get('value');
+
+    const olacDef = utils.getOLACBaseUrl(url);
+
+    if (!olacDef) {
+      return '';
+    }
+
+    return olacDef.baseUrl + value;
+  })
+});
--- a/common/corpus-common-addon/addon/helpers/get-link-type.js	Wed Jan 18 11:33:56 2017 +0100
+++ b/common/corpus-common-addon/addon/helpers/get-link-type.js	Thu Jan 19 13:53:17 2017 +0100
@@ -1,7 +1,7 @@
 import Ember from 'ember';
 import * as utils from 'corpus-common-addon/utils/utils';
 
-export function getLinkType(params /*, hash */) {
+export function getLinkType(params /* , hash */) {
   const url = params[0];
 
   if (!url) {
@@ -19,6 +19,9 @@
   if (utils.isViafLink(url)) {
     return 'doc-contributor';
   }
+  if (utils.isOLACLiteral(url)) {
+    return 'doc-olac';
+  }
 
   return 'doc-literal';
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/corpus-common-addon/addon/templates/components/doc-olac.hbs	Thu Jan 19 13:53:17 2017 +0100
@@ -0,0 +1,1 @@
+{{#if value}}{{value}}{{/if}}<span class="doc-supsub">{{#if olacUrl}}<sub>{{olacUrl}}</sub>{{else}}<sub>{{datatype}}</sub>{{/if}}</span>
--- a/common/corpus-common-addon/addon/utils/constants.js	Wed Jan 18 11:33:56 2017 +0100
+++ b/common/corpus-common-addon/addon/utils/constants.js	Thu Jan 19 13:53:17 2017 +0100
@@ -62,3 +62,21 @@
   p: 20, q: 21, r: 22, s: 23, t: 24, v: 25, w: 26, x: 27, z: 28
 };
 
+export const OLAC_BASE_URL = {
+  'http://www.language-archives.org/OLAC/1.1/linguistic-field': {
+    baseUrl: 'http://www.language-archives.org/REC/field.html#',
+    type: 'linguistic-field'
+  },
+  'http://www.language-archives.org/OLAC/1.1/discourse-type': {
+    baseUrl: 'http://www.language-archives.org/REC/discourse.html#',
+    type: 'discourse-type'
+  },
+  'http://www.language-archives.org/OLAC/1.1/linguistic-type': {
+    baseUrl: 'http://www.language-archives.org/REC/type.html#',
+    type: 'linguistic-type'
+  },
+  'http://www.language-archives.org/OLAC/1.1/role': {
+    baseUrl: 'http://www.language-archives.org/REC/role.html#',
+    type: 'role'
+  }
+};
--- a/common/corpus-common-addon/addon/utils/utils.js	Wed Jan 18 11:33:56 2017 +0100
+++ b/common/corpus-common-addon/addon/utils/utils.js	Thu Jan 19 13:53:17 2017 +0100
@@ -75,3 +75,36 @@
 
   return constants.NOID_CHARS[sum % constants.NOID_CHARS.length];
 }
+
+export function getOLACBaseUrl(literalVal) {
+  let olacRes = null;
+
+  if (!literalVal) {
+    return null;
+  }
+  if (typeof literalVal !== 'object') {
+    return null;
+  }
+  const datatype = literalVal.datatype;
+
+  if (!datatype) {
+    return null;
+  }
+
+  _.forEach(constants.OLAC_BASE_URL, function (olacDef, urlPrefix) {
+    if (_.startsWith(datatype, urlPrefix)) {
+      olacRes = olacDef;
+      return false; // we found it, we exit early
+    }
+
+    return true;
+  });
+
+  return olacRes;
+}
+
+export function isOLACLiteral(literalDef) {
+  const olacDef = getOLACBaseUrl(literalDef);
+
+  return Boolean(olacDef);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/corpus-common-addon/app/components/doc-olac.js	Thu Jan 19 13:53:17 2017 +0100
@@ -0,0 +1,1 @@
+export { default } from 'corpus-common-addon/components/doc-olac';
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/corpus-common-addon/tests/integration/components/doc-olac-test.js	Thu Jan 19 13:53:17 2017 +0100
@@ -0,0 +1,24 @@
+import { moduleForComponent, test } from 'ember-qunit';
+import hbs from 'htmlbars-inline-precompile';
+
+moduleForComponent('doc-olac', 'Integration | Component | doc olac', {
+  integration: true
+});
+
+test('it renders', function(assert) {
+  // Set any properties with this.set('myProperty', 'value');
+  // Handle any actions with this.on('myAction', function(val) { ... });
+
+  this.render(hbs`{{doc-olac}}`);
+
+  assert.equal(this.$().text().trim(), '');
+
+  // Template block usage:
+  this.render(hbs`
+    {{#doc-olac}}
+      template block text
+    {{/doc-olac}}
+  `);
+
+  assert.equal(this.$().text().trim(), 'template block text');
+});