Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for the other providers #376

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@using System.ComponentModel.DataAnnotations
<UiProviderConfig ProviderName="AzureQueue" Health="@Health" ProviderIconCssClass="bi-globe2">

<EditForm Model="Model" OnValidSubmit="SaveConfig">
<AntiforgeryToken />
<ValidationSummary />
<dl>
<dt><label for="QueueConnectionString">Queue Connection String:</label></dt>
<dd>
<InputText name="QueueConnectionString" @bind-Value="Model.QueueConnectionString" placeholder="Queue Connection String" />
<ValidationMessage For="() => Model.QueueConnectionString" class="text-danger" />
</dd>
<dt><label for="Enabled">Enabled:</label></dt>
<dd>
<InputCheckbox name="Enabled" @bind-Value="Model.Enabled" />
</dd>
</dl>

<button type="submit" class="btn btn-primary">Save</button>

</EditForm>

</UiProviderConfig>

@code {

[Parameter, EditorRequired]
public ISocialMediaProvider Provider { get; set; } = null!;

public (SocialMediaStatus Status, string Message) Health { get; set; } = (SocialMediaStatus.Unknown, string.Empty);


public ViewModel Model { get; set; } = new();

protected override async Task OnParametersSetAsync()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

Model = new ViewModel
{
QueueConnectionString = providerConfiguration.GetConfigurationByKey("QueueConnectionString"),
Enabled = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("Enabled")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("Enabled"))
};

Health = await Provider.GetHealth();

await base.OnParametersSetAsync();

}

private async Task SaveConfig()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

providerConfiguration.SetConfigurationByKey("QueueConnectionString", Model.QueueConnectionString);
providerConfiguration.SetConfigurationByKey("Enabled", Model.Enabled.ToString());

await Provider.SaveConfiguration(ConfigureTagzAppFactory.Current, providerConfiguration);

}

public class ViewModel
{

// add properties for each of the fields you want to edit

[Required]
public string QueueConnectionString { get; set; }

public bool Enabled { get; set; }


}

}
143 changes: 143 additions & 0 deletions src/TagzApp.Blazor.Client/Components/Admin/Blazot.Config.Ui.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
@using System.ComponentModel.DataAnnotations
@using System.Text.Json
<UiProviderConfig ProviderName="Blazot" Health="@Health" ProviderIconCssClass="bi-blazot">

<EditForm Model="Model" OnValidSubmit="SaveConfig">
<AntiforgeryToken />
<ValidationSummary />
<dl>
<dt><label for="ApiKey">Api Key:</label></dt>
<dd>
<InputText name="ApiKey" @bind-Value="Model.ApiKey" placeholder="Api Key" />
<ValidationMessage For="() => Model.ApiKey" class="text-danger" />
</dd>
<dt><label for="SecretAuthKey">Secret Auth Key:</label></dt>
<dd>
<InputText name="SecretAuthKey" @bind-Value="Model.SecretAuthKey" placeholder="Secret Auth Key" />
<ValidationMessage For="() => Model.SecretAuthKey" class="text-danger" />
</dd>
<dt><label for="BaseAddress">Base Address:</label></dt>
<dd>
<InputText name="BaseAddress" @bind-Value="Model.BaseAddress" placeholder="Base Address of Mastodon Server" />
<ValidationMessage For="() => Model.BaseAddress" class="text-danger" />
</dd>
<dt><label for="Timeout">Timeout:</label></dt>
<dd>
<input name="Timeout" @bind="Model.Timeout" pattern="\d{2}:\d{2}:\d{2}" />
<ValidationMessage For="() => Model.Timeout" class="text-danger" />
</dd>
<dt>Default Headers:</dt>
<dd>
@* Generate a set of textboxes to collect values for the DefaultHeaders dictionary in ViewModel*@
<InputDictionary Value="@Model.DefaultHeaders" KeyCaption="Name" />

</dd>
<dt><label for="UseHttp2">UseHttp2:</label></dt>
<dd>
<InputCheckbox name="UseHttp2" @bind-Value="Model.UseHttp2" />
</dd>
<dt><label for="WindowRequests">Window Requests:</label></dt>
<dd>
<InputNumber name="WindowRequests" @bind-Value="Model.WindowRequests" />
<ValidationMessage For="() => Model.WindowRequests" class="text-danger" />
</dd>
<dt><label for="WindowSeconds">Window Seconds:</label></dt>
<dd>
<InputNumber name="WindowSeconds" @bind-Value="Model.WindowSeconds" />
<ValidationMessage For="() => Model.WindowSeconds" class="text-danger" />
</dd>

