Skip to content

Commit

Permalink
- Added a visual indication on the UI to tell the admin there is a up…
Browse files Browse the repository at this point in the history
…date available.

- We are now also recording the last scheduled run in the database
tidusjar committed Apr 29, 2016
1 parent af028f0 commit df3dc4a
Showing 28 changed files with 392 additions and 45 deletions.
2 changes: 2 additions & 0 deletions PlexRequests.Core/CacheKeys.cs
Original file line number Diff line number Diff line change
@@ -47,5 +47,7 @@ public struct TimeFrameMinutes
public const string CouchPotatoQueued = "CouchPotatoQueued";

public const string GetBaseUrl = "GetBaseUrl";

public const string LastestProductVersion = "LatestProductVersion";
}
}
3 changes: 1 addition & 2 deletions PlexRequests.Core/JsonRequestService.cs
Original file line number Diff line number Diff line change
@@ -49,10 +49,9 @@ public long AddRequest(RequestedModel model)
var entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId };
var id = Repo.Insert(entity);

// TODO Keep an eye on this, since we are now doing 2 DB update for 1 single request, inserting and then updating
model.Id = (int)id;

entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = (int)id, MusicId = model.MusicBrainzId};
entity = new RequestBlobs { Type = model.Type, Content = ByteConverterHelper.ReturnBytes(model), ProviderId = model.ProviderId, Id = (int)id, MusicId = model.MusicBrainzId };
var result = Repo.Update(entity);

return result ? id : -1;
10 changes: 0 additions & 10 deletions PlexRequests.Core/Models/StatusModel.cs
Original file line number Diff line number Diff line change
@@ -24,21 +24,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion

using System.Text.RegularExpressions;

