Skip to content

Commit

Permalink
Finished #659
Browse files Browse the repository at this point in the history
#236 has been modified slightly. Needs testing on Different systems
  • Loading branch information
Jamie.Rees authored and Jamie.Rees committed Nov 8, 2016
1 parent 1793c6f commit 1c7fb2e
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 37 deletions.
3 changes: 2 additions & 1 deletion PlexRequests.Core/Models/StatusModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace PlexRequests.Core.Models
{
public class StatusModel
{
public string Version { get; set; }
public string CurrentVersion { get; set; }
public string NewVersion { get; set; }
public bool UpdateAvailable { get; set; }
public string UpdateUri { get; set; }
public string DownloadUri { get; set; }
Expand Down
1 change: 1 addition & 0 deletions PlexRequests.Core/PlexRequests.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
Expand Down
26 changes: 25 additions & 1 deletion PlexRequests.Core/SettingModels/SystemSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,38 @@
// ************************************************************************/
#endregion

using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using PlexRequests.Core.Models;

namespace PlexRequests.Core.SettingModels
{
public class SystemSettings : Settings
{
public bool UseEarlyAccessPreviewBuilds { get; set; }
public Branches Branch { get; set; }

public StatusModel Status { get; set; }

public List<BranchDropdown> BranchDropdown { get; set; }
}

public class BranchDropdown
{
public bool Selected { get; set; }
public string Name { get; set; }
public Branches Value { get; set; }
}

public enum Branches
{
[Display(Name = "Stable")]
Stable,

[Display(Name = "Early Access Preview")]
EarlyAccessPreview,

[Display(Name = "Development")]
Dev,
}
}
48 changes: 35 additions & 13 deletions PlexRequests.Core/StatusChecker/StatusChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public StatusChecker(ISettingsService<SystemSettings> ss)
public async Task<StatusModel> GetStatus()
{
var settings = await SystemSettings.GetSettingsAsync();
var isEap = settings.UseEarlyAccessPreviewBuilds;
var stable = settings.Branch == Branches.Stable;

if (isEap)
if (!stable)
{
// Early Access Preview Releases
return GetLatestEapRelease();
return GetAppveyorRelease(settings.Branch);
}

// Stable releases
Expand All @@ -76,15 +76,15 @@ private async Task<StatusModel> GetLatestGithubRelease()
var assemblyVersion = AssemblyHelper.GetProductVersion();
var model = new StatusModel
{
Version = assemblyVersion,
CurrentVersion = assemblyVersion,
};

var releases = await Git.Repository.Release.GetAll(Owner, RepoName);
var latestRelease = releases.FirstOrDefault();

if (latestRelease == null)
{
return new StatusModel { Version = "Unknown" };
return new StatusModel { NewVersion = "Unknown" };
}
var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty;
Expand All @@ -93,6 +93,7 @@ private async Task<StatusModel> GetLatestGithubRelease()
{
model.UpdateAvailable = true;
model.UpdateUri = latestRelease.HtmlUrl;
model.NewVersion = latestVersion;
}

model.ReleaseNotes = latestRelease.Body;
Expand All @@ -102,17 +103,27 @@ private async Task<StatusModel> GetLatestGithubRelease()
return model;
}

private StatusModel GetLatestEapRelease()
private StatusModel GetAppveyorRelease(Branches branch)
{
var request = new ApiRequest();

// Get latest EAP Build
var eapBranchRequest = new RestRequest
{
Resource = "/projects/tidusjar/requestplex/branch/EAP",
Method = Method.GET
};


switch (branch)
{
case Branches.Dev:
eapBranchRequest.Resource = "/projects/tidusjar/requestplex/branch/dev";
break;
case Branches.EarlyAccessPreview:
eapBranchRequest.Resource = "/projects/tidusjar/requestplex/branch/EAP";
break;
}

var api = StringCipher.Decrypt(Api,"Appveyor");
eapBranchRequest.AddHeader("Authorization", $"Bearer {api}");
eapBranchRequest.AddHeader("Content-Type", "application/json");
Expand All @@ -139,15 +150,26 @@ private StatusModel GetLatestEapRelease()

var downloadLink = $"{AppveyorApiUrl}/buildjobs/{jobId}/artifacts/{artifactResult.fileName}";

return new StatusModel
var branchDisplay = EnumHelper<Branches>.GetDisplayValue(branch);
var localVersion = AssemblyHelper.GetProductVersion();
var localVersionExtended = $"{localVersion.Remove(localVersion.Length - 2, 2)}00";

var model = new StatusModel
{
DownloadUri = downloadLink,
ReleaseNotes = "Early Access Preview (See recent commits for details)",
ReleaseTitle = "Plex Requests Early Access Preview",
Version = branchResult.build.version,
UpdateAvailable = true,
UpdateUri = downloadLink
ReleaseNotes = $"{branchDisplay} (See recent commits for details)",
ReleaseTitle = $"Plex Requests {branchDisplay}",
NewVersion = branchResult.build.version,
UpdateUri = downloadLink,
CurrentVersion = localVersionExtended
};

if (!localVersionExtended.Equals(branchResult.build.version, StringComparison.CurrentCultureIgnoreCase))
{
model.UpdateAvailable = true;
}

return model;
}
}
}
17 changes: 17 additions & 0 deletions PlexRequests.UI/Content/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,20 @@ label {
position: relative;
margin-right: 0; } }

