1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

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.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.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 @@ public class ResourceMappingFixture : TestBase
[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);

View File

@ -8,8 +8,9 @@ public class QualityProfileResource : RestResource
{
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 @@ public class QualityResource : RestResource
public Int32 Id { get; set; }
public Int32 Weight { 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.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 @@ public QualityProfilesModule(QualityProfileService qualityProvider)
CreateResource = Create;
DeleteResource = DeleteProfile;
}
private QualityProfileResource Create(QualityProfileResource resource)
@ -46,13 +57,29 @@ private QualityProfileResource Update(QualityProfileResource resource)
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
};
}
}
}

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

View File

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

View File

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

View File

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

View File

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