namespace PlexRequests.Core.Models
{
public class StatusModel
{
public string Version { get; set; }
public int DBVersion {
get
{
string trimStatus = new Regex("[^0-9]", RegexOptions.Compiled).Replace(Version, string.Empty).PadRight(4, '0');
return int.Parse(trimStatus);
}
}
public bool UpdateAvailable { get; set; }
public string UpdateUri { get; set; }
public string DownloadUri { get; set; }
10 changes: 6 additions & 4 deletions PlexRequests.Core/Setup.cs
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Mono.Data.Sqlite;
using NLog;
@@ -72,18 +73,19 @@ public string SetupDb(string urlBase)

private int CheckSchema()
{
var checker = new StatusChecker();
var status = checker.GetStatus();
var productVersion = AssemblyHelper.GetProductVersion();
var trimStatus = new Regex("[^0-9]", RegexOptions.Compiled).Replace(productVersion, string.Empty).PadRight(4, '0');
var version = int.Parse(trimStatus);

var connection = Db.DbConnection();
var schema = connection.GetSchemaVersion();
if (schema == null)
{
connection.CreateSchema(status.DBVersion); // Set the default.
connection.CreateSchema(version); // Set the default.
schema = connection.GetSchemaVersion();
}

var version = schema.SchemaVersion;
version = schema.SchemaVersion;

return version;
}
33 changes: 33 additions & 0 deletions PlexRequests.Services/Interfaces/IJobRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IJobRecord.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Services.Interfaces
{
public interface IJobRecord
{
void Record(string jobName);
}
}
8 changes: 7 additions & 1 deletion PlexRequests.Services/Jobs/CouchPotatoCacher.cs
Original file line number Diff line number Diff line change
@@ -41,16 +41,18 @@ namespace PlexRequests.Services.Jobs
{
public class CouchPotatoCacher : IJob, ICouchPotatoCacher
{
public CouchPotatoCacher(ISettingsService<CouchPotatoSettings> cpSettings, ICouchPotatoApi cpApi, ICacheProvider cache)
public CouchPotatoCacher(ISettingsService<CouchPotatoSettings> cpSettings, ICouchPotatoApi cpApi, ICacheProvider cache, IJobRecord rec)
{
CpSettings = cpSettings;
CpApi = cpApi;
Cache = cache;
Job = rec;
}

private ISettingsService<CouchPotatoSettings> CpSettings { get; }
private ICacheProvider Cache { get; }
private ICouchPotatoApi CpApi { get; }
private IJobRecord Job { get; }

private static Logger Log = LogManager.GetCurrentClassLogger();

@@ -74,6 +76,10 @@ public void Queued()
{
Log.Error(ex, "Failed caching queued items from CouchPotato");
}
finally
{
Job.Record(JobNames.CpCacher);
}
}
}

37 changes: 37 additions & 0 deletions PlexRequests.Services/Jobs/JobNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: JobNames.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Services
{
public static class JobNames
{
public const string StoreBackup = "Database Backup";
public const string CpCacher = "CouchPotato Cacher";
public const string SonarrCacher = "Sonarr Cacher";
public const string SrCacher = "SickRage Cacher";
public const string PlexChecker = "Plex Availability Cacher";
}
}
59 changes: 59 additions & 0 deletions PlexRequests.Services/Jobs/JobRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: JobRecord.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Linq;

using PlexRequests.Services.Interfaces;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;

namespace PlexRequests.Services
{
public class JobRecord : IJobRecord
{
public JobRecord(IRepository<ScheduledJobs> repo)
{
Repo = repo;
}
private IRepository<ScheduledJobs> Repo { get; }
public void Record(string jobName)
{
var allJobs = Repo.GetAll();
var storeJob = allJobs.FirstOrDefault(x => x.Name == jobName);
if (storeJob != null)
{
storeJob.LastRun = DateTime.UtcNow;
Repo.Update(storeJob);
}
else
{
var job = new ScheduledJobs { LastRun = DateTime.UtcNow, Name = jobName };
Repo.Insert(job);
}
}
}
}
6 changes: 5 additions & 1 deletion PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs
Original file line number Diff line number Diff line change
@@ -47,14 +47,15 @@ namespace PlexRequests.Services.Jobs
public class PlexAvailabilityChecker : IJob, IAvailabilityChecker
{
public PlexAvailabilityChecker(ISettingsService<PlexSettings> plexSettings, ISettingsService<AuthenticationSettings> auth, IRequestService request, IPlexApi plex, ICacheProvider cache,
INotificationService notify)
INotificationService notify, IJobRecord rec)
{
Plex = plexSettings;
Auth = auth;
RequestService = request;
PlexApi = plex;
Cache = cache;
Notification = notify;
Job = rec;
}

private ISettingsService<PlexSettings> Plex { get; }
@@ -64,6 +65,7 @@ public PlexAvailabilityChecker(ISettingsService<PlexSettings> plexSettings, ISet
private IPlexApi PlexApi { get; }
private ICacheProvider Cache { get; }
private INotificationService Notification { get; }
private IJobRecord Job { get; }

public void CheckAndUpdateAll()
{
@@ -144,6 +146,8 @@ public void CheckAndUpdateAll()
RequestService.BatchUpdate(modifiedModel);
}

Job.Record(JobNames.PlexChecker);

}

public List<PlexMovie> GetPlexMovies()
8 changes: 7 additions & 1 deletion PlexRequests.Services/Jobs/SickRageCacher.cs
Original file line number Diff line number Diff line change
@@ -41,18 +41,20 @@ namespace PlexRequests.Services.Jobs
{
public class SickRageCacher : IJob, ISickRageCacher
{
public SickRageCacher(ISettingsService<SickRageSettings> srSettings, ISickRageApi srApi, ICacheProvider cache)
public SickRageCacher(ISettingsService<SickRageSettings> srSettings, ISickRageApi srApi, ICacheProvider cache, IJobRecord rec)
{
SrSettings = srSettings;
SrApi = srApi;
Cache = cache;
Job = rec;
}

private ISettingsService<SickRageSettings> SrSettings { get; }
private ICacheProvider Cache { get; }
private ISickRageApi SrApi { get; }

private static Logger Log = LogManager.GetCurrentClassLogger();
private IJobRecord Job { get; }

public void Queued()
{
@@ -74,6 +76,10 @@ public void Queued()
{
Log.Error(ex, "Failed caching queued items from SickRage");
}
finally
{
Job.Record(JobNames.SrCacher);
}
}
}

10 changes: 9 additions & 1 deletion PlexRequests.Services/Jobs/SonarrCacher.cs
Original file line number Diff line number Diff line change
@@ -35,23 +35,27 @@
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Services.Interfaces;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;

using Quartz;

namespace PlexRequests.Services.Jobs
{
public class SonarrCacher : IJob, ISonarrCacher
{
public SonarrCacher(ISettingsService<SonarrSettings> sonarrSettings, ISonarrApi sonarrApi, ICacheProvider cache)
public SonarrCacher(ISettingsService<SonarrSettings> sonarrSettings, ISonarrApi sonarrApi, ICacheProvider cache, IJobRecord rec)
{
SonarrSettings = sonarrSettings;
SonarrApi = sonarrApi;
Job = rec;
Cache = cache;
}

private ISettingsService<SonarrSettings> SonarrSettings { get; }
private ICacheProvider Cache { get; }
private ISonarrApi SonarrApi { get; }
private IJobRecord Job { get; }

private static Logger Log = LogManager.GetCurrentClassLogger();

@@ -75,6 +79,10 @@ public void Queued()
{
Log.Error(ex, "Failed caching queued items from Sonarr");
}
finally
{
Job.Record(JobNames.SonarrCacher);
}
}
}

11 changes: 10 additions & 1 deletion PlexRequests.Services/Jobs/StoreBackup.cs
Original file line number Diff line number Diff line change
@@ -30,7 +30,10 @@

using NLog;

using PlexRequests.Services.Interfaces;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;

using Quartz;

@@ -40,12 +43,14 @@ namespace PlexRequests.Services.Jobs
{
public class StoreBackup : IJob
{
public StoreBackup(ISqliteConfiguration sql)
public StoreBackup(ISqliteConfiguration sql, IJobRecord rec)
{
Sql = sql;
JobRecord = rec;
}

private ISqliteConfiguration Sql { get; }
private IJobRecord JobRecord { get; }

private static Logger Log = LogManager.GetCurrentClassLogger();

@@ -82,6 +87,10 @@ private void TakeBackup()
Log.Warn(e);
Log.Warn("Exception when trying to copy the backup.");
}
finally
{
JobRecord.Record(JobNames.StoreBackup);
}

}
}
3 changes: 3 additions & 0 deletions PlexRequests.Services/PlexRequests.Services.csproj
Original file line number Diff line number Diff line change
@@ -93,6 +93,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Interfaces\IJobRecord.cs" />
<Compile Include="Jobs\JobRecord.cs" />
<Compile Include="Jobs\JobNames.cs" />
<Compile Include="Jobs\StoreBackup.cs" />
<Compile Include="Jobs\CouchPotatoCacher.cs" />
<Compile Include="Jobs\PlexAvailabilityChecker.cs" />
39 changes: 39 additions & 0 deletions PlexRequests.Store/Models/ScheduledJobs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: LogEntity.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;

using Dapper.Contrib.Extensions;

namespace PlexRequests.Store.Models
{
[Table("ScheduledJobs")]
public class ScheduledJobs : Entity
{
public string Name { get; set; }
public DateTime LastRun { get; set; }
}
}
1 change: 1 addition & 0 deletions PlexRequests.Store/PlexRequests.Store.csproj
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@
<ItemGroup>
<Compile Include="DbConfiguration.cs" />
<Compile Include="Entity.cs" />
<Compile Include="Models\ScheduledJobs.cs" />
<Compile Include="Repository\IRequestRepository.cs" />
<Compile Include="Repository\ISettingsRepository.cs" />
<Compile Include="ISqliteConfiguration.cs" />
9 changes: 8 additions & 1 deletion PlexRequests.Store/SqlTables.sql
Original file line number Diff line number Diff line change
@@ -45,5 +45,12 @@ CREATE UNIQUE INDEX IF NOT EXISTS Logs_Id ON Logs (Id);
CREATE TABLE IF NOT EXISTS DBInfo
(
SchemaVersion INTEGER
);

);
CREATE TABLE IF NOT EXISTS ScheduledJobs
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Name varchar(100) NOT NULL,
LastRun varchar(100) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS ScheduledJobs_Id ON ScheduledJobs (Id);
2 changes: 2 additions & 0 deletions PlexRequests.UI/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -87,8 +87,10 @@ protected override void ConfigureRequestContainer(TinyIoCContainer container, Na

// Repo's
container.Register<IRepository<LogEntity>, GenericRepository<LogEntity>>();
container.Register<IRepository<ScheduledJobs>, GenericRepository<ScheduledJobs>>();
container.Register<IRequestService, JsonRequestService>();
container.Register<ISettingsRepository, SettingsJsonRepository>();
container.Register<IJobRecord, JobRecord>();

// Services
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
4 changes: 4 additions & 0 deletions PlexRequests.UI/Content/custom.css
Original file line number Diff line number Diff line change
@@ -220,3 +220,7 @@ label {
border-radius: 0 0.25rem 0.25rem 0 !important;
padding: 12px 8px; }

#updateAvailable {
background-color: #ffa400;
text-align: center; }

2 changes: 1 addition & 1 deletion PlexRequests.UI/Content/custom.min.css
8 changes: 6 additions & 2 deletions PlexRequests.UI/Content/custom.scss
Original file line number Diff line number Diff line change
@@ -7,8 +7,7 @@ $warning-colour: #f0ad4e;
$danger-colour: #d9534f;
$success-colour: #5cb85c;
$i:
!important
;
!important;

@media (min-width: 768px ) {
.row {
@@ -279,4 +278,9 @@ $border-radius: 10px;
.btn-split .btn.dropdown-toggle {
border-radius: 0 .25rem .25rem 0 $i;
padding: 12px 8px;
}

#updateAvailable {
background-color: rgb(255, 164, 0);
text-align: center;
}
2 changes: 1 addition & 1 deletion PlexRequests.UI/Jobs/CustomJobFactory.cs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
namespace PlexRequests.UI.Jobs
{
/// <summary>
/// The custom job factory we are using so we are able to use our IoC container with DI in our Jobs.
/// The custom job factory we are using so we are able to use our IoC container with DI in our JobNames.
/// </summary>
/// <seealso cref="Quartz.Spi.IJobFactory" />
public class CustomJobFactory : IJobFactory
33 changes: 33 additions & 0 deletions PlexRequests.UI/Models/JsonUpdateAvailableModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: JsonUpdateAvailableModel.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.UI.Models
{
public class JsonUpdateAvailableModel
{
public bool UpdateAvailable { get; set; }
}
}
14 changes: 7 additions & 7 deletions PlexRequests.UI/Modules/AdminModule.cs
Original file line number Diff line number Diff line change
@@ -295,8 +295,8 @@ private Response SaveCouchPotato()
}

var result = CpService.SaveSettings(couchPotatoSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for CouchPotato!" }
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for CouchPotato!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}

@@ -429,7 +429,7 @@ private Response TestEmailNotifications()
finally
{
NotificationService.UnSubscribe(new EmailMessageNotification(EmailService));
}
}
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Email Notification!" });
}

