Skip to content

Commit

Permalink
Add archives link at the bottom of the homepage and author pages. Sup…
Browse files Browse the repository at this point in the history
…port by-month views of authors. Closes #156. Closes #157.
  • Loading branch information
BenLubar committed Apr 1, 2016
1 parent b7e0682 commit 6556bfe
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 23 deletions.
6 changes: 4 additions & 2 deletions SqlScripts/OBJECTS/4.PROCS/1.Articles_GetArticles.sql
Expand Up @@ -16,17 +16,19 @@ GO

CREATE PROCEDURE [Articles_GetArticles]
(
@Series_Slug NVARCHAR(255),
@Series_Slug NVARCHAR(255) = NULL,
@PublishedStatus_Name VARCHAR(15),
@RangeStart_Date DATETIME,
@RangeEnd_Date DATETIME
@RangeEnd_Date DATETIME,
@Author_Slug NVARCHAR(255) = NULL
)
AS
BEGIN


SELECT * FROM [Articles_Extended]
WHERE (@Series_Slug IS NULL OR [Series_Slug] = @Series_Slug)
AND (@Author_Slug IS NULL OR [Author_Slug] = @Author_Slug)
AND (@PublishedStatus_Name IS NULL OR [PublishedStatus_Name] = @PublishedStatus_Name)
AND (@PublishedStatus_Name <> 'Published' OR [Published_Date] < GETDATE())
AND (@RangeStart_Date IS NULL OR [Published_Date] > @RangeStart_Date)
Expand Down
6 changes: 6 additions & 0 deletions TheDailyWtf/App_Start/RouteConfig.cs
Expand Up @@ -276,6 +276,12 @@ public static void RegisterRoutes(RouteCollection routes)
defaults: new { controller = "Authors", action = "ViewAuthor" }
);

routes.MapRoute(
name: "ViewAuthorByMonth",
url: "authors/{year}/{month}/{authorSlug}",
defaults: new { controller = "Authors", action = "ViewAuthorByMonth" }
);

// API Routes

routes.MapRoute(
Expand Down
9 changes: 9 additions & 0 deletions TheDailyWtf/Content/Css/main.css
Expand Up @@ -1668,3 +1668,12 @@ button {
.validation-summary-errors ul {
margin-bottom: 0;
}
.archives-link {
font-size: 1.2em;
display: block;
text-align: center;
margin-top: 1em;
padding: 1em;
background-color: #fff;
box-shadow: 0 8px 6px -6px #808080;
}
10 changes: 10 additions & 0 deletions TheDailyWtf/Content/Css/main.less
Expand Up @@ -1770,3 +1770,13 @@ button {
margin-bottom: 0;
}
}

.archives-link {
font-size: 1.2em;
display: block;
text-align: center;
margin-top: 1em;
padding: 1em;
background-color: @tdwtf-white;
box-shadow: 0 8px 6px -6px @tdwtf-grey;
}
9 changes: 8 additions & 1 deletion TheDailyWtf/Controllers/AuthorsController.cs
@@ -1,4 +1,4 @@
using System.Security.Principal;
using System;
using System.Web.Mvc;
using TheDailyWtf.ViewModels;

Expand All @@ -14,5 +14,12 @@ public ActionResult ViewAuthor(string authorSlug)
{
return View(new ViewAuthorViewModel(authorSlug));
}

[OutputCache(CacheProfile = CacheProfile.Timed5Minutes)]
public ActionResult ViewAuthorByMonth(int year, int month, string authorSlug)
{
var date = new DateTime(year, month, 1);
return View(new ViewAuthorViewModel(authorSlug, date));
}
}
}
9 changes: 5 additions & 4 deletions TheDailyWtf/Data/StoredProcs.cs
Expand Up @@ -257,12 +257,13 @@ public Tables.Articles_Extended Execute()
/// </summary>
public class Articles_GetArticles : WrappedStoredProcedure<SqlServerDataFactory>
{
public Articles_GetArticles(string Series_Slug, string PublishedStatus_Name, DateTime? RangeStart_Date, DateTime? RangeEnd_Date)
public Articles_GetArticles(string Series_Slug, string PublishedStatus_Name, DateTime? RangeStart_Date, DateTime? RangeEnd_Date, string Author_Slug)
{
AddParam("@Series_Slug", DbType.String, 255, ParameterDirection.Input, Series_Slug);
AddParam("@PublishedStatus_Name", DbType.AnsiString, 15, ParameterDirection.Input, PublishedStatus_Name);
AddParam("@RangeStart_Date", DbType.DateTime, 0, ParameterDirection.Input, RangeStart_Date);
AddParam("@RangeEnd_Date", DbType.DateTime, 0, ParameterDirection.Input, RangeEnd_Date);
AddParam("@Author_Slug", DbType.String, 255, ParameterDirection.Input, Author_Slug);
}
public IEnumerable<Tables.Articles_Extended> Execute()
{
Expand Down Expand Up @@ -660,9 +661,9 @@ public static StoredProcedures.Articles_GetArticleBySlug Articles_GetArticleBySl
return new StoredProcedures.Articles_GetArticleBySlug(Article_Slug);
}

public static StoredProcedures.Articles_GetArticles Articles_GetArticles(string Series_Slug, string PublishedStatus_Name, DateTime? RangeStart_Date, DateTime? RangeEnd_Date)
public static StoredProcedures.Articles_GetArticles Articles_GetArticles(string Series_Slug, string PublishedStatus_Name, DateTime? RangeStart_Date, DateTime? RangeEnd_Date, string Author_Slug = null)
{
return new StoredProcedures.Articles_GetArticles(Series_Slug, PublishedStatus_Name, RangeStart_Date, RangeEnd_Date);
return new StoredProcedures.Articles_GetArticles(Series_Slug, PublishedStatus_Name, RangeStart_Date, RangeEnd_Date, Author_Slug);
}

public static StoredProcedures.Articles_GetFeaturedComments Articles_GetFeaturedComments(int? Article_Id)
Expand Down Expand Up @@ -720,7 +721,7 @@ public static StoredProcedures.Authors_ValidateLogin Authors_ValidateLogin(strin
return new StoredProcedures.Authors_ValidateLogin(Author_Slug, Password_Text, Valid_Indicator);
}

public static StoredProcedures.Comments_CreateOrUpdateComment Comments_CreateOrUpdateComment(int? Comment_Id, int? Article_Id, string Body_Html, string User_Name, DateTime? Posted_Date, string User_IP, string User_Token, int? Parent_Comment_Id)
public static StoredProcedures.Comments_CreateOrUpdateComment Comments_CreateOrUpdateComment(int? Comment_Id, int? Article_Id, string Body_Html, string User_Name, DateTime? Posted_Date, string User_IP, string User_Token, int? Parent_Comment_Id = null)
{
return new StoredProcedures.Comments_CreateOrUpdateComment(Comment_Id, Article_Id, Body_Html, User_Name, Posted_Date, User_IP, User_Token, Parent_Comment_Id);
}
Expand Down
29 changes: 20 additions & 9 deletions TheDailyWtf/Models/ArticleModel.cs
Expand Up @@ -98,22 +98,33 @@ public static IEnumerable<ArticleModel> GetAllArticlesBySeries(string series)
return articles.Select(a => ArticleModel.FromTable(a));
}

