Delay Profiles

New: Select preferred protocol (usenet/torrent)
New: Option to delay grabs from usenet/torrents independently
This commit is contained in:
Mark McDowall
2014-11-23 16:07:46 -08:00
parent 0d61b5dc97
commit 37a1398338
51 changed files with 1164 additions and 342 deletions

View File

@@ -0,0 +1,12 @@
'use strict';
define(
[
'backbone',
'Settings/Profile/Delay/DelayProfileModel'
], function (Backbone, DelayProfileModel) {
return Backbone.Collection.extend({
model: DelayProfileModel,
url : window.NzbDrone.ApiRoot + '/delayprofile'
});
});

View File

@@ -0,0 +1,17 @@
'use strict';
define([
'backbone.collectionview',
'Settings/Profile/Delay/DelayProfileItemView'
], function (BackboneSortableCollectionView, DelayProfileItemView) {
return BackboneSortableCollectionView.extend({
className : 'delay-profiles',
modelView : DelayProfileItemView,
events: {
'click li, td' : '_listItem_onMousedown',
'dblclick li, td' : '_listItem_onDoubleClick',
'keydown' : '_onKeydown'
}
});
});

View File

@@ -0,0 +1,27 @@
'use strict';
define([
'jquery',
'AppLayout',
'marionette',
'Settings/Profile/Delay/Edit/DelayProfileEditView'
], function ($, AppLayout, Marionette, EditView) {
return Marionette.ItemView.extend({
template : 'Settings/Profile/Delay/DelayProfileItemViewTemplate',
className : 'row',
events: {
'click .x-edit' : '_edit'
},
initialize: function () {
this.listenTo(this.model, 'sync', this.render);
},
_edit: function() {
var view = new EditView({ model: this.model, targetCollection: this.model.collection});
AppLayout.modalRegion.show(view);
}
});
});

View File