@@ -464,7 +464,7 @@ private Negotiator Status()
{
var checker = new StatusChecker();
var status = checker.GetStatus();
var md = new Markdown();
var md = new Markdown(new MarkdownOptions { AutoNewLines = true });
status.ReleaseNotes = md.Transform(status.ReleaseNotes);
return View["Status", status];
}
@@ -623,7 +623,7 @@ private Response LoadLogs()
{
JsonSettings.MaxJsonLength = int.MaxValue;
var allLogs = LogsRepo.GetAll().OrderByDescending(x => x.Id).Take(200);
var model = new DatatablesModel<LogEntity> {Data = new List<LogEntity>()};
var model = new DatatablesModel<LogEntity> { Data = new List<LogEntity>() };
foreach (var l in allLogs)
{
l.DateString = l.Date.ToString("G");
@@ -650,7 +650,7 @@ private Response UpdateLogLevels(int level)
settings.Level = level;
LogService.SaveSettings(settings);

return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"});
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}" });
}

private Negotiator Headphones()
@@ -673,7 +673,7 @@ private Response SaveHeadphones()
Log.Trace(settings.DumpJson());

var result = HeadphonesService.SaveSettings(settings);

Log.Info("Saved headphones settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Headphones!" }
7 changes: 7 additions & 0 deletions PlexRequests.UI/Modules/BaseAuthModule.cs
Original file line number Diff line number Diff line change
@@ -30,8 +30,11 @@
using PlexRequests.UI.Models;
using System;

