Commit 90861c22 by Chris Dodge

improvements on asset upload refresh. Now we don't need to refresh the whole…

improvements on asset upload refresh. Now we don't need to refresh the whole page, just insert the table tow
parent 5964ecc7
...@@ -718,8 +718,18 @@ def upload_asset(request, org, course, coursename): ...@@ -718,8 +718,18 @@ def upload_asset(request, org, course, coursename):
#then commit the content #then commit the content
contentstore().save(content) contentstore().save(content)
del_cached_content(content.location) del_cached_content(content.location)
# readback the saved content - we need the database timestamp
readback = contentstore().find(content.location)
response = HttpResponse('Upload completed') response_payload = {'displayname' : content.name,
'uploadDate' : get_date_display(readback.last_modified_at),
'url' : StaticContent.get_url_path_from_location(content.location),
'thumb_url' : StaticContent.get_url_path_from_location(thumbnail_content.location) if thumbnail_content is not None else None,
'msg' : 'Upload completed'
}
response = HttpResponse(json.dumps(response_payload))
response['asset_url'] = StaticContent.get_url_path_from_location(content.location) response['asset_url'] = StaticContent.get_url_path_from_location(content.location)
return response return response
...@@ -866,6 +876,10 @@ def asset_index(request, org, course, name): ...@@ -866,6 +876,10 @@ def asset_index(request, org, course, name):
course_reference = StaticContent.compute_location(org, course, name) course_reference = StaticContent.compute_location(org, course, name)
assets = contentstore().get_all_content_for_course(course_reference) assets = contentstore().get_all_content_for_course(course_reference)
# sort in reverse upload date order
assets = sorted(assets, key=lambda asset: asset['uploadDate'], reverse=True)
thumbnails = contentstore().get_all_content_thumbnails_for_course(course_reference) thumbnails = contentstore().get_all_content_thumbnails_for_course(course_reference)
asset_display = [] asset_display = []
for asset in assets: for asset in assets:
......
...@@ -335,10 +335,21 @@ function displayFinishedUpload(xhr) { ...@@ -335,10 +335,21 @@ function displayFinishedUpload(xhr) {
if(xhr.status = 200){ if(xhr.status = 200){
markAsLoaded(); markAsLoaded();
} }
var resp = JSON.parse(xhr.responseText);
$('.upload-modal .copy-button').attr('href', xhr.getResponseHeader('asset_url')); $('.upload-modal .copy-button').attr('href', xhr.getResponseHeader('asset_url'));
$('.upload-modal .progress-fill').html(xhr.responseText); $('.upload-modal .progress-fill').html(resp.msg);
$('.upload-modal .choose-file-button').html('Load Another File').show(); $('.upload-modal .choose-file-button').html('Load Another File').show();
$('.upload-modal .progress-fill').width('100%'); $('.upload-modal .progress-fill').width('100%');
// see if this id already exists, if so, then user must have updated an existing piece of content
$("tr[data-id='" + resp.url + "']").remove();
var template = $('#new-asset-element').html();
var html = Mustache.to_html(template, resp);
$('table > tbody > tr:first').before(html);
$("tr[data-id='" + resp.url + "'] a.show-xml").toggle(showEmbeddableXML, hideEmbeddableXML);
} }
function markAsLoaded() { function markAsLoaded() {
...@@ -350,7 +361,6 @@ function hideModal(e) { ...@@ -350,7 +361,6 @@ function hideModal(e) {
e.preventDefault(); e.preventDefault();
$('.modal').hide(); $('.modal').hide();
$modalCover.hide(); $modalCover.hide();
location.reload();
} }
function onKeyUp(e) { function onKeyUp(e) {
......
...@@ -3,8 +3,36 @@ ...@@ -3,8 +3,36 @@
<%block name="bodyclass">assets</%block> <%block name="bodyclass">assets</%block>
<%block name="title">Courseware Assets</%block> <%block name="title">Courseware Assets</%block>
<%namespace name='static' file='static_content.html'/>
<%block name="jsextra">
<script src="${static.url('js/vendor/mustache.js')}"></script>
</%block>
<%block name="content"> <%block name="content">
<script type="text/template" id="new-asset-element">
<tr data-id='{{url}}'>
<td class="thumb-col">
<div class="thumb">
{{#thumb_url}}
<img src="{{thumb_url}}">
{{/thumb_url}}
</div>
</td>
<td class="name-col">
<a href="{{url}}" class="filename">{{displayname}}</a>
<div class="embeddable-xml"></div>
</td>
<td class="date-col">
{{uploadDate}}
</td>
<td class="embed-col">
<a class="show-xml" href="{{url}}">XML</a>
</td>
</tr>
</script>
<div class="main-wrapper"> <div class="main-wrapper">
<div class="inner-wrapper"> <div class="inner-wrapper">
<h1>Asset Library</h1> <h1>Asset Library</h1>
...@@ -22,9 +50,9 @@ ...@@ -22,9 +50,9 @@
<th class="embed-col">Embed</th> <th class="embed-col">Embed</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="asset_table_body">
% for asset in assets: % for asset in assets:
<tr> <tr data-id="${asset['url']}">
<td class="thumb-col"> <td class="thumb-col">
<div class="thumb"> <div class="thumb">
% if asset['thumb_url'] is not None: % if asset['thumb_url'] is not None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment