Skip to content

Commit

Permalink
Merge branch 'main' into issue1514-search-bar-autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
joelit authored Feb 1, 2024
2 parents 58ace93 + ed44f6e commit b5b6064
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 32 deletions.
43 changes: 25 additions & 18 deletions resource/css/skosmos.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ body {
margin: 0 5px;
}

#main-container.termpage .fa-copy {
color: var(--vocab-text);
font-size: 30px;
position: relative;
bottom: -3px;
}

#main-container.searchpage .fa-arrow-right, #main-container.searchpage-multi-vocab .fa-arrow-right {
color: var(--vocab-text);
font-size: 12px;
Expand All @@ -105,11 +98,6 @@ body {
text-align: center;
}

#main-container.searchpage .fa-copy, #main-container.searchpage-multi-vocab .fa-copy {
position: relative;
bottom: 5px;
}

.fa-magnifying-glass {
color: var(--search-button-text);
font-size: 22px;
Expand Down Expand Up @@ -734,16 +722,26 @@ body {
}

#concept-label h1 {
float: left;
display: inline;
}

.copy-clipboard {
border: none;
font-size: 20px;
#copy-preflabel {
color: var(--vocab-text);
font-size: 30px;
position: relative;
bottom: 10px;
left: 5px;
}

.copy-clipboard:active, .copy-clipboard:focus, .copy-clipboard:active:focus {
border: none;
#copy-uri {
color: var(--vocab-text);
position: relative;
bottom: 4px;
}

.copy-clipboard:focus {
border: 1px solid var(--vocab-text);
border-radius: 3px;
}

.property ul, .property li {
Expand Down Expand Up @@ -891,6 +889,15 @@ body {
border-radius: 0;
}

/* About page
*****************************************/
#about-content a {
font-size: 1.0em;
color: var(--vocab-link);
text-decoration: underline var(--secondary-medium-color) solid;
font-weight: 700;
}

/* Footer
*****************************************/
#footer p {
Expand Down
30 changes: 30 additions & 0 deletions resource/js/copy-to-clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// function for copying the content from a specific element (by id) to the clipboard
function copyToClipboard (id) {
const copyElem = document.getElementById(id)
const sel = window.getSelection()
const range = document.createRange()
range.selectNodeContents(copyElem)
sel.removeAllRanges()
sel.addRange(range)

navigator.clipboard.writeText(copyElem.innerText).catch((err) =>
console.error('Failed to copy text to clipboard: ', err))
}

function registerCopyToClipboardEvents () {
const copyPrefElem = document.getElementById('copy-preflabel')
if (copyPrefElem) {
copyPrefElem.addEventListener('click', () => copyToClipboard('concept-preflabel'))
}

const copyUriElem = document.getElementById('copy-uri')
if (copyUriElem) {
copyUriElem.addEventListener('click', () => copyToClipboard('concept-uri'))
}
}

// register the copyToClipboard function as event an handler for the copy buttons
registerCopyToClipboardEvents()

// re-register the event handlers after partial page loads
document.addEventListener('loadConceptPage', registerCopyToClipboardEvents)
3 changes: 3 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,6 @@ msgstr "Information"

msgid "Breadcrumbs"
msgstr "Breadcrumbs"

msgid "Copy to clipboard"
msgstr "Copy to clipboard"
3 changes: 3 additions & 0 deletions resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,6 @@ msgstr "Tietoja"

msgid "Breadcrumbs"
msgstr "Murupolut"

msgid "Copy to clipboard"
msgstr "Kopioi leikepöydälle"
3 changes: 3 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -887,3 +887,6 @@ msgstr "Information"

msgid "Breadcrumbs"
msgstr "Brödsmulor"

