Merge branch 'markus101'

This commit is contained in:
kay.one 2011-05-29 08:16:37 -07:00
commit 2e893284a2
8 changed files with 229 additions and 173 deletions

View File

@ -29,11 +29,12 @@ namespace NzbDrone.Web.Controllers
private readonly AutoConfigureProvider _autoConfigureProvider;
private readonly NotificationProvider _notificationProvider;
private readonly DiskProvider _diskProvider;
private readonly SeriesProvider _seriesProvider;
public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider,
QualityProvider qualityProvider, RootDirProvider rootDirProvider,
AutoConfigureProvider autoConfigureProvider, NotificationProvider notificationProvider,
DiskProvider diskProvider)
DiskProvider diskProvider, SeriesProvider seriesProvider)
{
_configProvider = configProvider;
_indexerProvider = indexerProvider;
@ -42,6 +43,7 @@ namespace NzbDrone.Web.Controllers
_autoConfigureProvider = autoConfigureProvider;
_notificationProvider = notificationProvider;
_diskProvider = diskProvider;
_seriesProvider = seriesProvider;
}
public ActionResult Test()
@ -131,21 +133,19 @@ namespace NzbDrone.Web.Controllers
ViewData["Qualities"] = qualityTypes;
var userProfiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile).ToList();
var profiles = _qualityProvider.GetAllProfiles().ToList();
var defaultQualityQualityProfileId = Convert.ToInt32(_configProvider.DefaultQualityProfile);
var downloadPropers = _configProvider.DownloadPropers;
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
var qualityProfileSelectList = new SelectList(profiles, "QualityProfileId", "Name");
var model = new QualityModel
{
Profiles = profiles,
UserProfiles = userProfiles,
DefaultQualityProfileId = defaultQualityQualityProfileId,
DownloadPropers = downloadPropers,
SelectList = selectList
QualityProfileSelectList = qualityProfileSelectList
};
return View("Index", model);
@ -199,7 +199,7 @@ namespace NzbDrone.Web.Controllers
return View("Index", model);
}
public ViewResult AddUserProfile()
public ViewResult AddProfile()
{
var qualityTypes = new List<QualityTypes>();
@ -208,12 +208,11 @@ namespace NzbDrone.Web.Controllers
qualityTypes.Add(qual);
}
ViewData["Qualities"] = qualityTypes;
ViewData["Qualities"] = new SelectList(qualityTypes);
var qualityProfile = new QualityProfile
{
Name = "New Profile",
UserProfile = true,
Allowed = new List<QualityTypes> { QualityTypes.Unknown },
Cutoff = QualityTypes.Unknown,
};
@ -224,7 +223,7 @@ namespace NzbDrone.Web.Controllers
ViewData["ProfileId"] = id;
return View("UserProfileSection", qualityProfile);
return View("QualityProfileItem", qualityProfile);
}
public ActionResult GetQualityProfileView(QualityProfile profile)
@ -235,10 +234,11 @@ namespace NzbDrone.Web.Controllers
{
qualityTypes.Add(qual);
}
ViewData["Qualities"] = qualityTypes;
ViewData["ProfileId"] = profile.QualityProfileId;
return PartialView("UserProfileSection", profile);
return PartialView("QualityProfileItem", profile);
}
public ViewResult AddRootDir()
@ -287,13 +287,16 @@ namespace NzbDrone.Web.Controllers
Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId, true));
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList };
return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, QualityProfileSelectList = selectList };
}
public JsonResult DeleteQualityProfile(int profileId)
{
try
{
if (_seriesProvider.GetAllSeries().Where(s => s.QualityProfileId == profileId).Count() != 0)
return new JsonResult { Data = "Unable to delete Profile, it is still in use." };
_qualityProvider.Delete(profileId);
}
@ -460,14 +463,18 @@ namespace NzbDrone.Web.Controllers
_configProvider.DownloadPropers = data.DownloadPropers;
//Saves only the Default Quality, skips User Profiles since none exist
if (data.UserProfiles == null)
if (data.Profiles == null)
return Content(SETTINGS_SAVED);
foreach (var profile in data.UserProfiles)
foreach (var profile in data.Profiles)
{
Logger.Debug(String.Format("Updating User Profile: {0}", profile));
Logger.Debug(String.Format("Updating Profile: {0}", profile));
profile.Allowed = new List<QualityTypes>();
//Remove the extra comma from the end and replace double commas with a single one (the Javascript gets a little crazy)
profile.AllowedString = profile.AllowedString.Replace(",,", ",").Trim(',');
foreach (var quality in profile.AllowedString.Split(','))
{
var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);

View File

@ -8,7 +8,6 @@ namespace NzbDrone.Web.Models
public class QualityModel
{
public List<QualityProfile> Profiles { get; set; }
public List<QualityProfile> UserProfiles { get; set; }
[DisplayName("Default Quality Profile")]
[Description("The default quality to use when adding series to NzbDrone")]
@ -18,6 +17,6 @@ namespace NzbDrone.Web.Models
[Description("Should NzbDrone download proper releases (to replace non-proper files)?")]
public bool DownloadPropers { get; set; }
public SelectList SelectList { get; set; }
public SelectList QualityProfileSelectList { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Web.Models
{
public class QualityTypeModel
{
public int Id { get; set; }
public QualityTypes Name { get; set; }
}
}

View File

@ -237,6 +237,7 @@
<Compile Include="Models\AddExistingManualModel.cs" />
<Compile Include="Models\AddExistingSeriesModel.cs" />
<Compile Include="Models\AddNewSeriesModel.cs" />
<Compile Include="Models\QualityTypeModel.cs" />
<Compile Include="Models\RootDirModel.cs" />
<Compile Include="Models\SabnzbdSettingsModel.cs" />
<Compile Include="Models\EpisodeSortingModel.cs" />
@ -712,7 +713,7 @@
<Content Include="Views\Series\SubMenu.cshtml" />
<Content Include="Views\Series\SeriesSearchResults.cshtml" />
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Settings\UserProfileSection.cshtml" />
<Content Include="Views\Settings\QualityProfileItem.cshtml" />
<Content Include="Views\System\Indexers.cshtml" />
<Content Include="Views\System\Config.cshtml" />
</ItemGroup>

View File

@ -62,7 +62,7 @@
<div class="config-section">
<div class="config-group">
<div class="config-title">@Html.LabelFor(m => m.DefaultQualityProfileId)</div>
<div class="config-value">@Html.DropDownListFor(m => m.DefaultQualityProfileId, Model.SelectList)</div>
<div class="config-value">@Html.DropDownListFor(m => m.DefaultQualityProfileId, Model.QualityProfileSelectList)</div>
</div>
<div class="config-group2">
<div class="config-validation">@Html.ValidationMessageFor(m => m.DefaultQualityProfileId)</div>
@ -74,13 +74,13 @@
<div id="leftSide" style="width:35%;">
<div style="padding-top: 10px;">
<div style="padding-left: 7px; margin-bottom: 5px;">
<a id="addItem" style="text-decoration:none;" href="@Url.Action("AddUserProfile", "Settings")">
<a id="addItem" style="text-decoration:none;" href="@Url.Action("AddProfile", "Settings")">
<img src="../../Content/Images/Plus.png" alt="Add New Profile" />
<h4 style="margin-left: 3px; display: inline; color: Black;">Add New Profile</h4></a>
</div>
<div id="user-profiles">
@foreach (var item in Model.UserProfiles)
<div id="profiles">
@foreach (var item in Model.Profiles)
{
Html.RenderAction("GetQualityProfileView", item);
}
@ -103,7 +103,7 @@
url: this.href,
cache: false,
success: function (html) {
$("#user-profiles").prepend(html);
$("#profiles").prepend(html);
}
});
@ -114,8 +114,6 @@
function deleteProfile(id) {
sendToServer(id);
$("#div_" + id).remove();
removeOption(id);
}
function sendToServer(id) {
@ -125,6 +123,16 @@
data: jQuery.param({ profileId: id }),
error: function (req, status, error) {
alert("Sorry! We could not delete your Profile at this time. " + error);
},
success: function (data, textStatus, jqXHR) {
if (data == "ok") {
$("#div_" + id).remove();
removeOption(id);
}
else {
alert(data);
}
}
});
}