<dt><label for="Enabled">Enabled:</label></dt>
<dd>
<InputCheckbox name="Enabled" @bind-Value="Model.Enabled" />
</dd>
</dl>

<button type="submit" class="btn btn-primary">Save</button>

</EditForm>

</UiProviderConfig>

@code {

[Parameter, EditorRequired]
public ISocialMediaProvider Provider { get; set; } = null!;

public (SocialMediaStatus Status, string Message) Health { get; set; } = (SocialMediaStatus.Unknown, string.Empty);


public ViewModel Model { get; set; } = new();

protected override async Task OnParametersSetAsync()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

var headers = providerConfiguration.GetConfigurationByKey("DefaultHeaders");
var headerDictionary = string.IsNullOrEmpty(headers) ? new() : JsonSerializer.Deserialize<Dictionary<string, string>>(headers);

Model = new ViewModel
{
BaseAddress = providerConfiguration.GetConfigurationByKey("BaseAddress"),
DefaultHeaders = headerDictionary,
Timeout = TimeSpan.Parse(providerConfiguration.GetConfigurationByKey("Timeout")),
UseHttp2 = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("UseHttp2")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("UseHttp2")),
Enabled = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("Enabled")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("Enabled"))
};

Health = await Provider.GetHealth();

await base.OnParametersSetAsync();

}

private async Task SaveConfig()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

Model.DefaultHeaders.Remove(string.Empty);

providerConfiguration.SetConfigurationByKey("BaseAddress", Model.BaseAddress);
providerConfiguration.SetConfigurationByKey("Timeout", Model.Timeout.ToString());
providerConfiguration.SetConfigurationByKey("DefaultHeaders", JsonSerializer.Serialize(Model.DefaultHeaders));
providerConfiguration.SetConfigurationByKey("UseHttp2", Model.UseHttp2.ToString());
providerConfiguration.SetConfigurationByKey("Enabled", Model.Enabled.ToString());

await Provider.SaveConfiguration(ConfigureTagzAppFactory.Current, providerConfiguration);

}

public class ViewModel
{

// add properties for each of the fields you want to edit
[Required]
public string ApiKey { get; set; }

[Required]
public string BaseAddress { get; set; }

public Dictionary<string, string> DefaultHeaders { get; set; } = new();

[Required]
public string SecretAuthKey { get; set; }

[Required]
public TimeSpan Timeout { get; set; }

public bool UseHttp2 { get; set; }

[Required]
public int WindowSeconds { get; set; }

[Required]
public int WindowRequests { get; set; }

public bool Enabled { get; set; }

}


}
112 changes: 112 additions & 0 deletions src/TagzApp.Blazor.Client/Components/Admin/Twitter.Config.Ui.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
@using System.ComponentModel.DataAnnotations
@using System.Text.Json
<UiProviderConfig ProviderName="Twitter" Health="@Health" ProviderIconCssClass="bi-twitter-x">

<EditForm Model="Model" OnValidSubmit="SaveConfig">
<AntiforgeryToken />
<ValidationSummary />
<dl>
<dt><label for="BaseAddress">Base Address:</label></dt>
<dd>
<InputText name="BaseAddress" @bind-Value="Model.BaseAddress" placeholder="Base Address of Mastodon Server" />
<ValidationMessage For="() => Model.BaseAddress" class="text-danger" />
</dd>
<dt><label for="Timeout">Timeout:</label></dt>
<dd>
<input name="Timeout" @bind="Model.Timeout" pattern="\d{2}:\d{2}:\d{2}" />
<ValidationMessage For="() => Model.Timeout" class="text-danger" />
</dd>
<dt>Default Headers:</dt>
<dd>
@* Generate a set of textboxes to collect values for the DefaultHeaders dictionary in ViewModel*@
<InputDictionary Value="@Model.DefaultHeaders" KeyCaption="Name" />

</dd>
<dt><label for="UseHttp2">UseHttp2:</label></dt>
<dd>
<InputCheckbox name="UseHttp2" @bind-Value="Model.UseHttp2" />
</dd>
<dt><label for="Enabled">Enabled:</label></dt>
<dd>
<InputCheckbox name="Enabled" @bind-Value="Model.Enabled" />
</dd>
</dl>