using Nancy.Security;

using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;

namespace PlexRequests.UI.Modules
{
@@ -52,6 +55,8 @@ protected string Username
}
}

protected bool IsAdmin => Context.CurrentUser.IsAuthenticated();

protected int DateTimeOffset
{
get
@@ -87,5 +92,7 @@ private Response CheckAuth()
: null;
}



}
}
12 changes: 2 additions & 10 deletions PlexRequests.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
@@ -124,14 +124,6 @@ public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings>
private IHeadphonesApi HeadphonesApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();

private bool IsAdmin
{
get
{
return Context.CurrentUser.IsAuthenticated();
}
}

private Negotiator RequestLoad()
{
var settings = PrService.GetSettings();
@@ -626,7 +618,7 @@ private Response RequestTvShow(int showId, string seasons, bool notify)
Status = showInfo.status,
RequestedDate = DateTime.UtcNow,
Approved = false,
RequestedUsers = new List<string>() { Username },
RequestedUsers = new List<string> { Username },
Issues = IssueState.None,
ImdbId = showInfo.externals?.imdb ?? string.Empty,
SeasonCount = showInfo.seasonCount
@@ -802,7 +794,7 @@ private Response RequestAlbum(string releaseId, bool notify)
}

var sender = new HeadphonesSender(HeadphonesApi, hpSettings, RequestService);
sender.AddAlbum(model);
sender.AddAlbum(model).Wait();
model.Approved = true;
RequestService.AddRequest(model);

