AddNew is functional, using jquery for adding and display changes.

pull/4/head
Mark McDowall 14 years ago
parent 5a8842e3db
commit 3d81bc8770

@ -7,6 +7,7 @@ namespace NzbDrone.Core.Providers
public interface ISyncProvider public interface ISyncProvider
{ {
bool BeginSyncUnmappedFolders(List<SeriesMappingModel> unmapped); bool BeginSyncUnmappedFolders(List<SeriesMappingModel> unmapped);
bool BeginAddNewSeries(string dir, int seriesId, string seriesName);
List<String> GetUnmappedFolders(string path); List<String> GetUnmappedFolders(string path);
} }
} }

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Providers
public bool BeginSyncUnmappedFolders(List<SeriesMappingModel> unmapped) public bool BeginSyncUnmappedFolders(List<SeriesMappingModel> unmapped)
{ {
Logger.Debug("User has request series folder scan"); Logger.Debug("User has requested series folder scan");
if (_seriesSyncThread == null || !_seriesSyncThread.IsAlive) if (_seriesSyncThread == null || !_seriesSyncThread.IsAlive)
{ {
Logger.Debug("Initializing background scan of series folder."); Logger.Debug("Initializing background scan of series folder.");
@ -90,6 +90,42 @@ namespace NzbDrone.Core.Providers
return true; return true;
} }
public bool BeginAddNewSeries(string dir, int seriesId, string seriesName)
{
Logger.Debug("User has requested adding of new series");
if (_seriesSyncThread == null || !_seriesSyncThread.IsAlive)
{
Logger.Debug("Initializing background add of of series folder.");
_seriesSyncThread = new Thread(SyncUnmappedFolders)
{
Name = "SyncUnmappedFolders",
Priority = ThreadPriority.Lowest
};
_syncList = new List<SeriesMappingModel>();
var path = dir + Path.DirectorySeparatorChar + seriesName;
//Create a directory for this new series
_diskProvider.CreateDirectory(path);
//Add it to the list so it will be processed
_syncList.Add(new SeriesMappingModel { Path = path, TvDbId = seriesId });
_seriesSyncThread.Start();
}
else
{
Logger.Warn("Series folder scan already in progress. Ignoring request.");
//return false if sync was already running, then we can tell the user to try again later
return false;
}
//return true if sync has started
return true;
}
private void SyncUnmappedFolders() private void SyncUnmappedFolders()
{ {
Logger.Info("Starting Series folder scan"); Logger.Info("Starting Series folder scan");

@ -169,26 +169,38 @@ namespace NzbDrone.Web.Controllers
return Content("Sync already in progress, please wait for it to complete before retrying."); return Content("Sync already in progress, please wait for it to complete before retrying.");
} }
public ActionResult AddNewSeries(string dir, int seriesId, string seriesName)
{
//Get TVDB Series Name
//Create new folder for series
//Add the new series to the Database
if (_syncProvider.BeginAddNewSeries(dir, seriesId, seriesName))
return Content("Adding new series has started.");
return Content("Unable to add new series, please wait for previous scans to complete first.");
}
public ActionResult SearchForSeries(string seriesName) public ActionResult SearchForSeries(string seriesName)
{ {
var model = new List<SeriesSearchResultModel>(); var model = new List<SeriesSearchResultModel>();
//Get Results from TvDb and convert them to something we can use. //Get Results from TvDb and convert them to something we can use.
foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName)) //foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName))
{ //{
model.Add(new SeriesSearchResultModel // model.Add(new SeriesSearchResultModel
{ // {
TvDbId = tvdbSearchResult.Id, // TvDbId = tvdbSearchResult.Id,
TvDbName = tvdbSearchResult.SeriesName, // TvDbName = tvdbSearchResult.SeriesName,
FirstAired = tvdbSearchResult.FirstAired // FirstAired = tvdbSearchResult.FirstAired
}); // });
} //}
ViewData["RootDirs"] = _rootDirProvider.GetAll(); ViewData["RootDirs"] = _rootDirProvider.GetAll();
ViewData["DirSep"] = Path.DirectorySeparatorChar; ViewData["DirSep"] = Path.DirectorySeparatorChar;
//model.Add(new SeriesSearchResultModel{ TvDbId = 12345, TvDbName = "30 Rock", FirstAired = DateTime.Today }); model.Add(new SeriesSearchResultModel{ TvDbId = 12345, TvDbName = "30 Rock", FirstAired = DateTime.Today });
//model.Add(new SeriesSearchResultModel { TvDbId = 65432, TvDbName = "The Office (US)", FirstAired = DateTime.Today.AddDays(-100) }); model.Add(new SeriesSearchResultModel { TvDbId = 65432, TvDbName = "The Office (US)", FirstAired = DateTime.Today.AddDays(-100) });
return PartialView("SeriesSearchResults", model); return PartialView("SeriesSearchResults", model);
} }

@ -18,14 +18,6 @@
<p> <p>
<button class="t.button" onclick="searchSeries ()">Search</button> <button class="t.button" onclick="searchSeries ()">Search</button>
</p> </p>
//Search Button - Perform AJAX search for this Series on TVDB
//Return results with Radio Box + First Aired information, (link to TVDB too?) + Hidden ID text
User selects radio button and then presses add (or skips which clears results and #new_series_id)
Add, ask user to choose where to save the show in (used when sorting) then add the show... Possibly ask user to choose Quality Profile
<div id="result"></div> <div id="result"></div>
@ -48,7 +40,7 @@
); );
} }
</script> </script>
<div id="tester"></div>
</asp:Content> </asp:Content>

