cleaned up qualityprofile response format.

pull/3113/head
Keivan Beigi 12 years ago
parent bdf86aa4ba
commit 3c53e6009d

@ -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);

@ -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<QualityResource> Qualities { get; set; }
public List<QualityResource> 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; }
}
}

@ -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<int> GetForeignKeys(this IEnumerable<ModelBase> models)
{
return models.Select(c => c.Id).Distinct();
}
}
public class QualityProfilesModule : NzbDroneRestModule<QualityProfileResource>
{
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<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
};
}
}
}

@ -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 {

@ -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'
});
});

@ -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 : '',

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

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

Loading…
Cancel
Save