#236 has been modified slightly. Needs testing on Different systems
pull/687/head
Jamie.Rees 8 years ago
parent 1793c6f592
commit 1c7fb2e93e

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

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

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

@ -59,12 +59,12 @@ namespace PlexRequests.Core.StatusChecker
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
@ -76,7 +76,7 @@ namespace PlexRequests.Core.StatusChecker
var assemblyVersion = AssemblyHelper.GetProductVersion();
var model = new StatusModel
{
Version = assemblyVersion,
CurrentVersion = assemblyVersion,
};
var releases = await Git.Repository.Release.GetAll(Owner, RepoName);
@ -84,7 +84,7 @@ namespace PlexRequests.Core.StatusChecker
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;
@ -93,6 +93,7 @@ namespace PlexRequests.Core.StatusChecker
{
model.UpdateAvailable = true;
model.UpdateUri = latestRelease.HtmlUrl;
model.NewVersion = latestVersion;
}
model.ReleaseNotes = latestRelease.Body;
@ -102,17 +103,27 @@ namespace PlexRequests.Core.StatusChecker
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");
@ -139,15 +150,26 @@ namespace PlexRequests.Core.StatusChecker
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;
}
}
}

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

File diff suppressed because one or more lines are too long

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

@ -26,6 +26,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using MarkdownSharp;
@ -49,8 +50,7 @@ namespace PlexRequests.UI.Modules.Admin
SystemSettings = ss;
Security.HasPermissionsResponse(Permissions.Administrator);
Get["/status", true] = async (x, ct) => await Status();
Post["/save", true] = async (x, ct) => await Save();
@ -70,6 +70,28 @@ namespace PlexRequests.UI.Modules.Admin
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];
}
@ -79,6 +101,9 @@ namespace PlexRequests.UI.Modules.Admin
await SystemSettings.SaveSettingsAsync(settings);
// Clear the cache
Cache.Remove(CacheKeys.LastestProductVersion);
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully Saved your settings"});
}

@ -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>
@ -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++;
@ -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) {

Loading…
Cancel
Save