Exemplo n.º 1
0
        public static IHtmlControl GetNewsView(SiteState state, LightObject currentUser, TopicStorage topic,
                                               out string description)
        {
            LightObject news = topic.Topic;

            description = BasketballHlp.GetDescriptionForNews(news);

            DateTime    localTime   = (news.Get(ObjectType.ActFrom) ?? DateTime.UtcNow).ToLocalTime();
            int         publisherId = news.Get(NewsType.PublisherId);
            LightObject publisher   = context.UserStorage.FindUser(publisherId);

            IHtmlControl editPanel = null;

            if (currentUser != null && (currentUser.Id == publisherId || currentUser.Get(BasketballUserType.IsModerator)))
            {
                editPanel = ViewNewsHlp.GetNewsEditPanel(state, topic);
            }

            IHtmlControl moderatorPanel = GetModeratorPanel(state, currentUser, topic, localTime);

            return(new HPanel(
                       Decor.Title(news.Get(NewsType.Title)),
                       new HLabel(localTime.ToString(Decor.timeFormat)).Block().FontBold(),
                       new HTextView(news.Get(NewsType.Text)).PositionRelative().Overflow("hidden"),
                       new HPanel(
                           new HLabel("Добавил:").MarginRight(5),
                           new HLink(UrlHlp.ShopUrl("user", publisherId), publisher?.Get(UserType.Login))
                           ),
                       new HLink(news.Get(NewsType.OriginUrl), news.Get(NewsType.OriginName)),
                       ViewTagHlp.GetViewTagsPanel(context.Tags.TagBox, topic.Topic),
                       editPanel,
                       moderatorPanel,
                       ViewCommentHlp.GetCommentsPanel(context.MessageConnection, state, currentUser, topic, topic.MessageLink.AllRows)
                       ));
        }
Exemplo n.º 2
0
        public static IHtmlControl GetFoundTagListView(SiteState state, out string title)
        {
            title = string.Format("Найденные теги по запросу: {0}", state.Option.Get(OptionType.SearchQuery));

            List <IHtmlControl> elements = new List <IHtmlControl>();

            int[] foundTagIds = state.Option.Get(OptionType.FoundTagIds);
            if (foundTagIds != null)
            {
                foreach (int tagId in foundTagIds)
                {
                    RowLink tagRow = context.Tags.TagBox.ObjectById.AnyRow(tagId);
                    if (tagRow == null)
                    {
                        continue;
                    }

                    string tagDisplay = TagType.DisplayName.Get(tagRow);

                    elements.Add(
                        new HPanel(
                            new HLink(ViewTagHlp.TagUrl(tagId, 0), tagDisplay)
                            ).MarginBottom(4)
                        );
                }
            }


            return(new HPanel(
                       Decor.Title(title),
                       new HPanel(
                           elements.ToArray()
                           )
                       ));
        }
Exemplo n.º 3
0
        public int[] SearchByTags(IDataLayer fabricConnection, string searchQuery)
        {
            if (StringHlp.IsEmpty(searchQuery))
            {
                return(new int[0]);
            }

            searchQuery = searchQuery.ToLower();

            string[] words = searchQuery.Split(new char[] { ' ', ',', '-' }, StringSplitOptions.RemoveEmptyEntries);
            if (words.Length == 0)
            {
                return(new int[0]);
            }

            //IEnumerable<int> tagIds = DictionaryHlp.GetValueOrDefault(tagIdsByWord, words[0]);
            //if (tagIds == null)
            //	return new int[0];

            IEnumerable <int> intersectTagIds = null;

            foreach (string word in words)
            {
                IEnumerable <int> tagIds = DictionaryHlp.GetValueOrDefault(tagIdsByWord, word);
                if (tagIds == null)
                {
                    return(new int[0]);
                }

                if (intersectTagIds == null)
                {
                    intersectTagIds = tagIds;
                }
                else
                {
                    intersectTagIds = intersectTagIds.Intersect(tagIds);
                }
            }

            List <Tuple <int, int> > tagIdsWithNewsCount = new List <Tuple <int, int> >();

            foreach (int tagId in intersectTagIds)
            {
                int[] newsIds = ViewTagHlp.GetNewsIdsForTag(fabricConnection, tagId);
                if (newsIds.Length > 0)
                {
                    tagIdsWithNewsCount.Add(new Tuple <int, int>(tagId, newsIds.Length));
                }
            }

            return(_.SortBy(tagIdsWithNewsCount, delegate(Tuple <int, int> tag)
                            { return tag.Item2; }).Select(ti => ti.Item1).Reverse().ToArray());
        }