@ -4,23 +4,32 @@
<div id="searchResults"> <div id="searchResults">
<fieldset> <fieldset>
<legend>Search Results</legend> <legend>Search Results</legend>
<% int r = 0; %>
<% foreach (var result in Model) <% foreach (var result in Model)
{ %> { %>
<%: Html.RadioButton("selectedSeries", result.TvDbId, new { @class="searchRadio examplePart", name = result.TvDbName }) %> <%: Html.RadioButton("selectedSeries", result.TvDbId, new { @class="searchRadio examplePart", id="searchRadio_" + r }) %>
<%: Html.Label(result.TvDbName) %> (<%: Html.Label(result.FirstAired.ToString()) %>) <b><%: Html.Label(result.TvDbName) %></b> (<%: Html.Label(result.FirstAired.ToString("MM/dd/yyyy"))%>)
<%: Html.TextBox(result.TvDbName + "_text", result.TvDbName, new { id = result.TvDbId + "_text", style="display:none" }) %>
<% r++;%>
<br /> <br />
<% } %> <%
} %>
</fieldset> </fieldset>
</div> </div>
<div id="RootDirectories" style="display:none"> <div id="RootDirectories" style="display:none">
<fieldset> <fieldset>
<legend>Root TV Folders</legend> <legend>Root TV Folders</legend>
<% int d = 0; %>
<% foreach (var dir in (List<RootDir>)ViewData["RootDirs"]) <% foreach (var dir in (List<RootDir>)ViewData["RootDirs"])
{ %> { %>
<%: Html.RadioButton("selectedRootDir", dir.RootDirId, dir.Default, new { @class="dirList examplePart", name = dir.Path }) %> <%: Html.RadioButton("selectedRootDir", dir.Path, dir.Default, new { @class="dirList examplePart", id="dirRadio_" + d }) %>
<%: Html.Label(dir.Path) %> <%: Html.Label(dir.Path) %>
<% if (dir.Default) { %>* <% } %> <% if (dir.Default) { %> * <% } %>
<% d++;%>
<br /> <br />
<% } %> <% } %>
</fieldset> </fieldset>
@ -30,14 +39,13 @@
<button class="t.button" onclick="addSeries ()">Add New Series</button> <button class="t.button" onclick="addSeries ()">Add New Series</button>
</div> </div>
<div id="tester"></div> <div id="addResult"></div>
<script type="text/javascript"> <script type="text/javascript">
$(".searchRadio").live("change", function () { $(".searchRadio").live("change", function () {
var checked = $(this).attr('checked'); var checked = $(this).attr('checked');
if (checked) { if (checked) {
$('#tester').text(this.value);
document.getElementById('RootDirectories').style.display = 'inline'; document.getElementById('RootDirectories').style.display = 'inline';
} }
}); });
@ -46,23 +54,38 @@
//Get the selected tvdbid + selected root folder //Get the selected tvdbid + selected root folder
//jquery bit below doesn't want to work... //jquery bit below doesn't want to work...
var checkedSeries = $('input:radio[name=selectedSeries]:checked').val(); var checkedSeries = $("input[name='selectedSeries']:checked").val();
//$('input:radio[name=selectedSeries]:checked').val(); //var checkedSeries = $('input.searchRadio:checked').val();
//var checkedSeries = $('input:radio[name=selectedSeries]:checked').val();
//var checkedSeries = $('input:radio[class=searchRadio]:checked').val();
var checkedDir = $("input[name='selectedRootDir']:checked").val();
$('#tester').text(checkedSeries.value); var id = "#" + checkedSeries + "_text";
var seriesName = $(id).val();
//$('#tester').text("Hello_jhasdajsd"); $("#addResult").load('<%=Url.Action("AddNewSeries", "Series") %>', {
dir: checkedDir,
seriesId: checkedSeries,
seriesName: seriesName
});
} }
// $(".examplePart").live("change", function() {
// var dir = $('.selectedRootDir:checked');
// var show = $('.selectedSeries:checked'); //Need to figure out how to use 'ViewData["DirSep"]' instead of hardcoding '\'
// var sep = "\\"; $(".examplePart").live("change", function () {
// var str = "Example: " + dir.name + sep + show.name; var dir = $("input[name='selectedRootDir']:checked").val();
var series = $("input[name='selectedSeries']:checked").val();
// $('#example').text(str); var id = "#" + series + "_text";
// var seriesName = $(id).val();
// });
//var sep = '<%= ViewData["DirSep"] %>';
var sep = "\\";
var str = "Example: " + dir + sep + seriesName;
$('#example').text(str);
});
</script> </script>

@ -29,9 +29,6 @@
<%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %> <%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %>
<fieldset> <fieldset>
<legend>General</legend> <legend>General</legend>
//Browse Button??
//Auto-Complete?
<div style="padding-top: 10px;"> <div style="padding-top: 10px;">
<div style="padding-left: 7px; margin-bottom: 5px;"> <div style="padding-left: 7px; margin-bottom: 5px;">

Loading…
Cancel
Save