Skip to content

Commit

Permalink
Added AlertBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Nov 1, 2022
1 parent 5757278 commit f9fe57e
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/DragonFly.API.Client/ClientContentService.ContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public async Task UpdateAsync(ContentItem entity)
await Client.PutAsJsonAsync($"api/content", entity.ToRest());
}

public async Task DeleteAsync(ContentItem entity)
{
await Client.DeleteAsync($"api/content/{entity.Schema.Name}/{entity.Id}");
}

public async Task PublishAsync(string schema, Guid id)
{
var response = await Client.PostAsync($"api/content/{schema}/{id}/publish", new StringContent(string.Empty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static IDragonFlyBuilder AddBlockField(this IDragonFlyBuilder builder)
api.RegisterBlock<QuoteBlock, QuoteBlockView>();
api.RegisterBlock<ReferenceBlock, ReferenceBlockView>();
api.RegisterBlock<ContainerBlock, ContainerBlockView>();
api.RegisterBlock<AlertBlock, AlertBlockView>();
api.RegisterBlock<UnknownBlock, UnknownBlockView>();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@inherits BlockComponent<AlertBlock>

<div class="alert-block">
<div class="mb-1">
<EnumView TEnum="AlertType" @bind-EnumValue="@Block.AlertType" />
</div>
<BlocksView Blocks="Block.Blocks" />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="mb-1">
<EnumView TEnum="CodeType" @bind-EnumValue="@Block.CodeType" />
</div>
<textarea class="form-control" @bind="@Block.Content" spellcheck="false" style="width:100%; height:40rem" />
<textarea class="form-control" @bind="@Block.Content" spellcheck="false" style="height:40rem" />
</div>

@code {
Expand Down
1 change: 1 addition & 0 deletions src/DragonFly.BlockField/BlockFieldManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void AddDefaults(this BlockFieldManager manager)
manager.Add<QuoteBlock>();
manager.Add<ReferenceBlock>();
manager.Add<ContainerBlock>();
manager.Add<AlertBlock>();

manager.Add<UnknownBlock>();
}
Expand Down
28 changes: 28 additions & 0 deletions src/DragonFly.BlockField/Blocks/AlertBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

namespace DragonFly.BlockField;

/// <summary>
/// AlertBlock
/// </summary>
public class AlertBlock : Block, IChildBlocks
{
public AlertBlock()
{
AlertType = AlertType.Info;
Blocks = new List<Block>();
}

public override string CssIcon => "fa-solid fa-circle-info";

public IList<Block> Blocks { get; set; }

public AlertType AlertType { get; set; }

public IEnumerable<Block> GetBlocks()
{
return Blocks;
}
}
23 changes: 23 additions & 0 deletions src/DragonFly.BlockField/Blocks/AlertType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DragonFly.BlockField;

public enum AlertType
{
Primary,
Secondary,
Success,
Info,
Warning,
Danger,
Light,
Dark
}
10 changes: 5 additions & 5 deletions src/DragonFly.ImageWizard/DragonFly.ImageWizard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ImageWizard.Core" Version="3.7.1" />
<PackageReference Include="ImageWizard.DocNET" Version="3.7.1" />
<PackageReference Include="ImageWizard.ImageSharp" Version="3.7.1" />
<PackageReference Include="ImageWizard.SvgNet" Version="3.7.1" />
<PackageReference Include="ImageWizard.Client" Version="3.7.1" />
<PackageReference Include="ImageWizard.Core" Version="3.7.3" />
<PackageReference Include="ImageWizard.DocNET" Version="3.7.3" />
<PackageReference Include="ImageWizard.ImageSharp" Version="3.7.3" />
<PackageReference Include="ImageWizard.SvgNet" Version="3.7.3" />
<PackageReference Include="ImageWizard.Client" Version="3.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 11 additions & 4 deletions src/DragonFly.Razor/Pages/ContentItems/ContentItemDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ protected override void BuildToolbarItems(IList<ToolbarItem> toolbarItems)
{
base.BuildToolbarItems(toolbarItems);

if(IsNewEntity)
if (IsNewEntity)
{
toolbarItems.AddCreateButton(this);
}
else
{
toolbarItems.Add(new ToolbarItem("Publish", BSColor.Success, () => PublishAsync()));
toolbarItems.Add(new ToolbarItem("Unpublish", BSColor.Dark, () => UnpublishAsync()));
toolbarItems.Add(new ToolbarItem("Clone", BSColor.Light, ()=> CloneAsync()));
toolbarItems.Add(new ToolbarItem("Clone", BSColor.Light, () => CloneAsync()));
toolbarItems.AddRefreshButton(this);
toolbarItems.AddSaveButton(this);
toolbarItems.AddDeleteButton(this);
Expand All @@ -73,7 +73,7 @@ protected override async Task RefreshActionAsync()

Entity = Schema.CreateContent();

if(CloneFromEntityId != null)
if (CloneFromEntityId != null)
{
ContentItem original = await ContentService.GetContentAsync(EntityType, CloneFromEntityId.Value);

Expand Down Expand Up @@ -105,6 +105,13 @@ protected override async Task UpdateActionAsync()
await ContentService.UpdateAsync(Entity);
}

protected override async Task DeleteActionAsync()
{
await ContentService.DeleteAsync(Entity);

NavigationManager.NavigateTo($"content/{EntityType}");
}

protected override void OnSaving(SavingEventArgs args)
{
ValidationContext = Entity.Validate();
Expand All @@ -127,5 +134,5 @@ public async Task PublishAsync()
public async Task UnpublishAsync()
{
await ContentService.UnpublishAsync(Entity.Schema.Name, Entity.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
<BSListGroup>

@foreach (var contentItem in SearchResult.Items)
@foreach (ContentItem contentItem in SearchResult.Items)
{
<button class="list-group-item list-group-item-action" @onclick="x => OpenItem(contentItem)">
<BSRow>
Expand Down
10 changes: 5 additions & 5 deletions src/DragonFlyTemplate/DragonFlyTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ImageWizard.Client" Version="3.7.1" />
<PackageReference Include="ImageWizard.Core" Version="3.7.1" />
<PackageReference Include="ImageWizard.ImageSharp" Version="3.7.1" />
<PackageReference Include="ImageWizard.OpenGraph" Version="3.7.1" />
<PackageReference Include="ImageWizard.SvgNet" Version="3.7.1" />
<PackageReference Include="ImageWizard.Client" Version="3.7.3" />
<PackageReference Include="ImageWizard.Core" Version="3.7.3" />
<PackageReference Include="ImageWizard.ImageSharp" Version="3.7.3" />
<PackageReference Include="ImageWizard.OpenGraph" Version="3.7.3" />
<PackageReference Include="ImageWizard.SvgNet" Version="3.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions src/DragonFlyTemplate/Extensions/AlertTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

using DragonFly.BlockField;

namespace DragonFly.AspNetCore;

public static class AlertTypeExtensions
{
public static string ToBootstrapCssClass(this AlertType alertType)
{
return alertType switch
{
AlertType.Primary => "alert-primary",
AlertType.Secondary => "alert alert-secondary",
AlertType.Success => "alert-success",
AlertType.Danger => "alert-danger",
AlertType.Warning => "alert-warning",
AlertType.Info => "alert-info",
AlertType.Light => "alert-light",
AlertType.Dark => "alert-dark",
_ => string.Empty
};
}
}
10 changes: 10 additions & 0 deletions src/DragonFlyTemplate/Pages/DisplayTemplates/AlertBlock.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@model AlertBlock

@if (Model.Blocks.Any())
{
<div class="block alert-block">
<div class="alert @Model.AlertType.ToBootstrapCssClass()">
@Html.DisplayFor(m => Model.Blocks)
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model CodeBlock

@if(Model.Content != null)
@if (Model.Content != null)
{
@*Stream resource = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DragonFlyTemplate.assets.prism.es5.min.js");
StreamReader reader = new StreamReader(resource, System.Text.Encoding.UTF8);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@model ContainerBlock

@if(Model.Blocks.Any())
@if (Model.Blocks.Any())
{
<div class="block container-block">
@Html.DisplayFor(m => Model.Blocks)
@Html.DisplayFor(m => Model.Blocks)
</div>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model HtmlBlock

@if(Model.HtmlText != null)
@if (Model.HtmlText != null)
{
<div class="block html-block">
@Html.Raw(Model.HtmlText)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@model QuoteBlock

@if(Model.Text != null)
@if (Model.Text != null)
{
<div class="block quote-block">
<figure class="text-center">
<figure class="text-center">
<blockquote class="blockquote" cite="@Model.Url">
<p>@Model.Text</p>
</blockquote>
Expand Down
26 changes: 26 additions & 0 deletions src/DragonFlyTemplate/Pages/DisplayTemplates/SlideshowBlock.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@model SlideshowBlock

@if (Model.Blocks.Any())
{
<div class="block slideshow-block">
<div class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
@for (int i = 0; i < Model.Blocks.Count; i++)
{
<div class="carousel-item @(i == 0 ? "active" : "")" data-bs-interval="1000000">
@Html.DisplayFor(m => Model.Blocks[i], Model.Blocks[i].Type)
</div>
}
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>

</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model TextBlock

@if(Model.Text != null)
@if (Model.Text != null)
{
<div class="block text-block">
<p>@Model.Text</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model UnknownBlock

@if(Model.Content != null)
@if (Model.Content != null)
{
<div class="block unknown-block">
<code>@Model.Content</code>
Expand Down
3 changes: 3 additions & 0 deletions src/DragonFlyTemplate/assets/scss/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,6 @@ body > header {
font-size: 1.25rem;
}

.carousel-item {
height: 200px;
}
6 changes: 5 additions & 1 deletion src/DragonFlyTemplate/assets/scss/blocks.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.block {
margin-bottom: 1rem;
margin-bottom: 2rem;

&:last-child {
margin-bottom: 0px;
}
}
9 changes: 8 additions & 1 deletion src/DragonFlyTemplate/wwwroot/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ body > header .title img {
font-size: 1.25rem;
}

.carousel-item {
height: 200px;
}

.project-item {
margin: 25px 0px;
padding: 25px 0px;
Expand Down Expand Up @@ -271,5 +275,8 @@ body > header .title img {
}

.block {
margin-bottom: 1rem;
margin-bottom: 2rem;
}
.block:last-child {
margin-bottom: 0px;
}
2 changes: 1 addition & 1 deletion src/DragonFlyTemplate/wwwroot/assets/css/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9fe57e

Please sign in to comment.