1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

updated json serilizer to return defaults

use enum text instead of number
This commit is contained in:
kay.one 2013-05-05 18:16:38 -07:00
parent a6aba16902
commit 40f384968a
7 changed files with 31 additions and 34 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
namespace NzbDrone.Common namespace NzbDrone.Common
@ -20,26 +21,18 @@ public class JsonSerializer : IJsonSerializer
public JsonSerializer() public JsonSerializer()
{ {
var setting = new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented,
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
};
_jsonNetSerializer = new Newtonsoft.Json.JsonSerializer() _jsonNetSerializer = new Newtonsoft.Json.JsonSerializer()
{ {
DateTimeZoneHandling = setting.DateTimeZoneHandling, DateTimeZoneHandling = DateTimeZoneHandling.Utc,
NullValueHandling = setting.NullValueHandling, NullValueHandling = NullValueHandling.Include,
Formatting = setting.Formatting, Formatting = Formatting.Indented,
DefaultValueHandling = setting.DefaultValueHandling, DefaultValueHandling = DefaultValueHandling.Include,
ContractResolver = new CamelCasePropertyNamesContractResolver() ContractResolver = new CamelCasePropertyNamesContractResolver()
}; };
_jsonNetSerializer.Converters.Add(new StringEnumConverter { CamelCaseText = true });
} }
public T Deserialize<T>(string json) where T : class, new() public T Deserialize<T>(string json) where T : class, new()
{ {
return JsonConvert.DeserializeObject<T>(json); return JsonConvert.DeserializeObject<T>(json);

View File

@ -17,9 +17,9 @@ public ModelEvent(T model, RepositoryAction action)
public enum RepositoryAction public enum RepositoryAction
{ {
Created, Created = 1,
Updated, Updated = 2,
Deleted Deleted = 3
} }
} }

View File

@ -11,9 +11,19 @@ define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'AddSeries/New/Sear
regions: { regions: {
searchResult: '#search-result' searchResult: '#search-result'
}, },
collection: new NzbDrone.Series.SeriesCollection(),
initialize: function () { initialize: function () {
this.collection = new NzbDrone.Series.SeriesCollection();
this.collection.parse = function (response) {
_.each(response, function (model) {
model.id = null;
});
return response;
};
NzbDrone.AddSeries.New.AddNewSeriesContext = this; NzbDrone.AddSeries.New.AddNewSeriesContext = this;
NzbDrone.vent.on(NzbDrone.Events.SeriesAdded, function (options) { NzbDrone.vent.on(NzbDrone.Events.SeriesAdded, function (options) {

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Backbone.Collection.prototype.BindSignalR = function (options) { _.extend(Backbone.Collection.prototype, {BindSignalR: function (options) {
if (!options || !options.url) { if (!options || !options.url) {
console.assert(this.url, 'url must be provided or collection must have url'); console.assert(this.url, 'url must be provided or collection must have url');
@ -34,14 +34,15 @@ Backbone.Collection.prototype.BindSignalR = function (options) {
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState))); console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
}); });
connection.received(function () { connection.received(function (model) {
console.debug(model);
self.fetch(); self.fetch();
}); });
connection.start({ transport: ['longPolling'] }); connection.start({ transport: ['longPolling'] });
return this; return this;
}; }});

View File

@ -33,11 +33,11 @@
{{#if bestDateString}} {{#if bestDateString}}
<span class="label">{{bestDateString}}</span> <span class="label">{{bestDateString}}</span>
{{else}} {{else}}
<span class="label label-inverse">{{statusText}}</span> <span class="label label-inverse">{{status}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}
<span class="label label-important">{{statusText}}</span> <span class="label label-important">{{status}}</span>
<span class="label label-info">{{seasonCount}} Seasons</span> <span class="label label-info">{{seasonCount}} Seasons</span>
{{/if}} {{/if}}
</div> </div>

View File

@ -26,7 +26,7 @@
{{#if bestDateString}} {{#if bestDateString}}
<span class="label label-inverse air-date" title="{{shortDate}}">{{bestDateString}}</span> <span class="label label-inverse air-date" title="{{shortDate}}">{{bestDateString}}</span>
{{else}} {{else}}
<span class="label label-inverse">{{statusText}}</span> <span class="label label-inverse">{{status}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}

View File

@ -23,7 +23,7 @@ define(['app', 'Quality/QualityProfileCollection', 'AddSeries/RootFolders/RootFo
}, },
poster : function () { poster : function () {
var poster = _.find(this.get('images'), function (image) { var poster = _.find(this.get('images'), function (image) {
return image.coverType === 1; return image.coverType === 'poster';
}); });
if (poster) { if (poster) {
@ -47,14 +47,7 @@ define(['app', 'Quality/QualityProfileCollection', 'AddSeries/RootFolders/RootFo
return "http://trakt.tv/show/" + this.get('titleSlug'); return "http://trakt.tv/show/" + this.get('titleSlug');
}, },
isContinuing : function () { isContinuing : function () {
return this.get('status') === 0; return this.get('status') === 'continuing';
},
statusText : function () {
if (this.get('status') === 0) {
return 'Continuing';
}
return 'Ended';
}, },
shortDate : function () { shortDate : function () {
var date = this.get('nextAiring'); var date = this.get('nextAiring');