@ -35,8 +35,10 @@ using MarkdownSharp;
using Nancy ;
using Nancy ;
using Nancy.ModelBinding ;
using Nancy.ModelBinding ;
using Nancy.Responses.Negotiation ;
using Nancy.Responses.Negotiation ;
using Ombi.Api.Interfaces ;
using Ombi.Common.Processes ;
using Ombi.Common.Processes ;
using Ombi.Core ;
using Ombi.Core ;
using Ombi.Core.Models ;
using Ombi.Core.SettingModels ;
using Ombi.Core.SettingModels ;
using Ombi.Core.StatusChecker ;
using Ombi.Core.StatusChecker ;
using Ombi.Helpers ;
using Ombi.Helpers ;
@ -50,11 +52,13 @@ namespace Ombi.UI.Modules.Admin
{
{
public class SystemStatusModule : BaseModule
public class SystemStatusModule : BaseModule
{
{
public SystemStatusModule ( ISettingsService < PlexRequestSettings > settingsService , ICacheProvider cache , ISettingsService < SystemSettings > ss , ISecurityExtensions security , IAnalytics a ) : base ( "admin" , settingsService , security )
public SystemStatusModule ( ISettingsService < PlexRequestSettings > settingsService , ICacheProvider cache , ISettingsService < SystemSettings > ss ,
ISecurityExtensions security , IAnalytics a , IAppveyorApi appveyor ) : base ( "admin" , settingsService , security )
{
{
Cache = cache ;
Cache = cache ;
SystemSettings = ss ;
SystemSettings = ss ;
Analytics = a ;
Analytics = a ;
AppveyorApi = appveyor ;
Before + = ( ctx ) = > Security . AdminLoginRedirect ( Permissions . Administrator , ctx ) ;
Before + = ( ctx ) = > Security . AdminLoginRedirect ( Permissions . Administrator , ctx ) ;
@ -62,11 +66,13 @@ namespace Ombi.UI.Modules.Admin
Post [ "/save" , true ] = async ( x , ct ) = > await Save ( ) ;
Post [ "/save" , true ] = async ( x , ct ) = > await Save ( ) ;
Post [ "/autoupdate" ] = x = > AutoUpdate ( ) ;
Post [ "/autoupdate" ] = x = > AutoUpdate ( ) ;
Get [ "/changes" , true ] = async ( x , ct ) = > await GetLatestChanges ( ) ;
}
}
private ICacheProvider Cache { get ; }
private ICacheProvider Cache { get ; }
private ISettingsService < SystemSettings > SystemSettings { get ; }
private ISettingsService < SystemSettings > SystemSettings { get ; }
private IAnalytics Analytics { get ; }
private IAnalytics Analytics { get ; }
private IAppveyorApi AppveyorApi { get ; }
private async Task < Negotiator > Status ( )
private async Task < Negotiator > Status ( )
{
{
@ -82,19 +88,19 @@ namespace Ombi.UI.Modules.Admin
{
{
new BranchDropdown
new BranchDropdown
{
{
Name = EnumHelper < Branches > . Get DisplayValue( Branches . Stable ) ,
Name = EnumHelper < Branches > . Get BranchValue< BranchAttribute > ( Branches . Stable ) . DisplayName ,
Value = Branches . Stable ,
Value = Branches . Stable ,
Selected = settings . Branch = = Branches . Stable
Selected = settings . Branch = = Branches . Stable
} ,
} ,
new BranchDropdown
new BranchDropdown
{
{
Name = EnumHelper < Branches > . Get DisplayValue ( Branches . EarlyAccessPreview ) ,
Name = EnumHelper < Branches > . Get BranchValue< BranchAttribute > ( Branches . EarlyAccessPreview ) . DisplayName ,
Value = Branches . EarlyAccessPreview ,
Value = Branches . EarlyAccessPreview ,
Selected = settings . Branch = = Branches . EarlyAccessPreview
Selected = settings . Branch = = Branches . EarlyAccessPreview
} ,
} ,
new BranchDropdown
new BranchDropdown
{
{
Name = EnumHelper < Branches > . Get DisplayValue( Branches . Dev ) ,
Name = EnumHelper < Branches > . Get BranchValue< BranchAttribute > ( Branches . Dev ) . DisplayName ,
Value = Branches . Dev ,
Value = Branches . Dev ,
Selected = settings . Branch = = Branches . Dev
Selected = settings . Branch = = Branches . Dev
} ,
} ,
@ -103,6 +109,34 @@ namespace Ombi.UI.Modules.Admin
return View [ "Status" , settings ] ;
return View [ "Status" , settings ] ;
}
}
public async Task < Response > GetLatestChanges ( )
{
var settings = await SystemSettings . GetSettingsAsync ( ) ;
var branchName = EnumHelper < Branches > . GetBranchValue < BranchAttribute > ( settings . Branch ) . BranchName ;
var changes = AppveyorApi . GetProjectHistory ( branchName ) ;
var currentVersion = AssemblyHelper . GetProductVersion ( ) ;
var model = new List < RecentUpdatesModel > ( ) ;
foreach ( var build in changes . builds )
{
model . Add ( new RecentUpdatesModel
{
Date = build . finished ,
Message = BuildAppveyorMessage ( build . message , build . messageExtended ) ,
Version = build . version ,
Installed = currentVersion . Equals ( build . version , StringComparison . CurrentCultureIgnoreCase ) ,
Branch = branchName
} ) ;
}
return Response . AsJson ( model ) ;
}
private string BuildAppveyorMessage ( string message , string extended )
{
return extended = = null ? message : $"{message} {extended}" ;
}
private async Task < Response > Save ( )
private async Task < Response > Save ( )
{
{