Skip to content

Commit

Permalink
Added support for specifying settings in the URL (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman authored Sep 7, 2022
1 parent 2541955 commit 130cfde
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
19 changes: 19 additions & 0 deletions GoToBible.Model/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ public static Uri AsUrl(this RenderingParameters parameters, UriKind uriKind = U
sb.Append('/');
sb.Append(Uri.EscapeDataString(parameters.SecondaryTranslation));
}

InterlinearMode mode = parameters.GetInterlinearMode();
if (mode != InterlinearMode.None)
{
sb.Append($"?settings={(int)mode}");
}
}

return new Uri(sb.ToString(), uriKind);
Expand Down Expand Up @@ -450,6 +456,19 @@ public static string EncodePassageForUrl(this string passage)
return segment;
}

/// <summary>
/// Gets the interlinear mode.
/// </summary>
/// <param name="parameters">The parameters.</param>
/// <returns>The interlinear mode.</returns>
public static InterlinearMode GetInterlinearMode(this RenderingParameters parameters)
{
InterlinearMode result = parameters.InterlinearIgnoresCase ? InterlinearMode.IgnoresCase : InterlinearMode.None;
result |= parameters.InterlinearIgnoresDiacritics ? InterlinearMode.IgnoresDiacritics : InterlinearMode.None;
result |= parameters.InterlinearIgnoresPunctuation ? InterlinearMode.IgnoresPunctuation : InterlinearMode.None;
return result;
}

/// <summary>
/// Renders the CSS.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions GoToBible.Model/InterlinearMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="InterlinearMode.cs" company="Conglomo">
// Copyright 2020-2022 Conglomo Limited. Please see LICENSE.md for license details.
// </copyright>
// -----------------------------------------------------------------------

namespace GoToBible.Model
{
using System;

/// <summary>
/// The interlinear mode.
/// </summary>
[Flags]
public enum InterlinearMode
{
/// <summary>
/// No special interlinear settings.
/// </summary>
None = 0,

/// <summary>
/// The interlinear ignores case.
/// </summary>
IgnoresCase = 1,

/// <summary>
/// The interlinear ignores diacritics.
/// </summary>
IgnoresDiacritics = 2,

/// <summary>
/// The interlinear ignores punctuation.
/// </summary>
IgnoresPunctuation = 4,
}
}
27 changes: 18 additions & 9 deletions GoToBible.Web/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@
[Parameter]
public string? SecondaryTranslation { get; set; }

/// <summary>
/// The settings passed in the query string.
/// </summary>
[Parameter]
[SupplyParameterFromQuery]
public int? Settings { get; set; }

/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
Expand All @@ -269,14 +276,7 @@
// If we don't have the ESV, default to the ENGESV, then the NET
if (this.translations.All(t => t.Code != "ESV"))
{
if (this.translations.Any(t => t.Code == "ENGESV"))
{
this.defaultTranslation = "ENGESV";
}
else
{
this.defaultTranslation = "NET";
}
this.defaultTranslation = this.translations.Any(t => t.Code == "ENGESV") ? "ENGESV" : "NET";
}

// Get the local copy of the rendering parameters
Expand Down Expand Up @@ -320,11 +320,20 @@
this.renderingParametersModel.SecondaryTranslation = this.SecondaryTranslation.DecodePassageFromUrl();
}

// Load the settings
// Load the settings from local storage
this.renderingParametersModel.InterlinearIgnoresCase = localRenderingParameters?.InterlinearIgnoresCase ?? false;
this.renderingParametersModel.InterlinearIgnoresDiacritics = localRenderingParameters?.InterlinearIgnoresDiacritics ?? false;
this.renderingParametersModel.InterlinearIgnoresPunctuation = localRenderingParameters?.InterlinearIgnoresPunctuation ?? false;

// Load the settings from the query string, if present
if (this.Settings.HasValue)
{
InterlinearMode settings = (InterlinearMode)this.Settings;
this.renderingParametersModel.InterlinearIgnoresCase = settings.HasFlag(InterlinearMode.IgnoresCase);
this.renderingParametersModel.InterlinearIgnoresDiacritics = settings.HasFlag(InterlinearMode.IgnoresDiacritics);
this.renderingParametersModel.InterlinearIgnoresPunctuation = settings.HasFlag(InterlinearMode.IgnoresPunctuation);
}

// Call the base implementation
await base.OnInitializedAsync();
}
Expand Down

0 comments on commit 130cfde

Please sign in to comment.