Skip to content

Commit

Permalink
create setup layout view with model
Browse files Browse the repository at this point in the history
  • Loading branch information
napoly committed Dec 28, 2024
1 parent 1ecb2ff commit e8ea4e4
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 49 deletions.
9 changes: 5 additions & 4 deletions BTCPayServer.Plugins.Monero/Controllers/UIPluginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Client;
using BTCPayServer.Plugins.Template.Data;
using BTCPayServer.Plugins.Template.Services;
using BTCPayServer.Plugins.Monero.Data;
using BTCPayServer.Plugins.Monero.Services;
using BTCPayServer.Plugins.Monero.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace BTCPayServer.Plugins.Template;
namespace BTCPayServer.Plugins.Monero;

[Route("~/XMR/setup")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanViewProfile)]
Expand All @@ -23,7 +24,7 @@ public UIPluginController(MoneroService PluginService)
// GET
public async Task<IActionResult> Index()

Check warning on line 25 in BTCPayServer.Plugins.Monero/Controllers/UIPluginController.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
return View(new PluginPageViewModel { Data = await _PluginService.Get() });
return View(new MoneroNodeViewModel{});
}
}

Expand Down
6 changes: 3 additions & 3 deletions BTCPayServer.Plugins.Monero/Data/MoneroDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BTCPayServer.Plugins.Template.Data;
using BTCPayServer.Plugins.Monero.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace BTCPayServer.Plugins.Template;
namespace BTCPayServer.Plugins.Monero;

public class MoneroDbContext : DbContext
{
Expand All @@ -24,6 +24,6 @@ public MoneroDbContext(DbContextOptions<MoneroDbContext> options, bool designTim
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("BTCPayServer.Plugins.Template");
modelBuilder.HasDefaultSchema("BTCPayServer.Plugins.Monero");
}
}
2 changes: 1 addition & 1 deletion BTCPayServer.Plugins.Monero/Data/PluginData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;

namespace BTCPayServer.Plugins.Template.Data;
namespace BTCPayServer.Plugins.Monero.Data;

public class PluginData
{
Expand Down
8 changes: 4 additions & 4 deletions BTCPayServer.Plugins.Monero/Migrations/20201117154419_Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace BTCPayServer.Plugins.Template.Migrations
namespace BTCPayServer.Plugins.Monero.Migrations
{
[DbContext(typeof(MoneroDbContext))]
[Migration("20201117154419_Init")]
Expand All @@ -11,11 +11,11 @@ public partial class Init : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "BTCPayServer.Plugins.Template");
name: "BTCPayServer.Plugins.Monero");

migrationBuilder.CreateTable(
name: "PluginRecords",
schema: "BTCPayServer.Plugins.Template",
schema: "BTCPayServer.Plugins.Monero",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Expand All @@ -31,7 +31,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PluginRecords",
schema: "BTCPayServer.Plugins.Template");
schema: "BTCPayServer.Plugins.Monero");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// <auto-generated />
using System;
using BTCPayServer.Plugins.Template;
using BTCPayServer.Plugins.Monero;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace BTCPayServer.Plugins.Template.Migrations
namespace BTCPayServer.Plugins.Monero.Migrations
{
[DbContext(typeof(MoneroDbContext))]
partial class MoneroDbContextModelSnapshot : ModelSnapshot
Expand All @@ -17,13 +17,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("BTCPayServer.Plugins.Template")
.HasDefaultSchema("BTCPayServer.Plugins.Monero")
.HasAnnotation("ProductVersion", "6.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("BTCPayServer.Plugins.Template.Data.PluginData", b =>
modelBuilder.Entity("BTCPayServer.Plugins.Monero.Data.PluginData", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
Expand All @@ -34,7 +34,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.ToTable("PluginRecords", "BTCPayServer.Plugins.Template");
b.ToTable("PluginRecords", "BTCPayServer.Plugins.Monero");
});
#pragma warning restore 612, 618
}
Expand Down
25 changes: 25 additions & 0 deletions BTCPayServer.Plugins.Monero/Model/MoneroNodeViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;

