1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

UI Cleanup - Updated Navbar, Profile, Quality and Release subtrees.

This commit is contained in:
Taloth Saldono 2015-02-13 22:47:42 +01:00
parent 29d9e3dadf
commit 860f55996c
10 changed files with 217 additions and 146 deletions

View File

@ -6,37 +6,54 @@ require('./Search');
module.exports = Marionette.Layout.extend({
template : 'Navbar/NavbarLayoutTemplate',
regions : {
health : '#x-health',
queue : '#x-queue-count'
},
ui : {
search : '.x-series-search',
collapse : '.x-navbar-collapse'
},
events : {"click a" : 'onClick'},
events : {
'click a' : 'onClick'
},
onRender : function() {
this.ui.search.bindSearch();
this.health.show(new HealthView());
this.queue.show(new QueueView());
},
onClick : function(event) {
event.preventDefault();
var target = $(event.target);
//look down for <a/>
var href = event.target.getAttribute('href');
//if couldn't find it look up'
if (!href && target.closest('a') && target.closest('a')[0]) {
var linkElement = target.closest('a')[0];
href = linkElement.getAttribute('href');
this.setActive(linkElement);
}
else {
} else {
this.setActive(event.target);
}
if ($(window).width() < 768) {
this.ui.collapse.collapse('hide');
}
},
setActive : function(element) {
//Todo: Set active on first load
this.$('a').removeClass('active');
$(element).addClass('active');
}

View File

@ -5,10 +5,19 @@ var Backbone = require('backbone');
var SeriesCollection = require('../Series/SeriesCollection');
require('typeahead');
module.exports = (function(){
vent.on(vent.Hotkeys.NavbarSearch, function() {
$('.x-series-search').focus();
});
var substringMatcher = function() {
return function findMatches (q, cb) {
var matches = _.select(SeriesCollection.toJSON(), function(series) {
return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1;
});
cb(matches);
};
};
$.fn.bindSearch = function() {
$(this).typeahead({
hint : true,
@ -19,18 +28,10 @@ module.exports = (function(){
displayKey : 'title',
source : substringMatcher()
});
$(this).on('typeahead:selected typeahead:autocompleted', function(e, series) {
this.blur();
$(this).val('');
Backbone.history.navigate('/series/{0}'.format(series.titleSlug), { trigger : true });
});
};
var substringMatcher = function(){
return function findMatches (q, cb){
var matches = _.select(SeriesCollection.toJSON(), function(series){
return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1;
});
cb(matches);
};
};
}).call(this);

View File

@ -1,12 +1,13 @@
var Backbone = require('backbone');
var ProfileModel = require('./ProfileModel');
module.exports = (function(){
var ProfileCollection = Backbone.Collection.extend({
model : ProfileModel,
url : window.NzbDrone.ApiRoot + '/profile'
});
var profiles = new ProfileCollection();
profiles.fetch();
return profiles;
}).call(this);
module.exports = profiles;

View File

@ -2,10 +2,13 @@ var ModelBase = require('../Settings/SettingsModelBase');
module.exports = ModelBase.extend({
baseInitialize : ModelBase.prototype.initialize,
initialize : function() {
var name = this.get('quality').name;
this.successMessage = 'Saved ' + name + ' quality settings';
this.errorMessage = 'Couldn\'t save ' + name + ' quality settings';
this.baseInitialize.call(this);
}
});

View File

@ -5,6 +5,7 @@ require('../Shared/FormatHelpers');
module.exports = Backgrid.Cell.extend({
className : 'age-cell',
render : function() {
var age = this.model.get('age');
var ageHours = this.model.get('ageHours');
@ -12,18 +13,23 @@ module.exports = Backgrid.Cell.extend({
var publishedFormatted = published.format('{0} {1}'.format(UiSettings.get('shortDateFormat'), UiSettings.time(true, true)));
var formatted = age;
var suffix = this.plural(age, 'day');
if (age === 0) {
formatted = ageHours.toFixed(1);
suffix = this.plural(Math.round(ageHours), 'hour');
}
this.$el.html('<div title="{2}">{0} {1}</div>'.format(formatted, suffix, publishedFormatted));
this.delegateEvents();
return this;
},
plural : function(input, unit) {
if (input === 1) {
return unit;
}
return unit + 's';
}
});

View File

@ -2,30 +2,40 @@ var Backgrid = require('backgrid');
module.exports = Backgrid.Cell.extend({
className : 'download-report-cell',
events : {click : '_onClick'},
events : {
'click' : '_onClick'
},
_onClick : function() {
if (!this.model.get('downloadAllowed')) {
return;
}
var self = this;
this.$el.html('<i class="icon-spinner icon-spin" />');
//Using success callback instead of promise so it
//gets called before the sync event is triggered
this.model.save(null, {
success : function() {
self.model.set('queued', true);
}
});
},
render : function() {
this.$el.empty();
if (this.model.get('queued')) {
this.$el.html('<i class="icon-nd-downloading" title="Added to downloaded queue" />');
}
else if(this.model.get('downloadAllowed')) {
} else if (this.model.get('downloadAllowed')) {
this.$el.html('<i class="icon-download-alt" title="Add to download queue" />');
}
else {
} else {
this.className = 'no-download-report-cell';
}
return this;
}
});

View File

@ -2,23 +2,27 @@ var Backgrid = require('backgrid');
module.exports = Backgrid.Cell.extend({
className : 'peers-cell',
render : function() {
if (this.model.get('protocol') === 'torrent') {
var seeders = this.model.get('seeders') || 0;
var leechers = this.model.get('leechers') || 0;
var level = 'danger';
if (seeders > 0) {
level = 'warning';
}
if(seeders > 10) {
} else if (seeders > 10) {
level = 'info';
}
if(seeders > 50) {
} else if (seeders > 50) {
level = 'primary';
}
this.$el.html('<div class="label label-{2}" title="{0} seeders, {1} leechers">{0} / {1}</div>'.format(seeders, leechers, level));
}
this.delegateEvents();
return this;
}
});

View File

@ -2,19 +2,23 @@ var Backgrid = require('backgrid');
module.exports = Backgrid.Cell.extend({
className : 'protocol-cell',
render : function() {
var protocol = this.model.get('protocol') || 'Unknown';
var label = '??';
if (protocol) {
if (protocol === 'torrent') {
label = 'torrent';
}
else if(protocol === 'usenet') {
} else if (protocol === 'usenet') {
label = 'nzb';
}
this.$el.html('<div class="label label-default protocol-{0}" title="{0}">{1}</div>'.format(protocol, label));
}
this.delegateEvents();
return this;
}
});

View File

@ -2,42 +2,55 @@ var PagableCollection = require('backbone.pageable');
var ReleaseModel = require('./ReleaseModel');
var AsSortedCollection = require('../Mixins/AsSortedCollection');
module.exports = (function(){
var Collection = PagableCollection.extend({
url : window.NzbDrone.ApiRoot + '/release',
model : ReleaseModel,
state : {
pageSize : 2000,
sortKey : 'download',
order : -1
},
mode : 'client',
sortMappings : {
quality : {sortKey : 'qualityWeight'},
rejections : {
'quality' : {
sortKey : 'qualityWeight'
},
'rejections' : {
sortValue : function(model) {
var rejections = model.get('rejections');
var releaseWeight = model.get('releaseWeight');
if (rejections.length !== 0) {
return releaseWeight + 1000000;
}
return releaseWeight;
}
},
download : {sortKey : 'releaseWeight'},
seeders : {
'download' : {
sortKey : 'releaseWeight'
},
'seeders' : {
sortValue : function(model) {
var seeders = model.get('seeders') || 0;
var leechers = model.get('leechers') || 0;
return seeders * 1000000 + leechers;
}
},
age : {sortKey : 'ageMinutes'}
'age' : {
sortKey : 'ageMinutes'
}
},
fetchEpisodeReleases : function(episodeId) {
return this.fetch({ data : { episodeId : episodeId } });
}
});
Collection = AsSortedCollection.call(Collection);
return Collection;
}).call(this);
module.exports = Collection;

View File

@ -10,48 +10,60 @@ var LoadingView = require('../Shared/LoadingView');
module.exports = Marionette.Layout.extend({
template : 'Release/ReleaseLayoutTemplate',
regions : {
grid : '#x-grid',
toolbar : '#x-toolbar'
},
columns : [{
columns : [
{
name : 'indexer',
label : 'Indexer',
sortable : true,
cell : IndexerCell
}, {
},
{
name : 'title',
label : 'Title',
sortable : true,
cell : Backgrid.StringCell
}, {
},
{
name : 'episodeNumbers',
episodes : 'episodeNumbers',
label : 'season',
cell : EpisodeNumberCell
}, {
},
{
name : 'size',
label : 'Size',
sortable : true,
cell : FileSizeCell
}, {
},
{
name : 'quality',
label : 'Quality',
sortable : true,
cell : QualityCell
}, {
},
{
name : 'rejections',
label : '',
cell : ApprovalStatusCell
}],
}
],
initialize : function() {
this.collection = new ReleaseCollection();
this.listenTo(this.collection, 'sync', this._showTable);
},
onRender : function() {
this.grid.show(new LoadingView());
this.collection.fetch();
},
_showTable : function() {
if (!this.isClosed) {
this.grid.show(new Backgrid.Grid({