Sonarr/src/UI/Activity/Queue/QueueView.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-02-03 01:18:45 +00:00
var _ = require('underscore');
var Marionette = require('marionette');
var QueueCollection = require('./QueueCollection');
module.exports = Marionette.ItemView.extend({
2015-02-13 21:03:50 +00:00
tagName : 'span',
initialize : function() {
2015-02-03 01:18:45 +00:00
this.listenTo(QueueCollection, 'sync', this.render);
QueueCollection.fetch();
},
2015-02-13 21:03:50 +00:00
render : function() {
2015-02-03 01:18:45 +00:00
this.$el.empty();
2015-02-13 21:03:50 +00:00
if (QueueCollection.length === 0) {
2015-02-03 01:18:45 +00:00
return this;
}
2015-02-13 21:03:50 +00:00
2015-02-03 01:18:45 +00:00
var count = QueueCollection.fullCollection.length;
var label = 'label-info';
2015-02-13 21:03:50 +00:00
var errors = QueueCollection.fullCollection.some(function(model) {
2015-02-03 01:18:45 +00:00
return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'error';
});
2015-02-13 21:03:50 +00:00
var warnings = QueueCollection.fullCollection.some(function(model) {
2015-02-03 01:18:45 +00:00
return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'warning';
});
2015-02-13 21:03:50 +00:00
if (errors) {
2015-02-03 01:18:45 +00:00
label = 'label-danger';
2015-02-13 21:03:50 +00:00
} else if (warnings) {
2015-02-03 01:18:45 +00:00
label = 'label-warning';
}
2015-02-13 21:03:50 +00:00
2015-02-03 01:18:45 +00:00
this.$el.html('<span class="label {0}">{1}</span>'.format(label, count));
return this;
}
});