Skip to content

Commit eac9bfd

Browse files
committed
Widget settings updates
1 parent 07e6105 commit eac9bfd

File tree

9 files changed

+177
-71
lines changed

9 files changed

+177
-71
lines changed

Blogifier.Core/Configuration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Blogifier.Core.Services.Data;
88
using Blogifier.Core.Services.Email;
99
using Blogifier.Core.Services.FileSystem;
10+
using Blogifier.Core.Services.Packages;
1011
using Blogifier.Core.Services.Routing;
1112
using Blogifier.Core.Services.Search;
1213
using Blogifier.Core.Services.Syndication.Rss;
@@ -41,6 +42,7 @@ public static void InitServices(IServiceCollection services, Action<DbContextOpt
4142
services.AddTransient<IComponentHelper, ComponentHelper>();
4243
services.AddTransient<IEmailService, SendGridService>();
4344
services.AddTransient<IConfigService, ConfigService>();
45+
services.AddTransient<IPackageService, PackageService>();
4446

4547
// add blog route from ApplicationSettings
4648
services.Configure<Microsoft.AspNetCore.Mvc.MvcOptions>(opt =>

Blogifier.Core/Controllers/PackagesController.cs

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
using Blogifier.Core.Data.Interfaces;
44
using Blogifier.Core.Data.Models;
55
using Blogifier.Core.Middleware;
6+
using Blogifier.Core.Services.Packages;
67
using Microsoft.AspNetCore.Authorization;
78
using Microsoft.AspNetCore.Mvc;
8-
using Microsoft.AspNetCore.Mvc.ViewEngines;
9-
using Microsoft.Extensions.Logging;
10-
using System;
119
using System.Collections.Generic;
12-
using System.Linq;
10+
using System.Threading.Tasks;
1311

1412
namespace Blogifier.Core.Controllers
1513
{
@@ -18,63 +16,24 @@ namespace Blogifier.Core.Controllers
1816
public class PackagesController : Controller
1917
{
2018
private readonly string _theme;
21-
private readonly ILogger _logger;
22-
private readonly ICompositeViewEngine _engine;
2319
IUnitOfWork _db;
20+
IPackageService _pkgs;
2421

25-
public PackagesController(IUnitOfWork db, ILogger<AdminController> logger, ICompositeViewEngine engine)
22+
public PackagesController(IUnitOfWork db, IPackageService pkgs)
2623
{
2724
_db = db;
28-
_logger = logger;
29-
_engine = engine;
25+
_pkgs = pkgs;
3026
_theme = $"~/{ApplicationSettings.BlogAdminFolder}/";
3127
}
3228

3329
[VerifyProfile]
3430
[HttpGet("widgets")]
35-
public IActionResult Widgets()
31+
public async Task<IActionResult> Widgets()
3632
{
37-
var model = new AdminPackagesModel { Profile = GetProfile() };
38-
39-
model.Packages = new List<PackageListItem>();
40-
41-
foreach (var assembly in Configuration.GetAssemblies())
42-
{
43-
var name = assembly.GetName().Name;
44-
45-
if (name != "Blogifier.Core")
46-
{
47-
var path = $"~/Views/Shared/Components/{name}/Settings.cshtml";
48-
var view = _engine.GetView("", path, false);
49-
50-
var item = new PackageListItem
51-
{
52-
Title = name,
53-
Description = name,
54-
Version = assembly.GetName().Version.ToString()
55-
};
56-
57-
try
58-
{
59-
Type t = assembly.GetType("PackageInfo");
60-
if (t != null)
61-
{
62-
var info = (IPackageInfo)Activator.CreateInstance(t);
63-
item = info.GetAttributes();
64-
}
65-
}
66-
catch { }
67-
68-
var disabled = Disabled();
69-
var maxLen = 70;
70-
71-
item.Description = item.Description.Length > maxLen ? item.Description.Substring(0, maxLen) + "..." : item.Description;
72-
item.HasSettings = view.Success;
73-
item.Enabled = disabled == null || !disabled.Contains(name);
74-
model.Packages.Add(item);
75-
}
76-
}
77-
33+
var model = new AdminPackagesModel {
34+
Profile = GetProfile(),
35+
Packages = await _pkgs.Find(PackageType.Widgets)
36+
};
7837
return View($"{_theme}Packages/Widgets.cshtml", model);
7938
}
8039

@@ -92,11 +51,5 @@ private Profile GetProfile()
9251
{
9352
return _db.Profiles.Single(b => b.IdentityName == User.Identity.Name);
9453
}
95-
96-
List<string> Disabled()
97-
{
98-
var field = _db.CustomFields.GetValue(CustomType.Application, 0, Constants.DisabledPackages);
99-
return string.IsNullOrEmpty(field) ? null : field.Split(',').ToList();
100-
}
10154
}
10255
}

Blogifier.Core/Data/Models/PackageModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Blogifier.Core.Common;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel.DataAnnotations;
45

@@ -17,6 +18,7 @@ public class AdminPackagesModel : AdminBaseModel
1718

1819
public class AdminSettingsModel : AdminBaseModel
1920
{
21+
public PackageListItem PackageItem { get; set; }
2022
public dynamic Settings { get; set; }
2123
}
2224

@@ -27,6 +29,7 @@ public class PackageListItem
2729
public string Description { get; set; }
2830
public string Icon { get; set; }
2931
public string Cover { get; set; }
32+
public string Author { get; set; }
3033
public string ProjectUrl { get; set; }
3134
public string Tags { get; set; }
3235

@@ -35,6 +38,7 @@ public class PackageListItem
3538
public double Rating { get; set; }
3639

3740
public string Version { get; set; }
41+
public DateTime LastUpdated { get; set; }
3842
public bool HasSettings { get; set; }
3943
public bool Enabled { get; set; }
4044
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using Blogifier.Core.Common;
2+
using Blogifier.Core.Data.Domain;
3+
using Blogifier.Core.Data.Interfaces;
4+
using Blogifier.Core.Data.Models;
5+
using Microsoft.AspNetCore.Mvc.ViewEngines;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
11+
namespace Blogifier.Core.Services.Packages
12+
{
13+
public interface IPackageService
14+
{
15+
Task<List<PackageListItem>> Find(PackageType packageType);
16+
Task<PackageListItem> Single(string id);
17+
}
18+
19+
public class PackageService : IPackageService
20+
{
21+
private readonly ICompositeViewEngine _engine;
22+
private readonly IUnitOfWork _db;
23+
24+
public PackageService(IUnitOfWork db, ICompositeViewEngine engine)
25+
{
26+
_db = db;
27+
_engine = engine;
28+
}
29+
30+
public Task<List<PackageListItem>> Find(PackageType packageType)
31+
{
32+
if(packageType == PackageType.Widgets)
33+
{
34+
return Task.FromResult(Widgets());
35+
}
36+
else
37+
{
38+
return null;
39+
}
40+
}
41+
42+
public Task<PackageListItem> Single(string id)
43+
{
44+
var item = Widgets().Where(w => w.Title == id).FirstOrDefault();
45+
return Task.FromResult(item);
46+
}
47+
48+
List<PackageListItem> Widgets()
49+
{
50+
var widgets = new List<PackageListItem>();
51+
52+
foreach (var assembly in Configuration.GetAssemblies())
53+
{
54+
var name = assembly.GetName().Name;
55+
56+
if (name != "Blogifier.Core")
57+
{
58+
var path = $"~/Views/Shared/Components/{name}/Settings.cshtml";
59+
var view = _engine.GetView("", path, false);
60+
61+
var item = new PackageListItem
62+
{
63+
Title = name,
64+
Description = name,
65+
Version = assembly.GetName().Version.ToString(),
66+
LastUpdated = System.IO.File.GetLastWriteTime(assembly.Location)
67+
};
68+
69+
try
70+
{
71+
Type t = assembly.GetType("PackageInfo");
72+
if (t != null)
73+
{
74+
var info = (IPackageInfo)Activator.CreateInstance(t);
75+
var attributes = info.GetAttributes();
76+
if(attributes != null)
77+
{
78+
item.Author = attributes.Author;
79+
item.Cover = attributes.Cover;
80+
item.Description = attributes.Description;
81+
item.Icon = attributes.Icon;
82+
item.ProjectUrl = attributes.ProjectUrl;
83+
item.Tags = attributes.Tags;
84+
item.Title = attributes.Title;
85+
}
86+
}
87+
}
88+
catch { }
89+
90+
var disabled = Disabled();
91+
var maxLen = 70;
92+
93+
item.Description = item.Description.Length > maxLen ? item.Description.Substring(0, maxLen) + "..." : item.Description;
94+
item.HasSettings = view.Success;
95+
item.Enabled = disabled == null || !disabled.Contains(name);
96+
widgets.Add(item);
97+
}
98+
}
99+
return widgets;
100+
}
101+
102+
List<string> Disabled()
103+
{
104+
var field = _db.CustomFields.GetValue(CustomType.Application, 0, Constants.DisabledPackages);
105+
return string.IsNullOrEmpty(field) ? null : field.Split(',').ToList();
106+
}
107+
}
108+
109+
public enum PackageType
110+
{
111+
Widgets,
112+
Themes,
113+
Plugins
114+
}
115+
}

Blogifier.Web/Views/Blogifier/Admin/_Layout/_PackagesSettings.cshtml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@using Blogifier.Core.Common
2+
@using Blogifier.Core.Data.Models
23
@{
34
Layout = $"~/{ApplicationSettings.BlogAdminFolder}/_Layout/_Layout.cshtml";
5+
var info = (PackageListItem)Model.PackageItem;
46
}
57
<div class="bf-header d-flex d-lg-none">@ViewData["Title"] <i class="fa fa-chevron-down"></i></div>
68
<div class="bf-main">
@@ -18,27 +20,31 @@
1820
<div class="p-3 mt-auto">
1921
<div class="bf-package-info-header">
2022
<img class="bf-package-info-logo" src="/embedded/lib/img/cover.png" alt="Package Title" />
21-
<h4 class="bf-package-info-title">Package Title</h4>
23+
<h4 class="bf-package-info-title">@info.Title</h4>
2224
<div class="bf-package-info-rating"><i class="fa fa-star active"></i><i class="fa fa-star active"></i><i class="fa fa-star active"></i><i class="fa fa-star active"></i><i class="fa fa-star"></i></div>
2325
</div>
24-
<p class="small">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus deleniti voluptas, magni voluptatum aut reprehenderit fugiat cumque in, molestias laudantium inventore, saepe hic incidunt repellat eius. Quisquam, eum saepe deserunt.</p>
26+
<p class="small">@info.Description</p>
2527
<hr class="my-4" />
2628
<table class="table bf-package-info-table">
2729
<tr>
2830
<td>Version</td>
29-
<td>4.13.0</td>
31+
<td>@info.Version</td>
3032
</tr>
3133
<tr>
3234
<td>Updated</td>
33-
<td>November 20, 2017</td>
35+
<td>@info.LastUpdated.ToString("MMM dd, yyyy")</td>
3436
</tr>
35-
<tr>
37+
@*<tr>
3638
<td>Installs</td>
3739
<td>48894</td>
38-
</tr>
40+
</tr>*@
3941
<tr>
4042
<td>Developer</td>
41-
<td><a class="mr-3" href="#" target="_blank">Ruslan Tur</a></td>
43+
<td><a class="mr-3" href="@info.ProjectUrl" target="_blank">@info.Author</a></td>
44+
</tr>
45+
<tr>
46+
<td>Tags</td>
47+
<td>@info.Tags</td>
4248
</tr>
4349
</table>
4450
</div>

Blogifier.Web/appsettings.Development.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"Default": "Debug",
66
"System": "Information",
77
"Microsoft": "Information"
8+
},
9+
"Blogifier": {
10+
"BlogRoute": "",
11+
"InitializeDatabase": false,
12+
"BlogAdminFolder": "Views/Blogifier/Admin",
13+
"ProfileAvatar": "/admin/img/avatar.png",
14+
"BlogStorageFolder": "data"
815
}
916
}
1017
}

