-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2111 from MIT-LCP/files-panel-history
files_panel dynamic navigation fixes
- Loading branch information
Showing
6 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
physionet-django/project/static/project/js/dynamic-files-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var panel = $('#files-panel'); | ||
var cur_dir = panel.find('[data-dfp-cur-dir]').data('dfp-cur-dir'); | ||
var panel_url = panel.find('[data-dfp-panel-url]').data('dfp-panel-url'); | ||
|
||
function navigateDir(subdir, page_url, push_history) { | ||
$.ajax({ | ||
type: 'GET', | ||
url: panel_url, | ||
data: {'subdir': subdir, 'v': '2'}, | ||
success: function(result) { | ||
if (push_history) | ||
history.pushState(subdir, '', page_url); | ||
else | ||
history.replaceState(subdir, '', page_url); | ||
panel.html(result); | ||
setClickHandlers(); | ||
}, | ||
}); | ||
} | ||
|
||
function setClickHandlers() { | ||
panel.find('a[data-dfp-dir]').click(function(event) { | ||
navigateDir($(this).data('dfp-dir'), this.href, true); | ||
event.preventDefault(); | ||
}); | ||
} | ||
setClickHandlers(); | ||
|
||
window.onpopstate = function(event) { | ||
if (event.state !== null) { | ||
navigateDir(event.state, window.location, false); | ||
} | ||
}; | ||
history.replaceState(cur_dir, ''); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
physionet-django/project/templates/project/files_panel_v2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{# Note: This template is used together with dynamic-files-panel.js. #} | ||
<div class="card-header" | ||
data-dfp-panel-url="{{ files_panel_url }}" | ||
data-dfp-cur-dir="{{ subdir }}"> | ||
Folder Navigation: | ||
{% spaceless %} | ||
<span class="dir-breadcrumbs"> | ||
{% for breadcrumb in dir_breadcrumbs %} | ||
{% if forloop.counter == dir_breadcrumbs|length %} | ||
<span class="dir-breadcrumb-self">{{ breadcrumb.name }}</span> | ||
{% else %} | ||
<a href="{{ breadcrumb.rel_path }}#files-panel" | ||
data-dfp-dir="{{ breadcrumb.full_subdir }}" | ||
class="dir-breadcrumb-up">{{ breadcrumb.name }}</a> | ||
<span class="dir-breadcrumb-sep">/</span> | ||
{% endif %} | ||
{% endfor %} | ||
</span> | ||
{% endspaceless %} | ||
</div> | ||
{% if file_error %} | ||
<div class="card-body"> | ||
<div class="alert alert-danger" role="alert"> | ||
{{ file_error|safe }} | ||
</div> | ||
</div> | ||
{% else %} | ||
{% if file_warning %} | ||
<div class="card-body"> | ||
<div class="alert alert-warning" role="alert"> | ||
{{ file_warning|safe }} | ||
</div> | ||
</div> | ||
{% endif %} | ||
<table class="files-panel"> | ||
<col class="files-panel-name"></col> | ||
<col class="files-panel-size"></col> | ||
<col class="files-panel-date"></col> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Size</th> | ||
<th>Modified</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% if subdir %} | ||
<tr class="parentdir"> | ||
<td><a href="../#files-panel" data-dfp-dir="{{ parent_dir }}">Parent Directory</a></td> | ||
<td></td> | ||
<td></td> | ||
</tr> | ||
{% endif %} | ||
{% for dir in display_dirs %} | ||
<tr class="subdir"> | ||
<td><a href="{{ dir.name }}/#files-panel" data-dfp-dir="{{ dir.full_subdir }}">{{ dir.name }}</a></td> | ||
<td></td> | ||
<td></td> | ||
</tr> | ||
{% endfor %} | ||
{% for file in display_files %} | ||
<tr> | ||
<td><a href="{{ file.name }}">{{ file.name }}</a> | ||
<a class="download" href="{{ file.download_url }}" | ||
title="Download {{ file.name }}"> | ||
<span class="visually-hidden">(download)</span> | ||
</a> | ||
</td> | ||
<td>{{ file.size }}</td> | ||
<td>{{ file.last_modified }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters