-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
2,520 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace BTCPayServer.Abstractions.Form; | ||
|
||
public abstract class Field | ||
public class Field | ||
{ | ||
// HTML5 compatible type string like "text", "textarea", "email", "password", etc. Each type is a class and may contain more fields (i.e. "select" would have options). | ||
public string Type; | ||
|
||
// The name of the HTML5 node. Should be used as the key for the posted data. | ||
public string Name; | ||
// The translated label of the field. | ||
public string Label; | ||
|
||
// HTML5 compatible type string like "text", "textarea", "email", "password", etc. Each type is a class and may contain more fields (i.e. "select" would have options). | ||
public string Type; | ||
|
||
// The value field is what is currently in the DB or what the user entered, but possibly not saved yet due to validation errors. | ||
// If this is the first the user sees the form, then value and original value are the same. Value changes as the user starts interacting with the form. | ||
public string Value; | ||
|
||
// The original value is the value that is currently saved in the backend. A "reset" button can be used to revert back to this. Should only be set from the constructor. | ||
public string OriginalValue; | ||
|
||
// A useful note shown below the field or via a tooltip / info icon. Should be translated for the user. | ||
public string HelpText; | ||
|
||
// The field is considered "valid" if there are no validation errors | ||
public List<string> ValidationErrors = new List<string>(); | ||
|
||
public bool Required = false; | ||
|
||
public bool IsValid() | ||
public virtual bool IsValid() | ||
{ | ||
return ValidationErrors.Count == 0; | ||
return ValidationErrors.Count == 0 && Fields.All(field => field.IsValid()); | ||
} | ||
|
||
[JsonExtensionData] public IDictionary<string, JToken> AdditionalData { get; set; } | ||
public List<Field> Fields { get; set; } = new(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace BTCPayServer.Abstractions.Form; | ||
|
||
public class Fieldset | ||
public class Fieldset : Field | ||
{ | ||
public bool Hidden { get; set; } | ||
public string Label { get; set; } | ||
|
||
public Fieldset() | ||
{ | ||
this.Fields = new List<Field>(); | ||
Type = "fieldset"; | ||
} | ||
|
||
public string Label { get; set; } | ||
public List<Field> Fields { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
|
||
namespace BTCPayServer.Data.Data; | ||
|
||
public class FormData | ||
{ | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
public string StoreId { get; set; } | ||
public StoreData Store { get; set; } | ||
|
||
public string Config { get; set; } | ||
|
||
|
||
internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databaseFacade) | ||
{ | ||
builder.Entity<FormData>() | ||
.HasOne(o => o.Store) | ||
.WithMany(o => o.Forms).OnDelete(DeleteBehavior.Cascade); | ||
if (databaseFacade.IsNpgsql()) | ||
{ | ||
builder.Entity<FormData>() | ||
.Property(o => o.Config) | ||
.HasColumnType("JSONB"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.