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

This commit is contained in:
Mark McDowall 2011-03-15 08:29:14 -07:00
parent 5a8842e3db
commit 3d81bc8770
6 changed files with 104 additions and 43 deletions

View File

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

View File

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Providers
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)
{
Logger.Debug("Initializing background scan of series folder.");
@ -90,6 +90,42 @@ namespace NzbDrone.Core.Providers
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()
{
Logger.Info("Starting Series folder scan");

View File

@ -169,26 +169,38 @@ namespace NzbDrone.Web.Controllers
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)
{
var model = new List<SeriesSearchResultModel>();
//Get Results from TvDb and convert them to something we can use.
foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName))
{
model.Add(new SeriesSearchResultModel
{
TvDbId = tvdbSearchResult.Id,
TvDbName = tvdbSearchResult.SeriesName,
FirstAired = tvdbSearchResult.FirstAired
});
}
//foreach (var tvdbSearchResult in _tvDbProvider.SearchSeries(seriesName))
//{
// model.Add(new SeriesSearchResultModel
// {
// TvDbId = tvdbSearchResult.Id,
// TvDbName = tvdbSearchResult.SeriesName,
// FirstAired = tvdbSearchResult.FirstAired
// });
//}
ViewData["RootDirs"] = _rootDirProvider.GetAll();
ViewData["DirSep"] = Path.DirectorySeparatorChar;
//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 = 12345, TvDbName = "30 Rock", FirstAired = DateTime.Today });
model.Add(new SeriesSearchResultModel { TvDbId = 65432, TvDbName = "The Office (US)", FirstAired = DateTime.Today.AddDays(-100) });
return PartialView("SeriesSearchResults", model);
}

View File

@ -19,14 +19,6 @@
<button class="t.button" onclick="searchSeries ()">Search</button>
</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>
<script type="text/javascript" language="javascript">
@ -48,7 +40,7 @@
);
}
</script>
<div id="tester"></div>
</asp:Content>

View File

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

View File

@ -30,9 +30,6 @@
<fieldset>
<legend>General</legend>
//Browse Button??
//Auto-Complete?
<div style="padding-top: 10px;">
<div style="padding-left: 7px; margin-bottom: 5px;">
<a id="addItem" style="text-decoration:none;" href="<%: Url.Action("AddRootDir", "Settings") %>">