Skip to content

Commit

Permalink
add common project badge (#1299, #1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Oct 18, 2023
1 parent 0a158f1 commit 6ac246c
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 108 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ Changelog for the **SODAR Core** Django app package. Loosely follows the
Unreleased
==========

Added
-----

- **Projectroles**
- ``_project_badge.html`` template (#1300)

Changed
-------

- **Appalerts**
- Use projectroles project badge templage (#1300)
- **Timeline**
- Truncate long project titles in badge (#1299)
- Use projectroles project badge templage (#1300)

Fixed
-----

Expand All @@ -17,6 +32,12 @@ Fixed
- **Timeline**
- ``get_timestamp()`` template tag crash from missing ``ProjectEventStatus`` (#1297)

Removed
-------

- **Timeline**
- ``_project_badge.html`` template (#1300)


v0.13.2 (2023-09-21)
====================
Expand Down
30 changes: 3 additions & 27 deletions appalerts/templates/appalerts/alert_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
{% block css %}
{{ block.super }}
<style type="text/css">
.sodar-app-alert-project-badge {
vertical-align: top;
margin-top: 2px;
overflow: hidden;
text-overflow: ellipsis;
max-width: 300px;
}
.sodar-app-alert-project-badge a {
color: inherit;
}
.sodar-app-alert-row div:nth-child(1) {
max-width: 40px;
}
Expand Down Expand Up @@ -95,21 +85,7 @@ <h2>
</div>
<div class="col pl-0">
{% if a.project %}
<span class="badge sodar-app-alert-project-badge mr-1
badge-{% if not a.project or can_view_project %}{{ a.level | lower }}{% else %}secondary{% endif %}"
title="{% get_display_name a.project.type title=True %}: {{ a.project.title }}"
data-toggle="tooltip" data-placement="top">
<i class="iconify"
data-icon="{% if a.project.type == 'PROJECT' %}mdi:cube{% else %}mdi:rhombus-split{% endif %}">
</i>
{% if can_view_project %}
<a href="{% url 'projectroles:detail' project=a.project.sodar_uuid %}">
{{ a.project.title }}
</a>
{% else %}
{{ a.project.title }}
{% endif %}
</span>
{% include 'projectroles/_project_badge.html' with project=a.project color=a.level can_view=can_view_project %}
{% endif %}
{{ a.message | safe }}
</div>
Expand Down Expand Up @@ -217,15 +193,15 @@ <h2>
showCancelLink: true
});
}
if ($('.sodar-app-alert-project-badge').length) {
if ($('.sodar-project-badge').length) {
tour.addStep('alert', {
title: 'Alert {% get_display_name 'PROJECT' title=True %} or ' +
'{% get_display_name 'CATEGORY' title=True %}',
text: 'This badge links to the ' +
'{% get_display_name 'PROJECT' %} or ' +
'{% get_display_name 'CATEGORY' %} to which the alerted ' +
'activity is related.',
attachTo: '.sodar-app-alert-project-badge top',
attachTo: '.sodar-project-badge top',
advanceOn: '.docs-link click',
showCancelLink: true
});
Expand Down
156 changes: 91 additions & 65 deletions docs/source/dev_resource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,97 @@ will disable the button after the initial click while the form is submitted.
This is especially recommended for forms responsible for creating objects.


Template Includes and Helpers
=============================

This section details general template includes and helpers provided by SODAR
Core. Unless otherwise mentioned, these can be imported from the projectroles
app.

For common template tags, see :ref:`app_projectroles_api_django_tags`.

Pagination Template
-------------------

A common template for adding navigation for list pagination can be found in
``projectroles/_pagination.html``. This can be included to any Django
``ListView`` template which provides the ``paginate_by`` definition, enabling
pagination. If a smaller layout is desired, the ``pg_small`` argument can be
used. An example can be seen below:

.. code-block:: django
{% include 'projectroles/_pagination.html' with pg_small=True %}
Project Badge
-------------

Projectroles provides a project badge which can be used to display a fixed-size
link to a category or a project among text. It can be included in your template
as follows:

.. code-block:: django
{% include 'projectroles/_project_badge.html' with project=project color='info' can_view=True %}
The following arguments are expected:

``project``
Project object for the related project or category.
``color``
String for the badge color (must correspond to bootstrap classes, e.g.
"info" or "success").
``can_view``
Boolean for whether the current user should have access to view the project.

Tour Help
---------

SODAR Core uses `Shepherd <https://shipshapecode.github.io/shepherd/docs/welcome/>`_
to present an optional interactive tour for a rendered page. To enable the tour
in your template, set it up inside the ``javascript`` template block. Within an
inline javascript structure, set the ``tourEnabled`` variable to ``true`` and
add steps according to the
`Shepherd documentation <https://shipshapecode.github.io/shepherd>`_.

Example:

.. code-block:: django
{% block javascript %}
{{ block.super }}
{# Tour content #}
<script type="text/javascript">
tourEnabled = true;
/* Normal step */
tour.addStep('id_of_step', {
title: 'Step Title',
text: 'Description of the step',
attachTo: '#some-element top',
advanceOn: '.docs-link click',
showCancelLink: true
});
/* Conditional step */
if ($('.potentially-existing-element').length) {
tour.addStep('id_of_another_step', {
title: 'Another Title',
text: 'Another description here',
attachTo: '.potentially-existing-element right',
advanceOn: '.docs-link click',
showCancelLink: true
});
}
</script>
{% endblock javascript %}
.. warning::

Make sure you call ``{{ block.super }}`` at the start of the declared
``javascript`` block or you will overwrite the site's default Javascript
setup!


App Settings
============

Expand Down Expand Up @@ -251,71 +342,6 @@ the Django database:
$ ./manage.py cleanappsettings
Pagination Template
===================

A common template for adding navigation for list pagination can be found in
``projectroles/_pagination.html``. This can be included to any Django
``ListView`` template which provides the ``paginate_by`` definition, enabling
pagination. If a smaller layout is desired, the ``pg_small`` argument can be
used. An example can be seen below:

.. code-block:: django
{% include 'projectroles/_pagination.html' with pg_small=True %}
Tour Help
=========

SODAR Core uses `Shepherd <https://shipshapecode.github.io/shepherd/docs/welcome/>`_
to present an optional interactive tour for a rendered page. To enable the tour
in your template, set it up inside the ``javascript`` template block. Within an
inline javascript structure, set the ``tourEnabled`` variable to ``true`` and add
steps according to the `Shepherd documentation <https://shipshapecode.github.io/shepherd>`_.

Example:

.. code-block:: django
{% block javascript %}
{{ block.super }}
{# Tour content #}
<script type="text/javascript">
tourEnabled = true;
/* Normal step */
tour.addStep('id_of_step', {
title: 'Step Title',
text: 'Description of the step',
attachTo: '#some-element top',
advanceOn: '.docs-link click',
showCancelLink: true
});
/* Conditional step */
if ($('.potentially-existing-element').length) {
tour.addStep('id_of_another_step', {
title: 'Another Title',
text: 'Another description here',
attachTo: '.potentially-existing-element right',
advanceOn: '.docs-link click',
showCancelLink: true
});
}
</script>
{% endblock javascript %}
.. warning::

Make sure you call ``{{ block.super }}`` at the start of the declared
``javascript`` block or you will overwrite the site's default Javascript
setup!


Project Modifying API
=====================

Expand Down
1 change: 1 addition & 0 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ releases, see the :ref:`full changelog<changelog>`.
v0.13.3 (WIP)
*************

- Add common project badge template
- Fix hidden JSON project setting reset on non-superuser project update
- General bug fixes and minor updates

Expand Down
12 changes: 12 additions & 0 deletions projectroles/static/projectroles/css/projectroles.css
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,18 @@ a.sodar-pr-btn-copy-secret i {
margin-left: 0;
}

/* Project badge */
span.sodar-project-badge {
vertical-align: top;
margin-top: 2px;
overflow: hidden;
text-overflow: ellipsis;
max-width: 300px;
}
span.sodar-project-badge a {
color: inherit;
}

/* NOTE: Notch visualizaton for sidebar moved into base.html */

.sodar-pr-sidebar-nav-ul li i {
Expand Down
19 changes: 19 additions & 0 deletions projectroles/templates/projectroles/_project_badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{# Badge to display a project/category link #}
{# Parameters: #}
{# project (Project object) #}
{# color (string) #}
{# can_view (boolean) #}
<span class="badge sodar-project-badge mr-1
badge-{% if not can_view %}secondary{% else %}{{ color|lower }}{% endif %}"
title="{{ project.full_title }}" data-toggle="tooltip" data-delay="500">
<i class="iconify"
data-icon="{% if project.type == 'PROJECT' %}mdi:cube{% else %}mdi:rhombus-split{% endif %}">
</i>
{% if can_view %}
<a href="{% url 'projectroles:detail' project=project.sodar_uuid %}">
{{ project.title }}
</a>
{% else %}
{{ project.title }}
{% endif %}
</span>
3 changes: 1 addition & 2 deletions timeline/templates/timeline/_list_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</td>
<td class="sodar-tl-item-desc">
{% if event.project and user.is_superuser and timeline_mode == 'admin' %}
{% include 'timeline/_project_badge.html' %}
{% include 'projectroles/_project_badge.html' with project=event.project color='info' can_view=True %}
{% endif %}
{% get_event_description event plugin_lookup request as event_desc %}
{{ event_desc|safe }}
Expand Down Expand Up @@ -73,4 +73,3 @@
{{ event.get_status.status_type }}
</td>
</tr>

4 changes: 2 additions & 2 deletions timeline/templates/timeline/_list_tour.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
showCancelLink: true
});
}
if ($('.sodar-tl-item-project-badge').length) {
if ($('.sodar-project-badge').length) {
tour.addStep('event_desc', {
title: '{% get_display_name 'PROJECT' title=True %} Badge',
text: 'This badge links to the {% get_display_name 'PROJECT' %} to ' +
'which the event is related.',
attachTo: '.sodar-tl-item-project-badge top',
attachTo: '.sodar-project-badge top',
advanceOn: '.docs-link click',
showCancelLink: true
});
Expand Down
11 changes: 0 additions & 11 deletions timeline/templates/timeline/_project_badge.html

This file was deleted.

2 changes: 1 addition & 1 deletion timeline/templates/timeline/_search_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<td>
<div class="sodar-overflow-container">
{% if event.project %}
{% include 'timeline/_project_badge.html' %}
{% include 'projectroles/_project_badge.html' with project=event.project color='info' can_view=True %}
{% endif %}
{% get_event_description t plugin_lookup request as event_desc %}
{{ event_desc|safe }}
Expand Down

0 comments on commit 6ac246c

Please sign in to comment.