@@ -0,0 +1,39 @@
 <div class="col-sm-2">
{{TitleCase preferredProtocol}}
</div>
<div class="col-sm-2">
{{#if_eq usenetDelay compare="0"}}
No delay
{{else}}
{{#if_eq usenetDelay compare="1"}}
1 minute
{{else}}
{{usenetDelay}} minutes
{{/if_eq}}
{{/if_eq}}
</div>
<div class="col-sm-2">
{{#if_eq torrentDelay compare="0"}}
No delay
{{else}}
{{#if_eq torrentDelay compare="1"}}
1 minute
{{else}}
{{torrentDelay}} minutes
{{/if_eq}}
{{/if_eq}}
</div>
<div class="col-sm-5">
{{tagDisplay tags}}
</div>
<div class="col-sm-1">
<div class="pull-right">
{{#unless_eq id compare="1"}}
<i class="drag-handle icon-reorder x-drag-handle" title="Reorder"/>
{{/unless_eq}}
<i class="icon-nd-edit x-edit" title="Edit"></i>
</div>
</div>

View File

@@ -0,0 +1,109 @@
'use strict';
define(
[
'jquery',
'underscore',
'vent',
'AppLayout',
'marionette',
'backbone',
'Settings/Profile/Delay/DelayProfileCollectionView',
'Settings/Profile/Delay/Edit/DelayProfileEditView',
'Settings/Profile/Delay/DelayProfileModel'
], function ($,
_,
vent,
AppLayout,
Marionette,
Backbone,
DelayProfileCollectionView,
EditView,
Model) {
return Marionette.Layout.extend({
template: 'Settings/Profile/Delay/DelayProfileLayoutTemplate',
regions: {
delayProfiles : '.x-rows'
},
events: {
'click .x-add' : '_add'
},
initialize: function (options) {
this.collection = options.collection;
this._updateOrderedCollection();
this.listenTo(this.collection, 'sync', this._updateOrderedCollection);
this.listenTo(this.collection, 'add', this._updateOrderedCollection);
this.listenTo(this.collection, 'remove', function () {
this.collection.fetch();
});
},
onRender: function () {
this.sortableListView = new DelayProfileCollectionView({
sortable : true,
collection : this.orderedCollection,
sortableOptions : {
handle: '.x-drag-handle'
},
sortableModelsFilter : function( model ) {
return model.get('id') !== 1;
}
});
this.delayProfiles.show(this.sortableListView);
this.listenTo(this.sortableListView, 'sortStop', this._updateOrder);
},
_updateOrder: function() {
var self = this;
this.collection.forEach(function (model) {
if (model.get('id') === 1) {
return;
}
var orderedModel = self.orderedCollection.get(model);
var order = self.orderedCollection.indexOf(orderedModel) + 1;
if (model.get('order') !== order) {
model.set('order', order);
model.save();
}
});
},
_add: function() {
var model = new Model({
preferredProtocol : 1,
usenetDelay : 0,
torrentDelay : 0,
order : this.collection.length,
tags : []
});
model.collection = this.collection;
var view = new EditView({ model: model, targetCollection: this.collection});
AppLayout.modalRegion.show(view);
},
_updateOrderedCollection: function () {
if (!this.orderedCollection) {
this.orderedCollection = new Backbone.Collection();
}
this.orderedCollection.reset(_.sortBy(this.collection.models, function (model) {
return model.get('order');
}));
}
});
});

View File

@@ -0,0 +1,24 @@
<fieldset class="advanced-setting">
<legend>Delay Profiles</legend>
<div class="col-md-12">
<div class="rule-setting-list">
<div class="rule-setting-header x-header hidden-xs">
<div class="row">
<span class="col-sm-2">Preferred Protocol</span>
<span class="col-sm-2">Usenet Delay</span>
<span class="col-sm-2">Torrent Delay</span>
<span class="col-sm-5">Tags</span>
</div>
</div>
<div class="rows x-rows"></div>
<div class="rule-setting-footer">
<div class="pull-right">
<span class="add-rule-setting-mapping">
<i class="icon-nd-add x-add" title="Add new delay profile" />
</span>
</div>
</div>
</div>
</div>
</fieldset>

View File

@@ -0,0 +1,8 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});

View File

@@ -0,0 +1,25 @@
'use strict';
define([
'vent',
'marionette'
], function (vent, Marionette) {
return Marionette.ItemView.extend({
template: 'Settings/Profile/Delay/Delete/DelayProfileDeleteViewTemplate',
events: {
'click .x-confirm-delete': '_delete'
},
_delete: function () {
var collection = this.model.collection;
this.model.destroy({
wait : true,
success: function () {
vent.trigger(vent.Commands.CloseModalCommand);
}
});
}
});
});

View File

@@ -0,0 +1,13 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Delete Delay Profile</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this delay profile?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">cancel</button>
<button class="btn btn-danger x-confirm-delete">delete</button>
</div>
</div>

View File

@@ -0,0 +1,48 @@
 'use strict';
define([
'vent',
'AppLayout',
'marionette',
'Settings/Profile/Delay/Delete/DelayProfileDeleteView',
'Mixins/AsModelBoundView',
'Mixins/AsValidatedView',
'Mixins/AsEditModalView',
'Mixins/TagInput',
'bootstrap'
], function (vent, AppLayout, Marionette, DeleteView, AsModelBoundView, AsValidatedView, AsEditModalView) {
var view = Marionette.ItemView.extend({
template: 'Settings/Profile/Delay/Edit/DelayProfileEditViewTemplate',
_deleteView: DeleteView,
ui: {
tags : '.x-tags'
},
initialize: function (options) {
this.targetCollection = options.targetCollection;
},
onRender: function () {
if (this.model.id !== 1) {
this.ui.tags.tagInput({
model : this.model,
property : 'tags'
});
}
},
_onAfterSave: function () {
this.targetCollection.add(this.model, { merge: true });
vent.trigger(vent.Commands.CloseModalCommand);
}
});
AsModelBoundView.call(view);
AsValidatedView.call(view);
AsEditModalView.call(view);
return view;
});

View File

@@ -0,0 +1,76 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" aria-hidden="true" data-dismiss="modal">&times;</button>
{{#if id}}
<h3>Edit - Delay Profile</h3>
{{else}}
<h3>Add - Delay Profile</h3>
{{/if}}
</div>
<div class="modal-body indexer-modal">
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Preferred Protocol</label>
<div class="col-sm-1 col-sm-push-5 help-inline">
<i class="icon-nd-form-info" title="Choose which protocol to use when choosing between otherwise equal releases" />
</div>
<div class="col-sm-5 col-sm-pull-1">
<select class="form-control" name="preferredProtocol">
<option value="1">Usenet</option>
<option value="2">Torrents</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Usenet Delay</label>
<div class="col-sm-1 col-sm-push-5 help-inline">
<i class="icon-nd-form-info" title="Delay in minutes to wait before grabbing a release from Usenet" />
</div>
<div class="col-sm-5 col-sm-pull-1">
<input type="number" class="form-control" name="usenetDelay"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Torrent Delay</label>
<div class="col-sm-1 col-sm-push-5 help-inline">
<i class="icon-nd-form-info" title="Delay in minutes to wait before grabbing a torrent" />
</div>
<div class="col-sm-5 col-sm-pull-1">
<input type="number" class="form-control" name="torrentDelay"/>
</div>
</div>
{{#if_eq id compare="1"}}
<div class="alert alert-info" role="alert">The default Delay Profile applies to all series unless overridden by a Delay Profile attached to a matching tag</div>
{{else}}
<div class="form-group">
<label class="col-sm-3 control-label">Tags</label>
<div class="col-sm-1 col-sm-push-5 help-inline">
<i class="icon-nd-form-info" title="One or more tags to apply these rules to matching series" />
</div>
<div class="col-sm-5 col-sm-pull-1">
<input type="text" class="form-control x-tags">
</div>
</div>
{{/if_eq}}
</div>
</div>
<div class="modal-footer">
{{#if id}}
<button class="btn btn-danger pull-left x-delete">delete</button>
{{/if}}
<span class="indicator x-indicator"><i class="icon-spinner icon-spin"></i></span>
<button class="btn" data-dismiss="modal">cancel</button>
<button class="btn btn-primary x-save">save</button>
</div>
</div>

View File

@@ -13,14 +13,7 @@ define(
template: 'Settings/Profile/Edit/EditProfileViewTemplate',
ui: {
cutoff : '.x-cutoff',
delay : '.x-delay',
delayMode : '.x-delay-mode'
},
events: {
'change .x-delay': 'toggleDelayMode',
'keyup .x-delay': 'toggleDelayMode'
cutoff : '.x-cutoff'
},
templateHelpers: function () {
@@ -29,30 +22,10 @@ define(
};
},
onShow: function () {
this.toggleDelayMode();
},
getCutoff: function () {
var self = this;
return _.findWhere(_.pluck(this.model.get('items'), 'quality'), { id: parseInt(self.ui.cutoff.val(), 10)});
},
toggleDelayMode: function () {
var delay = parseInt(this.ui.delay.val(), 10);
if (isNaN(delay)) {
return;
}
if (delay > 0 && Config.getValueBoolean(Config.Keys.AdvancedSettings)) {
this.ui.delayMode.show();
}
else {
this.ui.delayMode.hide();
}
}
});

View File

@@ -24,34 +24,6 @@
</div>
</div>
<div class="form-group advanced-setting">
<label class="col-sm-3 control-label">Delay</label>
<div class="col-sm-5">
<input type="number" min="0" max="72" name="grabDelay" class="form-control x-delay">
</div>
<div class="col-sm-1 help-inline">
<i class="icon-nd-form-info" title="Wait time in hours before grabbing a release automatically, set to 0 to disable. The highest allowed quality in the profile will be grabbed immediately when available."/>
</div>
</div>
<div class="form-group advanced-setting x-delay-mode">
<label class="col-sm-3 control-label">Delay Mode</label>
<div class="col-sm-5">
<select class="form-control" name="grabDelayMode">
<option value="first">First</option>
<option value="cutoff">Cutoff</option>
<option value="always">Always</option>
</select>
</div>
<div class="col-sm-1 help-inline">
<i class="icon-nd-form-info" data-html="true" title="First: Delay until first wanted release passes delay, grabbing best quality release at that time. Cutoff: Delay for all qualities below the cutoff. Always: Delay before grabbing all qualities"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Cutoff</label>

View File

@@ -5,22 +5,29 @@ define(
'marionette',
'Profile/ProfileCollection',
'Settings/Profile/ProfileCollectionView',
'Settings/Profile/Delay/DelayProfileLayout',
'Settings/Profile/Delay/DelayProfileCollection',
'Settings/Profile/Language/LanguageCollection'
], function (Marionette, ProfileCollection, ProfileCollectionView, LanguageCollection) {
], function (Marionette, ProfileCollection, ProfileCollectionView, DelayProfileLayout, DelayProfileCollection, LanguageCollection) {
return Marionette.Layout.extend({
template: 'Settings/Profile/ProfileLayoutTemplate',
regions: {
profile : '#profile'
profile : '#profile',
delayProfile : '#delay-profile'
},
initialize: function (options) {
this.settings = options.settings;
ProfileCollection.fetch();
this.delayProfileCollection = new DelayProfileCollection();
this.delayProfileCollection.fetch();
},
onShow: function () {
this.profile.show(new ProfileCollectionView({collection: ProfileCollection}));
this.delayProfile.show(new DelayProfileLayout({collection: this.delayProfileCollection}));
}
});
});

View File

@@ -1,3 +1,5 @@
<div class="row">
<div class="col-md-12" id="profile"/>
<div class="col-md-12 delay-profile-region" id="delay-profile"/>
</div>

View File

@@ -5,11 +5,8 @@
<div class="language">
{{languageLabel}}
{{#if_gt grabDelay compare="0"}}
<i class="icon-time" title="{{grabDelay}} hour, Mode: {{TitleCase grabDelayMode}}"></i>
{{/if_gt}}
</div>
<ul class="allowed-qualities">
{{allowedLabeler}}
</ul>

View File

@@ -29,3 +29,15 @@
margin-bottom: 3px;
}
}
.delay-profile-region {
margin-top : 30px;
}
.delay-profiles {
padding-left : 0px;
li {
list-style-type : none;
}
}