Added DeleteSeriesJob to remove series in BG.

Fixed SeriesUpdate Grid Edit to properly save SeasonFolder changes.
Added Delete to SeriesGrid.
This commit is contained in:
Mark McDowall 2011-05-11 19:53:19 -07:00
parent 4d7bb451f2
commit d97382ad0c
6 changed files with 135 additions and 41 deletions

View File

@ -133,6 +133,7 @@ namespace NzbDrone.Core
_kernel.Bind<IJob>().To<NewSeriesUpdate>().InTransientScope();
_kernel.Bind<IJob>().To<UpdateInfoJob>().InTransientScope();
_kernel.Bind<IJob>().To<MediaFileScanJob>().InTransientScope();
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope();
_kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30);

View File

@ -176,6 +176,7 @@
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
<Compile Include="Providers\AutoConfigureProvider.cs" />
<Compile Include="Providers\Indexer\NzbMatrixProvider.cs" />
<Compile Include="Providers\Jobs\DeleteSeriesJob.cs" />
<Compile Include="Providers\Jobs\MediaFileScanJob.cs" />
<Compile Include="Providers\Jobs\NewSeriesUpdate.cs" />
<Compile Include="Providers\Jobs\JobProvider.cs" />

View File

@ -0,0 +1,75 @@
using System;
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Repository;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers.Jobs
{
public class DeleteSeriesJob : IJob
{
private readonly SeriesProvider _seriesProvider;
private readonly IRepository _repository;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public DeleteSeriesJob(IRepository repository, SeriesProvider seriesProvider)
{
_repository = repository;
_seriesProvider = seriesProvider;
}
public string Name
{
get { return "Delete Series"; }
}
public int DefaultInterval
{
get { return 0; }
}
public void Start(ProgressNotification notification, int targetId)
{
DeleteSeries(notification, targetId);
}
private void DeleteSeries(ProgressNotification notification, int seriesId)
{
Logger.Warn("Deleting Series [{0}]", seriesId);
try
{
var series = _repository.Single<Series>(seriesId);
notification.CurrentMessage = String.Format("Beginning Delete of Series: {0}", series.Title);
Logger.Debug("Deleting Series from DB {0}", series.Title);
_repository.Delete<Series>(seriesId);
Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId);
var episodes = series.Episodes.Select(e => e.EpisodeId).ToList();
episodes.ForEach(e => _repository.DeleteMany<History>(h => h.EpisodeId == e));
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.EpisodeFiles);
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Episodes);
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Seasons);
notification.CurrentMessage = String.Format("Successfully deleted Series: {0}", series.Title);
Logger.Info("Successfully deleted Series [{0}]", seriesId);
}
catch (Exception e)
{
Logger.ErrorException("An error has occurred while deleting series: " + seriesId, e);
throw;
}
}
}
}

View File

