Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Web Preview #18

Merged
merged 32 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2e95cc0
Added settings for app ids on Google Play and Apple iTunes
Fenrikur Jun 16, 2019
8a26189
Push app IDs into view
Fenrikur Jun 16, 2019
d0a1d75
Minor formatting in Razor view template
Fenrikur Jun 16, 2019
48c7b72
Added Smart App Banner for iTunes
Fenrikur Jun 16, 2019
3e22f19
Web app manifest for Android Native App Install Prompt (still needs s…
Fenrikur Jun 16, 2019
b7d4830
Simple, responsive, model-agnostic web preview of Event and Dealer en…
Fenrikur Jun 16, 2019
3fb6b6f
Add message_id to PM push payload for iOS
Pinselohrkater Jun 22, 2019
49cacfa
Adding CID to all push payloads for Android
Pinselohrkater Jun 22, 2019
51c931c
Adding Event Auto-Tagger to CLI Toolbox
Pinselohrkater Jun 22, 2019
cc6f3ce
Added settings for app ids on Google Play and Apple iTunes
Fenrikur Jun 16, 2019
7e8b734
Push app IDs into view
Fenrikur Jun 16, 2019
24ef20e
Minor formatting in Razor view template
Fenrikur Jun 16, 2019
6cd70ed
Added Smart App Banner for iTunes
Fenrikur Jun 16, 2019
10c791d
Web app manifest for Android Native App Install Prompt (still needs s…
Fenrikur Jun 16, 2019
641c07c
Simple, responsive, model-agnostic web preview of Event and Dealer en…
Fenrikur Jun 16, 2019
d916a30
Merge branch 'feature/web-preview' of https://github.com/Pinselohrkat…
Pinselohrkater Jun 22, 2019
3857f2e
Draft refactor to use typed web views
Pinselohrkater Jun 22, 2019
6603e1f
ApiBaseUrl and WebBaseUrl are derived from baseUrl in appsettings.json
Fenrikur Jun 22, 2019
6cf173e
Directory for static web content added
Fenrikur Jun 22, 2019
994727c
Base URLs should not contain a trailing slash
Fenrikur Jun 22, 2019
577fc8f
Extended dealer preview
Fenrikur Jun 22, 2019
325ebc9
Added remaining properties for dealers
Fenrikur Jun 22, 2019
0b0fc54
Icons using Font Awesome 5 Free
Fenrikur Jun 22, 2019
e7e7f50
Preview for events
Fenrikur Jun 22, 2019
58f0860
Added favicon
Fenrikur Jul 8, 2019
b2a6e11
Switched from pure custom to Skeleton css
Fenrikur Jul 8, 2019
5082842
Moved all CSS and font assets to CDN
Fenrikur Jul 8, 2019
7066f30
Changed font to Fira Sans
Fenrikur Jul 8, 2019
147909a
Added subheadings to sections of Dealer preview
Fenrikur Jul 8, 2019
7b6b465
Unified design of summary items to responsive, interactive and non-in…
Fenrikur Jul 8, 2019
308bd39
Minor CSS fixes
Fenrikur Jul 8, 2019
ce68ad4
Minor refactoring/cleanup
Pinselohrkater Jul 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ public class ConventionSettings
{
public string ConventionIdentifier { get; set; }
public bool IsRegSysAuthenticationEnabled { get; set; }
public string ApiBaseUrl { get; set; }
public string BaseUrl { get; set; }
public string AppIdITunes { get; set; }
public string AppIdPlay { get; set; }
public string ApiBaseUrl => $"{BaseUrl}/Api";
public string ContentBaseUrl => $"{BaseUrl}/Web/Static";
public string WebBaseUrl => $"{BaseUrl}/Web";

public static ConventionSettings FromConfiguration(IConfiguration configuration)
=> new ConventionSettings()
{
ConventionIdentifier = configuration["global:conventionIdentifier"],
IsRegSysAuthenticationEnabled = Convert.ToInt32(configuration["global:regSysAuthenticationEnabled"]) == 1,
ApiBaseUrl = configuration["global:apiBaseUrl"]
BaseUrl = configuration["global:baseUrl"],
AppIdITunes = configuration["global:appIdITunes"],
AppIdPlay = configuration["global:appIdPlay"]
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)
Event = "Announcement",
Title = announcement.Title.RemoveMarkdown(),
Text = announcement.Content.RemoveMarkdown(),
RelatedId = announcement.Id
RelatedId = announcement.Id,
CID = _conventionSettings.ConventionIdentifier
},
to = $"/topics/{_conventionSettings.ConventionIdentifier}-android"
}),
Expand All @@ -58,7 +59,7 @@ public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)
data = new
{
@event = "announcement",
announcement_id = announcement.Id,
announcement_id = announcement.Id
},
notification = new {
title = announcement.Title.RemoveMarkdown(),
Expand All @@ -85,6 +86,7 @@ await SendPushNotificationAsync(new
data = new
{
@event = "notification",
message_id = relatedId
},
notification = new
{
Expand All @@ -104,7 +106,8 @@ await SendPushNotificationAsync(new
Event = "Notification",
Title = toastTitle,
Message = toastMessage,
RelatedId = relatedId
RelatedId = relatedId,
CID = _conventionSettings.ConventionIdentifier
},
to = recipient.DeviceId
});
Expand All @@ -120,6 +123,7 @@ public Task PushSyncRequestAsync()
data = new
{
Event = "Sync",
CID = _conventionSettings.ConventionIdentifier
},
to = $"/topics/{_conventionSettings.ConventionIdentifier}-android"
}),
Expand Down
83 changes: 75 additions & 8 deletions src/Eurofurence.App.Server.Web/Controllers/WebPreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,66 @@ public class WebPreviewController : BaseController
private readonly ConventionSettings _conventionSettings;
private readonly IEventService _eventService;
private readonly IEventConferenceDayService _eventConferenceDayService;
private readonly IEventConferenceRoomService _eventConferenceRoomService;
private readonly IEventConferenceTrackService _eventConferenceTrackService;
private readonly IDealerService _dealerService;

