Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML classes for properties so they can be targeted in JS and CSS #1046

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions model/ConceptProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public function getLabel()
return null;
}

/**
* Returns an alphanumeric ID for the property, suitable for use as a CSS identifier.
*/
public function getID()
{
return preg_replace('/[^A-Za-z0-9-]/', '_', $this->prop);
}

/**
* Returns text for the property tooltip.
* @return string
Expand Down
1 change: 1 addition & 0 deletions resource/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ function loadMappingProperties(concept, lang, contentLang, $htmlElement, concept
if (!found) {
conceptProperty = {
'type': conceptMappingPropertyValue.type[0],
'id': conceptMappingPropertyValue.type[0].replace(/[^A-Za-z-]/g, '_'),
'label': conceptMappingPropertyValue.typeLabel,
'notation': conceptMappingPropertyValue.notation,
'description': conceptMappingPropertyValue.description,
Expand Down
19 changes: 19 additions & 0 deletions tests/ConceptPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,23 @@ public function testGetPropertiesSubClassOfHiddenLabel()
$props = $concept->getProperties();
$this->assertEquals('skos:hiddenLabel', $props['subclass:prop1']->getSubPropertyOf());
}

/**
* @covers ConceptProperty::getID
*/
public function testGetIDShortenedURI()
{
$prop = new ConceptProperty('skosmos:testLabel', 'Test label');
$this->assertEquals('skosmos_testLabel', $prop->getID());
}

/**
* @covers ConceptProperty::getID
*/
public function testGetIDFullURI()
{
$prop = new ConceptProperty('http://rdaregistry.info/Elements/a/P50008', 'has hierarchical superior');
$this->assertEquals('http___rdaregistry_info_Elements_a_P50008', $prop->getID());
}

}
10 changes: 5 additions & 5 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
{% endif %}
{% spaceless %}
<div class="row{% if concept.type == 'skosext:DeprecatedConcept' %} deprecated{% endif %}">
<div class="row{% if concept.type == 'skosext:DeprecatedConcept' %} deprecated{% endif %} property prop-preflabel">
<div class="property-label property-label-pref">
<span class="versal">{% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %}{% if subPrefLabelTranslation %}{{ subPrefLabelTranslation|upper }}{% else %}{{ 'skos:prefLabel'|trans|upper }}{% endif %}</span>
</div>
Expand All @@ -60,7 +60,7 @@
{% endspaceless %}
{% for property in concept.properties %} {# loop through ConceptProperty objects #}
{% if property.getSubPropertyOf != 'skos:hiddenLabel' %}
<div class="row{% if property.type == 'dc:isReplacedBy' %} replaced-by{% endif%}">
<div class="row{% if property.type == 'dc:isReplacedBy' %} replaced-by{% endif%} property prop-{{property.ID}}">
<div class="property-label">
<span class="versal{% if property.type == 'rdf:type' %}-bold{% endif %}{% if property.description %} property-click" title="{{ property.description }}{% endif %}">{{ property.label|upper }}</span>
</div>
Expand Down Expand Up @@ -113,7 +113,7 @@
{% endfor %}
{% set foreignLabels = concept.foreignLabels %}
{% if foreignLabels %}
<div class="row">
<div class="row property prop-other-languages">
<div class="property-label"><span class="versal property-click" title="{% trans "foreign prefLabel help" %}" >{{ 'foreign prefLabels'|trans|upper }}</span></div>
<div class="property-value-column"><div class="property-value-wrapper">
{% for language,labels in foreignLabels %}
Expand All @@ -127,7 +127,7 @@
</div>
</div></div>
{% endif %}
<div class="row">
<div class="row property prop-uri">
<div class="property-label"><span class="versal">URI</span></div>
<div class="property-value-column"><div class="property-value-wrapper"><span class="versal uri-input-box" id="uri-input-box">{{ concept.uri }}</span> <button type="button" data-toggle="tooltip" data-placement="button" title="Copy to clipboard" class="btn btn-default btn-xs copy-clipboard" for="#uri-input-box"><span class="glyphicon glyphicon-copy" aria-hidden="true"></span></button></div></div>
</div>
Expand Down Expand Up @@ -166,7 +166,7 @@
{% verbatim %}
<template id="property-mappings-template">
{{#each properties}}
<div class="row{{#ifDeprecated concept.type 'skosext:DeprecatedConcept'}} deprecated{{/ifDeprecated}}">
<div class="row{{#ifDeprecated concept.type 'skosext:DeprecatedConcept'}} deprecated{{/ifDeprecated}} property prop-{{ id }}">
<div class="property-label"><span class="versal{{#ifNotInDescription type description}} property-click" title="{{ description }}{{/ifNotInDescription}}">{{toUpperCase label}}</span></div>
<div class="property-value-column">
{{#each values }} {{! loop through ConceptPropertyValue objects }}
Expand Down