Skip to content

Commit a16a459

Browse files
committed
Updates to notifications
1 parent 4ec9150 commit a16a459

File tree

13 files changed

+204
-110
lines changed

13 files changed

+204
-110
lines changed

docs/Notifications.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
Blogifier does not expose any endpoints to push notifications to the blog -
2-
it only pulls notifications from known sources. Notifications can be sent
3-
to individual user or to all application users.
1+
There are three types of notifications supported by Blogifier. They all listed and maintained
2+
in the admin under `admin/notifications`, along with newsletter subscriptions.
3+
All notifications require admin access.
44

5-
### Removing notificaton
6-
Every notification has an `active`
7-
flag and by closing specific notification in UI this flag is set to `false`
8-
and notification will no longer appear in the UI, but still exists on the back-end.
9-
There should be not too many notifications, mostly system generated. For now
10-
we just display 5 latest active notifications and do not clear old messages
11-
from database.
5+
### System notifications
6+
Notifications posted by the system, for example when new release is available. These are
7+
pull notifications, Blogifier calls external site (`github`) to check for system notifications.
128

13-
### Checking for Latest Release
14-
On admin page load, notification service calls Github API to check latest
15-
release available in Blogifier repository. This call is cached for 10
16-
minutes so it does not slow down admin site. If version in repository is newer,
17-
service will generate notification to all users providing link to download page.
18-
Eventually, this will be transformed into blog auto-update functionality with
19-
message sent only to admins and ability to upgrade blog from admin panel.
9+
### User notificatoins
10+
Right now mostly a placeholder. When implemented will allow blog users send messages to
11+
each other.
12+
13+
### Contact notificatoins
14+
Notifications submitted by "contact us" form, if theme supports this.