View File

@ -0,0 +1,118 @@
@model NzbDrone.Core.Repository.Quality.QualityProfile
@using System.Collections
@using NzbDrone.Core.Repository.Quality
@using NzbDrone.Web.Helpers
@{
Layout = null;
}
<script type="text/javascript">
$(document).ready(function () {
addOption('@Model.Name', '@ViewData["ProfileId"]');
});
</script>
@using (Html.BeginCollectionItem("Profiles"))
{
var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_');
var ugly = ViewData.TemplateInfo.HtmlFieldPrefix;
string selectable = String.Format("{0}_selectable", idClean);
string allowedStringName = String.Format("{0}_AllowedString", idClean);
string title = String.Format("{0}_Title", idClean);
string nameBox = String.Format("{0}_Name", idClean);
string cutoff = String.Format("{0}.Cutoff", ugly);
<style>
.selectableList .ui-selecting { background: #85AEF9; }
.selectableList .ui-selected { background: #065EFE; color: white; }
.selectableList { list-style-type: none; margin: 0; padding: 0; }
.selectableList li { margin: 3px; margin-left: 10px; padding-left: 0.4em; padding-bottom: 1.5em; padding-top: 0em; float: left; font-size: 1.2em; width: 110px; height: 6px; }
</style>
<script type="text/javascript">
$(function () {
$("#@selectable").selectable({
create: function () {
var result = "";
$(".ui-selected", this).each(function () {
result += this.id + ",";
});
$("#@allowedStringName").empty().val(result);
},
stop: function () {
var result = "";
$(".ui-selected", this).each(function () {
result += this.id + ",";
});
$("#@allowedStringName").empty().val(result);
}
});
})
</script>
<div class="profileSectionEditor" id="div_@(ViewData["ProfileId"])">
<fieldset style="width:264px; margin:5px; margin-top: 0px; border-color:#CCCCCD">
<div class="header">
<div id="qualityHeader" style="padding-bottom: 5px; margin: 0px;">
<h2 style="display:inline; padding-right: 4px; margin-left: 4px;" id="@title">@{Html.DisplayTextFor(m => m.Name);}</h2>
<a href="#" id="@Model.QualityProfileId" class="deleteRow" onclick="deleteProfile('@ViewData["ProfileId"]'); return false;" style="float:right; padding-top:15px; padding-right: 5px;"><img src="../../Content/Images/X.png" alt="Delete"/></a>
</div>
<div class="config-group" style="width: 255px; margin-bottom: 5px; margin-left: 5px;">
<div class="config-title">@Html.LabelFor(x => x.Name)</div>
<div class="config-value">@Html.TextBoxFor(x => x.Name, new { maxlength = 16 })</div>
<div class="config-validation">@Html.ValidationMessageFor(x => x.Name)</div>
</div>
<div class="config-group" style="width: 255px; margin-bottom: 5px; margin-left: 5px;">
<div class="config-title">@Html.LabelFor(x => x.Cutoff)</div>
<div class="config-value">@Html.DropDownListFor(m => m.Cutoff, new SelectList(ViewData["Qualities"] as IEnumerable, Model.Cutoff))</div>
<div class="config-validation">@Html.ValidationMessageFor(x => x.Cutoff)</div>
</div>
</div>
<div class="selectableDiv" style="margin-top: 30px;">
<ol id="@selectable" class="selectableList">
@{var qualitiesList = (List<QualityTypes>)ViewData["Qualities"];}
@for (int i = 0; i < qualitiesList.Count(); i++)
{
if (Model.Allowed != null)
{
if (Model.Allowed.Contains(qualitiesList[i]))
{
<li class="ui-widget-content ui-selected" id="@qualitiesList[i].ToString()">
@Html.Label(qualitiesList[i].ToString())
</li>
continue;
}
}
<li class="ui-widget-content" id="@qualitiesList[i].ToString()">
@Html.Label(qualitiesList[i].ToString())
</li>
}
</ol>
</div>
<div class="hiddenProfileDetails2">
@Html.HiddenFor(x => x.QualityProfileId)
@Html.HiddenFor(x => x.UserProfile)
@Html.HiddenFor(m => m.AllowedString)
</div>
</fieldset>
</div>
<script type="text/javascript">
$("#@nameBox").keyup(function () {
var value = $(this).val();
$("#@title").text(value);
renameOption(value, '@ViewData["ProfileId"]');
}).keyup();
</script>
}

View File

@ -1 +1,58 @@
Hello World
<input type="checkbox" id="id_chk1" class="chkbox" value="1" />Check 1<br/>
<input type="checkbox" id="id_chk2" class="chkbox" value="2" />Check 2<br/>
<input type="checkbox" id="id_chk3" class="chkbox" value="3" />Check 3<br/>
<input type="checkbox" id="id_chk4" class="chkbox" value="4" />Check 4<br/>
<input type="checkbox" id="id_chk5" class="chkbox" value="5" />Check 5<br/>
<input type="checkbox" id="id_chk6" class="chkbox" value="6" />Check 6<br/>
<input type="checkbox" id="id_chk7" class="chkbox" value="7" />Check 7<br/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
var lastChecked = null;
$(document).ready(function () {
$('.chkbox').click(function (event) {
if (!lastChecked) {
lastChecked = this;
return;
}
if (event.shiftKey) {
var start = $('.chkbox').index(this);
var end = $('.chkbox').index(lastChecked);
for (i = Math.min(start, end); i <= Math.max(start, end); i++) {
$('.chkbox')[i].checked = lastChecked.checked;
}
}
lastChecked = this;
});
});
</script>
<style>
#selectable .ui-selecting { background: #85AEF9; }
#selectable .ui-selected { background: #065EFE; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0; width: 110px; }
#selectable li { margin: 3px; padding-left: 0.4em; padding-bottom: 1.5em; padding-top: 0em; font-size: 1.2em; height: 6px; }
</style>
<script type="text/javascript">
$(function () {
$("#selectable").selectable();
});
</script>
<ol id="selectable">
<li class="ui-widget-content">Unknown</li>
<li class="ui-widget-content">SDTV</li>
<li class="ui-widget-content">DVD</li>
<li class="ui-widget-content">HDTV</li>
<li class="ui-widget-content">WEBDL</li>
<li class="ui-widget-content">Bluray720p</li>
<li class="ui-widget-content">Bluray1080p</li>
</ol>

View File

@ -1,148 +0,0 @@
@model NzbDrone.Core.Repository.Quality.QualityProfile
@using NzbDrone.Core.Repository.Quality
@using NzbDrone.Web.Helpers
@{
Layout = null;
}
<script type="text/javascript">
$(document).ready(function () {
addOption('@Model.Name', '@ViewData["ProfileId"]');
});
</script>
@using (Html.BeginCollectionItem("UserProfiles"))
{
var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_');
var ugly = ViewData.TemplateInfo.HtmlFieldPrefix;
string sortable1 = String.Format("{0}_sortable1", idClean);
string sortable2 = String.Format("{0}_sortable2", idClean);
string allowedStringName = String.Format("{0}_AllowedString", idClean);
string connectedSortable = String.Format("connected{0}", idClean);
string title = String.Format("{0}_Title", idClean);
string nameBox = String.Format("{0}_Name", idClean);
string cutoff = String.Format("{0}.Cutoff", ugly);
<style type="text/css">
.sortable1, .sortable2 { list-style-type: none; margin-right: 10px; background: #eee; padding-left: 5px; padding-right: 5px; padding-top: 0px; padding-bottom: 6px; width: 117px; margin-bottom: 3px; }
.allowedQualities, .otherQualities { list-style-type: none; float: left; margin-right: 10px; background: #eee; padding-left: 5px; padding-right: 5px; padding-top:6px; width: 122px; -khtml-border-radius:8px;border-radius:8px;-moz-border-radius:8px;-webkit-border-radius:8px; }
.sortable1 li, .sortable2 li { margin: 5px; margin-left: 0px; padding: 0px; font-size: 1.2em; width: 110px; -khtml-border-radius:8px;border-radius:8px;-moz-border-radius:8px;-webkit-border-radius:8px; }
.sortable1 li { background: #ddd; }
.sortable2 li { background: #DAA2A2; }
.sortableHeader { margin:2px; margin-left:12px }
.sortable1 li.ui-state-highlight, .sortable2 li.ui-state-highlight { background: #fbf5d0; border-color: #065EFE; }
.removeDiv { float: left; display:block; }
.ui-state-highlight { height: 1.5em; line-height: 1.2em; }
</style>
<script type="text/javascript">
$(function () {
$("#@sortable1, #@sortable2").sortable({
connectWith: ".@connectedSortable",
placeholder: "ui-state-highlight",
dropOnEmpty: true,
create: function (event, ui) {
var order = $('#@sortable1').sortable("toArray");
$("#@allowedStringName").val(order);
},
update: function (event, ui) {
var order = $('#@sortable1').sortable("toArray");
$("#@allowedStringName").val(order);
//If this is the first QualityType added to the Profile select it as the cutoff value (in-case the user forgets)
var $list = $('#@sortable1 li');
if ($list.length == 1) {
var $radios = $('input[name="@cutoff"]');
$radios.filter('[value=' + order + ']').attr('checked', true);
}
}
}).disableSelection();
});
</script>
<div class="userProfileSectionEditor" id="div_@(ViewData["ProfileId"])">
<fieldset style="width:285px; max-width:285px; margin:5px; margin-top: 0px; border-color:#CCCCCD">
<div id="tester"></div>
<div id="qualityHeader" style="padding-bottom: 5px; margin: 0px;">
<h2 style="display:inline; padding-right: 4px; margin-left: 4px;" id="@title">@{Html.DisplayTextFor(m => m.Name);}</h2>
<a href="#" id="@Model.QualityProfileId" class="deleteRow" onclick="deleteProfile('@ViewData["ProfileId"]')" style="float:right; padding-top:15px;"><img src="../../Content/Images/X.png" alt="Delete"/></a>
</div>
<div class="config-group" style="width: 270px; margin-bottom: 5px; margin-left: 5px;">
<div class="config-title">@Html.LabelFor(x => x.Name)</div>
<div class="config-value">@Html.TextBoxFor(x => x.Name, new { maxlength = 16})</div>
<div class="config-validation">@Html.ValidationMessageFor(x => x.Name)</div>
</div>
<div id="sortablesDiv" style="margin: 0px;">
<div class="allowedQualities">
<h4 class="sortableHeader">Allowed</h4>
<ul id="@sortable1" class="@connectedSortable sortable1">
@if (Model.Allowed != null)
{
for (int i = 0; i < Model.Allowed.Count(); i++)
{
<li class="ui-state-default" id="@Model.Allowed[i].ToString()">
@Html.RadioButtonFor(x => x.Cutoff, Model.Allowed[i])
@Html.DisplayTextFor(c => c.Allowed[i])
</li>
}
}
</ul>
</div>
<div class="otherQualities">
<h4 class="sortableHeader">Not-Allowed</h4>
<ul id="@sortable2" class="@connectedSortable sortable2">
@{var qualitiesList = (List<QualityTypes>)ViewData["Qualities"];}
@for (int i = 0; i < qualitiesList.Count(); i++)
{
//Skip Unknown and any item that is in the allowed list
//if (qualitiesList[i].ToString() == "Unknown")
//{
// continue;
//}
if (Model.Allowed != null)
{
if (Model.Allowed.Contains(qualitiesList[i]))
{
continue;
}
}
<li class="ui-state-default" id="@qualitiesList[i].ToString()">
@Html.RadioButtonFor(x => x.Cutoff, qualitiesList[i])
@Html.Label(qualitiesList[i].ToString())
</li>
}
</ul>
</div>
</div>
@Html.ValidationMessageFor(x => x.Cutoff)
<div class="hiddenProfileDetails">
@Html.TextBoxFor(x => x.QualityProfileId, new { @style = "display:none" })
@Html.CheckBoxFor(x => x.UserProfile, new { @style = "display:none" })
@Html.TextBoxFor(m => m.AllowedString, new { @style = "display:none" })
</div>
</fieldset>
</div>
<script type="text/javascript">
$("#@nameBox").keyup(function () {
var value = $(this).val();
$("#@title").text(value);
renameOption(value, '@ViewData["ProfileId"]');
}).keyup();
</script>
}