public const string VIEWDATA_OPENGRAPH_METADATA = nameof(OpenGraphMetadata);
public const string VIEWDATA_APPID_ITUNES = nameof(ConventionSettings.AppIdITunes);
public const string VIEWDATA_APPID_PLAY = nameof(ConventionSettings.AppIdPlay);
public const string VIEWDATA_BASE_URL = nameof(ConventionSettings.BaseUrl);
public const string VIEWDATA_API_BASE_URL = nameof(ConventionSettings.ApiBaseUrl);
public const string VIEWDATA_CONTENT_BASE_URL = nameof(ConventionSettings.ContentBaseUrl);
public const string VIEWDATA_WEB_BASE_URL = nameof(ConventionSettings.WebBaseUrl);

public WebPreviewController(
ConventionSettings conventionSettings,
IEventService eventService,
IEventService eventService,
IEventConferenceDayService eventConferenceDayService,
IEventConferenceRoomService eventConferenceRoomService,
IEventConferenceTrackService eventConferenceTrackService,
IDealerService dealerService
)
{
_conventionSettings = conventionSettings;
_eventService = eventService;
_eventConferenceDayService = eventConferenceDayService;
_eventConferenceRoomService = eventConferenceRoomService;
_eventConferenceTrackService = eventConferenceTrackService;
_dealerService = dealerService;
}

private void PopulateViewData()
{
ViewData[VIEWDATA_API_BASE_URL] = _conventionSettings.ApiBaseUrl;
ViewData[VIEWDATA_BASE_URL] = _conventionSettings.BaseUrl;
ViewData[VIEWDATA_WEB_BASE_URL] = _conventionSettings.WebBaseUrl;
ViewData[VIEWDATA_CONTENT_BASE_URL] = _conventionSettings.ContentBaseUrl;
ViewData[VIEWDATA_APPID_ITUNES] = _conventionSettings.AppIdITunes;
ViewData[VIEWDATA_APPID_PLAY] = _conventionSettings.AppIdPlay;
}

