private void WritePageLink(int page, StringBuilder sb, IDiscussable discussable, int firstUnreadPage, int viewComments, int totalComments, GetUrlByDiscussableDelegate GetThreadUrl, params object[] par) { bool hilight = firstUnreadPage > 0 && firstUnreadPage <= page && viewComments < totalComments; if (!hilight) sb.Append("<small>"); sb.Append("<a "); if (hilight) sb.Append("class=\"Unread\" "); sb.Append("href=\""); if (page > 1) sb.Append(GetThreadUrl(discussable, Cambro.Misc.Utility.Join(par, "k", this.K.ToString(), "c", page.ToString()))); else sb.Append(GetThreadUrl(discussable, Cambro.Misc.Utility.Join(par, "k", this.K.ToString()))); sb.Append("\">"); sb.Append(page.ToString()); sb.Append("</a>"); if (!hilight) sb.Append("</small>"); sb.Append(" "); }
public string PagesHtml(IDiscussable discussable, GetUrlByDiscussableDelegate GetThreadUrl, params object[] par) { int firstUnreadPage = 0; if (this.JoinedThreadUsr.ViewCommentsInUse > 0) { firstUnreadPage = (this.JoinedThreadUsr.ViewCommentsInUse / Vars.CommentsPerPage) + 1; } StringBuilder sb = new StringBuilder(); if (firstUnreadPage > 0 && LastPage >= firstUnreadPage && this.JoinedThreadUsr.ViewCommentsInUse < this.TotalComments) { int numLinks = 3; int midLinks = 2; sb.Append(" <a class=\"Unread\" href=\""); if (firstUnreadPage > 1) sb.Append(GetThreadUrl(discussable, Cambro.Misc.Utility.Join(par, "k", this.K.ToString(), "c", firstUnreadPage.ToString())) + "#Unread"); else sb.Append(GetThreadUrl(discussable, Cambro.Misc.Utility.Join(par, "k", this.K.ToString())) + "#Unread"); sb.Append("\" onmouseover=\"stt(UnreadString("); sb.Append(firstUnreadPage.ToString()); sb.Append("));\" onmouseout=\"htm();\">NEW</a>"); if (LastPage > 1) { sb.Append("<br><small>Page: </small>"); int gap1Start = numLinks; int gap1End = firstUnreadPage - midLinks; int gap2Start = firstUnreadPage + midLinks - 1; int gap2End = LastPage - numLinks + 1; bool hasGap1 = gap1Start < gap1End - 1; bool hasGap2 = gap2Start < gap2End - 1; int seq1End = hasGap1 ? gap1Start : (hasGap2 ? gap2Start : LastPage); int seq2End = hasGap2 ? gap2Start : LastPage; for (int i = 1; i <= seq1End; i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } if (hasGap1) { sb.Append("... "); for (int i = gap1End; i <= seq2End; i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } } if (hasGap2) { sb.Append("... "); for (int i = gap2End; i <= LastPage; i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } } } } else { if (firstUnreadPage == 0 && this.JoinedThreadUsr.ThreadK == this.K && this.JoinedThreadUsr.IsWatching && !this.JoinedThreadUsr.Status.Equals(ThreadUsr.StatusEnum.Archived) && !this.JoinedThreadUsr.Status.Equals(ThreadUsr.StatusEnum.UnArchived)) { sb.Append(" <a class=\"UnreadNew\" href=\""); sb.Append(GetThreadUrl(discussable, Cambro.Misc.Utility.Join(par, "k", this.K.ToString())) + "#Unread"); sb.Append("\" onmouseover=\"stt(UnreadNewString("); sb.Append(((int)this.JoinedThreadUsr.Status).ToString()); sb.Append(","); sb.Append(((int)this.JoinedThreadUsr.StatusChangeObjectType).ToString()); sb.Append("));\" onmouseout=\"htm();\">NEW</a>"); } int numLinks = 3; if (LastPage > 1) { sb.Append("<br><small>Page: </small>"); if (LastPage <= numLinks * 2) { for (int i = 1; i <= LastPage; i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } } else { for (int i = 1; i <= (numLinks); i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } sb.Append("... "); for (int i = LastPage - (numLinks) + 1; i <= LastPage; i++) { WritePageLink(i, sb, discussable, firstUnreadPage, this.JoinedThreadUsr.ViewCommentsInUse, this.TotalComments, GetThreadUrl, par); } } } } return sb.ToString(); }