From 3c53e6009d837a0d33fd3b7889c8cfe7d6828c88 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 30 May 2013 18:22:28 -0700 Subject: [PATCH] cleaned up qualityprofile response format. --- .../MappingTests/ResourceMappingFixture.cs | 4 +++ .../Qualities/QualityProfileResource.cs | 4 +-- .../Qualities/QualityProfilesModule.cs | 35 ++++++++++++++++--- UI/Content/Messenger/messenger.css | 2 ++ UI/Quality/QualitySizeCollection.js | 2 +- UI/Quality/qualityProfileModel.js | 10 ------ UI/Settings/Notifications/ItemTemplate.html | 4 +-- .../Profile/QualityProfileTemplate.html | 6 ++-- 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs b/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs index 2a25532ff..a453c8643 100644 --- a/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs +++ b/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs @@ -5,6 +5,7 @@ using NzbDrone.Api.Episodes; using NzbDrone.Api.History; using NzbDrone.Api.Indexers; using NzbDrone.Api.Mapping; +using NzbDrone.Api.Qualities; using NzbDrone.Api.RootFolders; using NzbDrone.Api.Series; using NzbDrone.Api.Update; @@ -12,6 +13,7 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Indexers; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Qualities; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Update; using NzbDrone.Test.Common; @@ -31,6 +33,8 @@ namespace NzbDrone.Api.Test.MappingTests [TestCase(typeof(DownloadDecision), typeof(ReleaseResource))] [TestCase(typeof(Core.History.History), typeof(HistoryResource))] [TestCase(typeof(UpdatePackage), typeof(UpdateResource))] + [TestCase(typeof(QualityProfile), typeof(QualityProfileResource))] + [TestCase(typeof(Quality), typeof(QualityResource))] public void matching_fields(Type modelType, Type resourceType) { MappingValidation.ValidateMapping(modelType, resourceType); diff --git a/NzbDrone.Api/Qualities/QualityProfileResource.cs b/NzbDrone.Api/Qualities/QualityProfileResource.cs index f757421db..363c5c90c 100644 --- a/NzbDrone.Api/Qualities/QualityProfileResource.cs +++ b/NzbDrone.Api/Qualities/QualityProfileResource.cs @@ -8,8 +8,9 @@ namespace NzbDrone.Api.Qualities { public Int32 Id { get; set; } public String Name { get; set; } - public Int32 Cutoff { get; set; } + public QualityResource Cutoff { get; set; } public List Qualities { get; set; } + public List Allowed { get; set; } } public class QualityResource : RestResource @@ -17,6 +18,5 @@ namespace NzbDrone.Api.Qualities public Int32 Id { get; set; } public Int32 Weight { get; set; } public String Name { get; set; } - public Boolean Allowed { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Qualities/QualityProfilesModule.cs b/NzbDrone.Api/Qualities/QualityProfilesModule.cs index 835e364e5..30fe10c02 100644 --- a/NzbDrone.Api/Qualities/QualityProfilesModule.cs +++ b/NzbDrone.Api/Qualities/QualityProfilesModule.cs @@ -1,9 +1,21 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using NzbDrone.Core.Datastore; using NzbDrone.Core.Qualities; using NzbDrone.Api.Mapping; +using System.Linq; namespace NzbDrone.Api.Qualities { + + public static class LazyLoadedExtensions + { + public static IEnumerable GetForeignKeys(this IEnumerable models) + { + return models.Select(c => c.Id).Distinct(); + } + } + public class QualityProfilesModule : NzbDroneRestModule { private readonly QualityProfileService _qualityProvider; @@ -22,7 +34,6 @@ namespace NzbDrone.Api.Qualities CreateResource = Create; DeleteResource = DeleteProfile; - } private QualityProfileResource Create(QualityProfileResource resource) @@ -46,13 +57,29 @@ namespace NzbDrone.Api.Qualities private QualityProfileResource GetById(int id) { - return ToResource(() => _qualityProvider.Get(id)); + return QualityToResource(_qualityProvider.Get(id)); } private List GetAll() { - return ToListResource(_qualityProvider.All); + var allProfiles = _qualityProvider.All(); + + + var profiles = allProfiles.Select(QualityToResource).ToList(); + + return profiles; } + private static QualityProfileResource QualityToResource(QualityProfile profile) + { + return new QualityProfileResource + { + Cutoff = profile.Cutoff.InjectTo(), + Qualities = Quality.All().InjectTo>(), + Allowed = profile.Allowed.InjectTo>(), + Name = profile.Name, + Id = profile.Id + }; + } } } \ No newline at end of file diff --git a/UI/Content/Messenger/messenger.css b/UI/Content/Messenger/messenger.css index e413d636f..9d6786bb0 100644 --- a/UI/Content/Messenger/messenger.css +++ b/UI/Content/Messenger/messenger.css @@ -83,6 +83,8 @@ ul.messenger.messenger-fixed.messenger-on-top.messenger-on-left, ul.messenger.me ul.messenger.messenger-fixed.messenger-on-right, ul.messenger.messenger-fixed.messenger-on-left { width: auto; min-width: 350px; + max-width: 800px; + word-wrap: break-word; } /* line 69, ../../src/sass/messenger.sass */ ul.messenger.messenger-fixed.messenger-on-right .messenger-actions, ul.messenger.messenger-fixed.messenger-on-left .messenger-actions { diff --git a/UI/Quality/QualitySizeCollection.js b/UI/Quality/QualitySizeCollection.js index da567d0ba..5c111019c 100644 --- a/UI/Quality/QualitySizeCollection.js +++ b/UI/Quality/QualitySizeCollection.js @@ -2,6 +2,6 @@ define(['app', 'Quality/QualitySizeModel'], function () { NzbDrone.Quality.QualitySizeCollection = Backbone.Collection.extend({ model: NzbDrone.Quality.QualitySizeModel, - url : NzbDrone.Constants.ApiRoot + '/qualitysizes' + url : NzbDrone.Constants.ApiRoot + '/qualitysize' }); }); diff --git a/UI/Quality/qualityProfileModel.js b/UI/Quality/qualityProfileModel.js index 462c90074..82ffd40c3 100644 --- a/UI/Quality/qualityProfileModel.js +++ b/UI/Quality/qualityProfileModel.js @@ -2,16 +2,6 @@ define(['app'], function () { NzbDrone.Quality.QualityProfileModel = Backbone.DeepModel.extend({ - mutators: { - allowed: function () { - return _.where(this.get('qualities'), { allowed: true }); - }, - - cutoffName: function () { - return _.findWhere(this.get('qualities'), { id: this.get('cutoff') }).name; - } - }, - defaults: { id : null, name : '', diff --git a/UI/Settings/Notifications/ItemTemplate.html b/UI/Settings/Notifications/ItemTemplate.html index 3b16ea0a3..35bd0f250 100644 --- a/UI/Settings/Notifications/ItemTemplate.html +++ b/UI/Settings/Notifications/ItemTemplate.html @@ -1,8 +1,8 @@  - + - \ No newline at end of file + diff --git a/UI/Settings/Quality/Profile/QualityProfileTemplate.html b/UI/Settings/Quality/Profile/QualityProfileTemplate.html index 5ac5ccdc1..c73eec5aa 100644 --- a/UI/Settings/Quality/Profile/QualityProfileTemplate.html +++ b/UI/Settings/Quality/Profile/QualityProfileTemplate.html @@ -1,11 +1,11 @@  {{#each allowed}} - {{name}} | + {{name}} | {{/each}} - + | Delete - \ No newline at end of file +