79 changes: 79 additions & 0 deletions PlexRequests.UI/Modules/UpdateCheckerModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UpdateCheckerModule.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;

using Nancy;

using NLog;

using PlexRequests.Core;
using PlexRequests.Helpers;
using PlexRequests.UI.Models;

namespace PlexRequests.UI.Modules
{
public class UpdateCheckerModule : BaseAuthModule
{
public UpdateCheckerModule(ICacheProvider provider) : base("updatechecker")
{
Cache = provider;

Get["/"] = _ => CheckLatestVersion();
}

private ICacheProvider Cache { get; }

private static Logger Log = LogManager.GetCurrentClassLogger();

private Response CheckLatestVersion()
{
try
{
if (!IsAdmin)
{
return Response.AsJson(new JsonUpdateAvailableModel { UpdateAvailable = false });
}

var checker = new StatusChecker();
var release = Cache.GetOrSet(CacheKeys.LastestProductVersion, () => checker.GetStatus(), 30);

if (release.UpdateAvailable)
{
return Response.AsJson(new JsonUpdateAvailableModel { UpdateAvailable = true});
}

return Response.AsJson(new JsonUpdateAvailableModel { UpdateAvailable = false });
}
catch (Exception e)
{
Log.Warn("Exception Thrown when attempting to check the status");
Log.Warn(e);
return Response.AsJson(new JsonUpdateAvailableModel { UpdateAvailable = false });
}
}
}
}
2 changes: 2 additions & 0 deletions PlexRequests.UI/PlexRequests.UI.csproj
Original file line number Diff line number Diff line change
@@ -185,12 +185,14 @@
<Compile Include="Jobs\CustomJobFactory.cs" />
<Compile Include="Jobs\Scheduler.cs" />
<Compile Include="Models\DatatablesModel.cs" />
<Compile Include="Models\JsonUpdateAvailableModel.cs" />
<Compile Include="Models\MovieSearchType.cs" />
<Compile Include="Models\QualityModel.cs" />
<Compile Include="Models\SearchViewModel.cs" />
<Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Models\SearchMovieViewModel.cs" />
<Compile Include="Modules\BaseModule.cs" />
<Compile Include="Modules\UpdateCheckerModule.cs" />
<Compile Include="Start\StartupOptions.cs" />
<Compile Include="Validators\HeadphonesValidator.cs" />
<Compile Include="Validators\PushoverSettingsValidator.cs" />
23 changes: 21 additions & 2 deletions PlexRequests.UI/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -34,15 +34,15 @@
</button>
<a class="navbar-brand" href="@url/search">Plex Requests</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
@Html.GetNavbarUrl(Context, "/search", "Search", "search")
@Html.GetNavbarUrl(Context, "/requests", "Requests", "plus-circle")
</ul>
<ul class="nav navbar-nav navbar-right">


@if (!Context.CurrentUser.IsAuthenticated())
{
<li><a href="@url/login"><i class="fa fa-user"></i> Admin</a></li>
@@ -66,6 +66,7 @@
</ul>
</div>
</div>
<div id="updateAvailable" hidden="hidden"></div>
</nav>

<div class="container">
@@ -82,6 +83,24 @@
$(function () {
var urlBase = '@Html.GetBaseUrl()';
var url = createBaseUrl(urlBase, '/updatechecker');
$.ajax({
type: "GET",
url: url,
dataType: "json",
success: function (response) {
if (response.updateAvailable) {
var status = createBaseUrl(urlBase, '/admin/status');
$('#updateAvailable').html("There is a new update available! Click <a style='color: white' href='"+status+"'>Here!</a>");
$('#updateAvailable').removeAttr("hidden");
}
},
error: function (e) {
console.log(e);
}
});
$(document).on('scroll', function () {
if ($(window).scrollTop() > 100) {

2 comments on commit df3dc4a

@tidusjar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tidusjar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.