cleaned up qualityprofile response format.

This commit is contained in:
Keivan Beigi 2013-05-30 18:22:28 -07:00
parent bdf86aa4ba
commit 3c53e6009d
8 changed files with 45 additions and 22 deletions

View File

@ -5,6 +5,7 @@ using NzbDrone.Api.Episodes;
using NzbDrone.Api.History; using NzbDrone.Api.History;
using NzbDrone.Api.Indexers; using NzbDrone.Api.Indexers;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using NzbDrone.Api.Qualities;
using NzbDrone.Api.RootFolders; using NzbDrone.Api.RootFolders;
using NzbDrone.Api.Series; using NzbDrone.Api.Series;
using NzbDrone.Api.Update; using NzbDrone.Api.Update;
@ -12,6 +13,7 @@ using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Update; using NzbDrone.Core.Update;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
@ -31,6 +33,8 @@ namespace NzbDrone.Api.Test.MappingTests
[TestCase(typeof(DownloadDecision), typeof(ReleaseResource))] [TestCase(typeof(DownloadDecision), typeof(ReleaseResource))]
[TestCase(typeof(Core.History.History), typeof(HistoryResource))] [TestCase(typeof(Core.History.History), typeof(HistoryResource))]
[TestCase(typeof(UpdatePackage), typeof(UpdateResource))] [TestCase(typeof(UpdatePackage), typeof(UpdateResource))]
[TestCase(typeof(QualityProfile), typeof(QualityProfileResource))]
[TestCase(typeof(Quality), typeof(QualityResource))]
public void matching_fields(Type modelType, Type resourceType) public void matching_fields(Type modelType, Type resourceType)
{ {
MappingValidation.ValidateMapping(modelType, resourceType); MappingValidation.ValidateMapping(modelType, resourceType);

View File

@ -8,8 +8,9 @@ namespace NzbDrone.Api.Qualities
{ {
public Int32 Id { get; set; } public Int32 Id { get; set; }
public String Name { get; set; } public String Name { get; set; }
public Int32 Cutoff { get; set; } public QualityResource Cutoff { get; set; }
public List<QualityResource> Qualities { get; set; } public List<QualityResource> Qualities { get; set; }
public List<QualityResource> Allowed { get; set; }
} }
public class QualityResource : RestResource public class QualityResource : RestResource
@ -17,6 +18,5 @@ namespace NzbDrone.Api.Qualities
public Int32 Id { get; set; } public Int32 Id { get; set; }
public Int32 Weight { get; set; } public Int32 Weight { get; set; }
public String Name { get; set; } public String Name { get; set; }
public Boolean Allowed { get; set; }
} }
} }

View File

@ -1,9 +1,21 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using System.Linq;
namespace NzbDrone.Api.Qualities namespace NzbDrone.Api.Qualities
{ {
public static class LazyLoadedExtensions
{
public static IEnumerable<int> GetForeignKeys(this IEnumerable<ModelBase> models)
{
return models.Select(c => c.Id).Distinct();
}
}
public class QualityProfilesModule : NzbDroneRestModule<QualityProfileResource> public class QualityProfilesModule : NzbDroneRestModule<QualityProfileResource>
{ {
private readonly QualityProfileService _qualityProvider; private readonly QualityProfileService _qualityProvider;
@ -22,7 +34,6 @@ namespace NzbDrone.Api.Qualities
CreateResource = Create; CreateResource = Create;
DeleteResource = DeleteProfile; DeleteResource = DeleteProfile;
} }
private QualityProfileResource Create(QualityProfileResource resource) private QualityProfileResource Create(QualityProfileResource resource)
@ -46,13 +57,29 @@ namespace NzbDrone.Api.Qualities
private QualityProfileResource GetById(int id) private QualityProfileResource GetById(int id)
{ {
return ToResource(() => _qualityProvider.Get(id)); return QualityToResource(_qualityProvider.Get(id));
} }
private List<QualityProfileResource> GetAll() private List<QualityProfileResource> 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<QualityResource>(),
Qualities = Quality.All().InjectTo<List<QualityResource>>(),
Allowed = profile.Allowed.InjectTo<List<QualityResource>>(),
Name = profile.Name,
Id = profile.Id
};
}
} }
} }

View File

@ -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 { ul.messenger.messenger-fixed.messenger-on-right, ul.messenger.messenger-fixed.messenger-on-left {
width: auto; width: auto;
min-width: 350px; min-width: 350px;
max-width: 800px;
word-wrap: break-word;
} }
/* line 69, ../../src/sass/messenger.sass */ /* line 69, ../../src/sass/messenger.sass */
ul.messenger.messenger-fixed.messenger-on-right .messenger-actions, ul.messenger.messenger-fixed.messenger-on-left .messenger-actions { ul.messenger.messenger-fixed.messenger-on-right .messenger-actions, ul.messenger.messenger-fixed.messenger-on-left .messenger-actions {

View File

@ -2,6 +2,6 @@
define(['app', 'Quality/QualitySizeModel'], function () { define(['app', 'Quality/QualitySizeModel'], function () {
NzbDrone.Quality.QualitySizeCollection = Backbone.Collection.extend({ NzbDrone.Quality.QualitySizeCollection = Backbone.Collection.extend({
model: NzbDrone.Quality.QualitySizeModel, model: NzbDrone.Quality.QualitySizeModel,
url : NzbDrone.Constants.ApiRoot + '/qualitysizes' url : NzbDrone.Constants.ApiRoot + '/qualitysize'
}); });
}); });

View File

@ -2,16 +2,6 @@
define(['app'], function () { define(['app'], function () {
NzbDrone.Quality.QualityProfileModel = Backbone.DeepModel.extend({ 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: { defaults: {
id : null, id : null,
name : '', name : '',

View File

@ -1,8 +1,8 @@
<td name="name"></td> <td name="name"></td>
<td name="onGrab"></td> <td name="onGrab"></td>
<td name="onDownload"></td> <td name="onDownload"></td>
<td name="cutoffName"></td> <td name="cutoff.name"></td>
<td> <td>
<i class="icon-cog x-edit" title="Edit"></i> <i class="icon-cog x-edit" title="Edit"></i>
<i class="icon-remove x-delete" title="Delete"></i> <i class="icon-remove x-delete" title="Delete"></i>
</td> </td>

View File

@ -1,11 +1,11 @@
<td name="name"></td> <td name="name"></td>
<td> <td>
{{#each allowed}} {{#each allowed}}
{{name}} | {{name}} |
{{/each}} {{/each}}
</td> </td>
<td name="cutoffName"></td> <td name="cutoff.name"></td>
<td> <td>
<i class="icon-cog x-edit" title="Edit Series"></i> <i class="icon-cog x-edit" title="Edit Series"></i>
| Delete | Delete
</td> </td>