Skip to content

Commit 4ec9150

Browse files
committed
Notifications updates
1 parent 9fb29cf commit 4ec9150

File tree

9 files changed

+236
-11
lines changed

9 files changed

+236
-11
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
@page
2+
@inject IViewLocalizer Localizer
3+
@{
4+
ViewData["Title"] = Localizer["contact"];
5+
}
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+
</style>
22+
<div class="bf-main">
23+
<partial name="~/Pages/Admin/Shared/_Notifybar.cshtml" />
24+
<div id="app" class="bf-body" style="display:none">
25+
<div class="bf-content">
26+
<label class="form-group-label">@Localizer["contact"]</label>
27+
28+
<div class="row">
29+
<div v-for="(item, index) in contacts" class="col-md-6 card-contact">
30+
<div class="card">
31+
<div class="card-body">
32+
<div class="form-group-label">
33+
{{getDate(item.dateNotified)}} / {{item.notifier.split("|")[0]}}
34+
<a href="#" v-on:click="remove(item.id)"><i class="fa fa-times"></i></a>
35+
</div>
36+
<div class="email">
37+
<a :href="'mailto:'+item.notifier.split('|')[1]+''">{{ item.notifier.split('|')[1] }}</a>
38+
</div>
39+
<hr />
40+
{{ item.content }}
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
46+
<div v-if="contacts && contacts.length == 0" class="bf-list-empty">
47+
@Localizer["not-found"]!
48+
</div>
49+
50+
<!-- Pagination -->
51+
<ul v-if="contacts && contacts.length > 0" class="bf-pagination d-flex">
52+
<li v-if="pager.showOlder" class="bf-pagination-item">
53+
<a class="bf-pagination-link" title="older" :href="pagelink('older')">
54+
<i class="bf-pagination-icon fa fa-chevron-left"></i>
55+
</a>
56+
</li>
57+
<li v-if="pager.showNewer" class="bf-pagination-item">
58+
<a class="bf-pagination-link" title="newer" :href="pagelink('newer')">
59+
<i class="bf-pagination-icon fa fa-chevron-right"></i>
60+
</a>
61+
</li>
62+
<li class="bf-pagination-item">
63+
<span class="bf-pagination-count">
64+
{{ cntFrom }}-{{ cntTo }} out of {{ pager.total }}
65+
</span>
66+
</li>
67+
</ul>
68+
<!--/Pagination -->
69+
</div>
70+
</div>
71+
</div>
72+
73+
@section Scripts{
74+
<script>
75+
new Vue({
76+
el: "#app",
77+
data: {
78+
contacts: [],
79+
pager: {},
80+
page: 1,
81+
cntFrom: 0,
82+
cntTo: 0
83+
},
84+
methods: {
85+
load: function (page) {
86+
axios.get(webRoot + 'api/notifications/contact?page=' + page)
87+
.then(response => {
88+
this.contacts = response.data.notifications;
89+
this.pager = response.data.pager;
90+
91+
this.cntFrom = this.pager.currentPage == 1 ? 1 : (this.pager.currentPage - 1) * this.pager.itemsPerPage + 1;
92+
this.cntTo = this.pager.currentPage * this.pager.itemsPerPage < this.pager.total ? this.pager.currentPage * this.pager.itemsPerPage : this.pager.total;
93+
$('#app').fadeIn();
94+
})
95+
.catch(function (error) { toastr.error(error); });
96+
},
97+
remove: function (id) {
98+
var result = confirm("Please confirm removing this message");
99+
if (result) {
100+
axios.delete(webRoot + 'api/notifications/remove/' + id)
101+
.then(response => {
102+
toastr.success('Removed');
103+
setTimeout(function () { location.reload(); }, 1000);
104+
})
105+
.catch(function (error) { toastr.error(error); });
106+
}
107+
return false;
108+
}
109+
},
110+
beforeMount() {
111+
this.load(1)
112+
}
113+
})
114+
</script>
115+
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
line-height: 2.5em;
99
border-bottom: 1px solid #efefef;
1010
}
11-
.post-grid-col {
12-
max-width: 200px !important
11+
.card {
12+
margin-bottom: 15px;
1313
}
1414
.card-email a {
1515
float: right;
16-
}
17-
.card-email {
18-
margin: 2px;
16+
color: red;
1917
}
2018
</style>
2119

2220
<div class="bf-main">
2321
<partial name="~/Pages/Admin/Shared/_Notifybar.cshtml" />
2422
<div id="app" class="bf-body">
25-
<div class="bf-content">
23+
<div class="bf-content" style="display:none">
2624

2725
<label class="form-group-label">@Localizer["newsletter-subscribers"]</label>
2826
<div id="importMsgs"></div>
2927
<div class="row">
30-
<div v-for="(item, index) in emails" class="col-4 card card-email">
31-
<div class="card-body">
32-
{{ item.email }} <a href="#" v-on:click="remove(item.email)"><i class="fa fa-times"></i></a>
28+
<div v-for="(item, index) in emails" class="col-md-4 card-email">
29+
<div class="card">
30+
<div class="card-body">
31+
{{ item.email }} <a href="#" v-on:click="remove(item.email)"><i class="fa fa-times"></i></a>
32+
</div>
3333
</div>
3434
</div>
3535
</div>
@@ -82,7 +82,7 @@
8282
8383
this.cntFrom = this.pager.currentPage == 1 ? 1 : (this.pager.currentPage - 1) * this.pager.itemsPerPage + 1;
8484
this.cntTo = this.pager.currentPage * this.pager.itemsPerPage < this.pager.total ? this.pager.currentPage * this.pager.itemsPerPage : this.pager.total;
85-
$('#app').fadeIn();
85+
$('.bf-content').fadeIn();
8686
})
8787
.catch(function (error) { toastr.error(error); });
8888
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<li is-active-route asp-controller="notifications" asp-action="newsletter">
2424
<a href="~/admin/notifications/newsletter">@Localizer["newsletter"]</a>
2525
</li>
26+
<li is-active-route asp-controller="notifications" asp-action="contact">
27+
<a href="~/admin/notifications/contact">@Localizer["contact"]</a>
28+
</li>
2629
}
2730
</ul>
2831
</div>