Exemplo n.º 4
0
        static IHtmlControl GetSearchPanel(SiteState state)
        {
            string editName    = "searchText";
            string buttonName  = "searchButton";
            string contentName = "searchContent";

            return(new HPanel(
                       new HTextEdit(editName, new HPlaceholder(new HTone().Color("#ccc")).ToStyles())
                       .BoxSizing().Width(150).Placeholder("Поиск по тегам")
                       .Padding(6).TabIndex(1).Color("#fff").Border("none").Background("none")
                       .CssAttribute("user-select", "none").CssAttribute("outline", "none")
                       .OnKeyDown(string.Format("if (e.keyCode == 13) $('.{0}').click();", buttonName)),
                       new HButton(buttonName, " ",
                                   std.BeforeAwesome(@"\f002", 0).FontSize(18).Color(Decor.menuColor)
                                   ).PositionAbsolute().Left(0).Top(5).MarginLeft(12)
                       .Title("Найти тег")
                       .Event("search_tag", contentName,
                              delegate(JsonData json)
            {
                string searchQuery = json.GetText(editName);
                if (searchQuery == null || searchQuery.Length < 1)
                {
                    state.Operation.Message = "Введите тег";
                    return;
                }

                int[] tagIds = context.Tags.SearchByTags(context.FabricConnection, searchQuery);
                if (tagIds.Length == 0)
                {
                    state.Operation.Message = "Ничего не найдено";
                    return;
                }

                if (tagIds.Length == 1)
                {
                    state.RedirectUrl = ViewTagHlp.TagUrl(tagIds[0], 0);
                    return;
                }

                state.Option.Set(OptionType.SearchQuery, searchQuery);
                state.Option.Set(OptionType.FoundTagIds, tagIds);
            }
                              )
                       ).InlineBlock().PositionRelative().EditContainer(contentName).FontSize(12)
                   .PaddingLeft(35).PaddingRight(10).MarginLeft(17).MarginBottom(4).MarginTop(3)
                   .Background("rgba(255,255,255,0.2)").Border("1px solid #aaa").BorderRadius(15));
        }
Exemplo n.º 5
0
        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)
                           )
                       ));
        }
Exemplo n.º 6
0
        static IHtmlControl GetNewsEditPanel(SiteState state, TopicStorage topic)
        {
            LightObject news = topic.Topic;

            string blockHint = string.Format("news_edit_{0}", news.Id);

            IHtmlControl redoPanel = null;

            if (state.BlockHint == blockHint)
            {
                IHtmlControl deletePanel = null;
                if (state.ModeratorMode)
                {
                    deletePanel = DeleteTopicPanel(state, topic);
                }

                if (state.Tag == null)
                {
                    state.Tag = ViewTagHlp.GetTopicDisplayTags(context.Tags.TagBox, topic.Topic);
                }

                redoPanel = new HPanel(
                    deletePanel,
                    Decor.PropertyEdit("newsTitle", "Заголовок новости", news.Get(NewsType.Title)),
                    new HPanel(
                        HtmlHlp.CKEditorCreate("newsText", news.Get(NewsType.Text), "300px", true)
                        ),
                    ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, false),
                    Decor.PropertyEdit("newsOriginName", "Источник", news.Get(NewsType.OriginName)),
                    Decor.PropertyEdit("newsOriginUrl", "Ссылка", news.Get(NewsType.OriginUrl)),
                    Decor.Button("Изменить новость").CKEditorOnUpdateAll().MarginTop(10)
                    .Event("save_news_edit", "editNewsData",
                           delegate(JsonData json)
                {
                    string title      = json.GetText("newsTitle");
                    string text       = json.GetText("newsText");
                    string originName = json.GetText("newsOriginName");
                    string originUrl  = json.GetText("newsOriginUrl");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }
                    if (!operation.Validate(text, "Не задан текст"))
                    {
                        return;
                    }

                    LightKin editNews = DataBox.LoadKin(context.FabricConnection, NewsType.News, news.Id);

                    editNews.SetWithoutCheck(NewsType.Title, title);

                    editNews.Set(NewsType.Text, text);
                    editNews.Set(NewsType.OriginName, originName);
                    editNews.Set(NewsType.OriginUrl, originUrl);

                    editNews.Set(ObjectType.ActTill, DateTime.UtcNow);

                    ViewTagHlp.SaveTags(context, state, editNews);

                    editNews.Box.Update();

                    context.UpdateNews();
                    context.NewsStorages.ForTopic(news.Id).UpdateTopic();

                    state.BlockHint = "";
                },
                           news.Id
                           )
                    ).EditContainer("editNewsData")
                            .Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            return(new HPanel(
                       Decor.Button("Редактировать")
                       .Event("news_edit", "", delegate
            {
                state.SetBlockHint(blockHint);
            }
                              ),
                       redoPanel
                       ).MarginTop(10));
        }
