More backbone

pull/21/head
Mark McDowall 12 years ago
parent ccccb9a4cd
commit 0333da1062

@ -16,14 +16,17 @@ namespace NzbDrone.Api
//Mapper.CreateMap<QualityTypes, Int32>()
// .ForMember(dest => dest, opt => opt.ResolveUsing<QualityTypesToIntResolver>());
Mapper.CreateMap<Int32, QualityTypes>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src));
//Mapper.CreateMap<Int32, QualityTypes>()
// .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src));
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId));
//Mapper.CreateMap<QualityProfile, QualityProfileModel>()
// .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId));
Mapper.CreateMap<QualityProfileModel, QualityProfile>()
.ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id));
//Mapper.CreateMap<QualityProfileModel, QualityProfile>()
// .ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id));
Mapper.CreateMap<QualityTypes, QualityProfileType>()
.ForMember(dest => dest.Allowed, opt => opt.Ignore());
}
}
}

@ -103,6 +103,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QualityProfiles\QualityProfileModel.cs" />
<Compile Include="QualityProfiles\QualityProfileService.cs" />
<Compile Include="QualityProfiles\QualityProfileType.cs" />
<Compile Include="Resolvers\QualityTypesToIntResolver.cs" />
</ItemGroup>
<ItemGroup>

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

@ -29,11 +29,14 @@ namespace NzbDrone.Api.QualityProfiles
if (request.Id == 0)
{
var profiles = _qualityProvider.All();
return Mapper.Map<IEnumerable<QualityProfile>, IEnumerable<QualityProfileModel>>(profiles);
var models = new List<QualityProfileModel>();
profiles.ForEach(p => models.Add(ToModel(p)));
return models;
}
var profile = _qualityProvider.Get(request.Id);
return Mapper.Map<QualityProfile, QualityProfileModel>(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>, List<QualityProfileType>>(QualityTypes.All());
model.Qualities.ForEach(quality =>
{
quality.Allowed = profile.Allowed.SingleOrDefault(q => q.Id == quality.Id) != null;
});
return model;
}
}
}

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

@ -2,7 +2,7 @@
urlRoot: '/api/qualityprofiles',
idAttribute: 'id',
idAttribute: 'Id',
initialize: function () {
this.validators = {};
@ -11,9 +11,9 @@
return value.length > 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
}
});

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

@ -122,7 +122,16 @@
<script id="QualityProfileTemplate" type="text/template">
<%= Name %>
<%= Cutoff %>
<%= Allowed %>
<% _.each(Qualities, function(quality) { %>
<input id="<%= Id %>_<%= quality.Id %>"
class="quality-selectee"
type="checkbox"
value="<%= quality.Allowed %>"
data-quality-id="<%= quality.Id %>"
<%= quality.Allowed ? 'checked="checked"' : '' %>
/>
<label for="<%= Id %>_<%= quality.Id %>"><%= quality.Name %></label>
<% }); %>
</script>
<script id="QualityProfileCollectionTemplate" type="text/template">

Loading…
Cancel
Save