Theme Viewer + Theme Updater (#2952)

This commit is contained in:
Joe Milazzo 2024-05-13 17:00:13 -05:00 committed by GitHub
parent 24302d4fcc
commit 38e7c1c131
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 4563 additions and 284 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,78 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace API.Data.Migrations
{
/// <inheritdoc />
public partial class SiteThemeFields : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Author",
table: "SiteTheme",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CompatibleVersion",
table: "SiteTheme",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "SiteTheme",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "GitHubPath",
table: "SiteTheme",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "PreviewUrls",
table: "SiteTheme",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "ShaHash",
table: "SiteTheme",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Author",
table: "SiteTheme");
migrationBuilder.DropColumn(
name: "CompatibleVersion",
table: "SiteTheme");
migrationBuilder.DropColumn(
name: "Description",
table: "SiteTheme");
migrationBuilder.DropColumn(
name: "GitHubPath",
table: "SiteTheme");
migrationBuilder.DropColumn(
name: "PreviewUrls",
table: "SiteTheme");
migrationBuilder.DropColumn(
name: "ShaHash",
table: "SiteTheme");
}
}
}

View file

@ -1871,15 +1871,27 @@ namespace API.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Author")
.HasColumnType("TEXT");
b.Property<string>("CompatibleVersion")
.HasColumnType("TEXT");
b.Property<DateTime>("Created")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedUtc")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("FileName")
.HasColumnType("TEXT");
b.Property<string>("GitHubPath")
.HasColumnType("TEXT");
b.Property<bool>("IsDefault")
.HasColumnType("INTEGER");
@ -1895,9 +1907,15 @@ namespace API.Data.Migrations
b.Property<string>("NormalizedName")
.HasColumnType("TEXT");
b.Property<string>("PreviewUrls")
.HasColumnType("TEXT");
b.Property<int>("Provider")
.HasColumnType("INTEGER");
b.Property<string>("ShaHash")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("SiteTheme");

View file

@ -19,6 +19,8 @@ public interface ISiteThemeRepository
Task<SiteThemeDto?> GetThemeDtoByName(string themeName);
Task<SiteTheme> GetDefaultTheme();
Task<IEnumerable<SiteTheme>> GetThemes();
Task<SiteTheme?> GetTheme(int themeId);
Task<bool> IsThemeInUse(int themeId);
}
public class SiteThemeRepository : ISiteThemeRepository
@ -88,6 +90,19 @@ public class SiteThemeRepository : ISiteThemeRepository
.ToListAsync();
}
public async Task<SiteTheme> GetTheme(int themeId)
{
return await _context.SiteTheme
.Where(t => t.Id == themeId)
.FirstOrDefaultAsync();
}
public async Task<bool> IsThemeInUse(int themeId)
{
return await _context.AppUserPreferences
.AnyAsync(p => p.Theme.Id == themeId);
}
public async Task<SiteThemeDto?> GetThemeDto(int themeId)
{
return await _context.SiteTheme

View file

@ -25,8 +25,8 @@ public static class Seed
/// </summary>
public static ImmutableArray<ServerSetting> DefaultSettings;
public static readonly ImmutableArray<SiteTheme> DefaultThemes = ImmutableArray.Create(
new List<SiteTheme>
public static readonly ImmutableArray<SiteTheme> DefaultThemes = [
..new List<SiteTheme>
{
new()
{
@ -36,7 +36,8 @@ public static class Seed
FileName = "dark.scss",
IsDefault = true,
}
}.ToArray());
}.ToArray()
];
public static readonly ImmutableArray<AppUserDashboardStream> DefaultStreams = ImmutableArray.Create(
new List<AppUserDashboardStream>