From 0333da1062ecca8527f71154bb6806da2052f396 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 24 Nov 2012 00:03:38 -0800 Subject: [PATCH] More backbone --- NzbDrone.Api/Bootstrapper.cs | 15 +++++++----- NzbDrone.Api/NzbDrone.Api.csproj | 1 + .../QualityProfiles/QualityProfileModel.cs | 4 +-- .../QualityProfiles/QualityProfileService.cs | 23 ++++++++++++++++-- .../QualityProfiles/QualityProfileType.cs | 15 ++++++++++++ .../FakesAssemblies/Ninject.Web.Mvc.Fakes.dll | Bin 89088 -> 89088 bytes .../Scripts/backbone/models/qualityProfile.js | 16 ++++++------ .../Scripts/backbone/views/qualityProfiles.js | 12 ++++++++- NzbDrone.Web/Views/Settings/Quality.cshtml | 11 ++++++++- 9 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 NzbDrone.Api/QualityProfiles/QualityProfileType.cs diff --git a/NzbDrone.Api/Bootstrapper.cs b/NzbDrone.Api/Bootstrapper.cs index f8db1f13a..d065673fb 100644 --- a/NzbDrone.Api/Bootstrapper.cs +++ b/NzbDrone.Api/Bootstrapper.cs @@ -16,14 +16,17 @@ namespace NzbDrone.Api //Mapper.CreateMap() // .ForMember(dest => dest, opt => opt.ResolveUsing()); - Mapper.CreateMap() - .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src)); + //Mapper.CreateMap() + // .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src)); - Mapper.CreateMap() - .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId)); + //Mapper.CreateMap() + // .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId)); - Mapper.CreateMap() - .ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id)); + //Mapper.CreateMap() + // .ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id)); + + Mapper.CreateMap() + .ForMember(dest => dest.Allowed, opt => opt.Ignore()); } } } diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 0f159eca9..27e849c94 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -103,6 +103,7 @@ + diff --git a/NzbDrone.Api/QualityProfiles/QualityProfileModel.cs b/NzbDrone.Api/QualityProfiles/QualityProfileModel.cs index 5a9048f3e..7692f30e1 100644 --- a/NzbDrone.Api/QualityProfiles/QualityProfileModel.cs +++ b/NzbDrone.Api/QualityProfiles/QualityProfileModel.cs @@ -11,6 +11,6 @@ namespace NzbDrone.Api.QualityProfiles public Int32 Id { get; set; } public String Name { get; set; } public Int32 Cutoff { get; set; } - public List Allowed { get; set; } + public List Qualities { get; set; } } -} +} \ No newline at end of file diff --git a/NzbDrone.Api/QualityProfiles/QualityProfileService.cs b/NzbDrone.Api/QualityProfiles/QualityProfileService.cs index a80c1ace0..61cc52244 100644 --- a/NzbDrone.Api/QualityProfiles/QualityProfileService.cs +++ b/NzbDrone.Api/QualityProfiles/QualityProfileService.cs @@ -29,11 +29,14 @@ namespace NzbDrone.Api.QualityProfiles if (request.Id == 0) { var profiles = _qualityProvider.All(); - return Mapper.Map, IEnumerable>(profiles); + var models = new List(); + + profiles.ForEach(p => models.Add(ToModel(p))); + return models; } var profile = _qualityProvider.Get(request.Id); - return Mapper.Map(profile); + return ToModel(profile); } public override object OnPost(QualityProfileModel data) @@ -58,5 +61,21 @@ namespace NzbDrone.Api.QualityProfiles return "ok"; } + + public QualityProfileModel ToModel(QualityProfile profile) + { + var model = new QualityProfileModel(); + model.Id = profile.QualityProfileId; + model.Name = profile.Name; + model.Cutoff = (int)profile.Cutoff; + model.Qualities = Mapper.Map, List>(QualityTypes.All()); + + model.Qualities.ForEach(quality => + { + quality.Allowed = profile.Allowed.SingleOrDefault(q => q.Id == quality.Id) != null; + }); + + return model; + } } } \ No newline at end of file diff --git a/NzbDrone.Api/QualityProfiles/QualityProfileType.cs b/NzbDrone.Api/QualityProfiles/QualityProfileType.cs new file mode 100644 index 000000000..b2b7f1b0b --- /dev/null +++ b/NzbDrone.Api/QualityProfiles/QualityProfileType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Api.QualityProfiles +{ + public class QualityProfileType + { + public Int32 Id { get; set; } + public Int32 Weight { get; set; } + public String Name { get; set; } + public Boolean Allowed { get; set; } + } +} diff --git a/NzbDrone.Web/FakesAssemblies/Ninject.Web.Mvc.Fakes.dll b/NzbDrone.Web/FakesAssemblies/Ninject.Web.Mvc.Fakes.dll index 4ab4a50946ffbf340ad9d8c38fbbd7ea76d3643c..3f0b67053a43cade51377574a9545216c834c53c 100644 GIT binary patch delta 235 zcmV;{>}0$;ZVy`sgI_j7+o&;qy60s%M^5DasMWw%}&MzNw~SK(bO_q-XQKcB delta 235 zcmV7ZzH|jN_W{atUS|6zg?jfS3-^HR z7&}*);LF07ls8R6d==1y&M$x5%4||xpnP5(eN+#v@MFslQW8oG{dL5v1%bp%tF|@H z>j9jD&;qy60s%M^5Fwe4jX-F~K&M>23ii_kn70@f0Z2V8ezuuV000000ssI29033T lcyR#$cvArYQd2}zW-&q?b?SIQh`e)x 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' }; }; - this.validators.allowed = function (value) { - return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' }; - }; + //this.validators.allowed = function (value) { + // return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' }; + //}; this.validators.cutoff = function (value) { return value != null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' }; @@ -42,9 +42,9 @@ }, defaults: { - id: null, - name: '', - allowed: {}, - cutoff: null + Id: null, + Name: '', + //allowed: {}, + Cutoff: null } }); \ No newline at end of file diff --git a/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js b/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js index a71e81e28..e4d8a9f69 100644 --- a/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js +++ b/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js @@ -1,7 +1,17 @@ QualityProfileView = Backbone.Marionette.ItemView.extend({ tagName: "div", className: "quality-profile", - template: "#QualityProfileTemplate" + template: "#QualityProfileTemplate", + events: { + 'click .quality-selectee': 'toggleAllowed' + }, + toggleAllowed: function (e) { + //Add to cutoff + //Update model + + var checked = $(e.target).attr('checked') != undefined; + this.model.set({ }); + } }); QualityProfileCollectionView = Backbone.Marionette.CompositeView.extend({ diff --git a/NzbDrone.Web/Views/Settings/Quality.cshtml b/NzbDrone.Web/Views/Settings/Quality.cshtml index 485c710eb..7a3070992 100644 --- a/NzbDrone.Web/Views/Settings/Quality.cshtml +++ b/NzbDrone.Web/Views/Settings/Quality.cshtml @@ -122,7 +122,16 @@