Skip to content

Commit

Permalink
Added HtmlWidgets component
Browse files Browse the repository at this point in the history
  • Loading branch information
rxtur committed Sep 17, 2018
1 parent 728caed commit 5377b95
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 7 deletions.
4 changes: 4 additions & 0 deletions plugins/Common/Common.csproj
Expand Up @@ -13,6 +13,10 @@
<EmbeddedResource Include="Views\**\*" />
</ItemGroup>

<ItemGroup>
<None Remove="Views\Widgets\HtmlBlock\Index.cshtml" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Core\Core.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions plugins/Common/Views/Widgets/HtmlBlock/Index.cshtml
@@ -0,0 +1 @@
@Html.Raw(Model)
44 changes: 44 additions & 0 deletions plugins/Common/Widgets/HtmlBlock.cs
@@ -0,0 +1,44 @@
using Core.Services;
using Microsoft.AspNetCore.Mvc;

namespace Common.Widgets
{
[ViewComponent(Name = "HtmlBlock")]
public class HtmlBlock : ViewComponent
{
IDataService _db;

public HtmlBlock(IDataService db)
{
_db = db;
}

public IViewComponentResult Invoke(string id, string theme, string author)
{
string model = @"<ul class=""blog-social nav ml-auto my-auto"">
<li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-twitter""></i></a></li>
<li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-google-plus""></i></a></li>
<li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-facebook-official""></i></a></li>
</ul>";

var existing = _db.HtmlWidgets.Single(w => w.Name == id && w.Theme == theme && w.Author == author);

if (existing == null)
{
_db.HtmlWidgets.Add(new Core.Data.HtmlWidget {
Name = id,
Theme = theme,
Author = author,
Content = model
});
_db.Complete();
}
else
{
model = existing.Content;
}

return View("~/Views/Widgets/HtmlBlock/Index.cshtml", model);
}
}
}
12 changes: 5 additions & 7 deletions src/App/Views/Themes/Standard/_Shared/_Header.cshtml
@@ -1,16 +1,14 @@
<header class="blog-header d-flex flex-column">
<div class="container d-flex">
<a href="~/" class="blog-logo my-auto d-flex">
<img src="~/@AppSettings.Logo" alt="@AppSettings.Title" class="my-auto" />
@if(ViewData["bodyClass"] != null && ViewData["bodyClass"].ToString() != "home") {
<img src="~/@AppSettings.Logo" alt="@AppSettings.Title" class="my-auto" />
@if (ViewData["bodyClass"] != null && ViewData["bodyClass"].ToString() != "home")
{
<span class="my-auto">@AppSettings.Title</span>
}
</a>
<ul class="blog-social nav ml-auto my-auto">
<li class="blog-social-item"><a href="#" target="_blank" class="blog-social-link"><i class="blog-social-icon fa fa-twitter"></i></a></li>
<li class="blog-social-item"><a href="#" target="_blank" class="blog-social-link"><i class="blog-social-icon fa fa-google-plus"></i></a></li>
<li class="blog-social-item"><a href="#" target="_blank" class="blog-social-link"><i class="blog-social-icon fa fa-facebook-official"></i></a></li>
</ul>
@await Component.InvokeAsync("HtmlBlock", new { id = "social-btns", theme = "Standard", author = "" })

<button class="blog-search-toggle btn-unstyled" type="button" data-toggle="modal" data-target="#blog-search"><i class="fa fa-search"></i></button>
</div>
</header>
Binary file modified src/App/app.db
Binary file not shown.
1 change: 1 addition & 0 deletions src/Core/Data/AppDbContext.cs
Expand Up @@ -15,6 +15,7 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
public DbSet<BlogPost> BlogPosts { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Notification> Notifications { get; set; }
public DbSet<HtmlWidget> HtmlWidtes { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Data/Domain/HtmlWidget.cs
@@ -0,0 +1,11 @@
namespace Core.Data
{
public class HtmlWidget
{
public int Id { get; set; }
public string Name { get; set; }
public string Theme { get; set; }
public string Author { get; set; }
public string Content { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Core/Data/Repositories/HtmlWidgetRepository.cs
@@ -0,0 +1,16 @@
namespace Core.Data
{
public interface IHtmlWidgetRepository : IRepository<HtmlWidget>
{
}

public class HtmlWidgetRepository : Repository<HtmlWidget>, IHtmlWidgetRepository
{
AppDbContext _db;

public HtmlWidgetRepository(AppDbContext db) : base(db)
{
_db = db;
}
}
}

0 comments on commit 5377b95

Please sign in to comment.