NatLibFi/Skosmos

View on GitHub
src/view/scripts.inc.twig

Summary

Maintainability
Test Coverage
<!-- Skosmos variables passed from the backend to the frontend code-->
<!-- NB: Do not add comments inside the JS object as it would break JSON parsing -->
<script id="skosmos-global-vars">
{% set mockup_translations = {
    "fi": {
        "fi": "suomi",
        "en": "englanti",
        "se": "pohjoissaame",
        "sv": "ruotsi",
        "all": "kaikilla kielillä"
    },
    "sv": {
        "fi": "finska",
        "en": "engelska",
        "se": "nordsamiska",
        "sv": "svenska",
        "all": "på alla språk"
    },
    "en": {
        "fi": "Finnish",
        "en": "English",
        "se": "Northern Sami",
        "sv": "Swedish",
        "all": "In all languages"
    }
} %}
window.SKOSMOS = {
  "content_lang": "{{ request.contentLang }}",
  "explicitLangCodes": {{ explicit_langcodes ? "true" : "false" }},
  "lang": "{{ request.lang }}",
  "vocab": "{{ request.vocabid }}",
  "waypoint_results": {{ parameters ? parameters.searchLimit : "null" }},
  {%- if request.page == "page" and concept %}
  "prefLabels": [{"lang": "{{ concept.label.lang }}","label": "{{ concept.label }}"}{% for lang in concept.foreignLabels %}{% for literal in lang %}{% if literal.type == "skos:prefLabel" %},{"lang": "{{literal.lang}}", "label": "{{literal.label}}"}{% endif %}{% endfor %}{% endfor %}],
  "uri": "{{ concept.uri }}",
  {% endif %}
  {%- if request.vocab ~%}
  "languageOrder": [{% for lang in request.vocab.config.languageOrder(request.contentLang) %}"{{ lang }}"{% if not loop.last %}, {% endif %}{% endfor %}],
  "showNotation": {{ request.vocab.config.showNotation ? "true" : "false" }},
  "sortByNotation": {% if request.vocab.config.sortByNotation %}"{{ request.vocab.config.sortByNotation }}"{% else %}null{% endif ~%},
  "uriSpace": {% if request.vocab.uriSpace %}"{{ request.vocab.uriSpace }}"{% else %}null{% endif ~%},
  "vocShortName": "{{ request.vocab.config.shortname }}",
  {%- endif %}
  {%- if plugin_params ~%}
  "pluginParameters": {{ plugin_params|raw }},
  {%- endif %}
  {%- if request.plugins.callbacks ~%}
  "pluginCallbacks": [{% for function in request.plugins.callbacks %}{% if not loop.first %}, {% endif %}"{{ function }}"{% endfor %}],
  {%- endif ~%}
  {%- if custom_labels -%}
  "customLabels": { 
    {%- for k, v in custom_labels -%}
      {%- set label = v['label'][request.lang] -%}
      {%- set description = v['description'][request.lang] -%}
      {%- if not loop.first -%}, {%- endif -%}"{{k}}": ["{{label[:1]|upper ~ label[1:]}}", "{{description[:1]|upper ~ description[1:]}}"]{%- endfor -%} 
  },
  {%- endif -%}
  "baseHref": "{{ BaseHref }}",
  "language_strings": { {% for lang in request.vocab.config.languages %}"{{ lang }}": "{{ mockup_translations[request.lang][lang] }}", {% endfor -%}
                      "all": "{{ mockup_translations[request.lang].all }}" },
  "msgs" : { "fi": { "No results": "Ei hakutuloksia",
                     "http://www.yso.fi/onto/yso-meta/Concept": "Yleiskäsite",
                     "http://www.yso.fi/onto/yso-meta/Hierarchy": "Hierarkisoiva käsite",
                     "skos:Concept": "Käsite",
                     "Loading more items": "Ladataan sisältöä"},
             "sv": { "No results": "Inga sökresultat",
                     "http://www.yso.fi/onto/yso-meta/Concept": "Allmänbegrepp",
                     "http://www.yso.fi/onto/yso-meta/Hierarchy": "Hierarki",
                     "skos:Concept": "Begrepp",
                     "Loading more items": "Laddar mera resultat"},
             "en": { "No results": "No results",
                     "http://www.yso.fi/onto/yso-meta/Concept": "General concept",
                     "http://www.yso.fi/onto/yso-meta/Hierarchy": "Hierarchy",
                     "skos:Concept": "Concept",
                     "Loading more items": "Loading more items"}}
}
</script>

<!-- Search result data -->
<script type="application/ld+json">
  {%- if concept -%}
    {{ concept.dumpJsonLd|raw }}
  {%- else -%}
    {}
  {%- endif -%}
</script>

<!-- Plugin JS sources -->
{% for files in request.plugins.pluginsJS %}
  {% for file in files %}<script src="{{ file }}"></script>{% endfor %}
{% endfor %}

<!-- Bootstrap -->
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>

<!-- Vue.js -->
<script src="node_modules/vue/dist/vue.global.js"></script>

<!-- Helper methods shared by Vue.js components -->
<script src="resource/js/partial-page-load.js"></script>
<script src="resource/js/get-concept-url.js"></script>
<script src="resource/js/translation-service.js"></script>

<!-- Vue.js components -->
<script src="resource/js/vocab-counts.js"></script>
<script src="resource/js/term-counts.js"></script>
<script src="resource/js/concept-mappings.js"></script>
<script src="resource/js/tab-alpha.js"></script>
<script src="resource/js/tab-hierarchy.js"></script>
<script src="resource/js/vocab-search.js"></script>

<!-- Other (non-Vue) JS functionality -->
<script src="resource/js/copy-to-clipboard.js"></script>