Packages/Widgets/Newsletter/NewsletterController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ public IActionResult Settings(string search = "")
5959
Emails = emails,
6060
Pager = new Pager(1)
6161
};
62-
63-
var model = new AdminSettingsModel { Profile = profile, Settings = settings };
62+
63+
var info = new PackageInfo();
64+
65+
var model = new AdminSettingsModel {
66+
Profile = profile,
67+
Settings = settings,
68+
PackageItem = info.GetAttributes()
69+
};
6470

6571
return View("~/Views/Shared/Components/Newsletter/Settings.cshtml", model);
6672
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Blogifier.Core.Data.Models;
2+
using System.Reflection;
23

34
public class PackageInfo : IPackageInfo
45
{
@@ -7,10 +8,13 @@ public PackageListItem GetAttributes()
78
return new PackageListItem
89
{
910
Title = "Newsletter",
10-
Description = "Newsletter email subscription widget",
11+
Version = "1.0.0",
12+
Description = "Newsletter widget for Blogifier allows visitors to subscribe to new publications by email.",
1113
Icon = "https://avatars0.githubusercontent.com/u/19671571?v=4&amp;s=180",
14+
Author = "Blogifier",
1215
ProjectUrl = "https://github.com/blogifierdotnet/Blogifier",
13-
Tags = "widget,newsletter,email"
16+
Tags = "widget,newsletter,email",
17+
LastUpdated = System.IO.File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location)
1418
};
1519
}
1620
}

