2012-04-23 08:31:11 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using NzbDrone.Core;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository.Search;
|
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
public class SearchHistoryController : Controller
|
2012-04-23 08:31:11 +02:00
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
private readonly SearchHistoryProvider _searchHistoryProvider;
|
2012-04-23 08:31:11 +02:00
|
|
|
|
|
2012-04-23 09:38:42 +02:00
|
|
|
|
public SearchHistoryController(SearchHistoryProvider searchHistoryProvider)
|
2012-04-23 08:31:11 +02:00
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
_searchHistoryProvider = searchHistoryProvider;
|
2012-04-23 08:31:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
var results = _searchHistoryProvider.AllSearchHistory();
|
2012-04-23 08:31:11 +02:00
|
|
|
|
|
2012-04-23 09:38:42 +02:00
|
|
|
|
var model = results.Select(s => new SearchHistoryModel
|
2012-04-23 08:31:11 +02:00
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
SearchTime = s.SearchTime.ToString(),
|
|
|
|
|
DisplayName = GetDisplayName(s),
|
|
|
|
|
ReportCount = s.TotalItems,
|
|
|
|
|
Successful = s.SuccessfulCount > 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Details(int searchId)
|
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
var searchResult = _searchHistoryProvider.GetSearchHistory(searchId);
|
2012-04-23 08:31:11 +02:00
|
|
|
|
var model = new SearchDetailsModel
|
|
|
|
|
{
|
|
|
|
|
Id = searchResult.Id,
|
|
|
|
|
DisplayName = GetDisplayName(searchResult),
|
2012-04-23 09:38:42 +02:00
|
|
|
|
SearchHistoryItems =
|
|
|
|
|
searchResult.SearchHistoryItems.Select(s => new SearchItemModel
|
2012-04-23 08:31:11 +02:00
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
ReportTitle = s.ReportTitle,
|
|
|
|
|
Indexer = s.Indexer,
|
|
|
|
|
NzbUrl = s.NzbUrl,
|
|
|
|
|
NzbInfoUrl = s.NzbInfoUrl,
|
|
|
|
|
Success = s.Success,
|
|
|
|
|
SearchError = s.SearchError.AddSpacesToEnum().Replace("None", "Grabbed"),
|
|
|
|
|
Quality = s.Quality.ToString(),
|
|
|
|
|
QualityInt = (int)s.Quality,
|
|
|
|
|
Proper = s.Proper,
|
|
|
|
|
Age = s.Age,
|
|
|
|
|
Size = s.Size.ToBestFileSize(1),
|
|
|
|
|
Language = s.Language.ToString()
|
|
|
|
|
}).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult ForceDownload(int id)
|
|
|
|
|
{
|
2012-04-23 09:38:42 +02:00
|
|
|
|
_searchHistoryProvider.ForceDownload(id);
|
2012-04-23 08:31:11 +02:00
|
|
|
|
|
|
|
|
|
return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 09:38:42 +02:00
|
|
|
|
public string GetDisplayName(SearchHistory searchResult)
|
2012-04-23 08:31:11 +02:00
|
|
|
|
{
|
|
|
|
|
if (!searchResult.EpisodeNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return String.Format("{0} - Season {1}", searchResult.SeriesTitle, searchResult.SeasonNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string episodeString;
|
|
|
|
|
|
|
|
|
|
if (searchResult.IsDaily)
|
|
|
|
|
episodeString = searchResult.AirDate.ToShortDateString().Replace('/', '-');
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
episodeString = String.Format("S{0:00}E{1:00}", searchResult.SeasonNumber,
|
|
|
|
|
searchResult.EpisodeNumber);
|
|
|
|
|
|
|
|
|
|
return String.Format("{0} - {1} - {2}", searchResult.SeriesTitle, episodeString, searchResult.EpisodeTitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|