src/App/Pages/Admin/Notifications/Index.cshtml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,43 @@
33
@{
44
ViewData["Title"] = Localizer["notifications"];
55
}
6-
6+
<style>
7+
.modal-body .row {
8+
line-height: 2.5em;
9+
border-bottom: 1px solid #efefef;
10+
}
11+
.card-contact {
12+
margin-bottom: 10px;
13+
}
14+
.btn-group {
15+
margin-top: 15px;
16+
}
17+
.form-group-label a {
18+
float: right;
19+
color: red;
20+
}
21+
h1 {
22+
font-size: 1.2em;
23+
}
24+
</style>
725
<div class="bf-main">
826
<partial name="~/Pages/Admin/Shared/_Notifybar.cshtml" />
927
<div id="app" class="bf-body">
10-
<div class="bf-content">
11-
<label class="form-group-label">@Localizer["notifications"] placeholder</label>
12-
28+
<div class="bf-content" style="display:none">
29+
<div class="row">
30+
<div v-for="(item, index) in messages" class="col-md-6 card-contact">
31+
<div class="card">
32+
<div class="card-body">
33+
<div class="form-group-label">
34+
{{getDate(item.dateNotified)}} / {{item.notifier}}
35+
<a href="#" v-on:click="remove(item.id)"><i class="fa fa-times"></i></a>
36+
</div>
37+
<hr />
38+
<div v-html="item.content"> </div>
39+
</div>
40+
</div>
41+
</div>
42+
</div>
1343
</div>
1444
</div>
1545
</div>
@@ -19,10 +49,36 @@
1949
new Vue({
2050
el: "#app",
2151
data: {
52+
messages: [],
53+
pager: {},
54+
page: 1,
55+
cntFrom: 0,
56+
cntTo: 0
2257
},
2358
methods: {
2459
load: function (page) {
60+
axios.get(webRoot + 'api/notifications/system?page=' + page)
61+
.then(response => {
62+
this.messages = response.data.notifications;
63+
this.pager = response.data.pager;
2564
65+
this.cntFrom = this.pager.currentPage == 1 ? 1 : (this.pager.currentPage - 1) * this.pager.itemsPerPage + 1;
66+
this.cntTo = this.pager.currentPage * this.pager.itemsPerPage < this.pager.total ? this.pager.currentPage * this.pager.itemsPerPage : this.pager.total;
67+
$('.bf-content').fadeIn();
68+
})
69+
.catch(function (error) { toastr.error(error); });
70+
},
71+
remove: function (id) {
72+
var result = confirm("Please confirm removing this message");
73+
if (result) {
74+
axios.delete(webRoot + 'api/notifications/remove/' + id)
75+
.then(response => {
76+
toastr.success('Removed');
77+
setTimeout(function () { location.reload(); }, 1000);
78+
})
79+
.catch(function (error) { toastr.error(error); });
80+
}
81+
return false;
2682
}
2783
},
2884
beforeMount() {

src/App/Pages/Admin/Shared/_Layout.cshtml

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if(user != null)
1212
{
1313
_isAdmin = user.IsAdmin;
14-
_notifications = await _notes.GetNotifications(user.Id);
14+
//_notifications = await _notes.PullSystemNotifications(AlertType.System);
1515
}
1616
}
1717
catch { }
@@ -106,42 +106,6 @@
106106
<a class="taskbar-item-link" href="#" onclick="document.getElementById('frmOut').submit()" title="@Localizer["sign-out"]"><i class="taskbar-item-icon fas fa-sign-out-alt"></i></a>
107107
</li>
108108
</ul>
109-
110-
<!-- Modal Notifications -->
111-
<div class="modal fade" id="notifications" tabindex="-1" role="dialog" aria-labelledby="notificationsLabel" aria-hidden="true">
112-
<div class="modal-dialog" role="document">
113-
<div class="modal-content">
114-
<div class="modal-header">
115-
<h4 class="modal-title" id="settingsLabel">@Localizer["notifications"]</h4>
116-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
117-
</div>
118-
<div class="modal-body">
119-
@if (_notifications.Count() > 0)
120-
{
121-
foreach (var note in _notifications)
122-
{
123-
@if (note.AlertType == AlertType.Sticky)
124-
{
125-
<div class="alert alert-warning" role="alert">
126-
@Html.Raw(note.Content)
127-
</div>
128-
}
129-
else
130-
{
131-
<div class="alert alert-primary" role="alert">
132-
@Html.Raw(note.Content)
133-
<button type="button" class="close" onclick="notificationsController.remove('@note.Id')" data-dismiss="alert" aria-label="Close">
134-
<span aria-hidden="true">&times;</span>
135-
</button>
136-
</div>
137-
}
138-
}
139-
}
140-
</div>
141-
</div>
142-
</div>
143-
</div>
144-
145109
<form method="post" id="frmOut" name="frmOut" asp-controller="Account" asp-action="Logout"></form>
146110

147111
@RenderBody()

src/App/wwwroot/admin/js/app/notificationsController.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
var notificationsController = function (dataService) {
2-
function open() {
3-
$('#notifications').modal();
4-
return false;
5-
}
62
function remove(id) {
73
dataService.remove("api/settings/removenotification/" + id, removeCallback, fail);
84
}

src/Core/Api/NotificationsController.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Core.Data.Models;
33
using Core.Helpers;
44
using Core.Services;
5+
using Markdig;
56
using Microsoft.AspNetCore.Cors;
67
using Microsoft.AspNetCore.Http;
78
using Microsoft.AspNetCore.Mvc;
@@ -128,12 +129,22 @@ public async Task<NotificationModel> GetNotifications(string type, int page = 1)
128129
{
129130
var pager = new Pager(page);
130131
IEnumerable<Notification> items;
131-
AlertType noteType = AlertType.Primary;
132+
AlertType noteType = AlertType.System;
132133

133134
if (type.ToUpper() == "CONTACT")
135+
{
134136
noteType = AlertType.Contact;
135-
136-
items = await _data.Notifications.GetList(n => n.AlertType == noteType, pager);
137+
items = await _data.Notifications.GetList(n => n.AlertType == noteType, pager);
138+
}
139+
else
140+
{
141+
await _notes.PullSystemNotifications();
142+
items = await _data.Notifications.GetList(n => n.AlertType == noteType && n.Active == true, pager);
143+
foreach (var item in items)
144+
{
145+
item.Content = Markdown.ToHtml(item.Content);
146+
}
147+
}
137148

138149
if (page < 1 || page > pager.LastPage)
139150
return null;
@@ -159,7 +170,17 @@ public IActionResult Delete(int id)
159170
var notification = _data.Notifications.Single(n => n.Id == id);
160171
if (notification != null)
161172
{
162-
_data.Notifications.Remove(notification);
173+
if(notification.AlertType == AlertType.System)
174+
{
175+
// system notifications pulled from external sources
176+
// if just remove it, it will be pulled again
177+
// so just mark it as inactive instead
178+
notification.Active = false;
179+
}
180+
else
181+
{
182+
_data.Notifications.Remove(notification);
183+
}
163184
_data.Complete();
164185
}
165186
return Ok(Resources.Removed);

src/Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class Constants
44
{
55
public static string ConfigSectionKey = "Blogifier";
66
public static string ConfigRepoKey = "GithubRepoUrl";
7+
public static string ConfigNotificationsKey = "GithubNotificationsUrl";
78

89
public static string NewestVersion = "last-version";
910
public static string UpgradeDirectory = "_upgrade";

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.2</TargetFramework>
5-
<Version>2.4.1.0</Version>
5+
<Version>2.4.1.1</Version>
66
</PropertyGroup>
77

88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/Core/Data/AppData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static void Seed(AppDbContext context)
8181
context.Notifications.Add(new Notification
8282
{
8383
Notifier = "Blogifier",
84-
AlertType = AlertType.Primary,
84+
AlertType = AlertType.System,
8585
AuthorId = 0,
8686
Content = "Welcome to Blogifier!",
8787
Active = true,

src/Core/Data/Domain/Notification.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public class Newsletter
2121

2222
public enum AlertType
2323
{
24-
Primary, Sticky, Contact
24+
System, User, Contact
2525
}
2626
}

src/Core/Data/Models/GithubModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,17 @@ public class Repository
8585
public string zipball_url { get; set; }
8686
public string body { get; set; }
8787
}
88+
89+
public class GithubFile
90+
{
91+
public string name { get; set; }
92+
public string path { get; set; }
93+
public string sha { get; set; }
94+
public int size { get; set; }
95+
public string url { get; set; }
96+
public string html_url { get; set; }
97+
public string git_url { get; set; }
98+
public string download_url { get; set; }
99+
public string type { get; set; }
100+
}
88101
}

0 commit comments

Comments
 (0)