[HttpGet("Events/{Id}")]
public async Task<ActionResult> GetEventById(Guid Id)
{
var @event = await _eventService.FindOneAsync(Id);
if (@event == null) return NotFound();

var eventConferenceDay = await _eventConferenceDayService.FindOneAsync(@event.ConferenceDayId);
var eventConferenceRoom = await _eventConferenceRoomService.FindOneAsync(@event.ConferenceRoomId);
var eventConferenceTrack = await _eventConferenceTrackService.FindOneAsync(@event.ConferenceTrackId);

PopulateViewData();

return new WebPreviewMetadata()
ViewData[VIEWDATA_OPENGRAPH_METADATA] = new OpenGraphMetadata()
.WithTitle(@event.Title)
.WithDescription($"{eventConferenceDay.Name} {@event.StartTime}-{@event.EndTime}\n{@event.Description}")
.AsViewResult();
.WithDescription($"{eventConferenceDay.Name} {@event.StartTime}-{@event.EndTime}\n{@event.Description}");

ViewData["eventConferenceDay"] = eventConferenceDay;
ViewData["eventConferenceRoom"] = eventConferenceRoom;
ViewData["eventConferenceTrack"] = eventConferenceTrack;

return View("EventPreview", @event);
}

[HttpGet("Dealers/{Id}")]
Expand All @@ -49,12 +82,46 @@ public async Task<ActionResult> GetDealerById(Guid Id)
var dealer = await _dealerService.FindOneAsync(Id);
if (dealer == null) return NotFound();

return new WebPreviewMetadata()
PopulateViewData();

ViewData[VIEWDATA_OPENGRAPH_METADATA] = new OpenGraphMetadata()
.WithTitle(string.IsNullOrEmpty(dealer.DisplayName) ? dealer.AttendeeNickname : dealer.DisplayName)
.WithDescription(dealer.ShortDescription)
.WithImage(dealer.ArtistImageId.HasValue ? $"{_conventionSettings.ApiBaseUrl}Images/{dealer.ArtistImageId}/Content" : string.Empty)
.AsViewResult();
.WithImage(dealer.ArtistImageId.HasValue ? $"{_conventionSettings.ApiBaseUrl}/Images/{dealer.ArtistImageId}/Content" : string.Empty);

return View("DealerPreview", dealer);
}

[HttpGet("manifest.json")]
public ActionResult GetManifest()
{
return Json(new
{
short_name = "Eurofurence",
name = "Eurofurence",
icons = new[] {
new {
//TODO: provide actual icon for Android app
src = "/images/icon192.png",
type = "image/png",
sizes = "192x192"
},
new {
//TODO: provide actual icon for Android app
src = "/images/icon512.png",
type = "image/png",
sizes = "512x512"
}
},
prefer_related_applications = true,
related_applications = new[] {
new {
platform = "play",
id = _conventionSettings.AppIdPlay
}
}
});
}

}
}
}
52 changes: 52 additions & 0 deletions src/Eurofurence.App.Server.Web/Extensions/OpenGraphMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;

namespace Eurofurence.App.Server.Web.Extensions
{
public class OpenGraphMetadata
{
public Dictionary<string, string> Properties { get; private set; }
public string Redirect { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }

public OpenGraphMetadata()
{
Properties = new Dictionary<string, string>();
}

public OpenGraphMetadata WithProperty(string property, string value)
{
Properties.Add(property, value);
return this;
}
public OpenGraphMetadata WithTitle(string value)
{
Title = value;
Properties.Add("og:title", value);
return this;
}

public OpenGraphMetadata WithDescription(string value)
{
Description = value;
Properties.Add("og:description", value);
return this;
}

public OpenGraphMetadata WithRedirect(string targetUrl)
{
Redirect = targetUrl;
return this;
}

public OpenGraphMetadata WithImage(string imageUrl)
{
if (string.IsNullOrWhiteSpace(imageUrl)) return this;

ImageUrl = imageUrl;
Properties.Add("og:image", imageUrl);
return this;
}
}
}
62 changes: 0 additions & 62 deletions src/Eurofurence.App.Server.Web/Extensions/WebPreviewMetadata.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/Eurofurence.App.Server.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
});
});

services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.All;
});

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

services.AddSwaggerGen(options =>
Expand Down Expand Up @@ -261,6 +266,8 @@ IApplicationLifetime appLifetime
app.UseCors("CorsPolicy");
app.UseAuthentication();

app.UseStaticFiles("/Web/Static");

app.Use(async (context, next) =>
{
using (LogContext.PushProperty("IPAddress",
Expand Down
36 changes: 0 additions & 36 deletions src/Eurofurence.App.Server.Web/Views/Shared/WebPreview.cshtml

This file was deleted.

Loading