public static IHtmlControl JumpBar(string urlWithoutPageIndex, int allItemCount, int itemCountOnPage, int pageIndex) { int pageCount = BinaryHlp.RoundUp(allItemCount, itemCountOnPage); int startIndex = Math.Max(0, pageIndex - 9); int endIndex = Math.Min(startIndex + 20, pageCount); List <IHtmlControl> items = new List <IHtmlControl>(); if (pageIndex > 0) { items.Add( new HLink(JumpPageUrl(urlWithoutPageIndex, pageIndex - 1), "назад").FontBold().MarginRight(10) ); } for (int i = startIndex; i < endIndex; ++i) { items.Add(ViewJumpHlp.JumpElement(urlWithoutPageIndex, i, i == pageIndex, i == startIndex)); } if (pageIndex < pageCount - 1) { items.Add( new HLink(JumpPageUrl(urlWithoutPageIndex, pageIndex + 1), "далее").FontBold().MarginLeft(10) ); } return(new HPanel( items.ToArray() ).MarginTop(25).MarginLeft(5)); }
public static IHtmlControl GetNewsListView(SiteState state, LightObject currentUser, int pageNumber) { //int pageCount = BinaryHlp.RoundUp(allNewsIds.Length, newsCountOnPage); //int curPos = pageNumber * newsCountOnPage; //if (curPos < 0 || curPos >= allNewsIds.Length) // return null; //int[] newsIds = ArrayHlp.GetRange(allNewsIds, curPos, Math.Min(newsCountOnPage, allNewsIds.Length - curPos)); //LightHead[] newsList = ArrayHlp.Convert(newsIds, delegate (int id) //{ return new LightHead(context.News, id); } //); int[] allNewsIds = context.News.AllObjectIds; IHtmlControl[] items = GetNewsItems(state, allNewsIds, pageNumber); if (items == null) { return(null); } //string title = StringHlp.IsEmpty(tag) ? "Новости" : "Теги"; return(new HPanel( Decor.Title("Новости"), //Decor.Subtitle(string.Format("Тег — {0}", tag)), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar("/novosti", allNewsIds.Length, newsCountOnPage, pageNumber) ) )); }
public static IHtmlControl GetArticleListView(SiteState state, LightObject currentUser, int pageNumber) { int[] allArticleIds = context.Articles.AllObjectIds; int pageCount = BinaryHlp.RoundUp(allArticleIds.Length, articleCountOnPage); int curPos = pageNumber * articleCountOnPage; if (curPos < 0 || curPos >= allArticleIds.Length) { return(new HPanel()); } int[] articleIds = ArrayHlp.GetRange(allArticleIds, curPos, Math.Min(articleCountOnPage, allArticleIds.Length - curPos) ); LightObject[] articleList = ArrayHlp.Convert(articleIds, delegate(int id) { return(new LightObject(context.Articles, id)); } ); IHtmlControl[] items = GetArticleItems(state, articleList); return(new HPanel( Decor.Title("Статьи").MarginBottom(15), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar("/stati", context.Articles.AllObjectIds.Length, articleCountOnPage, pageNumber) ) )); }
public static IHtmlControl GetTopicView(SiteState state, LightObject currentUser, TopicStorage topic, int pageNumber) { if (topic == null || topic.Topic == null) { return(null); } int? forumSectionId = topic.Topic.GetParentId(ForumSectionType.TopicLinks); LightSection forumSection = context.Store.Sections.FindSection(forumSectionId); if (forumSection == null) { return(null); } IHtmlControl editPanel = null; if (state.ModeratorMode) { editPanel = GetTopicRedoPanel(state, currentUser, forumSection, topic); } RowLink[] allMessages = topic.MessageLink.AllRows; RowLink[] pageMessages = ViewJumpHlp.GetPageItems(allMessages, forumMessageCountOnPage, pageNumber); if (pageMessages == null) { return(null); } return(new HPanel( Decor.Title(topic.Topic.Get(TopicType.Title)).MarginBottom(15), new HPanel( new HLink("/forum", "Форумы"), ArrowElement(), new HLink(UrlHlp.ShopUrl("page", forumSectionId), forumSection?.Get(SectionType.Title) ) ).MarginBottom(10), editPanel, ViewJumpHlp.JumpBar(string.Format("/topic/{0}", topic.TopicId), allMessages.Length, forumMessageCountOnPage, pageNumber ).MarginBottom(5), ViewCommentHlp.GetCommentsPanel(context.ForumConnection, state, currentUser, topic, pageMessages), ViewJumpHlp.JumpBar(string.Format("/topic/{0}", topic.TopicId), allMessages.Length, forumMessageCountOnPage, pageNumber ).MarginTop(10) )); }
public static IHtmlControl GetTagView(SiteState state, LightObject currentUser, int?tagId, int pageNumber, out string title, out string description) { title = ""; description = ""; if (tagId == null) { return(null); } RowLink tagRow = context.Tags.TagBox.ObjectById.AnyRow(tagId.Value); if (tagRow == null) { return(null); } string tagDisplay = TagType.DisplayName.Get(tagRow); title = string.Format("{0} - все новости на basketball.ru.com", tagDisplay); description = string.Format("{0} - все новости. Живое обсуждение баскетбольных событий на basketball.ru.com", tagDisplay); int[] newsIds = ViewTagHlp.GetNewsIdsForTag(context.FabricConnection, tagId.Value); IHtmlControl[] items = GetNewsItems(state, newsIds, pageNumber); if (items == null) { return(null); } string urlWithoutPageIndex = string.Format("/tags?tag={0}", tagId.Value); return(new HPanel( Decor.Title(tagDisplay), //.Color(Decor.subtitleColor), //Decor.Subtitle(string.Format("Тег — {0}", tagDisplay)).MarginTop(5), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar(urlWithoutPageIndex, newsIds.Length, newsCountOnPage, pageNumber) ) )); }
static IHtmlControl[] GetNewsItems(SiteState state, int[] allNewsIds, int pageNumber) { //int pageCount = BinaryHlp.RoundUp(allNewsIds.Length, newsCountOnPage); //int curPos = pageNumber * newsCountOnPage; //if (curPos < 0 || curPos >= allNewsIds.Length) // return null; //int[] newsIds = ArrayHlp.GetRange(allNewsIds, curPos, Math.Min(newsCountOnPage, allNewsIds.Length - curPos)); int[] newsIds = ViewJumpHlp.GetPageItems(allNewsIds, newsCountOnPage, pageNumber); if (newsIds == null) { return(null); } LightHead[] newsList = ArrayHlp.Convert(newsIds, delegate(int id) { return(new LightHead(context.News, id)); } ); return(GetNewsItems(state, newsList)); }