private static IEnumerable<ArticleModel> GetArticlesByMonth(DateTime month, string series = null, string author = null)
{
var monthStart = new DateTime(month.Year, month.Month, 1);
var articles = StoredProcs.Articles_GetArticles(
Series_Slug: series,
PublishedStatus_Name: Domains.PublishedStatus.Published,
RangeStart_Date: monthStart,
RangeEnd_Date: monthStart.AddMonths(1).AddSeconds(-1.0),
Author_Slug: author
).Execute();

return articles.Select(a => ArticleModel.FromTable(a));
}

public static IEnumerable<ArticleModel> GetAllArticlesByMonth(DateTime month)
{
return GetSeriesArticlesByMonth(null, month);
return GetArticlesByMonth(month);
}

public static IEnumerable<ArticleModel> GetSeriesArticlesByMonth(string series, DateTime month)
{
var monthStart = new DateTime(month.Year, month.Month, 1);
var articles = StoredProcs.Articles_GetArticles(
series,
Domains.PublishedStatus.Published,
monthStart,
monthStart.AddMonths(1).AddSeconds(-1.0)
).Execute();
return GetArticlesByMonth(month, series: series);
}

return articles.Select(a => ArticleModel.FromTable(a));
public static IEnumerable<ArticleModel> GetAuthorArticlesByMonth(string author, DateTime month)
{
return GetArticlesByMonth(month, author: author);
}

