1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-24 17:01:38 +00:00

Calendar now using EpisodeResource

This commit is contained in:
Mark McDowall 2013-04-30 18:54:15 -07:00
parent 0da2047ca5
commit 11cef70406
10 changed files with 61 additions and 93 deletions

View file

@ -36,14 +36,6 @@ public static void InitializeAutomapper()
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>();
}

View file

@ -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 @@ private Response GetEpisodesBetweenStartAndEndDate()
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();
}
}
}

View file

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

View file

@ -28,5 +28,6 @@ public class EpisodeResource : RestResource
public DateTime? EndTime { get; set; }
public DateTime? GrabDate { get; set; }
public PostDownloadStatusType PostDownloadStatus { get; set; }
public Core.Tv.Series Series { get; set; }
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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