From 343a794c2a3ae22f86e159ac4441f299ecbe1321 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 24 May 2013 19:08:26 -0700 Subject: [PATCH] existing series search shows first suggestion requests are sent to server sequentially not to kill the client. --- NzbDrone.Api/Series/SeriesLookupModule.cs | 6 ++- UI/AddSeries/AddSeriesLayout.js | 7 +++- UI/AddSeries/Existing/ImportSeriesView.js | 46 ++++++++++++++++------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/NzbDrone.Api/Series/SeriesLookupModule.cs b/NzbDrone.Api/Series/SeriesLookupModule.cs index e8a2b1a7d..7cf6832bb 100644 --- a/NzbDrone.Api/Series/SeriesLookupModule.cs +++ b/NzbDrone.Api/Series/SeriesLookupModule.cs @@ -1,6 +1,8 @@ -using Nancy; +using System.Threading; +using Nancy; using NzbDrone.Api.Extensions; using NzbDrone.Core.MetadataSource; +using System.Linq; namespace NzbDrone.Api.Series { @@ -19,7 +21,7 @@ namespace NzbDrone.Api.Series private Response GetQualityType() { var tvDbResults = _searchProxy.SearchForNewSeries((string)Request.Query.term); - return tvDbResults.AsResponse(); + return tvDbResults.FirstOrDefault().AsResponse(); } } } \ No newline at end of file diff --git a/UI/AddSeries/AddSeriesLayout.js b/UI/AddSeries/AddSeriesLayout.js index 205ec88b5..c0ec5320b 100644 --- a/UI/AddSeries/AddSeriesLayout.js +++ b/UI/AddSeries/AddSeriesLayout.js @@ -65,11 +65,14 @@ define([ 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(); this.addNew.show(new NzbDrone.AddSeries.New.AddNewSeriesView()); - this.importExisting.show(new NzbDrone.AddSeries.Existing.ImportSeriesView()); this.rootFolders.show(new NzbDrone.AddSeries.RootDirView()); this.listenTo(rootFolderCollection, 'add', this.evaluateActions, this); diff --git a/UI/AddSeries/Existing/ImportSeriesView.js b/UI/AddSeries/Existing/ImportSeriesView.js index 108cfc978..8bff9bee4 100644 --- a/UI/AddSeries/Existing/ImportSeriesView.js +++ b/UI/AddSeries/Existing/ImportSeriesView.js @@ -45,7 +45,7 @@ define([ self.trigger('seriesAdded'); self.close(); }, - fail: function () { + fail : function () { icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); } }); @@ -59,7 +59,7 @@ define([ itemView : NzbDrone.AddSeries.Existing.FolderMatchResultView, events: { - 'click .x-btn-search': 'search', + 'click .x-btn-search' : 'search', 'keydown .x-txt-search': 'keyDown' }, @@ -73,7 +73,7 @@ define([ this.collection = new NzbDrone.AddSeries.Collection(); this.collection.bind('reset', this.collectionReset, this); - this.on("itemview:seriesAdded", function(){ + this.on("itemview:seriesAdded", function () { this.close(); }); }, @@ -85,6 +85,8 @@ define([ search: function () { var icon = this.ui.searchButton.find('icon'); + var deferred = $.Deferred(); + this.collection.reset(); icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled'); @@ -92,23 +94,27 @@ define([ data : { term: this.ui.searchText.val() }, success: function (collection) { icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); + deferred.resolve(); }, fail : function () { icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); + deferred.reject(); } }); + + return deferred.promise(); }, keyDown: function (e) { //Check for enter being pressed - var code = (e.keyCode ? e.keyCode : e.which); - if(code === 13) { + var code = (e.keyCode ? e.keyCode :e.which); + if (code === 13) { this.search(); } }, collectionReset: function () { - _.each(this.collection.models, function (model){ + _.each(this.collection.models, function (model) { model.set('isExisting', true); }); }, @@ -141,15 +147,27 @@ define([ refreshItems: function () { 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; - } }); });