Exemplo n.º 7
0
        public static IHtmlControl GetActualNewsBlock(SiteState state, LightObject currentUser)
        {
            IHtmlControl[] items = ViewNewsHlp.GetNewsItems(state, context.ActualNews);

            HPanel editBlock = null;
            string editHint  = "news_add";

            if (state.BlockHint == editHint)
            {
                if (state.Tag == null)
                {
                    state.Tag = new List <string>();
                }

                string unsaveText = BasketballHlp.AddCommentFromCookie();

                editBlock = new HPanel(
                    Decor.PropertyEdit("newsTitle", "Заголовок новости"),
                    new HPanel(
                        HtmlHlp.CKEditorCreate("newsText", unsaveText, "300px", true)
                        ),
                    ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, true),
                    Decor.PropertyEdit("newsOriginName", "Источник"),
                    Decor.PropertyEdit("newsOriginUrl", "Ссылка"),
                    Decor.Button("Добавить новость").MarginTop(10) //.CKEditorOnUpdateAll()
                    .OnClick(string.Format("CK_updateAll(); {0}", BasketballHlp.AddCommentToCookieScript("newsText")))
                    .Event("save_news_add", "addNewsData",
                           delegate(JsonData json)
                {
                    string title      = json.GetText("newsTitle");
                    string text       = json.GetText("newsText");
                    string originName = json.GetText("newsOriginName");
                    string originUrl  = json.GetText("newsOriginUrl");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }

                    if (!operation.Validate(text, "Не задан текст"))
                    {
                        return;
                    }

                    ParentBox editBox = new ParentBox(context.FabricConnection, "1=0");

                    int addNewsId        = editBox.CreateObject(NewsType.News, NewsType.Title.CreateXmlIds(title), DateTime.UtcNow);
                    LightParent editNews = new LightParent(editBox, addNewsId);

                    editNews.Set(NewsType.PublisherId, currentUser.Id);
                    editNews.Set(NewsType.Text, text);
                    editNews.Set(NewsType.OriginName, originName);
                    editNews.Set(NewsType.OriginUrl, originUrl);

                    ViewTagHlp.SaveTags(context, state, editNews);

                    editBox.Update();

                    context.UpdateNews();

                    state.BlockHint = "";
                    state.Tag       = null;

                    BasketballHlp.ResetAddComment();
                }
                           )
                    ).EditContainer("addNewsData").Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            IHtmlControl addButton = null;

            if (currentUser != null && !BasketballHlp.NoRedactor(currentUser))
            {
                addButton = Decor.Button("Добавить").MarginLeft(10)
                            .Event("news_add", "", delegate
                {
                    state.Tag = null;
                    state.SetBlockHint(editHint);
                }
                                   );
            }

            return(new HPanel(
                       Decor.Subtitle("Новости"),
                       new HPanel(
                           items.ToArray()
                           ),
                       new HPanel(
                           new HLink("/novosti",
                                     "Все новости",
                                     new HBefore().ContentIcon(5, 12).BackgroundImage(UrlHlp.ImageUrl("pointer.gif")).MarginRight(5).VAlign(-2)
                                     ).FontBold(),
                           addButton
                           ).MarginTop(15),
                       editBlock
                       ));
        }