Added auto complete to AddSeries RootDir

pull/2/head
Mark McDowall 12 years ago committed by kay.one
parent 7ed148b12c
commit 7f0dc84b29

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using NzbDrone.Api.Extentions;
using NzbDrone.Common;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Api.Directories
{
public class DirectoryModule : NzbDroneApiModule
{
private readonly DiskProvider _diskProvider;
public DirectoryModule(DiskProvider diskProvider)
: base("/directories")
{
_diskProvider = diskProvider;
Post["/"] = x => GetDirectories();
}
private Response GetDirectories()
{
if (!Request.Form.query.HasValue)
return new List<string>().AsResponse();
string query = Request.Form.query.Value;
IEnumerable<String> dirs = null;
try
{
//Windows (Including UNC)
var windowsSep = query.LastIndexOf('\\');
if (windowsSep > -1)
{
dirs = _diskProvider.GetDirectories(query.Substring(0, windowsSep + 1));
}
//Unix
var index = query.LastIndexOf('/');
if (index > -1)
{
dirs = _diskProvider.GetDirectories(query.Substring(0, index + 1));
}
}
catch (Exception)
{
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
return new List<string>().AsResponse();
}
if (dirs == null)
throw new Exception("A valid path was not provided");
return dirs.AsResponse();
}
}
}

@ -92,6 +92,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Directories\DirectoryModule.cs" />
<Compile Include="Extentions\NancyJsonSerializer.cs" /> <Compile Include="Extentions\NancyJsonSerializer.cs" />
<Compile Include="Extentions\Serializer.cs" /> <Compile Include="Extentions\Serializer.cs" />
<Compile Include="RootFolders\RootFolderModule.cs" /> <Compile Include="RootFolders\RootFolderModule.cs" />

@ -148,7 +148,7 @@
<VisualStudio> <VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties> <WebProjectProperties>
<UseIIS>True</UseIIS> <UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort> <AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>1306</DevelopmentServerPort> <DevelopmentServerPort>1306</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath> <DevelopmentServerVPath>/</DevelopmentServerVPath>

@ -410,6 +410,7 @@
<Content Include="_backboneApp\JsLibraries\backbone.marionette.js" /> <Content Include="_backboneApp\JsLibraries\backbone.marionette.js" />
<Content Include="_backboneApp\AddSeries\addSeriesLayoutTemplate.html" /> <Content Include="_backboneApp\AddSeries\addSeriesLayoutTemplate.html" />
<Content Include="_backboneApp\Series\SeriesModel.js" /> <Content Include="_backboneApp\Series\SeriesModel.js" />
<Content Include="_backboneApp\Shared\AutoComplete.js" />
<Content Include="_backboneApp\Shared\NotificationModel.js" /> <Content Include="_backboneApp\Shared\NotificationModel.js" />
<Content Include="_backboneApp\Shared\NotificationTemplate.html" /> <Content Include="_backboneApp\Shared\NotificationTemplate.html" />
<Content Include="_backboneApp\Shared\NotificationView.js" /> <Content Include="_backboneApp\Shared\NotificationView.js" />

@ -2,6 +2,7 @@
/// <reference path="../../app.js" /> /// <reference path="../../app.js" />
/// <reference path="RootDirModel.js" /> /// <reference path="RootDirModel.js" />
/// <reference path="RootDirCollection.js" /> /// <reference path="RootDirCollection.js" />
/// <reference path="../../Shared/AutoComplete.js" />
NzbDrone.AddSeries.RootDirItemView = Backbone.Marionette.ItemView.extend({ NzbDrone.AddSeries.RootDirItemView = Backbone.Marionette.ItemView.extend({
@ -53,6 +54,8 @@ NzbDrone.AddSeries.RootDirView = Backbone.Marionette.Layout.extend({
this.currentDirs.show(new NzbDrone.AddSeries.RootDirListView({ collection: this.collection })); this.currentDirs.show(new NzbDrone.AddSeries.RootDirListView({ collection: this.collection }));
this.collection.fetch(); this.collection.fetch();
this.ui.pathInput.folderAutoComplete();
}, },

@ -41,6 +41,10 @@ body {
text-align: center; text-align: center;
} }
.nz-center .typeahead {
text-align: left;
}
#footer-region { #footer-region {
font-size: 16px; font-size: 16px;
text-decoration: none; text-decoration: none;

@ -0,0 +1,16 @@
$.fn.folderAutoComplete = function () {
$(this).typeahead({
source: function (query, process) {
$.ajax({
url: '/api/directories',
dataType: "json",
type: "POST",
data: { query: query },
success: function (data) {
process(data);
}
});
},
minLength: 3
});
}
Loading…
Cancel
Save