msgid "Copy to clipboard"
msgstr "Kopiera till urklipp"
4 changes: 3 additions & 1 deletion src/view/about-info.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{# This is the template for the about page. You can enter any html here and show different language versions by using the lang value in a twig conditional as demonstrated below. #}
{% block content %}
<div id="about-content">
{% if request.lang == 'fi' %}
<h4>Tietoja sanastoselaimesta</h4>
<h2>Tietoja sanastoselaimesta</h2>
<p>Skosmos on web-pohjainen sanasto ja ontologiaselain.</p>
<a href="http://github.com/NatLibFi/Skosmos">Skosmos GitHub-repositorio</a>
{% elseif request.lang == 'sv' %}
Expand All @@ -13,4 +14,5 @@
<p>Skosmos is a web based open source ontology browser.</p>
<a href="http://github.com/NatLibFi/Skosmos">Skosmos GitHub repository</a>
{% endif %}
</div>
{% endblock %}
10 changes: 4 additions & 6 deletions src/view/base-template.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
<link href="{{ ServiceCustomCss }}" media="screen, print" rel="stylesheet" type="text/css">
{% endif %}
{% for plugin, files in request.plugins.pluginsCSS %}{% for file in files %}<link href="{{ file }}" media="screen, print" rel="stylesheet" type="text/css">{% endfor %}{% endfor %}

<title>{{ ServiceName }}{% block title %}{% endblock %}</title>
</head>
<body{% if request.vocabid == '' and request.page != 'feedback' and request.page != 'about' and request.page != 'search' %} class="bg-light frontpage-logo"{% else %} class="bg-medium vocab-{{ request.vocabid }}"{% endif %}>
<noscript>
<strong>We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<a class="visually-hidden" id="skiptocontent" href="{{ request.langurl }}#maincontent">Skip to main</a>
<header>
<a class="visually-hidden" id="skiptocontent" href="{{ request.langurl }}#maincontent">Skip to main</a>
<div class="container-fluid bg-dark d-flex my-auto py-3 px-4 text-bg-dark">
{% if request.vocabid == '' and request.page != 'about' and request.page != 'feedback' %}
<span class="fs-6 py-3 text-light">Yhteishaku sanastoista v</span>
Expand Down Expand Up @@ -62,7 +58,6 @@
{% endif %}
</ul>
</div>

<div class="container-fluid bg-light py-4 px-4" id="headerbar">
{% if request.vocabid == '' %}
<div id="skosmos-logo">
Expand All @@ -82,6 +77,9 @@
</header>
<main id="main-container" class="{% if request.vocabid == '' or global_search %} frontpage{% elseif concept_uri != '' %} termpage{% elseif request.vocab != '' %} vocabpage{% if list_style %} {{ list_style }}{% endif %}{% endif %}">
<div class="container">
<noscript>
<strong>We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div class="row" tabindex="-1">
{% block content %}
{% endblock %}
Expand Down
16 changes: 12 additions & 4 deletions src/view/concept-card.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
<div class="row" id="concept-heading">
<div class="col-sm-4 px-0" id="concept-property-label">{{ "skos:prefLabel" | trans }}</div>
<div class="col-sm-8" id="concept-label">
<h1 class="mb-0">{{ concept.label }}</h1>
<button class="btn btn-default copy-clipboard" type="button"
<h1 id="concept-preflabel"
class="mb-0 user-select-all">{{ concept.label }}</h1><button
class="btn btn-default copy-clipboard px-1" type="button" id="copy-preflabel"
data-bs-toggle="tooltip" data-bs-placement="button" title="{{ 'Copy to clipboard' | trans }}">
<i class="fa-regular fa-copy"></i>
<i class="fa-regular fa-copy"></i>
</button>
</div>
</div>
Expand Down Expand Up @@ -87,7 +88,14 @@
{% endif %}
<div class="row property prop-uri">
<div class="col-sm-4 px-0 property-label"><h2>URI</h2></div>
<div class="col-sm-8" id="concept-uri"><a href="#">{{ concept.uri }}</a></div>
<div class="col-sm-8">
<span id="concept-uri"
class="user-select-all">{{ concept.uri }}</span><button
class="btn btn-default copy-clipboard px-1" type="button" id="copy-uri"
data-bs-toggle="tooltip" data-bs-placement="button" title="{{ 'Copy to clipboard' | trans }}">
<i class="fa-regular fa-copy"></i>
</button>
</div>
</div>
<div class="row property prop-download">
<div class="col-sm-4 px-0 property-label">
Expand Down
5 changes: 4 additions & 1 deletion src/view/scripts.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SKOSMOS = {
{%- if request.plugins.callbacks ~%}
"pluginCallbacks": [{% for function in request.plugins.callbacks %}{% if not loop.first %}, {% endif %}"{{ function }}"{% endfor %}],
{%- endif ~%}
"language_strings" :{ "fi": { "fi": "suomi",
"language_strings": { "fi": { "fi": "suomi",
"en": "englanti",
"se": "pohjoissaame",
"sv": "ruotsi",
Expand Down Expand Up @@ -76,3 +76,6 @@ const SKOSMOS = {
<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>
1 change: 0 additions & 1 deletion src/view/search-results.inc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
<li class="list-group-item px-0 py-1">
<span class="uri-icon">URI</span>
<span class="search-result-uri">{{ concept.uri }}</span>
<i class="fa-regular fa-copy"></i> <!-- no copy to clipboard functionality yet -->
</li>
{%~ endif ~%}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/accessibility/axe-about.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'cypress-axe';
/* If you want the test to be skipped, add a skip command after the describe part:
- test enabled: describe('Check accessibility of ...
- test to be skipped: describe.skip('Check accessibility of ... */
describe.skip('Check accessibility of the about page', () => {
describe('Check accessibility of the about page', () => {
before(() => {
cy.visit('/fi/about')
cy.injectAxe()
Expand Down
24 changes: 24 additions & 0 deletions tests/cypress/template/concept.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ describe('Concept page', () => {
// check the concept prefLabel
cy.get('#concept-heading h1').invoke('text').should('equal', 'music research')
})
it('concept preflabel can be copied to clipboard', () => {
cy.visit('/yso/en/page/p21685') // go to "music research" concept page

// click the copy to clipboard button next to the prefLabel
cy.get('#copy-preflabel').click()

// check that the clipboard now contains "music research"
// NOTE: This test may fail when running Cypress interactively in a browser.
// The reason is browser security policies for accessing the clipboard.
// If that happens, make sure the browser window has focus and re-run the test.
cy.window().its('navigator.clipboard').invoke('readText').then((result) => {}).should('equal', 'music research');
})
it('contains concept type', () => {
cy.visit('/yso/en/page/p21685') // go to "music research" concept page

Expand Down Expand Up @@ -219,6 +231,18 @@ describe('Concept page', () => {
// check the broader concept
cy.get('#concept-uri').invoke('text').should('equal', 'http://www.yso.fi/onto/yso/p21685')
})
it('concept URI can be copied to clipboard', () => {
cy.visit('/yso/en/page/p21685') // go to "music research" concept page

// click the copy to clipboard button next to the URI
cy.get('#copy-uri').click()

// check that the clipboard now contains "http://www.yso.fi/onto/yso/p21685"
// NOTE: This test may fail when running Cypress interactively in a browser.
// The reason is browser security policies for accessing the clipboard.
// If that happens, make sure the browser window has focus and re-run the test.
cy.window().its('navigator.clipboard').invoke('readText').then((result) => {}).should('equal', 'http://www.yso.fi/onto/yso/p21685');
})
it('contains created & modified times (English)', () => {
cy.visit('/yso/en/page/p21685') // go to "music research" concept page (English)

Expand Down

0 comments on commit b5b6064

Please sign in to comment.