namespace BTCPayServer.Plugins.Monero.Model
{
public enum MoneroNodeType
{
Internal,
Custom
}

public class MoneroNodeViewModel
{
public MoneroNodeType MoneroNodeType { get; set; }
public string StoreId { get; set; }

Check warning on line 14 in BTCPayServer.Plugins.Monero/Model/MoneroNodeViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'StoreId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string CryptoCode { get; set; }

Check warning on line 15 in BTCPayServer.Plugins.Monero/Model/MoneroNodeViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CryptoCode' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool CanUseInternalNode { get; set; }
public bool SkipPortTest { get; set; }

[Display(Name = "Enabled")]
public bool Enabled { get; set; } = true;

[Display(Name = "Connection string")]
public string ConnectionString { get; set; }

Check warning on line 23 in BTCPayServer.Plugins.Monero/Model/MoneroNodeViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ConnectionString' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
4 changes: 2 additions & 2 deletions BTCPayServer.Plugins.Monero/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Abstractions.Services;
using BTCPayServer.Plugins.Template.Services;
using BTCPayServer.Plugins.Monero.Services;
using Microsoft.Extensions.DependencyInjection;

namespace BTCPayServer.Plugins.Template;
namespace BTCPayServer.Plugins.Monero;

public class Plugin : BaseBTCPayServerPlugin
{
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Plugins.Monero/PluginMigrationRunner.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Plugins.Template.Services;
using BTCPayServer.Plugins.Monero.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;

namespace BTCPayServer.Plugins.Template;
namespace BTCPayServer.Plugins.Monero;

public class PluginMigrationRunner : IHostedService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace BTCPayServer.Plugins.Template.Services;
namespace BTCPayServer.Plugins.Monero.Services;

// This is a demo class to show you how to integrate Hosted Service in the BTCPayServer plugin. Remove it from your project.
public class ApplicationPartsLogger : IHostedService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Extensions.Options;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;

namespace BTCPayServer.Plugins.Template.Services;
namespace BTCPayServer.Plugins.Monero.Services;

public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<MoneroDbContext>
{
Expand All @@ -24,7 +24,7 @@ public MoneroDbContext CreateDbContext(string[] args)

public class MoneroDbContextFactory : BaseDbContextFactory<MoneroDbContext>
{
public MoneroDbContextFactory(IOptions<DatabaseOptions> options) : base(options, "BTCPayServer.Plugins.Template")
public MoneroDbContextFactory(IOptions<DatabaseOptions> options) : base(options, "BTCPayServer.Plugins.Monero")
{
}

Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Plugins.Monero/Services/MoneroService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BTCPayServer.Plugins.Template.Data;
using BTCPayServer.Plugins.Monero.Data;
using Microsoft.EntityFrameworkCore;

namespace BTCPayServer.Plugins.Template.Services;
namespace BTCPayServer.Plugins.Monero.Services;

public class MoneroService
{
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer.Plugins.Monero/Views/PluginNavPages.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BTCPayServer.Plugins.Template.Views;
namespace BTCPayServer.Plugins.Monero.Views;

public enum PluginNavPages
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Plugins.Template.Views
@using BTCPayServer.Plugins.Monero.Views
@using Microsoft.AspNetCore.Mvc.TagHelpers

<li class="nav-item">
Expand Down
62 changes: 41 additions & 21 deletions BTCPayServer.Plugins.Monero/Views/UIPlugin/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Plugins.Template.Views
@model BTCPayServer.Plugins.Template.PluginPageViewModel
@using BTCPayServer.Plugins.Monero.Views
@using BTCPayServer.Plugins.Monero.Model
@model BTCPayServer.Plugins.Monero.Model.MoneroNodeViewModel
@{
ViewData.SetActivePage(PluginNavPages.Index, "Plugin Template");
ViewData.SetActivePage(PluginNavPages.Index, "Connect to a Monero node");
}
<h1>@ViewData["Title"]</h1>
<p>Here is an image loaded from the plugin</p>
<p>
<a href="https://twitter.com/NicolasDorier/status/1307221679014256640">
<img src="/Resources/img/screengrab.png"/>
</a>
</p>

<h2>Persisted Data</h2>
<p>
The following is data persisted to the configured database but in an isolated DbContext.
Every time you start BTCPay Server with this plugin enabled, a timestamp is logged.
</p>
<ul class="list-group">
@foreach (var item in Model.Data)
{
<li class="list-group-item">@item.Id at @item.Timestamp.ToString("F")</li>
}
</ul>
@section PageHeadContent {
<style>
#save { min-width: 7rem; }
#MoneroNodeTypeTabs ul {
list-style: none;
padding-left: 0;
}
#MoneroNodeTypeTabs ul li code,
#MoneroNodeTypeTabs pre {
display: block;
color: var(--btcpay-code-text);
background: var(--btcpay-bg-tile);
margin: .25rem 0;
padding: .75rem 1rem;
border-radius: 4px;
}
</style>
}

<h1 class="text-center mb-5">@ViewData["Title"]</h1>

<form method="post" class="mt-n2 text-center">
<div id="MoneroNodeTypeTablist" class="nav btcpay-pills align-items-center justify-content-center mb-3" role="tablist">
<input asp-for="MoneroNodeType" value="@MoneroNodeType.Internal" type="radio" id="[email protected]" data-bs-toggle="pill" data-bs-target="#InternalSetup" role="tab" aria-controls="InternalSetup" aria-selected="@(Model.MoneroNodeType == MoneroNodeType.Internal ? "true" : "false")" class="@(Model.MoneroNodeType == MoneroNodeType.Internal ? "active" : "")" disabled="@(!Model.CanUseInternalNode)">
<label asp-for="MoneroNodeType" for="@($"MoneroNodeType-{MoneroNodeType.Internal}")" text-translate="true">Use internal node</label>

<input asp-for="MoneroNodeType" value="@MoneroNodeType.Custom" type="radio" id="[email protected]" data-bs-toggle="pill" data-bs-target="#CustomSetup" role="tab" aria-controls="CustomSetup" aria-selected="@(Model.MoneroNodeType == MoneroNodeType.Custom ? "true" : "false")" class="@(Model.MoneroNodeType == MoneroNodeType.Custom ? "active" : "")">
<label asp-for="MoneroNodeType" for="@($"MoneroNodeType-{MoneroNodeType.Custom}")" text-translate="true">Use custom node</label>
</div>
<div class="text-start mt-4">
<button id="page-primary" name="command" type="submit" value="save" class="btn btn-primary me-2">Save</button>
</div>
</form>

@section PageFootContent {
<partial name="_ValidationScriptsPartial"/>
}

0 comments on commit e8ea4e4

Please sign in to comment.