existing series search shows first suggestion

requests are sent to server sequentially not to kill the client.
This commit is contained in:
Keivan Beigi 2013-05-24 19:08:26 -07:00
parent 482cbc20a3
commit 343a794c2a
3 changed files with 41 additions and 18 deletions

View File

@ -1,6 +1,8 @@
using Nancy; using System.Threading;
using Nancy;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
using NzbDrone.Core.MetadataSource; using NzbDrone.Core.MetadataSource;
using System.Linq;
namespace NzbDrone.Api.Series namespace NzbDrone.Api.Series
{ {
@ -19,7 +21,7 @@ namespace NzbDrone.Api.Series
private Response GetQualityType() private Response GetQualityType()
{ {
var tvDbResults = _searchProxy.SearchForNewSeries((string)Request.Query.term); var tvDbResults = _searchProxy.SearchForNewSeries((string)Request.Query.term);
return tvDbResults.AsResponse(); return tvDbResults.FirstOrDefault().AsResponse();
} }
} }
} }

View File

@ -65,11 +65,14 @@ define([
onRender: function () { onRender: function () {
rootFolderCollection.fetch(); var self = this;
rootFolderCollection.fetch({success: function () {
self.importExisting.show(new NzbDrone.AddSeries.Existing.RootFolderCompositeView({model: rootFolderCollection.at(0)}));
}});
qualityProfileCollection.fetch(); qualityProfileCollection.fetch();
this.addNew.show(new NzbDrone.AddSeries.New.AddNewSeriesView()); this.addNew.show(new NzbDrone.AddSeries.New.AddNewSeriesView());
this.importExisting.show(new NzbDrone.AddSeries.Existing.ImportSeriesView());
this.rootFolders.show(new NzbDrone.AddSeries.RootDirView()); this.rootFolders.show(new NzbDrone.AddSeries.RootDirView());
this.listenTo(rootFolderCollection, 'add', this.evaluateActions, this); this.listenTo(rootFolderCollection, 'add', this.evaluateActions, this);

View File

@ -85,6 +85,8 @@ define([
search: function () { search: function () {
var icon = this.ui.searchButton.find('icon'); var icon = this.ui.searchButton.find('icon');
var deferred = $.Deferred();
this.collection.reset(); this.collection.reset();
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled'); icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
@ -92,11 +94,15 @@ define([
data : { term: this.ui.searchText.val() }, data : { term: this.ui.searchText.val() },
success: function (collection) { success: function (collection) {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.resolve();
}, },
fail : function () { fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
} }
}); });
return deferred.promise();
}, },
keyDown: function (e) { keyDown: function (e) {
@ -141,15 +147,27 @@ define([
refreshItems: function () { refreshItems: function () {
this.collection.importItems(this.model); this.collection.importItems(this.model);
},
showCollection: function () {
this.showAndSearch(0);
},
showAndSearch: function (index) {
var model = this.collection.at(index);
if (model) {
var that = this;
var currentIndex = index;
this.addItemView(model, this.getItemView(), index);
console.log('start');
$.when(this.children.findByModel(model).search())
.then(function () {
console.log('done');
that.showAndSearch(currentIndex + 1);
});
} }
});
NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({
itemView: NzbDrone.AddSeries.Existing.RootFolderCompositeView,
initialize: function () {
this.collection = rootFolders;
} }
}); });
}); });