public static IEnumerable<ArticleModel> GetRecentArticles()
Expand Down
3 changes: 3 additions & 0 deletions TheDailyWtf/TheDailyWtf.csproj
Expand Up @@ -509,6 +509,9 @@
<ItemGroup>
<Content Include="Views\Admin\FooterAdList.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Authors\ViewAuthorByMonth.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
2 changes: 1 addition & 1 deletion TheDailyWtf/ViewModels/ArticlesIndexViewModel.cs
Expand Up @@ -18,7 +18,7 @@ public ArticlesIndexViewModel()
public DateInfo ReferenceDate { get; set; }
public SeriesModel Series { get; set; }
public string SeriesDescription { get { return this.Series != null ? this.Series.Description : ""; } }
public bool PaginateArticleListByMonth { get { return this.Series == null || paginatedSeries.Contains(this.Series.Slug); } }
public bool PaginateArticleListByMonth { get { return true; /* BenLubar(2016-04-01) - do we still need this? It was causing less populated categories to only ever show the last 8 articles. */ } }
public string ListHeading
{
get
Expand Down
10 changes: 10 additions & 0 deletions TheDailyWtf/ViewModels/HomeIndexViewModel.cs
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TheDailyWtf.Models;
Expand All @@ -21,5 +22,14 @@ public IEnumerable<DimensionRoot> AllAdDimensions
{
get { return AdRotator.DimensionRoots; }
}

public string ArchivesUrl
{
get
{
var date = DateTime.Today;
return string.Format("/articles/{0}/{1}", date.Year, date.Month);
}
}
}
}
18 changes: 17 additions & 1 deletion TheDailyWtf/ViewModels/ViewAuthorViewModel.cs
Expand Up @@ -7,19 +7,35 @@ namespace TheDailyWtf.ViewModels
{
public class ViewAuthorViewModel : WtfViewModelBase
{
public ViewAuthorViewModel(string slug)
public ViewAuthorViewModel(string slug, DateTime? month = null)
{
this.Author = AuthorModel.GetAuthorBySlug(slug);
this.ReferenceDate = month.HasValue ? new ArticlesIndexViewModel.DateInfo(month.Value) : null;
}

public AuthorModel Author { get; set; }
public ArticlesIndexViewModel.DateInfo ReferenceDate { get; set; }
public IEnumerable<ArticleItemViewModel> Articles
{
get
{
if (this.ReferenceDate != null)
{
return ArticleModel.GetAuthorArticlesByMonth(this.Author.Slug, this.ReferenceDate.Reference)
.Select(a => new ArticleItemViewModel(a));
}
return ArticleModel.GetRecentArticlesByAuthor(this.Author.Slug)
.Select(a => new ArticleItemViewModel(a));
}
}

private string FormatUrl(DateTime date)
{
return string.Format("/authors/{0}/{1}/{2}", date.Year, date.Month, this.Author.Slug);
}

public string ArchivesUrl { get { return this.FormatUrl(this.Articles.Last().Article.PublishedDate.Value); } }
public string PreviousMonthUrl { get { return this.FormatUrl(this.ReferenceDate.PrevMonth); } }
public string NextMonthUrl { get { return this.FormatUrl(this.ReferenceDate.NextMonth); } }
}
}
7 changes: 3 additions & 4 deletions TheDailyWtf/Views/Articles/Index.cshtml
Expand Up @@ -13,11 +13,10 @@
<div class="prev">
<a href="@Model.PreviousMonthUrl"><img src="~/Content/Images/circled-arrow.svg" />@Model.ReferenceDate.PreviousMonthAndYear</a>
</div>
<div class="next">
<a href="@Model.NextMonthUrl" class="@Model.ReferenceDate.NextMonthCssClass">@Model.ReferenceDate.NextMonthAndYear<img src="~/Content/Images/circled-arrow.svg" /></a>
</div>
<div class="next">
<a href="@Model.NextMonthUrl" class="@Model.ReferenceDate.NextMonthCssClass">@Model.ReferenceDate.NextMonthAndYear<img src="~/Content/Images/circled-arrow.svg" /></a>
</div>
<span>@Model.ReferenceDate.CurrentMonthAndYear</span>

}
</div>

Expand Down
6 changes: 5 additions & 1 deletion TheDailyWtf/Views/Authors/ViewAuthor.cshtml
Expand Up @@ -24,7 +24,11 @@
@Html.Partial(Views.Shared.PartialArticleItem, article)
}

@if (!Model.Articles.Any())
@if (Model.Articles.Any())
{
<p><a href="@Model.ArchivesUrl" class="archives-link">Archives</a></p>
}
else
{
<p>There are no articles to display.</p>
}
Expand Down
41 changes: 41 additions & 0 deletions TheDailyWtf/Views/Authors/ViewAuthorByMonth.cshtml
@@ -0,0 +1,41 @@
@model ViewAuthorViewModel

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="content" id="listing">

<div class="author-box">
<div class="author-image-container">
<img src="@Model.Author.ImageUrl" />
</div>
<div class="author-details">
<h1 class="title">@Model.Author.Name</h1>

<p class="credentials">@Model.Author.ShortDescription</p>
</div>
</div>

<div class="series-nav">
<div class="prev">
<a href="@Model.PreviousMonthUrl"><img src="~/Content/Images/circled-arrow.svg" />@Model.ReferenceDate.PreviousMonthAndYear</a>
</div>
<div class="next">
<a href="@Model.NextMonthUrl" class="@Model.ReferenceDate.NextMonthCssClass">@Model.ReferenceDate.NextMonthAndYear<img src="~/Content/Images/circled-arrow.svg" /></a>
</div>
<span>@Model.ReferenceDate.CurrentMonthAndYear</span>
</div>

<div id="article-feed">
@foreach (var article in Model.Articles)
{
@Html.Partial(Views.Shared.PartialArticleItem, article)
}

@if (!Model.Articles.Any())
{
<p>There are no articles to display.</p>
}
</div>
</div>
2 changes: 2 additions & 0 deletions TheDailyWtf/Views/Home/Index.cshtml
Expand Up @@ -112,5 +112,7 @@
{
@Html.Partial(Views.Shared.PartialArticleItem, article)
}

<p><a href="@Model.ArchivesUrl" class="archives-link">Archives</a></p>
</div>
</div>

0 comments on commit 6556bfe

Please sign in to comment.