Skip to content

Commit

Permalink
ui: add badges
Browse files Browse the repository at this point in the history
* closes #114
  • Loading branch information
anikachurilova committed Jul 18, 2023
1 parent 2cee5dd commit 4cde2d8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 31 deletions.
4 changes: 3 additions & 1 deletion invenio_github/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ def remove_hook(self, repo_id, name):

def repo_last_published_release(self, repo):
"""Retrieves the repository last release."""
return repo.latest_release(ReleaseStatus.PUBLISHED)
release_object = repo.latest_release(ReleaseStatus.PUBLISHED)
release_instance = current_github.release_api_class(release_object)
return release_instance

def get_repository_releases(self, repo):
"""Retrieve repository releases. Returns API release objects."""
Expand Down
5 changes: 5 additions & 0 deletions invenio_github/assets/semantic-ui/js/invenio_github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// Invenio Github is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.
import $ from "jquery";

function addResultMessage(element, color, message) {
element.classList.remove("hidden");
Expand Down Expand Up @@ -104,3 +105,7 @@ function sendEnableDisableRequest(checked, repo) {
}
}
}

$("#record-doi-badge").on("click", function () {
$("#doi-modal").modal("show");
});
41 changes: 20 additions & 21 deletions invenio_github/templates/semantic-ui/invenio_github/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@
Invenio is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}
{%- macro doi_badge(doi, github_id, modal_name='') %}
{%- macro doi_badge(doi, doi_url, github_id) %}
{%- block doi_badge scoped %}
{% set doi_url = url_for('invenio_github_badge.latest_doi', github_id=github_id, _external=True) %}
{% set image_url = url_for('invenio_github_badge.index', github_id=github_id, _external=True) %}
{% set modal_name = modal_name or (doi | replace('/', '-')) %}
<span class="get-badge" data-toggle="tooltip" data-placement="bottom" title="Get the DOI badge!">
<img data-toggle="modal" data-target="[data-modal='{{ modal_name }}']" src="{{ image_url }}" alt="{{ doi }}"/>
</span>
<div class="modal fade badge-modal" data-modal='{{ modal_name }}'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h4>DOI Badge</h4>
<p>
<small class="text-muted">
This badge points to the latest released version of your repository. If you want a DOI badge for a specific release, please follow the DOI link for one of the specific releases and grab badge from the archived record.
</small>
</p>
{% from "invenio_formatter/macros/badges.html" import badges_formats_list %}
{{ badges_formats_list(image_url, doi_url)}}
</div>
</div>
{% set image_url = url_for('invenio_github_badge.index', repo_github_id=github_id, _external=True) %}
<a class="ui blue image label">
<img id="record-doi-badge" src="{{ url_for('invenio_formatter_badges.badge', title='DOI', value=doi, ext='svg', _external=True, _scheme='https') }}" alt="{{ doi }}">
</a>

<div id="doi-modal" class="ui modal fade">
<div class="header">{{ _("DOI Badge") }}</div>
<div class="content">
<small>
{{ _("This badge points to the latest released version of your repository. If you want a DOI badge for a specific release, please follow the DOI link for one of the specific releases and grab badge from the archived record.") }}
</small>
<h4>
<small>{{ _("DOI") }}</small>
</h4>
<h4>
<pre>{{ doi }}</pre>
</h4>
{% from "semantic-ui/invenio_formatter/macros/badges.html" import badges_formats_list %}
{{ badges_formats_list(image_url, doi_url)}}
</div>
</div>
{%- endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2>
<div class="column"></div>
<div class="column centered">
<br>
<a class="ui label blue" href="https://doi.org/10.5281/zenodo.8475">
<a href="https://doi.org/10.5281/zenodo.8475">
<img src="{{ url_for('invenio_formatter_badges.badge', title='doi', value='10.5281/zenodo.8475', ext='svg') }}" alt="10.5281/zenodo.8475">
</a>
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Invenio is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}
{%- from "invenio_github/helpers.html" import doi_badge with context -%}
{%- set release = repo.get('latest') %}
{%- block repository_item %}
<div class="ui grid">
<div class="ten wide column">
Expand All @@ -16,6 +18,14 @@ <h4>
</a>
<a href="{{ url_for('.get_repository', repo_name=repo.full_name) }}">{{ repo.full_name }}</a>
</h4>
{%- if release.record %}
{%- set id_doi = release.record.pids.get('doi', {}).get('identifier') %}
{%- endif %}
{%- if id_doi %}
<p>
{{ doi_badge(id_doi, doi_url=release.self_url, github_id=repo_id) }}
</p>
{%- endif %}
</div>
</div>
<div class="four wide column">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@
#}

{%- import "invenio_github/settings/helpers.html" as helpers with context %}
{%- from "invenio_github/helpers.html" import doi_badge with context -%}

{%- extends config.GITHUB_SETTINGS_TEMPLATE %}

{%- block settings_content %}
{%- set github_rel_url = 'https://github.com/{0}/releases/new'.format(repo.name) %}
{%- set latest_success_pid = None %}
{%- set latest_published = repo.latest_release(status='D') %}
{% set active = true %}
{%- if latest_published %}
{%- set latest_success_pid = latest_published.release_id %}
{%- endif %}
{%- block repo_details_header %}
{%- block repo_details_header scoped %}
<div class="repositories-list">
<div class="ui grid">
<div class="eleven wide column">
<h1>
<i class="github icon"></i>
{{ repo.name }}
</h1>
{%- if latest_release.record %}
{%- set id_doi = latest_release.record.pids.get('doi', {}).get('identifier') %}
{%- endif %}
{%- if id_doi %}
<p>{{ doi_badge(id_doi, doi_url=latest_release.self_url, github_id=repo.github_id) }}</p>
{%- endif %}
</div>
<div class="four wide right aligned column">
<div id="repo-switch-message" class="ui label hidden"></div>
Expand Down Expand Up @@ -135,6 +138,18 @@ <h5>
</h5>
</a>
<br>
{%- if release.record %}
{%- set release_doi = release.record.pids.get('doi', {}).get('identifier') %}
{%- endif %}
{%- if release_doi %}
<p>
<a href={{release.self_url}}>
<i class="barcode icon"></i>
DOI: {{release_doi}}
</a>
</p>
{%- endif %}
<br>
<p>
<a href="{{ release.event.payload.release.html_url if release.event else 'https://github.com/{0}/releases/tag/{1}'.format(repo.name, release.model.tag) }}">
<i class="github icon tab-menu-accordion"></i>
Expand Down
3 changes: 1 addition & 2 deletions invenio_github/views/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def index(repo_github_id):
try:
github_api = GitHubAPI(current_user.id)
repo = github_api.get_repository(repo_github_id=repo_github_id)
release_object = github_api.repo_last_published_release(repo)
release = current_github.release_api_class(release_object)
release = github_api.repo_last_published_release(repo)
badge_url = url_for(
"invenio_formatter_badges.badge",
title=release.badge_title,
Expand Down
2 changes: 2 additions & 0 deletions invenio_github/views/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def get_repository(repo_name):

try:
repo = github.get_repository(repo_name)
latest_release = github.repo_last_published_release(repo)
default_branch = (
github.account.extra_data.get("repos", [])
.get(str(repo.github_id), None)
Expand All @@ -142,6 +143,7 @@ def get_repository(repo_name):
releases = github.get_repository_releases(repo=repo)
return render_template(
current_app.config["GITHUB_TEMPLATE_VIEW"],
latest_release=latest_release,
repo=repo,
releases=releases,
default_branch=default_branch,
Expand Down

0 comments on commit 4cde2d8

Please sign in to comment.