mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-19 11:41:30 +00:00
Website announcements fixes and additions (#818)
* Render line breaks in announcement content * Track announcement publisher * Change paragraph tag to a div for consistency * Fix bottom padding for announcement content * Track publisher user entity rather than just the username * Potentially fix a migration failure * Final code cleanup * Fix linq statement chaining style --------- Co-authored-by: Dagg <daggintosh@outlook.com>
This commit is contained in:
parent
14ebad07f3
commit
f965be88b7
5 changed files with 96 additions and 11 deletions
|
@ -37,11 +37,21 @@
|
|||
@foreach (WebsiteAnnouncementEntity announcement in Model.Announcements)
|
||||
{
|
||||
<div class="ui blue segment" style="position: relative;">
|
||||
<h3>@announcement.Title</h3>
|
||||
<p style="white-space: initial;">
|
||||
@announcement.Content
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<h3>@announcement.Title</h3>
|
||||
<div style="padding-bottom: 2em;">
|
||||
<span style="white-space: pre-line; ">@announcement.Content</span>
|
||||
</div>
|
||||
@if (announcement.Publisher != null)
|
||||
{
|
||||
<div class="ui tiny bottom left attached label">
|
||||
Posted by
|
||||
<a style="color: black" href="~/user/@announcement.Publisher.UserId">
|
||||
@announcement.Publisher.Username
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (Model.User != null && Model.User.IsAdmin)
|
||||
{
|
||||
<form method="post">
|
||||
|
@ -57,7 +67,7 @@
|
|||
</form>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ public class AnnouncePage : BaseLayout
|
|||
public async Task<IActionResult> OnGet()
|
||||
{
|
||||
this.Announcements = await this.Database.WebsiteAnnouncements
|
||||
.Include(a => a.Publisher)
|
||||
.OrderByDescending(a => a.AnnouncementId)
|
||||
.ToListAsync();
|
||||
|
||||
|
@ -42,8 +43,9 @@ public class AnnouncePage : BaseLayout
|
|||
|
||||
WebsiteAnnouncementEntity announcement = new()
|
||||
{
|
||||
Title = title,
|
||||
Content = content,
|
||||
Title = title.Trim(),
|
||||
Content = content.Trim(),
|
||||
PublisherId = user.UserId,
|
||||
};
|
||||
|
||||
await this.Database.WebsiteAnnouncements.AddAsync(announcement);
|
||||
|
@ -55,8 +57,7 @@ public class AnnouncePage : BaseLayout
|
|||
? content[..250] + $"... [read more]({ServerConfiguration.Instance.ExternalUrl}/announce)"
|
||||
: content;
|
||||
|
||||
await WebhookHelper.SendWebhook($":mega: {title}",
|
||||
truncatedAnnouncement);
|
||||
await WebhookHelper.SendWebhook($":mega: {title}", truncatedAnnouncement);
|
||||
}
|
||||
|
||||
return this.RedirectToPage();
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ProjectLighthouse.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20230624203015_AddPostedByToWebAnnouncements")]
|
||||
public partial class AddPostedByToWebAnnouncements : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PublisherId",
|
||||
table: "WebsiteAnnouncements",
|
||||
type: "int",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WebsiteAnnouncements_PublisherId",
|
||||
table: "WebsiteAnnouncements",
|
||||
column: "PublisherId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_WebsiteAnnouncements_Users_PublisherId",
|
||||
table: "WebsiteAnnouncements",
|
||||
column: "PublisherId",
|
||||
principalTable: "Users",
|
||||
principalColumn: "UserId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_WebsiteAnnouncements_Users_PublisherId",
|
||||
table: "WebsiteAnnouncements");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_WebsiteAnnouncements_PublisherId",
|
||||
table: "WebsiteAnnouncements");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PublisherId",
|
||||
table: "WebsiteAnnouncements");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1033,10 +1033,15 @@ namespace ProjectLighthouse.Migrations
|
|||
b.Property<string>("Content")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("PublisherId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Identifier");
|
||||
b.HasKey("AnnouncementId");
|
||||
|
||||
b.HasIndex("PublisherId");
|
||||
|
||||
b.ToTable("WebsiteAnnouncements");
|
||||
});
|
||||
|
@ -1394,6 +1399,15 @@ namespace ProjectLighthouse.Migrations
|
|||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Website.WebsiteAnnouncementEntity", b =>
|
||||
{
|
||||
b.HasOne("LBPUnion.ProjectLighthouse.Types.Entities.Profile.UserEntity", "Publisher")
|
||||
.WithMany()
|
||||
.HasForeignKey("PublisherId");
|
||||
|
||||
b.Navigation("Publisher");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Profile.PhotoEntity", b =>
|
||||
{
|
||||
b.Navigation("PhotoSubjects");
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Types.Entities.Website;
|
||||
|
||||
|
@ -10,4 +12,13 @@ public class WebsiteAnnouncementEntity
|
|||
public string Title { get; set; }
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
#nullable enable
|
||||
|
||||
public int? PublisherId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(PublisherId))]
|
||||
public UserEntity? Publisher { get; set; }
|
||||
|
||||
#nullable disable
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue