Skip to content

Commit

Permalink
feat(display): remove ListContext, make List options required
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Sep 8, 2021
1 parent 96055b7 commit 619a399
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 118 deletions.
58 changes: 30 additions & 28 deletions apps/Sitko.Blockly.Demo/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@
@using Sitko.Blockly.Display
@using Sitko.Core.Storage
@inherits BaseComponent
<PageContainer Title="Posts">
<PageContainer Title="Posts">
<Breadcrumb>
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>Posts</BreadcrumbItem>
</Breadcrumb>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>Posts</BreadcrumbItem>
</Breadcrumb>
<Content>
</Content>
<ExtraContent>
<Button>
<a href="/Posts/Add">Add</a>
</Button>
</ExtraContent>
<ChildContent>
@foreach (Post post in Posts)
{
<Card Title="@post.Title">
<Extra>
<a href="/Posts/@post.Id/Edit">
<Button>Edit</Button>
</a>
</Extra>
<ChildContent>
<AntBlocksList TEntity="Post" Entity="post" EntityBlocks="post.Blocks" Options="@(new AntDesignBlocklyListOptions {Storage = GetService<IStorage<BlocklyStorageOptions>>(), Mode = BlocksListMode.Preview})" EntityUrl="@($"/Posts/{post.Id}")"></AntBlocksList>
</ChildContent>
</Card>
}
</Breadcrumb>
<Content>
</Content>
<ExtraContent>
<Button>
<a href="/Posts/Add">Add</a>
</Button>
</ExtraContent>
<ChildContent>
@foreach (Post post in Posts)
{
<Card Title="@post.Title">
<Extra>
<a href="/Posts/@post.Id/Edit">
<Button>Edit</Button>
</a>
</Extra>
<ChildContent>
<AntBlocksList
EntityBlocks="post.Blocks" Options="@(new AntDesignBlocklyListOptions(BlocksListMode.Preview, GetService<IStorage<BlocklyStorageOptions>>(), $"Posts/{post.Id}"))">
</AntBlocksList>
</ChildContent>
</Card>
}

</ChildContent>
</PageContainer>
</ChildContent>
</PageContainer>


