Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an update loop to the importmedia page that shows the current s…

…tatus of the importer as well as a list of warnings/errors that were generated during the import
  • Loading branch information...
commit a71aa9fc202fe6458f5f43d3f1769865f22684c7 1 parent ed2bace
@MusikPolice authored
View
6 musik/web/api/importmedia.py
@@ -46,8 +46,10 @@ def GET(self):
status = {
'outstanding_tasks': cherrypy.request.db.query(ImportTask).filter(ImportTask.completed == None).count(),
'current_task': current_task,
- 'warnings': [warning.as_dict() for warning in warnings],
- 'errors': [error.as_dict() for error in errors]
+
+ # each result set is turned into a list of json objects and then reversed so more recent messages come first
+ 'warnings': [warning.as_dict() for warning in warnings][::-1],
+ 'errors': [error.as_dict() for error in errors][::-1]
}
# using a special JSONEncoder that can handle datetime objects
View
62 static/js/importmedia.js
@@ -1,5 +1,62 @@
+var nullCount = 0
+
+function update_status() {
+ $.ajax({
+ type: 'GET',
+ url: 'http://localhost:8080/api/importer/',
+ contentType: 'application/json; charset=utf-8',
+ success: function(data, textStatus, jqXHR) {
+ if (data['current_task'] != null) {
+ //update the status display
+ $('#status .numtasks').html(data['outstanding_tasks']);
+ $('#status .currenttask').html(data['current_task']['uri']);
+ }
+ else
+ {
+ $('#status .numtasks').html('0');
+ $('#status .currenttask').html('None');
+ }
+
+ if (data['warnings'] != null && data['warnings'].length > 0) {
+ $('#warnings ul').html('');
+ for (var i = 0; i < data['warnings'].length; i++) {
+ $('#warnings ul').append('<li>' + data['warnings'][i]['message'] + '</li>');
+ }
+ $('#warnings').show();
+ }
+
+ if (data['errors'] != null && data['errors'].length > 0) {
+ $('#errors ul').html('');
+ for (var i = 0; i < data['errors'].length; i++) {
+ $('#errors ul').append('<li>' + data['errors'][i]['message'] + '</li>');
+ }
+ $('#errors').show();
+ }
+
+ if (data['outstanding_tasks'] == 0) {
+ nullCount += 1;
+ }
+ else
+ {
+ nullCount = 0;
+ }
+
+ //we'll fire 10 extra requests after the number of outstanding tasks first appears to be zero.
+ //this should help to account for the importer taking a moment to respond to our requests
+ if (nullCount < 10) {
+ //do it again in a half second
+ setTimeout(update_status, 500);
+ }
+ },
+ dataType: 'json'
+ });
+}
+
$(document).ready(function() {
$('.validate-error').hide();
+ $('#warnings').hide();
+ $('#errors').hide();
+ update_status();
});
$('#importmedia').submit(function(event) {
@@ -22,15 +79,14 @@ $('#importmedia').submit(function(event) {
path: $('#path').val()
}
//TODO: error and success handling need some work
+ nullCount = 0;
$.ajax({
type: 'POST',
url: 'http://localhost:8080/api/importer/',
contentType: 'application/json; charset=utf-8',
data: $.toJSON(req),
dataType: 'text',
- success: function(){
- alert('great success!');
- },
+ success: update_status(),
error: function(jqXHR){
alert(jqXHR.responseText);
}
View
43 templates/importmedia.html
@@ -1,27 +1,38 @@
<h2>Import Media</h2>
- <div class="grater">
- <div>
-
- <div class="validate-error" id="validate-error-top"></div>
+ <div id="validate-error-top" class="validate-error grater"></div>
- <form id="importmedia">
- <p>
- <label for="path">Path to music directory</label>
- <input id="path" name="path" type="text">
- </p>
+ <div class="grater">
+ <p>From this page, you can import all of your precious media files into the musik database.</p>
+ <form id="importmedia">
+ <p>
+ <label for="path">Enter the path to your music directory:</label>
+ <input id="path" name="path" type="text">
+ </p>
+
+ <button type="submit" class="btn btn-primary">Import Music</button>
+ </form>
+ </div>
- <button type="submit" class="btn btn-primary">Import Music</button>
- </form>
+ <!-- status pane -->
+ <div id="status" class="grater">
+ <h4>Importer Status:</h4>
+ <p>Currently importing: <span class="currenttask">Some Task</span></p>
+ <p>Remaining tasks: <span class="numtasks">9999</span></p>
+ </div>
- </div>
+ <div id="warnings" class="grater">
+ <h4>Warnings:</h4>
+ <ul>
+ </ul>
+ </div>
- <div>
- <p>From this page, you can import all of your precious media files into the musik database.</p>
- </div>
+ <div id="errors" class="grater">
+ <h4>Errors:</h4>
+ <ul>
+ </ul>
</div>
% for js_file in js_appends:
<script type="text/javascript" src="/static/js/${js_file}"></script>
% endfor
-
Please sign in to comment.
Something went wrong with that request. Please try again.