#lightbox {
background-color: grey;
filter: alpha(opacity=50);
/* IE */
opacity: 0.5;
/* Safari, Opera */
-moz-opacity: 0.50;
/* FireFox */
top: 0px;
left: 0px;
z-index: 20;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-position: center;
position: absolute; }

2 changes: 1 addition & 1 deletion PlexRequests.UI/Content/base.min.css

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions PlexRequests.UI/Content/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ $info-colour: #5bc0de;
$warning-colour: #f0ad4e;
$danger-colour: #d9534f;
$success-colour: #5cb85c;
$i:
!important
;
$i:!important;

@media (min-width: 768px ) {
.row {
Expand Down Expand Up @@ -551,4 +549,20 @@ $border-radius: 10px;
position: relative;
margin-right: 0;
}
}
}

#lightbox {

background-color: grey;
filter:alpha(opacity=50); /* IE */
opacity: 0.5; /* Safari, Opera */
-moz-opacity:0.50; /* FireFox */
top: 0px;
left: 0px;
z-index: 20;
height: 100%;
width: 100%;
background-repeat:no-repeat;
background-position:center;
position:absolute;
}
29 changes: 27 additions & 2 deletions PlexRequests.UI/Modules/Admin/SystemStatusModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using MarkdownSharp;
Expand All @@ -49,8 +50,7 @@ public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService,
SystemSettings = ss;

Security.HasPermissionsResponse(Permissions.Administrator);



Get["/status", true] = async (x, ct) => await Status();
Post["/save", true] = async (x, ct) => await Save();

Expand All @@ -70,6 +70,28 @@ private async Task<Negotiator> Status()

settings.Status = status;

settings.BranchDropdown = new List<BranchDropdown>
{
new BranchDropdown
{
Name = EnumHelper<Branches>.GetDisplayValue(Branches.Stable),
Value = Branches.Stable,
Selected = settings.Branch == Branches.Stable
},
new BranchDropdown
{
Name = EnumHelper<Branches>.GetDisplayValue(Branches.EarlyAccessPreview),
Value = Branches.EarlyAccessPreview,
Selected = settings.Branch == Branches.EarlyAccessPreview
},
new BranchDropdown
{
Name = EnumHelper<Branches>.GetDisplayValue(Branches.Dev),
Value = Branches.Dev,
Selected = settings.Branch == Branches.Dev
},
};

return View["Status", settings];
}

Expand All @@ -79,6 +101,9 @@ private async Task<Response> Save()

await SystemSettings.SaveSettingsAsync(settings);

// Clear the cache
Cache.Remove(CacheKeys.LastestProductVersion);

return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully Saved your settings"});
}

Expand Down
49 changes: 34 additions & 15 deletions PlexRequests.UI/Views/Admin/Status.cshtml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
@using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.SystemSettings>
@Html.Partial("_Sidebar")

<div id="lightbox" style="display:none"></div>
<div class="col-sm-8 col-sm-push-1">
<fieldset>
<legend>Status</legend>


<div class="form-group">
<label class="control-label">Version: </label>
<label class="control-label">@Model.Status.Version</label>
<label class="control-label">Current Version: </label>
<label class="control-label">@Model.Status.CurrentVersion</label>
</div>

<form id="mainForm" method="post" action="save">

@if (Model.Status.UpdateAvailable)
{
<div class="form-group">
<div class="checkbox">
<label class="control-label">New Version: </label>
<label class="control-label">@Model.Status.NewVersion</label>
</div>
}

@if (Model.UseEarlyAccessPreviewBuilds)
{
<input type="checkbox" id="UseEarlyAccessPreviewBuilds" name="UseEarlyAccessPreviewBuilds" checked="checked"><label for="UseEarlyAccessPreviewBuilds">Use Early Access Preview Builds</label>
}
else
{
<input type="checkbox" id="UseEarlyAccessPreviewBuilds" name="UseEarlyAccessPreviewBuilds"><label for="UseEarlyAccessPreviewBuilds">Use Early Access Preview Builds</label>
}
<form id="mainForm" method="post" action="save">

<div class="form-group">
<label for="select" class="control-label">Code Branch</label>
<div id="branches">
<select class="form-control form-control-custom" id="select">
@foreach (var b in Model.BranchDropdown)
{
if (b.Selected)
{
<option selected='selected' value='@b.Value'>@b.Name</option>
}
else
{
<option value='@b.Value'>@b.Name</option>
}
}
</select>
</div>
</div>
<button id="saveSettings" class="btn btn-success-outline">Save</button>
Expand Down Expand Up @@ -68,6 +81,7 @@
e.preventDefault();
$('body').append("<i class=\"fa fa-spinner fa-spin fa-5x fa-fw\" style=\"position: absolute; top: 20%; left: 50%;\"></i>");
$('#autoUpdate').prop("disabled", "disabled");
document.getElementById("lightbox").style.display = "";
var count = 0;
setInterval(function () {
count++;
Expand All @@ -92,10 +106,15 @@
$('#saveSettings').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
var branches = $("#branches option:selected").val();
var data = $form.serialize();
data = data + "&branch=" + branches;
$.ajax({
type: $form.prop("method"),
url: $form.prop("action"),
data: $form.serialize(),
data: data,
dataType: "json",
success: function (response) {
if (response.result === true) {
Expand Down

0 comments on commit 1c7fb2e

Please sign in to comment.