src/App/Resources/admin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,5 +585,11 @@
585585
"zh-tw": "電子郵件訂閱列表",
586586
"pt-BR": "Lista de assinantes de e-mail"
587587
}
588+
},
589+
"contact": {
590+
"Values": {
591+
"en-US": "Contact",
592+
"ru-RU": "Контакт"
593+
}
588594
}
589595
}

src/App/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void ConfigureServices(IServiceCollection services)
7777
{
7878
new CultureInfo("en-US"),
7979
new CultureInfo("es-ES"),
80+
new CultureInfo("pt-BR"),
8081
new CultureInfo("ru-RU"),
8182
new CultureInfo("zh-cn"),
8283
new CultureInfo("zh-tw")

src/Core/Api/NotificationsController.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using Core.Helpers;
44
using Core.Services;
55
using Microsoft.AspNetCore.Cors;
6+
using Microsoft.AspNetCore.Http;
67
using Microsoft.AspNetCore.Mvc;
8+
using System;
79
using System.Collections.Generic;
810
using System.Linq;
911
using System.Threading.Tasks;
@@ -113,5 +115,59 @@ await _notes.AddNotification(
113115
}
114116
return Ok();
115117
}
118+
119+
/// <summary>
120+
/// Get notifications by type (admins only)
121+
/// </summary>
122+
/// <param name="type">Notification type, like contact, newsletter etc</param>
123+
/// <param name="page">Page number</param>
124+
/// <returns>List of notifications</returns>
125+
[HttpGet("{type}")]
126+
[Administrator]
127+
public async Task<NotificationModel> GetNotifications(string type, int page = 1)
128+
{
129+
var pager = new Pager(page);
130+
IEnumerable<Notification> items;
131+
AlertType noteType = AlertType.Primary;
132+
133+
if (type.ToUpper() == "CONTACT")
134+
noteType = AlertType.Contact;
135+
136+
items = await _data.Notifications.GetList(n => n.AlertType == noteType, pager);
137+
138+
if (page < 1 || page > pager.LastPage)
139+
return null;
140+
141+
return new NotificationModel
142+
{
143+
Notifications = items,
144+
Pager = pager
145+
};
146+
}
147+
148+
/// <summary>
149+
/// Remove notification (admins only)
150+
/// </summary>
151+
/// <param name="id">Notification ID</param>
152+
/// <returns>Ok on success</returns>
153+
[Administrator]
154+
[HttpDelete("remove/{id}")]
155+
public IActionResult Delete(int id)
156+
{
157+
try
158+
{
159+
var notification = _data.Notifications.Single(n => n.Id == id);
160+
if (notification != null)
161+
{
162+
_data.Notifications.Remove(notification);
163+
_data.Complete();
164+
}
165+
return Ok(Resources.Removed);
166+
}
167+
catch (Exception ex)
168+
{
169+
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
170+
}
171+
}
116172
}
117173
}

src/Core/CoreAPI.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Core/Data/Models/NotificationModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class NewsletterModel
1010
public Pager Pager { get; set; }
1111
}
1212

13+
public class NotificationModel
14+
{
15+
public IEnumerable<Notification> Notifications { get; set; }
16+
public Pager Pager { get; set; }
17+
}
18+
1319
public class ContactModel
1420
{
1521
[Required]

src/Core/Data/Repositories/NotificationRepository.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
namespace Core.Data
1+
using Core.Helpers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Linq.Expressions;
6+
using System.Threading.Tasks;
7+
8+
namespace Core.Data
29
{
310
public interface INotificationRepository : IRepository<Notification>
411
{
12+
Task<IEnumerable<Notification>> GetList(Expression<Func<Notification, bool>> predicate, Pager pager);
513
}
614

715
public class NotificationRepository : Repository<Notification>, INotificationRepository
@@ -12,5 +20,20 @@ public NotificationRepository(AppDbContext db) : base(db)
1220
{
1321
_db = db;
1422
}
23+
24+
public async Task<IEnumerable<Notification>> GetList(Expression<Func<Notification, bool>> predicate, Pager pager)
25+
{
26+
var take = pager.ItemsPerPage == 0 ? 10 : pager.ItemsPerPage;
27+
var skip = pager.CurrentPage * take - take;
28+
29+
var messages = _db.Notifications.Where(predicate)
30+
.OrderByDescending(e => e.Id).ToList();
31+
32+
pager.Configure(messages.Count);
33+
34+
var list = messages.Skip(skip).Take(take).ToList();
35+
36+
return await Task.FromResult(list);
37+
}
1538
}
1639
}

0 commit comments

Comments
 (0)