Packages/Widgets/Newsletter/Views/Shared/Components/Newsletter/Settings.cshtml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
<!-- Toolbar -->
1010
<div class="bf-toolbar d-flex align-items-center">
11-
<label class="custom-control custom-checkbox custom-control-single mr-3"><input class="custom-control-input item-checkbox" type="checkbox" id="selectAll" name="selectAll"><span class="item-control custom-control-indicator"></span></label>
11+
<label class="custom-control custom-checkbox custom-control-single mr-3">
12+
<input class="custom-control-input item-checkbox" type="checkbox" id="selectAll" name="selectAll">
13+
<span class="item-control custom-control-indicator"></span>
14+
</label>
1215
<div id="postActionButtons" class="btn-group mr-3">
13-
<button type="button" class="btn btn-outline-secondary btn-icon btn-sm btn-rounded" disabled="disabled" data-tooltip onclick="return newsletter.remove()" title="Remove"><i class="fa fa-trash"></i></button>
16+
<button type="button" class="btn btn-outline-secondary btn-icon btn-sm btn-rounded" disabled="disabled" data-tooltip onclick="return newsletter.remove()" title="Remove">
17+
<i class="fa fa-trash"></i>
18+
</button>
19+
</div>
20+
<div class="loading loading-sm mr-3">
21+
<div class="loading-dot-1"></div>
22+
<div class="loading-dot-2"></div>
23+
<div class="loading-dot-3"></div>
1424
</div>
15-
<div class="loading loading-sm mr-3"><div class="loading-dot-1"></div><div class="loading-dot-2"></div><div class="loading-dot-3"></div></div>
1625
</div>
1726
<!--/Toolbar -->
1827

0 commit comments

Comments
 (0)