<button type="submit" class="btn btn-primary">Save</button>

</EditForm>

</UiProviderConfig>

@code {

[Parameter, EditorRequired]
public ISocialMediaProvider Provider { get; set; } = null!;

public (SocialMediaStatus Status, string Message) Health { get; set; } = (SocialMediaStatus.Unknown, string.Empty);


public ViewModel Model { get; set; } = new();

protected override async Task OnParametersSetAsync()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

var headers = providerConfiguration.GetConfigurationByKey("DefaultHeaders");
var headerDictionary = string.IsNullOrEmpty(headers) ? new() : JsonSerializer.Deserialize<Dictionary<string, string>>(headers);

Model = new ViewModel
{
BaseAddress = providerConfiguration.GetConfigurationByKey("BaseAddress"),
DefaultHeaders = headerDictionary,
Timeout = TimeSpan.Parse(providerConfiguration.GetConfigurationByKey("Timeout")),
UseHttp2 = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("UseHttp2")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("UseHttp2")),
Enabled = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("Enabled")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("Enabled"))
};

Health = await Provider.GetHealth();

await base.OnParametersSetAsync();

}

private async Task SaveConfig()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

Model.DefaultHeaders.Remove(string.Empty);

providerConfiguration.SetConfigurationByKey("BaseAddress", Model.BaseAddress);
providerConfiguration.SetConfigurationByKey("Timeout", Model.Timeout.ToString());
providerConfiguration.SetConfigurationByKey("DefaultHeaders", JsonSerializer.Serialize(Model.DefaultHeaders));
providerConfiguration.SetConfigurationByKey("UseHttp2", Model.UseHttp2.ToString());
providerConfiguration.SetConfigurationByKey("Enabled", Model.Enabled.ToString());

await Provider.SaveConfiguration(ConfigureTagzAppFactory.Current, providerConfiguration);

}

public class ViewModel
{

// add properties for each of the fields you want to edit

[Required]
public string BaseAddress { get; set; }

[Required]
public TimeSpan Timeout { get; set; }

public Dictionary<string, string> DefaultHeaders { get; set; } = new();

public bool UseHttp2 { get; set; }

public bool Enabled { get; set; }


}


}
12 changes: 1 addition & 11 deletions src/TagzApp.Blazor.Client/Components/ModerationMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</div>
</div>

<i class="provider bi @MapProviderToIcon(Content.Provider)"></i>
<i class="provider bi @ContentModel.MapProviderToIcon(Content.Provider)"></i>

<div class="time">
<div>@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")</div>
Expand Down Expand Up @@ -188,14 +188,4 @@
StateHasChanged();
}

public static string MapProviderToIcon(string provider) =>
provider?.ToLowerInvariant().Trim() switch
{
"bluesky" => "icon-bluesky",
"twitter" => "bi-twitter-x",
"website" => "bi-globe2",
"youtube-chat" => "bi-youtube",
_ => $"bi-{provider?.ToLowerInvariant().Trim() ?? "question-circle"}"
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<label title="@provider.Name"
class="btn btn-outline-primary providerSwitch"
@onclick="() => ToggleProviderFilter(provider.Id)"
for="@provider.Id"><i class="provider bi @WaterfallMessage.MapProviderToIcon(provider.Id)"></i></label>
for="@provider.Id"><i class="provider bi @ContentModel.MapProviderToIcon(provider.Id)"></i></label>
}

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/TagzApp.Blazor.Client/Components/Pages/Overlay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="author">@Content.AuthorDisplayName</div>
<div class="authorUserName">@Content.AuthorUserName</div>
</div>
<i class="provider bi @WaterfallMessage.MapProviderToIcon(Content.Provider)"></i>
<i class="provider bi @ContentModel.MapProviderToIcon(Content.Provider)"></i>
<span class="time">@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")</span>

<span class="content">@((MarkupString)(Content.FormatContentWithEmotes()))</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
<span class="time">
@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")
<i class="provider bi ${window.TagzApp.MapProviderToIconClass(content.provider)}"></i>
<i class="provider bi @ContentModel.MapProviderToIcon(Content.Provider)"></i>
</span>
<span class="content">@((MarkupString)(Content.FormatContentWithEmotes()))</span>

Expand Down
Loading
Loading