@ -98,8 +98,6 @@ namespace NzbDrone.Core.Providers.Jobs
return true;
}
/// <summary>
/// Starts the execution of a job asynchronously
/// </summary>
@ -107,7 +105,7 @@ namespace NzbDrone.Core.Providers.Jobs
/// <param name="targetId">The targetId could be any Id parameter eg. SeriesId. it will be passed to the job implementation
/// to allow it to filter it's target of execution.</param>
/// <returns>True if ran, false if skipped</returns>
public bool BeginExecute(Type jobType, int targetId = 0)
public virtual bool BeginExecute(Type jobType, int targetId = 0)
{
lock (ExecutionLock)
{

View File

@ -67,23 +67,7 @@ namespace NzbDrone.Web.Controllers
[GridAction]
public ActionResult _AjaxSeriesGrid()
{
var series = new List<SeriesModel>();
var seriesInDb = _seriesProvider.GetAllSeries().ToList();
seriesInDb.ForEach(s => series.Add(new SeriesModel
{
SeriesId = s.SeriesId,
Title = s.Title,
AirsDayOfWeek = s.AirsDayOfWeek.ToString(),
Monitored = s.Monitored,
Overview = s.Overview,
Path = s.Path,
QualityProfileId = s.QualityProfileId,
QualityProfileName = s.QualityProfile.Name,
SeasonsCount = s.Seasons.Count,
SeasonFolder = s.SeasonFolder,
Status = s.Status
}));
var series = GetSeriesModels(_seriesProvider.GetAllSeries().ToList());
return View(new GridModel(series));
}
@ -95,29 +79,28 @@ namespace NzbDrone.Web.Controllers
var oldSeries = _seriesProvider.GetSeries(id);
oldSeries.Path = path;
oldSeries.Monitored = monitored;
oldSeries.SeasonFolder = monitored;
oldSeries.SeasonFolder = seasonFolder;
oldSeries.QualityProfileId = qualityProfileId;
_seriesProvider.UpdateSeries(oldSeries);
var series = new List<SeriesModel>();
var series = GetSeriesModels(_seriesProvider.GetAllSeries().ToList());
return View(new GridModel(series));
}
[GridAction]
public ActionResult _DeleteAjaxSeriesEditing(int id)
{
//Grab the series from the DB so we can remove it from the list we return to the client
var seriesInDb = _seriesProvider.GetAllSeries().ToList();
seriesInDb.ForEach(s => series.Add(new SeriesModel
{
SeriesId = s.SeriesId,
Title = s.Title,
AirsDayOfWeek = s.AirsDayOfWeek.ToString(),
Monitored = s.Monitored,
Overview = s.Overview,
Path = s.Path,
QualityProfileId = s.QualityProfileId,
QualityProfileName = s.QualityProfile.Name,
SeasonsCount = s.Seasons.Count,
SeasonFolder = s.SeasonFolder,
Status = s.Status
}));
//Remove this so we don't send it back to the client (since it hasn't really been deleted yet)
seriesInDb.RemoveAll(s => s.SeriesId == id);
//Start removing this series
_jobProvider.BeginExecute(typeof(DeleteSeriesJob), id);
var series = GetSeriesModels(seriesInDb);
return View(new GridModel(series));
}
@ -264,9 +247,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult Delete(int seriesId)
{
//Need to add seriesProvider.Update
_seriesProvider.DeleteSeries(seriesId);
_jobProvider.BeginExecute(typeof(DeleteSeriesJob), seriesId);
return RedirectToAction("Index", "Series");
}
@ -321,5 +302,27 @@ namespace NzbDrone.Web.Controllers
//Return the path relative to the Series' Folder
return file.Path.Replace(file.Series.Path, "").Trim(Path.DirectorySeparatorChar);
}
private List<SeriesModel> GetSeriesModels(List<Series> seriesInDb)
{
var series = new List<SeriesModel>();
seriesInDb.ForEach(s => series.Add(new SeriesModel
{
SeriesId = s.SeriesId,
Title = s.Title,
AirsDayOfWeek = s.AirsDayOfWeek.ToString(),
Monitored = s.Monitored,
Overview = s.Overview,
Path = s.Path,
QualityProfileId = s.QualityProfileId,
QualityProfileName = s.QualityProfile.Name,
SeasonsCount = s.Seasons.Count,
SeasonFolder = s.SeasonFolder,
Status = s.Status
}));
return series;
}
}
}

View File

@ -19,7 +19,9 @@
})
.DataBinding(data => data.Ajax()
.Select("_AjaxSeriesGrid", "Series")
.Update("_SaveAjaxSeriesEditing", "Series"))
.Update("_SaveAjaxSeriesEditing", "Series")
.Delete("_DeleteAjaxSeriesEditing", "Series"))
.Columns(columns =>
{
columns.Bound(o => o.Title)
@ -31,11 +33,25 @@
columns.Bound(o => o.Status);
columns.Bound(o => o.AirsDayOfWeek);
columns.Bound(o => o.Path);
columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Image)).Title("Edit").Width(50);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
}).Title("Actions").Width(80);
})
.Editable(editor => editor.Mode(GridEditMode.PopUp))
.Sortable(sort => sort.OrderBy(order => order.Add(o => o.Title).Ascending()).Enabled(true))
.DetailView(detailView => detailView.ClientTemplate("<div style=\"width:95%\"><#= Overview #></div>"))
.ClientEvents(clientEvents => clientEvents.OnEdit("grid_edit"))
.Render();}
}
<script type="text/javascript">
function grid_edit(args) {
$(args.form)
.closest(".t-window")
.data("tWindow")
.center();
}
</script>