Skip to content

Commit 89d8e43

Browse files
committed
Settings themes page, in progress
1 parent eb541b4 commit 89d8e43

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@page
2+
@model App.Pages.Admin.Settings.ThemesModel
3+
@{
4+
ViewData["Title"] = "Themes";
5+
}
6+
<div class="bf-main">
7+
<partial name="~/Pages/Admin/Settings/_Taskbar.cshtml" />
8+
<div class="bf-body">
9+
<!-- Grid -->
10+
<div class="bf-posts-grid d-flex" aria-label="posts">
11+
@foreach (var theme in Model.Themes)
12+
{
13+
<div class="post-grid-col">
14+
<div class="post-grid-item">
15+
<a class="item-link" style="background-image:url(https://placehold.it/180x100);"><div class="item-title mt-auto">@theme.Value</div></a>
16+
<div class="item-info d-flex align-items-center">
17+
<span class="item-date mr-auto">@theme.Value</span>
18+
@if (theme.Value == Model.BlogItem.Theme)
19+
{
20+
<button class="btn-unstyled item-favorite ml-3" data-tooltip="" title="" data-original-title="default">
21+
<i class="fas fa-star"></i>
22+
</button>
23+
<a class="item-show ml-3" href="#" target="_blank" data-tooltip="" title="" data-original-title="settings">
24+
<i class="fas fa-sliders-h"></i>
25+
</a>
26+
}
27+
else
28+
{
29+
<button class="btn-unstyled item-favorite ml-3" data-tooltip="" title="" data-original-title="set as default">
30+
<i class="far fa-star"></i>
31+
</button>
32+
<a class="item-show ml-4" href="#" data-tooltip="" title="" data-original-title="Delete">
33+
<i class="fas fa-trash" style="color: #ff6666"></i>
34+
</a>
35+
}
36+
</div>
37+
</div>
38+
</div>
39+
}
40+
</div>
41+
<!--/Grid -->
42+
</div>
43+
</div>
44+
@section Scripts{
45+
@if (Model.ShowMessage)
46+
{
47+
<script>toastr.success('@Model.Message')</script>
48+
}
49+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using Core;
2+
using Core.Data;
3+
using Core.Services;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.AspNetCore.Mvc.Rendering;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace App.Pages.Admin.Settings
11+
{
12+
public class ThemesModel : AdminPageModel
13+
{
14+
IDataService _db;
15+
IStorageService _storage;
16+
INotificationService _ns;
17+
18+
[BindProperty]
19+
public IEnumerable<SelectListItem> Themes { get; set; }
20+
public BlogItem BlogItem { get; set; }
21+
22+
public ThemesModel(IDataService db, IStorageService storage, INotificationService ns)
23+
{
24+
_db = db;
25+
_storage = storage;
26+
_ns = ns;
27+
}
28+
29+
public async Task<IActionResult> OnGetAsync()
30+
{
31+
var author = await _db.Authors.GetItem(a => a.AppUserName == User.Identity.Name);
32+
IsAdmin = author.IsAdmin;
33+
34+
Notifications = await _ns.GetNotifications(author.Id);
35+
36+
if (!IsAdmin)
37+
return RedirectToPage("../Shared/_Error", new { code = 403 });
38+
39+
BlogItem = await _db.CustomFields.GetBlogSettings();
40+
Themes = GetThemes();
41+
42+
return Page();
43+
}
44+
45+
List<SelectListItem> GetThemes()
46+
{
47+
var themes = new List<SelectListItem>();
48+
var combined = new List<string>();
49+
50+
var storageThemes = _storage.GetThemes();
51+
52+
if (storageThemes != null)
53+
combined.AddRange(storageThemes);
54+
55+
if (AppConfig.EmbeddedThemes != null)
56+
combined.AddRange(AppConfig.EmbeddedThemes);
57+
58+
combined = combined.Distinct().ToList();
59+
combined.Sort();
60+
61+
if (combined != null && combined.Count > 0)
62+
{
63+
var current = new SelectListItem();
64+
foreach (var theme in combined)
65+
{
66+
var item = new SelectListItem { Text = theme, Value = theme };
67+
if (theme == BlogItem.Theme)
68+
current = item;
69+
else
70+
themes.Add(item);
71+
}
72+
themes.Insert(0, current);
73+
}
74+
75+
return themes;
76+
}
77+
}
78+
}

src/App/Pages/Admin/Settings/_Taskbar.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
</li>
1717
@if (Model.IsAdmin)
1818
{
19+
<li is-active-route asp-controller="settings" asp-action="themes">
20+
<a href="~/admin/settings/themes">Themes</a>
21+
</li>
1922
<li is-active-route asp-controller="settings" asp-action="users">
2023
<a href="~/admin/settings/users">Users</a>
2124
</li>

src/App/app.db

0 Bytes
Binary file not shown.

src/Core/Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
<Version>2.1.0.1</Version>
5+
<Version>2.1.0.2</Version>
66
</PropertyGroup>
77

88
<ItemGroup>

0 commit comments

Comments
 (0)