Option to convert ical feed items to all-day events

This commit is contained in:
Sander Ploegsma 2017-01-16 22:19:50 +01:00 committed by Taloth
parent 01e2f4e7e5
commit da451cfe03
3 changed files with 42 additions and 3 deletions

View File

@ -37,6 +37,7 @@ namespace NzbDrone.Api.Calendar
var end = DateTime.Today.AddDays(futureDays); var end = DateTime.Today.AddDays(futureDays);
var unmonitored = false; var unmonitored = false;
var premiersOnly = false; var premiersOnly = false;
var asAllDay = false;
var tags = new List<int>(); var tags = new List<int>();
// TODO: Remove start/end parameters in v3, they don't work well for iCal // TODO: Remove start/end parameters in v3, they don't work well for iCal
@ -46,6 +47,7 @@ namespace NzbDrone.Api.Calendar
var queryFutureDays = Request.Query.FutureDays; var queryFutureDays = Request.Query.FutureDays;
var queryUnmonitored = Request.Query.Unmonitored; var queryUnmonitored = Request.Query.Unmonitored;
var queryPremiersOnly = Request.Query.PremiersOnly; var queryPremiersOnly = Request.Query.PremiersOnly;
var queryAsAllDay = Request.Query.AsAllDay;
var queryTags = Request.Query.Tags; var queryTags = Request.Query.Tags;
if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value);
@ -73,6 +75,11 @@ namespace NzbDrone.Api.Calendar
premiersOnly = bool.Parse(queryPremiersOnly.Value); premiersOnly = bool.Parse(queryPremiersOnly.Value);
} }
if (queryAsAllDay.HasValue)
{
asAllDay = bool.Parse(queryAsAllDay.Value);
}
if (queryTags.HasValue) if (queryTags.HasValue)
{ {
var tagInput = (string)queryTags.Value.ToString(); var tagInput = (string)queryTags.Value.ToString();
@ -102,11 +109,19 @@ namespace NzbDrone.Api.Calendar
var occurrence = calendar.Create<Event>(); var occurrence = calendar.Create<Event>();
occurrence.Uid = "NzbDrone_episode_" + episode.Id; occurrence.Uid = "NzbDrone_episode_" + episode.Id;
occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = true };
occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
occurrence.Description = episode.Overview; occurrence.Description = episode.Overview;
occurrence.Categories = new List<string>() { episode.Series.Network }; occurrence.Categories = new List<string>() { episode.Series.Network };
if (asAllDay)
{
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = false };
}
else
{
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = true };
occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
}
switch (episode.Series.SeriesType) switch (episode.Series.SeriesType)
{ {
case SeriesTypes.Daily: case SeriesTypes.Daily:

View File

@ -9,6 +9,7 @@ module.exports = Marionette.Layout.extend({
ui : { ui : {
includeUnmonitored : '.x-includeUnmonitored', includeUnmonitored : '.x-includeUnmonitored',
premiersOnly : '.x-premiersOnly', premiersOnly : '.x-premiersOnly',
asAllDay : '.x-asAllDay',
tags : '.x-tags', tags : '.x-tags',
icalUrl : '.x-ical-url', icalUrl : '.x-ical-url',
icalCopy : '.x-ical-copy', icalCopy : '.x-ical-copy',
@ -18,6 +19,7 @@ module.exports = Marionette.Layout.extend({
events : { events : {
'click .x-includeUnmonitored' : '_updateUrl', 'click .x-includeUnmonitored' : '_updateUrl',
'click .x-premiersOnly' : '_updateUrl', 'click .x-premiersOnly' : '_updateUrl',
'click .x-asAllDay' : '_updateUrl',
'itemAdded .x-tags' : '_updateUrl', 'itemAdded .x-tags' : '_updateUrl',
'itemRemoved .x-tags' : '_updateUrl' 'itemRemoved .x-tags' : '_updateUrl'
}, },
@ -29,7 +31,7 @@ module.exports = Marionette.Layout.extend({
}, },
_updateUrl : function() { _updateUrl : function() {
var icalUrl = window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?'; var icalUrl = window.location.host + StatusModel.get('urlBase') + '/feed/calendar/Sonarr.ics?';
if (this.ui.includeUnmonitored.prop('checked')) { if (this.ui.includeUnmonitored.prop('checked')) {
icalUrl += 'unmonitored=true&'; icalUrl += 'unmonitored=true&';
@ -39,6 +41,10 @@ module.exports = Marionette.Layout.extend({
icalUrl += 'premiersOnly=true&'; icalUrl += 'premiersOnly=true&';
} }
if (this.ui.asAllDay.prop('checked')) {
icalUrl += 'asAllDay=true&';
}
if (this.ui.tags.val()) { if (this.ui.tags.val()) {
icalUrl += 'tags=' + this.ui.tags.val() + '&'; icalUrl += 'tags=' + this.ui.tags.val() + '&';
} }

View File

@ -41,6 +41,24 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-3 control-label">Show as All-Day Events</label>
<div class="col-sm-4">
<div class="input-group">
<label class="checkbox toggle well">
<input type="checkbox" name="asAllDay" class="form-control x-asAllDay"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">Tags</label> <label class="col-sm-3 control-label">Tags</label>