Allow games to select redistributables required

redistributables
Pat Hartl 2023-10-22 17:59:00 -05:00
parent 9327511245
commit 9e1b8ad7e3
8 changed files with 1697 additions and 0 deletions

View File

@ -0,0 +1,37 @@
@typeparam TItem where TItem : BaseModel
<Transfer DataSource="TransferItems" TargetKeys="TargetKeys" OnChange="OnChange" Titles="new string[] { LeftTitle, RightTitle }" />
@code {
[Parameter] public string LeftTitle { get; set; } = "";
[Parameter] public string RightTitle { get; set; } = "";
[Parameter] public Func<TItem, string> TitleSelector { get; set; }
[Parameter] public IEnumerable<TItem> DataSource { get; set; }
[Parameter] public ICollection<TItem> Values { get; set; } = new List<TItem>();
[Parameter] public EventCallback<ICollection<TItem>> ValuesChanged { get; set; }
IEnumerable<TransferItem> TransferItems { get; set; } = new List<TransferItem>();
List<string> TargetKeys { get; set; } = new List<string>();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
TransferItems = DataSource.Select(i => new TransferItem()
{
Key = i.Id.ToString(),
Title = TitleSelector.Invoke(i)
});
TargetKeys = Values.Select(i => i.Id.ToString()).ToList();
}
}
async Task OnChange(TransferChangeArgs e)
{
Values = DataSource.Where(i => e.TargetKeys.Contains(i.Id.ToString())).ToList();
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(Values);
}
}

View File

@ -81,6 +81,15 @@ namespace LANCommander.Data
g => g.HasOne<Game>().WithMany().HasForeignKey("GameId") g => g.HasOne<Game>().WithMany().HasForeignKey("GameId")
); );
builder.Entity<Game>()
.HasMany(g => g.Redistributables)
.WithMany(r => r.Games)
.UsingEntity<Dictionary<string, object>>(
"GameRedistributable",
gr => gr.HasOne<Redistributable>().WithMany().HasForeignKey("RedistributableId"),
gr => gr.HasOne<Game>().WithMany().HasForeignKey("GameId")
);
builder.Entity<User>() builder.Entity<User>()
.HasMany(u => u.GameSaves) .HasMany(u => u.GameSaves)
.WithOne(gs => gs.User) .WithOne(gs => gs.User)

View File

@ -34,6 +34,7 @@ namespace LANCommander.Data.Models
public virtual ICollection<GameSave>? GameSaves { get; set; } public virtual ICollection<GameSave>? GameSaves { get; set; }
public virtual ICollection<SavePath>? SavePaths { get; set; } public virtual ICollection<SavePath>? SavePaths { get; set; }
public virtual ICollection<Server>? Servers { get; set; } public virtual ICollection<Server>? Servers { get; set; }
public virtual ICollection<Redistributable>? Redistributables { get; set; }
public string? ValidKeyRegex { get; set; } public string? ValidKeyRegex { get; set; }
public virtual ICollection<Key>? Keys { get; set; } public virtual ICollection<Key>? Keys { get; set; }

View File

@ -11,5 +11,6 @@ namespace LANCommander.Data.Models
public virtual ICollection<Archive>? Archives { get; set; } public virtual ICollection<Archive>? Archives { get; set; }
public virtual ICollection<Script>? Scripts { get; set; } public virtual ICollection<Script>? Scripts { get; set; }
public virtual ICollection<Game>? Games { get; set; }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LANCommander.Migrations
{
/// <inheritdoc />
public partial class AddGameRedistributableRelationship : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "GameRedistributable",
columns: table => new
{
GameId = table.Column<Guid>(type: "TEXT", nullable: false),
RedistributableId = table.Column<Guid>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GameRedistributable", x => new { x.GameId, x.RedistributableId });
table.ForeignKey(
name: "FK_GameRedistributable_Games_GameId",
column: x => x.GameId,
principalTable: "Games",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GameRedistributable_Redistributables_RedistributableId",
column: x => x.RedistributableId,
principalTable: "Redistributables",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_GameRedistributable_RedistributableId",
table: "GameRedistributable",
column: "RedistributableId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GameRedistributable");
}
}
}

View File

@ -81,6 +81,21 @@ namespace LANCommander.Migrations
b.ToTable("GamePublisher"); b.ToTable("GamePublisher");
}); });
modelBuilder.Entity("GameRedistributable", b =>
{
b.Property<Guid>("GameId")
.HasColumnType("TEXT");
b.Property<Guid>("RedistributableId")
.HasColumnType("TEXT");
b.HasKey("GameId", "RedistributableId");
b.HasIndex("RedistributableId");
b.ToTable("GameRedistributable");
});
modelBuilder.Entity("GameTag", b => modelBuilder.Entity("GameTag", b =>
{ {
b.Property<Guid>("GamesId") b.Property<Guid>("GamesId")
@ -1073,6 +1088,21 @@ namespace LANCommander.Migrations
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("GameRedistributable", b =>
{
b.HasOne("LANCommander.Data.Models.Game", null)
.WithMany()
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LANCommander.Data.Models.Redistributable", null)
.WithMany()
.HasForeignKey("RedistributableId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GameTag", b => modelBuilder.Entity("GameTag", b =>
{ {
b.HasOne("LANCommander.Data.Models.Game", null) b.HasOne("LANCommander.Data.Models.Game", null)

View File

@ -12,6 +12,7 @@
@inject TagService TagService @inject TagService TagService
@inject ArchiveService ArchiveService @inject ArchiveService ArchiveService
@inject ScriptService ScriptService @inject ScriptService ScriptService
@inject RedistributableService RedistributableService
@inject IMessageService MessageService @inject IMessageService MessageService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ModalService ModalService @inject ModalService ModalService
@ -97,6 +98,9 @@
<FormItem Label="Tags"> <FormItem Label="Tags">
<TagsInput Entities="Tags" @bind-Values="Game.Tags" OptionLabelSelector="c => c.Name" TItem="Data.Models.Tag" /> <TagsInput Entities="Tags" @bind-Values="Game.Tags" OptionLabelSelector="c => c.Name" TItem="Data.Models.Tag" />
</FormItem> </FormItem>
<FormItem Label="Redistributables">
<TransferInput LeftTitle="Available" RightTitle="Selected" DataSource="Redistributables" TitleSelector="r => r.Name" @bind-Values="Game.Redistributables" />
</FormItem>
</Form> </Form>
</div> </div>
@ -160,6 +164,9 @@ else
IEnumerable<Company> Companies; IEnumerable<Company> Companies;
IEnumerable<Genre> Genres; IEnumerable<Genre> Genres;
IEnumerable<Data.Models.Tag> Tags; IEnumerable<Data.Models.Tag> Tags;
IEnumerable<Redistributable> Redistributables = new List<Redistributable>();
IEnumerable<TransferItem> RedistributableTargetItems = new List<TransferItem>();
IEnumerable<string> TargetRedistributables = new List<string>();
FilePickerDialog ArchiveFilePickerDialog; FilePickerDialog ArchiveFilePickerDialog;
@ -206,6 +213,13 @@ else
Companies = await CompanyService.Get(); Companies = await CompanyService.Get();
Genres = await GenreService.Get(); Genres = await GenreService.Get();
Tags = await TagService.Get(); Tags = await TagService.Get();
Redistributables = await RedistributableService.Get();
RedistributableTargetItems = Redistributables.Select(r => new TransferItem
{
Title = r.Name,
Description = r.Description,
Key = r.Id.ToString()
});
} }
private async Task Save() private async Task Save()