Calendar now using EpisodeResource

pull/4/head
Mark McDowall 12 years ago
parent 0da2047ca5
commit 11cef70406

@ -36,14 +36,6 @@ namespace NzbDrone.Api
Mapper.CreateMap<QualitySizeResource, QualitySize>()
.ForMember(dest => dest.QualityId, opt => opt.MapFrom(src => src.Id));
//Calendar
Mapper.CreateMap<Episode, CalendarResource>()
.ForMember(dest => dest.SeriesTitle, opt => opt.MapFrom(src => src.Series.Title))
.ForMember(dest => dest.EpisodeTitle, opt => opt.MapFrom(src => src.Title))
.ForMember(dest => dest.Start, opt => opt.MapFrom(src => src.AirDate))
.ForMember(dest => dest.End, opt => opt.ResolveUsing<EndTimeResolver>());
//Episode
Mapper.CreateMap<Episode, EpisodeResource>();
}

@ -2,6 +2,7 @@
using System.Collections.Generic;
using AutoMapper;
using Nancy;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Tv;
@ -31,7 +32,7 @@ namespace NzbDrone.Api.Calendar
if(queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value);
var episodes = _episodeService.EpisodesBetweenDates(start, end);
return Mapper.Map<List<Episode>, List<CalendarResource>>(episodes).AsResponse();
return Mapper.Map<List<Episode>, List<EpisodeResource>>(episodes).AsResponse();
}
}
}

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Api.Calendar
{
public class CalendarResource
{
public Int32 SeriesId { get; set; }
public String SeriesTitle { get; set; }
public Int32 EpisodeId { get; set; }
public String EpisodeTitle { get; set; }
public Int32 SeasonNumber { get; set; }
public Int32 EpisodeNumber { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public Int32 Status { get; set; }
public String Overview { get; set; }
}
}

@ -28,5 +28,6 @@ namespace NzbDrone.Api.Episodes
public DateTime? EndTime { get; set; }
public DateTime? GrabDate { get; set; }
public PostDownloadStatusType PostDownloadStatus { get; set; }
public Core.Tv.Series Series { get; set; }
}
}

@ -84,7 +84,6 @@
<ItemGroup>
<Compile Include="AutomapperBootstraper.cs" />
<Compile Include="Calendar\CalendarModule.cs" />
<Compile Include="Calendar\CalendarResource.cs" />
<Compile Include="Commands\CommandModule.cs" />
<Compile Include="Commands\CommandResource.cs" />
<Compile Include="Directories\DirectoryModule.cs" />

@ -1,8 +1,8 @@
"use strict";
define(['app', 'Calendar/CalendarModel'], function () {
define(['app', 'Series/EpisodeModel'], function () {
NzbDrone.Calendar.CalendarCollection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/calendar',
model : NzbDrone.Calendar.CalendarModel,
model : NzbDrone.Series.EpisodeModel,
comparator: function (model) {
return model.get('start');
}

@ -36,7 +36,7 @@ define(['app', 'Calendar/CalendarItemView'], function () {
element.popover({
title : '{seriesTitle} - {season}x{episode} - {episodeTitle}'.assign({
seriesTitle : event.seriesTitle,
seriesTitle : event.title,
season : event.seasonNumber,
episode : event.episodeNumber.pad(2),
episodeTitle: event.episodeTitle
@ -65,6 +65,14 @@ define(['app', 'Calendar/CalendarItemView'], function () {
bbView.calendar.fetch({
data : { start: startDate, end: endDate },
success: function (calendarCollection) {
_.each(calendarCollection.models, function(element) {
var episodeTitle = element.get('title');
var seriesTitle = element.get('series').title;
element.set('title', seriesTitle);
element.set('episodeTitle', episodeTitle);
});
callback(calendarCollection.toJSON());
}
});

@ -3,6 +3,6 @@
<h1>{{day}}</h1>
<h4>{{month}}</h4>
</div>
<h4>{{seriesTitle}}</h4>
<h4>{{series.title}}</h4>
<p>{{startTime}} {{bestDateString}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p>
</div>

@ -1,57 +0,0 @@
"use strict";
define(['app'], function () {
NzbDrone.Calendar.CalendarModel = Backbone.Model.extend({
mutators: {
title : function () {
return this.get('seriesTitle');
},
allDay : function () {
return false;
},
day : function () {
return Date.create(this.get('start')).format('{dd}');
},
month : function () {
return Date.create(this.get('start')).format('{MON}');
},
startTime : function () {
var start = Date.create(this.get('start'));
if (start.format('{mm}') === '00') {
return start.format('{h}{tt}');
}
return start.format('{h}.{mm}{tt}');
},
paddedEpisodeNumber: function () {
return this.get('episodeNumber');
},
statusLevel : function () {
var status = this.get('status');
var currentTime = Date.create();
var start = Date.create(this.get('start'));
var end = Date.create(this.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
if (start.isBefore(currentTime) || status === 'Missing') {
return 'danger';
}
if (status === 'Ready') {
return 'success';
}
return 'primary';
},
bestDateString : function () {
return bestDateString(this.get('start'));
}
},
defaults: {
status: 0
}
});
});

@ -8,11 +8,56 @@ define(['app'], function () {
},
paddedEpisodeNumber: function () {
return this.get('episodeNumber');
},
allDay : function () {
return false;
},
day : function () {
return Date.create(this.get('airDate')).format('{dd}');
},
month : function () {
return Date.create(this.get('airDate')).format('{MON}');
},
startTime : function () {
var start = Date.create(this.get('airDate'));
if (start.format('{mm}') === '00') {
return start.format('{h}{tt}');
}
return start.format('{h}.{mm}{tt}');
},
start : function () {
return this.get('airDate');
},
end : function () {
return this.get('endTime');
},
statusLevel : function () {
var status = this.get('status');
var currentTime = Date.create();
var start = Date.create(this.get('start'));
var end = Date.create(this.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
if (start.isBefore(currentTime) || status === 'Missing') {
return 'danger';
}
if (status === 'Ready') {
return 'success';
}
return 'primary';
}
},
defaults: {
seasonNumber: 0
seasonNumber: 0,
status: 0
}
});
});

Loading…
Cancel
Save