Browse Source

Refresh attendees area on user registration.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
be89cdcc2e
  1. 41
      eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs
  2. 35
      eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/Default.cshtml
  3. 18
      eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/attendees-area.js
  4. 2
      eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js

41
eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventHub.Events.Registrations; using EventHub.Events.Registrations;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -10,6 +12,7 @@ namespace EventHub.Web.Pages.Events.Components.AttendeesArea
[Widget( [Widget(
AutoInitialize = true, AutoInitialize = true,
RefreshUrl = "/Widgets/EventAttendeesArea", RefreshUrl = "/Widgets/EventAttendeesArea",
ScriptFiles = new[] {"/Pages/Events/Components/AttendeesArea/attendees-area.js"},
StyleFiles = new[] {"/Pages/Events/Components/AttendeesArea/attendees-area.css"} StyleFiles = new[] {"/Pages/Events/Components/AttendeesArea/attendees-area.css"}
)] )]
public class AttendeesAreaViewComponent : AbpViewComponent public class AttendeesAreaViewComponent : AbpViewComponent
@ -27,8 +30,44 @@ namespace EventHub.Web.Pages.Events.Components.AttendeesArea
return View( return View(
"~/Pages/Events/Components/AttendeesArea/Default.cshtml", "~/Pages/Events/Components/AttendeesArea/Default.cshtml",
result new AttendeesAreaViewComponentModel
{
EventId = eventId,
Attendees = result.Items,
TotalCount = result.TotalCount
}
); );
} }
public class AttendeesAreaViewComponentModel
{
public IReadOnlyList<EventAttendeeDto> Attendees { get; set; }
public long TotalCount { get; set; }
public Guid EventId { get; set; }
public string GetAttendeeName(EventAttendeeDto attendee)
{
var nameBuilder = new StringBuilder();
if (!attendee.Name.IsNullOrEmpty())
{
nameBuilder.Append(attendee.Name);
}
if (!attendee.Surname.IsNullOrEmpty())
{
nameBuilder.Append(attendee.Surname);
}
if (nameBuilder.Length == 0)
{
nameBuilder.Append(attendee.UserName);
}
return nameBuilder.ToString();
}
}
} }
} }

35
eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/Default.cshtml

@ -1,41 +1,14 @@
@using System.Text @model EventHub.Web.Pages.Events.Components.AttendeesArea.AttendeesAreaViewComponent.AttendeesAreaViewComponentModel
@using System.Threading.Channels <abp-card class="mb-3" data-event-id="@Model.EventId">
@using EventHub.Events.Registrations
@model Volo.Abp.Application.Dtos.PagedResultDto<EventHub.Events.Registrations.EventAttendeeDto>
<abp-card class="mb-3">
<abp-card-body> <abp-card-body>
<abp-card-title>Attendees (@Model.TotalCount)</abp-card-title> <abp-card-title>Attendees (@Model.TotalCount)</abp-card-title>
<abp-card-text> <abp-card-text>
<ul id="EventAttendeeList"> <ul id="EventAttendeeList">
@foreach (var attendee in Model.Items) @foreach (var attendee in Model.Attendees)
{ {
<li class="border p-2 mb-2"><i class="fas fa-user"></i> @GetAttendeeName(attendee)</li> <li class="border p-2 mb-2"><i class="fas fa-user"></i> @Model.GetAttendeeName(attendee)</li>
} }
</ul> </ul>
</abp-card-text> </abp-card-text>
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>
@functions
{
private static string GetAttendeeName(EventAttendeeDto attendee)
{
var nameBuilder = new StringBuilder();
if (!attendee.Name.IsNullOrEmpty())
{
nameBuilder.Append(attendee.Name);
}
if (!attendee.Surname.IsNullOrEmpty())
{
nameBuilder.Append(attendee.Surname);
}
if (nameBuilder.Length == 0)
{
nameBuilder.Append(attendee.UserName);
}
return nameBuilder.ToString();
}
}

18
eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/attendees-area.js

@ -0,0 +1,18 @@
(function () {
abp.widgets.AttendeesArea = function ($wrapper) {
var eventId = $wrapper.find('[data-event-id]').attr('data-event-id');
return {
getFilters: function () {
return {
eventId: eventId
};
}
};
};
abp.event.on("EventHub.Event.RegistrationStatusChanged", function(){
$('[data-widget-name="AttendeesArea"]')
.data('abp-widget-manager')
.refresh();
});
})();

2
eventhub/src/EventHub.Web/Pages/Events/Components/RegistrationArea/registration-area.js

@ -20,6 +20,7 @@
url: $registerButton.attr('data-url') url: $registerButton.attr('data-url')
}).then(function (){ }).then(function (){
widgetManager.refresh(); widgetManager.refresh();
abp.event.trigger('EventHub.Event.RegistrationStatusChanged');
abp.message.success(l('EventRegisterSuccessMessage'), l('EventRegisterSuccessMessageTitle')); abp.message.success(l('EventRegisterSuccessMessage'), l('EventRegisterSuccessMessageTitle'));
}).always(function (){ }).always(function (){
$registerButton.buttonBusy(false); $registerButton.buttonBusy(false);
@ -34,6 +35,7 @@
url: $cancelRegistrationButton.attr('data-url') url: $cancelRegistrationButton.attr('data-url')
}).then(function (){ }).then(function (){
widgetManager.refresh(); widgetManager.refresh();
abp.event.trigger('EventHub.Event.RegistrationStatusChanged');
abp.notify.info(l('EventRegistrationCancelledMessage')); abp.notify.info(l('EventRegistrationCancelledMessage'));
}).always(function (){ }).always(function (){
$cancelRegistrationButton.buttonBusy(false); $cancelRegistrationButton.buttonBusy(false);

Loading…
Cancel
Save