Skip to content

Commit

Permalink
add jquery updating (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jun 20, 2024
1 parent 1d6b56a commit 990cc26
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
41 changes: 40 additions & 1 deletion projectroles/static/projectroles/js/project_detail.js
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
// TODO: Add remote site link updating here
/* Project detail view specific JQuery */

/* Update target/peer remote project links once accessed */
var updateRemoteProjectLinks = function() {
var linkUuids = [];
$('.sodar-pr-link-remote').each(function() {
if (!$(this).hasClass('sodar-pr-link-remote-source')
&& $(this).attr('disabled') === 'disabled') {
linkUuids.push($(this).attr('data-uuid'));
}
});
if (linkUuids.length > 0) {
var queryParams = []
for (var i = 0; i < linkUuids.length; i++) {
queryParams.push(['rp', linkUuids[i]])
}
$.ajax({
url: window.remoteLinkUrl + '?' + new URLSearchParams(queryParams),
method: 'GET',
dataType: 'JSON',
}).done(function (data) {
for (var k in data) {
var elem = $('a[data-uuid="' +k + '"]');
if (elem.attr('disabled') === 'disabled' && data[k] === true) {
elem.removeAttr('disabled');
}
}
});
}};

$(document).ready(function() {
// Set up remote project link updating, omit categories
if ($('div#sodar-pr-page-container-detail').attr(
'data-project-type') === 'PROJECT') {
updateRemoteProjectLinks();
setInterval(function () {
updateRemoteProjectLinks();
}, 5000);
}
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% load projectroles_common_tags %}

{# TODO: Add UUID as data attribute #}
{# TODO: Add JQuery to enable accessed target projects #}
<a class="btn {% if site.user_display %}btn-info{% else %}btn-secondary{% endif %}
mr-1 mb-1 sodar-pr-link-remote sodar-pr-link-remote-{{ site.mode|lower }}"
href="{{ site.get_url }}{% url 'projectroles:detail' project=object.sodar_uuid %}"
data-uuid="{{ rp.sodar_uuid }}"
role="button"
{% if site.description %}title="{{ site.description }}" data-toggle="tooltip"{% endif %}
{% if site.mode != 'SOURCE' and not site.get_access_date %}
Expand Down
9 changes: 8 additions & 1 deletion projectroles/templates/projectroles/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
{% if can_view_project %}
{% include 'projectroles/_project_header.html' %}

<div class="container-fluid sodar-page-container">
<div class="container-fluid sodar-page-container"
id="sodar-pr-page-container-detail"
data-project-type="{{ object.type }}">
{# Links to remote projects #}
{% if object.type == 'PROJECT' %}
{% if target_projects %}
Expand Down Expand Up @@ -120,12 +122,17 @@ <h4>

{% block javascript %}
{{ block.super }}
<script type="text/javascript">
window.remoteLinkUrl = "{% url 'projectroles:ajax_remote_access' project=object.sodar_uuid %}";
</script>
{% if object.type == 'CATEGORY' %}
<!-- Project list -->
<script type="text/javascript" src="{% static 'projectroles/js/project_list.js' %}"></script>
{% endif %}
<!-- Project starring -->
<script type="text/javascript" src="{% static 'projectroles/js/project_star.js' %}"></script>
<!-- Project detail view specific -->
<script type="text/javascript" src="{% static 'projectroles/js/project_detail.js' %}"></script>

<!-- Tour content -->
<script type="text/javascript">
Expand Down
21 changes: 20 additions & 1 deletion projectroles/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,26 @@ def test_remote_project_not_accessed(self):
)
self.assertEqual(elem.get_attribute('disabled'), 'true')

# TODO: Test link with updating date_access by JQuery
def test_remote_project_update(self):
"""Test non-accessed remote project with client side update"""
self._setup_remotes()
self.remote_project.date_access = None
self.remote_project.save()
self.login_and_redirect(self.superuser, self.url)
elem = self.selenium.find_element(
By.CLASS_NAME, 'sodar-pr-link-remote-target'
)
self.assertEqual(elem.get_attribute('disabled'), 'true')
self.remote_project.date_access = timezone.now()
self.remote_project.save()
xp = (
'//a[contains(@class, "sodar-pr-link-remote-target") '
'and not(@disabled)]'
)
WebDriverWait(self.selenium, 15).until(
ec.presence_of_element_located((By.XPATH, xp))
)
self.assertEqual(elem.get_attribute('disabled'), None)

def test_peer_project_source(self):
"""Test visibility of peer projects on SOURCE site"""
Expand Down

0 comments on commit 990cc26

Please sign in to comment.