@code{
Expand Down
4 changes: 2 additions & 2 deletions apps/Sitko.Blockly.Demo/Pages/Show.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/Posts/{PostId:guid}"
@using Sitko.Blockly.Demo.Data.Entities
@using Sitko.Core.Storage
@using Sitko.Blockly.Display
@inherits BaseComponent
@if (Post is not null)
{
Expand All @@ -20,7 +20,7 @@
<Content>
</Content>
<ChildContent>
<AntBlocksList TEntity="Post" Entity="Post" EntityBlocks="Post.Blocks" EntityUrl="@($"/Posts/{PostId}")" Options="@(new AntDesignBlocklyListOptions {Storage = GetService<IStorage<BlocklyStorageOptions>>()})"></AntBlocksList>
<AntBlocksList EntityBlocks="Post.Blocks" Options="@(new AntDesignBlocklyListOptions(BlocksListMode.Full, GetService<IStorage<BlocklyStorageOptions>>()))"></AntBlocksList>
</ChildContent>
</PageContainer>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

namespace Sitko.Blockly.AntDesignComponents.Display
{
using Core.Storage;
using Sitko.Blockly.Display;

public class AntDesignBlocklyListOptions : BlazorBlocklyListOptions
{
public AntDesignBlocklyListOptions(BlocksListMode mode = BlocksListMode.Full,
IStorage? storage = null, string? entityUrl = null) : base(mode, storage, entityUrl)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
@inherits CutBlockComponent<AntDesignBlocklyListOptions>
<a href="@Context.EntityUrl">
<Button>
@{
if (string.IsNullOrEmpty(Block.ButtonText))
{
<span>
@LocalizationProvider["Read more..."]
</span>
@if (Options.EntityUrl is not null)
{
<a href="@Options.EntityUrl">
<Button>
@{
if (string.IsNullOrEmpty(Block.ButtonText))
{
<span>
@LocalizationProvider["Read more..."]
</span>
}
else
{
<span>
@Block.ButtonText
</span>
}
}
else
{
<span>
@Block.ButtonText
</span>
}
}
</Button>
</a>
</Button>
</a>

}
else
{
<AntBlockErrorComponent Error="@LocalizationProvider["Not Entity url provided"]"></AntBlockErrorComponent>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@inherits FilesBlockComponent<AntDesignBlocklyListOptions>
@if (ListOptions.Storage is not null)
@if (Options.Storage is not null)
{
<ul>
@foreach (var file in Block.Files)
{
<li>
<AntDesign.Icon Type="paper-clip"/> <a target="_blank" rel="noopener noreferrer" title="@file.FileName" href="@ListOptions.Storage.PublicUri(file)">@file.FileName</a><span class="filesize">&nbsp;(@file.HumanSize)</span>
<AntDesign.Icon Type="paper-clip"/> <a target="_blank" rel="noopener noreferrer" title="@file.FileName" href="@Options.Storage.PublicUri(file)">@file.FileName</a><span class="filesize">&nbsp;(@file.HumanSize)</span>
</li>
}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@inherits GalleryBlockComponent<AntDesignBlocklyListOptions>
@if (ListOptions.Storage is not null)
@if (Options.Storage is not null)
{
if (Block.Pictures.Any())
{
Expand All @@ -10,7 +10,7 @@
@foreach (var image in Block.Pictures)
{
<CarouselSlick>
<img src="@ListOptions.Storage.PublicUri(image).ToString()" alt="Image: @image.FileName"/>
<img src="@Options.Storage.PublicUri(image).ToString()" alt="Image: @image.FileName"/>
</CarouselSlick>
}
</Carousel>
Expand All @@ -20,7 +20,7 @@
{
var image = Block.Pictures.First();
<div class="single-image">
<img src="@ListOptions.Storage.PublicUri(image).ToString()" alt="Image: @image.FileName"/>
<img src="@Options.Storage.PublicUri(image).ToString()" alt="Image: @image.FileName"/>
</div>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
@((MarkupString) Block.Text)
</div>
<footer class="author">
@if (ListOptions.Storage is not null && Block.Picture != null)
@if (Options.Storage is not null && Block.Picture != null)
{
<div class="picture" style="background-image: url(@ListOptions.Storage.PublicUri(Block.Picture))">
<div class="picture" style="background-image: url(@Options.Storage.PublicUri(Block.Picture))">
</div>
}
<cite>
@{
var authorText = Block.Author;
@if (ListOptions.Storage is null || Block.Picture is null)
@if (Options.Storage is null || Block.Picture is null)
{
authorText = $"— {authorText}";
}
Expand Down
6 changes: 6 additions & 0 deletions src/Sitko.Blockly.Blazor/Display/BlazorBlocklyListOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace Sitko.Blockly.Blazor.Display
{
using Core.Storage;

public class BlazorBlocklyListOptions : BlocklyListOptions
{
public BlazorBlocklyListOptions(BlocksListMode mode = BlocksListMode.Full,
IStorage? storage = null, string? entityUrl = null) : base(mode, storage, entityUrl)
{
}
}
}
24 changes: 3 additions & 21 deletions src/Sitko.Blockly.Blazor/Display/BlockComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Sitko.Blockly.Display;
using Sitko.Core.App.Blazor.Components;

namespace Sitko.Blockly.Blazor.Display
Expand All @@ -10,33 +9,16 @@ public abstract class BlockComponent<TBlock> : BaseComponent
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public TBlock Block { get; set; } = null!;
[Parameter] public TBlock Block { get; set; } = null!;
}

public abstract class BlockComponent<TBlock, TListOptions> : BlockComponent<TBlock>
where TListOptions : BlazorBlocklyListOptions, new()
where TListOptions : BlazorBlocklyListOptions
where TBlock : ContentBlock
{
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public BlockListContext Context { get; set; } = null!;

protected TListOptions ListOptions { get; set; } = new();

[Parameter]
public TListOptions? Options
{
get => ListOptions;
set
{
if (value is not null)
{
ListOptions = value;
}
}
}
[Parameter] public TListOptions Options { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
CutBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.CutBlock, TListOptions>
where TListOptions : BlazorBlocklyListOptions, new()
where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
FilesBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.FilesBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
GalleryBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.GalleryBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
IframeBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.IframeBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class QuoteBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.QuoteBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
TextBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TextBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks

public abstract class
TwitchBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TwitchBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
protected ElementReference ContainerRef { get; set; }
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks

public abstract class
TwitterBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TwitterBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
protected ElementReference ContainerRef { get; set; }
[Inject] protected IJSRuntime JsRuntime { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public abstract class
YoutubeBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.YoutubeBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
TListOptions> where TListOptions : BlazorBlocklyListOptions
{
}
}
Loading

0 comments on commit 619a399

Please sign in to comment.