protected override PageContent getContent()
        {
            var mod    = getMod();
            var tagIds = ComponentStateItem.Create(
                "tags",
                ArticleId.HasValue
                                        ? ArticleTagsTableRetrieval.GetRowsLinkedToArticle(ArticleId.Value).Select(i => i.TagId).Materialize()
                                        : Enumerable.Empty <int>().Materialize(),
                v => v.All(id => TagsTableRetrieval.GetRowMatchingId(id, returnNullIfNoMatch: true) != null),
                true);

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(
                           modificationMethod: () => {
                if (!ArticleId.HasValue)
                {
                    mod.ArticleId = MainSequence.GetNextValue();
                    mod.Slug = getSuffixedSlug(mod.Title.ToUrlSlug());
                    mod.CreationDateAndTime = DateTime.UtcNow;
                }
                mod.Execute();

                if (ArticleId.HasValue)
                {
                    ArticleTagsModification.DeleteRows(new ArticleTagsTableEqualityConditions.ArticleId(ArticleId.Value));
                }
                foreach (var i in tagIds.Value.Value)
                {
                    ArticleTagsModification.InsertRow(mod.ArticleId, i);
                }
            },
                           actionGetter: () => new PostBackAction(Article.GetInfo(mod.ArticleId)))
                       .ToCollection(),
                       () => {
                var stack = FormItemList.CreateStack(generalSetup: new FormItemListSetup(etherealContent: tagIds.ToCollection()));

                stack.AddItems(
                    mod.GetTitleTextControlFormItem(false, label: "Article title".ToComponents(), value: ArticleId.HasValue ? null : "")
                    .Append(
                        mod.GetDescriptionTextControlFormItem(false, label: "What's this article about?".ToComponents(), value: ArticleId.HasValue ? null : ""))
                    .Append(
                        mod.GetBodyMarkdownTextControlFormItem(
                            false,
                            label: "Write your article (in markdown)".ToComponents(),
                            controlSetup: TextControlSetup.Create(numberOfRows: 8),
                            value: ArticleId.HasValue ? null : ""))
                    .Append(getTagFormItem(tagIds.Value))
                    .Materialize());

                return new UiPageContent(contentFootActions: new ButtonSetup("Publish Article").ToCollection()).Add(stack);
            }));
        }
 private IReadOnlyCollection <PhrasingComponent> getTagListComponents(DataValue <IReadOnlyCollection <int> > tagIds, UpdateRegionSet removeUpdateRegions) =>
 tagIds.Value.Select(
     tagId => new GenericPhrasingContainer(
         new EwfButton(
             new CustomButtonStyle(children: new FontAwesomeIcon("fa-times").ToCollection()),
             behavior: new PostBackBehavior(
                 postBack: PostBack.CreateIntermediate(
                     removeUpdateRegions.ToCollection(),
                     id: PostBack.GetCompositeId("removeTag", tagId.ToString()),
                     modificationMethod: () => tagIds.Value = tagIds.Value.Where(i => i != tagId).Materialize())))
         .Concat(" {0}".FormatWith(TagsTableRetrieval.GetRowMatchingId(tagId).TagName).ToComponents())
         .Materialize(),
         classes: ElementClasses.EditorTag))
 .Materialize();
        private void addTag(DataValue <IReadOnlyCollection <int> > tagIds, DataValue <string> tagName)
        {
            var tagId = TagsTableRetrieval.GetAllRows().MatchingName(tagName.Value)?.TagId;

            if (!tagId.HasValue)
            {
                tagId = MainSequence.GetNextValue();
                TagsModification.InsertRow(tagId.Value, tagName.Value);
            }

            if (!tagIds.Value.Contains(tagId.Value))
            {
                tagIds.Value = tagIds.Value.Append(tagId.Value).Materialize();
            }
        }
        private FlowComponent getTagSection(DataValue <string> filter, UpdateRegionSet resultUpdateRegions)
        {
            var tags = ArticleTagsTableRetrieval.GetRows()
                       .Select(i => i.TagId)
                       .GroupBy(i => i)
                       .OrderByDescending(i => i.Count())
                       .Take(20)
                       .Select(i => TagsTableRetrieval.GetRowMatchingId(i.Key));

            return(new Section(
                       "Popular Tags",
                       new WrappingList(
                           tags.Select(
                               i => (WrappingListItem) new EwfButton(
                                   new StandardButtonStyle(i.TagName, buttonSize: ButtonSize.ShrinkWrap),
                                   behavior: new PostBackBehavior(
                                       postBack: PostBack.CreateIntermediate(
                                           resultUpdateRegions.ToCollection(),
                                           id: PostBack.GetCompositeId("tag", i.TagId.ToString()),
                                           modificationMethod: () => filter.Value = "tag{0}".FormatWith(i.TagId)))).ToComponentListItem()),
                           generalSetup: new ComponentListSetup(classes: ElementClasses.Tag)).ToCollection(),
                       style: SectionStyle.Box));
        }
 private IReadOnlyCollection <PhrasingComponent> getTagTabComponents(string filter) =>
 filter.StartsWith("tag")
                         ? new FontAwesomeIcon("fa-hashtag")
 .Concat(" {0}".FormatWith(TagsTableRetrieval.GetRowMatchingId(int.Parse(filter.Substring(3))).TagName).ToComponents())
 .Materialize()
                         : Enumerable.Empty <PhrasingComponent>().Materialize();
Example #6
0
 internal static IReadOnlyCollection <FlowComponent> GetTagDisplay(int articleId, IEnumerable <ArticleTagsTableRetrieval.Row> tags) =>
 new LineList(
     tags.OrderByTagId().Select(i => (LineListItem)TagsTableRetrieval.GetRowMatchingId(i.TagId).TagName.ToComponents().ToComponentListItem()),
     generalSetup: new ComponentListSetup(classes: ElementClasses.Tag)).ToCollection();