private IReadOnlyCollection <FlowComponent> getNewCommentComponents(UpdateRegionSet createUpdateRegions)
        {
            if (AppTools.User == null)
            {
                return(new Paragraph(
                           new EwfHyperlink(
                               EnterpriseWebLibrary.EnterpriseWebFramework.UserManagement.Pages.LogIn.GetInfo(Home.GetInfo().GetUrl()),
                               new StandardHyperlinkStyle("Sign in")).Concat(" or ".ToComponents())
                           .Append(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle("sign up")))
                           .Concat(" to add comments on this article.".ToComponents())
                           .Materialize()).ToCollection());
            }

            commentMod = getCommentMod();
            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateIntermediate(
                           createUpdateRegions.ToCollection(),
                           id: "comment",
                           modificationMethod: () => {
                commentMod.CommentId = MainSequence.GetNextValue();
                commentMod.Execute();
            })
                       .ToCollection(),
                       () => new FlowIdContainer(
                           commentMod.GetBodyTextTextControlFormItem(
                               false,
                               label: Enumerable.Empty <PhrasingComponent>().Materialize(),
                               controlSetup: TextControlSetup.Create(numberOfRows: 3, placeholder: "Write a comment..."),
                               value: "")
                           .ToComponentCollection()
                           .Append(new EwfButton(new StandardButtonStyle("Post Comment"))),
                           updateRegionSets: createUpdateRegions.ToCollection()).ToCollection()));
        }
        private IEnumerable <Control> getNonIdListRegionBlocks()
        {
            var addRs    = new UpdateRegionSet();
            var removeRs = new UpdateRegionSet();

            yield return
                (new ControlLine(
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             addRs.ToSingleElementArray(),
                             DataUpdate,
                             id: "nonIdAdd",
                             firstModificationMethod: () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Concat(new[] { 0, 0 })),
                         new ButtonActionControlStyle("Add Two Items"),
                         usesSubmitBehavior: false),
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             removeRs.ToSingleElementArray(),
                             DataUpdate,
                             id: "nonIdRemove",
                             firstModificationMethod:
                             () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Take(parametersModification.NonIdItemStates.Count() - 2)),
                         new ButtonActionControlStyle("Remove Two Items"),
                         usesSubmitBehavior: false)));

            var stack = ControlStack.Create(true, tailUpdateRegions: new[] { new TailUpdateRegion(addRs, 0), new TailUpdateRegion(removeRs, 2) });

            for (var i = 0; i < info.NonIdItemStates.Count(); i += 1)
            {
                stack.AddItem(getNonIdItem(i));
            }

            yield return(new Box("Control List With Non-ID Items", stack.ToSingleElementArray()));
        }
Exemple #3
0
        private IReadOnlyCollection <FlowComponent> getIdListRegionComponents()
        {
            var components = new List <FlowComponent>();

            var rs = new UpdateRegionSet();

            components.Add(
                new LineList(
                    new EwfButton(
                        new StandardButtonStyle("Add Item"),
                        behavior: new PostBackBehavior(
                            postBack: PostBack.CreateIntermediate(
                                rs.ToCollection(),
                                id: "idAdd",
                                firstModificationMethod: () =>
                                parametersModification.ItemIds = (parametersModification.ItemIds.Any() ? parametersModification.ItemIds.Min() - 1 : 0).ToCollection()
                                                                 .Concat(parametersModification.ItemIds)))).ToCollection()
                    .ToComponentListItem()
                    .ToLineListItemCollection()));

            var stack = new StackList(
                info.ItemIds.Select(getIdItem),
                setup: new ComponentListSetup(
                    itemInsertionUpdateRegions: new ItemInsertionUpdateRegion(rs.ToCollection(), () => parametersModification.ItemIds.First().ToString().ToCollection())
                    .ToCollection()));

            components.Add(new Section("Control List With ID Items", stack.ToCollection(), style: SectionStyle.Box));
            return(components);
        }
        private IEnumerable <Control> getIdListRegionBlocks()
        {
            var rs = new UpdateRegionSet();

            yield return
                (new ControlLine(
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             rs.ToSingleElementArray(),
                             DataUpdate,
                             id: "idAdd",
                             firstModificationMethod:
                             () =>
                             parametersModification.ItemIds =
                                 (parametersModification.ItemIds.Any() ? parametersModification.ItemIds.Min() - 1 : 0).ToSingleElementArray().Concat(parametersModification.ItemIds)),
                         new ButtonActionControlStyle("Add Item"),
                         usesSubmitBehavior: false)));

            var stack = ControlStack.Create(
                true,
                itemInsertionUpdateRegions:
                new ItemInsertionUpdateRegion(rs, () => parametersModification.ItemIds.First().ToString().ToSingleElementArray()).ToSingleElementArray());

            foreach (var i in info.ItemIds)
            {
                stack.AddItem(getIdItem(i));
            }

            yield return(new Box("Control List With ID Items", stack.ToSingleElementArray()));
        }
        private IEnumerable <Control> getBasicRegionBlocks()
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: "basic");

            yield return(new Paragraph(new PostBackButton(pb, new ButtonActionControlStyle("Toggle Basic Region Below"), usesSubmitBehavior: false)));

            var regionControls    = new List <Control>();
            var dynamicFieldValue = new DataValue <string>();

            if (info.Toggled)
            {
                regionControls.Add(
                    FormItem.Create(
                        "Dynamic Field",
                        new EwfTextBox("This was just added!"),
                        validationGetter: control => new EwfValidation((pbv, validator) => dynamicFieldValue.Value = control.GetPostBackValue(pbv), pb)).ToControl());
            }
            else
            {
                regionControls.Add(new Paragraph("Nothing here yet."));
            }
            yield return(new NamingPlaceholder(new Box("Basic Update Region", regionControls).ToSingleElementArray(), updateRegionSet: rs));

            pb.AddModificationMethod(() => parametersModification.Toggled = !parametersModification.Toggled);
            pb.AddModificationMethod(
                () =>
                AddStatusMessage(StatusMessageType.Info, info.Toggled ? "Dynamic field value was '{0}'.".FormatWith(dynamicFieldValue.Value) : "Dynamic field added."));
        }
Exemple #6
0
        private EwfTableItemGroup getItemGroup(int groupNumber)
        {
            var updateRegionSet = new UpdateRegionSet();

            return
                (new EwfTableItemGroup(
                     () =>
                     new EwfTableItemGroupRemainingData(
                         new PlaceHolder().AddControlsReturnThis("Group {0}".FormatWith(groupNumber).ToComponents().GetControls()),
                         groupHeadClickScript:
                         ClickScript.CreatePostBackScript(
                             PostBack.CreateIntermediate(
                                 null,
                                 id: "group{0}".FormatWith(groupNumber),
                                 firstModificationMethod: () => AddStatusMessage(StatusMessageType.Info, "You clicked group {0}.".FormatWith(groupNumber)))),
                         tailUpdateRegions: groupNumber == 1 ? new TailUpdateRegion(updateRegionSet.ToCollection(), 1).ToCollection() : null),
                     groupNumber == 1
                                                ? getItems(info.FirstGroupItemCount)
                     .Concat(
                         new Func <EwfTableItem>(
                             () =>
                             new EwfTableItem(
                                 new PostBackButton(
                                     new ButtonActionControlStyle("Add Row"),
                                     usesSubmitBehavior: false,
                                     postBack:
                                     PostBack.CreateIntermediate(
                                         updateRegionSet.ToCollection(),
                                         id: "addRow",
                                         firstModificationMethod: () => parametersModification.FirstGroupItemCount += 1)).ToCell(new TableCellSetup(fieldSpan: 2)))).ToCollection())
                                                : getItems(250)));
        }
        private IReadOnlyCollection <FlowComponent> getCommentComponents()
        {
            var components = new List <FlowComponent>();

            var createUpdateRegions = new UpdateRegionSet();

            components.AddRange(getNewCommentComponents(createUpdateRegions));

            var usersById = UsersTableRetrieval.GetRows().ToIdDictionary();

            components.Add(
                new StackList(
                    CommentsTableRetrieval.GetRows(new CommentsTableEqualityConditions.ArticleId(ArticleId))
                    .OrderByDescending(i => i.CommentId)
                    .Select(
                        i => {
                var deleteUpdateRegions = new UpdateRegionSet();
                return(new Paragraph(i.BodyText.ToComponents()).Append(getCommentFooter(i, usersById[i.AuthorId], deleteUpdateRegions))
                       .Materialize()
                       .ToComponentListItem(i.CommentId.ToString(), removalUpdateRegionSets: deleteUpdateRegions.ToCollection()));
            }),
                    setup: new ComponentListSetup(
                        classes: ElementClasses.Comment,
                        itemInsertionUpdateRegions: AppTools.User != null
                                                                                    ? new ItemInsertionUpdateRegion(
                            createUpdateRegions.ToCollection(),
                            () => commentMod.CommentId.ToString().ToCollection()).ToCollection()
                                                                                    : null)));

            return(components);
        }
Exemple #8
0
        protected override void loadData()
        {
            var updateRegionSet = new UpdateRegionSet();

            EwfUiStatics.SetPageActions(
                new ActionButtonSetup(
                    "Remove Last Group",
                    new PostBackButton(
                        PostBack.CreateIntermediate(
                            updateRegionSet.ToCollection(),
                            id: "removeLastGroup",
                            firstModificationMethod: () => {
                if (info.GroupCount <= 0)
                {
                    throw new DataModificationException("No groups to remove.");
                }
                parametersModification.GroupCount -= 1;
            }))));

            place.Controls.Add(
                EwfTable.CreateWithItemGroups(
                    Enumerable.Range(1, info.GroupCount).Select(getItemGroup),
                    defaultItemLimit: DataRowLimit.Fifty,
                    caption: "Caption",
                    subCaption: "Sub caption",
                    fields:
                    new[]
                    { new EwfTableField(size: Unit.Percentage(1), toolTip: "First column!"), new EwfTableField(size: Unit.Percentage(2), toolTip: "Second column!") },
                    headItems: new EwfTableItem("First Column", "Second Column").ToCollection(),
                    tailUpdateRegions: new TailUpdateRegion(updateRegionSet.ToCollection(), 1).ToCollection()));
        }
Exemple #9
0
        private ComponentListItem getNonIdItem(int i)
        {
            var rs = new UpdateRegionSet();

            var items = new List <ComponentListItem>();

            if (info.NonIdItemStates.ElementAt(i) == 1)
            {
                items.Add(new TextControl("Item {0}".FormatWith(i), true).ToFormItem().ToListItem());
            }
            else
            {
                items.Add("Item {0}".FormatWith(i).ToComponents().ToComponentListItem());
            }
            items.Add(
                new EwfButton(
                    new StandardButtonStyle("Toggle", buttonSize: ButtonSize.ShrinkWrap),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("nonId", i.ToString()),
                            firstModificationMethod: () => parametersModification.NonIdItemStates =
                                parametersModification.NonIdItemStates.Select(
                                    (state, index) => index == i ? (state + 1) % 2 : state))))
                .ToCollection()
                .ToComponentListItem());

            return(new StackList(items).ToCollection().ToComponentListItem(updateRegionSets: rs.ToCollection()));
        }
Exemple #10
0
        private EwfTableItemGroup getItemGroup(int groupNumber)
        {
            var updateRegionSet = new UpdateRegionSet();

            return(EwfTableItemGroup.Create(
                       () => new EwfTableItemGroupRemainingData(
                           "Group {0}".FormatWith(groupNumber).ToComponents(),
                           groupActions: groupNumber == 2
                                                              ? new ButtonSetup(
                               "Action 1",
                               behavior: new PostBackBehavior(
                                   postBack: PostBack.CreateIntermediate(
                                       null,
                                       id: PostBack.GetCompositeId(groupNumber.ToString(), "action1"),
                                       modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 1")))).Append(
                               new ButtonSetup(
                                   "Action 2",
                                   behavior: new PostBackBehavior(
                                       postBack: PostBack.CreateIntermediate(
                                           null,
                                           id: PostBack.GetCompositeId(groupNumber.ToString(), "action2"),
                                           modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 2")))))
                           .Materialize()
                                                              : null,
                           groupHeadActivationBehavior: ElementActivationBehavior.CreateButton(
                               new PostBackBehavior(
                                   postBack: PostBack.CreateIntermediate(
                                       null,
                                       id: "group{0}".FormatWith(groupNumber),
                                       modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "You clicked group {0}.".FormatWith(groupNumber))))),
                           tailUpdateRegions: groupNumber == 1 ? new TailUpdateRegion(updateRegionSet.ToCollection(), 1).ToCollection() : null),
                       groupNumber == 1
                                        ? getItems(FirstGroupItemCount, true)
                       .Concat(
                           new Func <EwfTableItem>(
                               () => EwfTableItem.Create(
                                   new EwfButton(
                                       new StandardButtonStyle("Add Row"),
                                       behavior: new PostBackBehavior(
                                           postBack: PostBack.CreateIntermediate(
                                               updateRegionSet.ToCollection(),
                                               id: "addRow",
                                               modificationMethod: () => parametersModification.FirstGroupItemCount += 1))).ToCollection()
                                   .ToCell(),
                                   "".ToCell())).ToCollection())
                                        : getItems(250, false),
                       selectedItemActions: groupNumber == 1
                                                             ? SelectedItemAction.CreateWithIntermediatePostBackBehavior <int>(
                           "Echo group IDs",
                           null,
                           ids => AddStatusMessage(
                               StatusMessageType.Info,
                               StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)))
                       .ToCollection()
                                                             : Enumerable.Empty <SelectedItemAction <int> >().Materialize()));
        }
 private FlowComponent getArticleSection(DataValue <string> filter, UpdateRegionSet resultUpdateRegions) =>
 new Section(
     new LineList(
         new[]
 {
     getUserTabComponents(filter, resultUpdateRegions), getGlobalTabComponents(filter, resultUpdateRegions),
     getTagTabComponents(filter.Value)
 }.Where(i => i.Any())
         .Select(i => (LineListItem)i.ToComponentListItem()),
         verticalAlignment: FlexboxVerticalAlignment.Center).Append <FlowComponent>(
         new FlowIdContainer(getResultTable(filter.Value).ToCollection(), updateRegionSets: resultUpdateRegions.ToCollection()))
     .Materialize());
        private ControlListItem getIdItem(int id)
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: PostBack.GetCompositeId("id", id.ToString()));

            var itemStack = ControlStack.Create(true);

            itemStack.AddControls(new EwfTextBox("ID {0}".FormatWith(id)));
            itemStack.AddControls(
                new PostBackButton(pb, new ButtonActionControlStyle("Remove", buttonSize: ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false));

            pb.AddModificationMethod(() => parametersModification.ItemIds = parametersModification.ItemIds.Where(i => i != id).ToArray());

            return(new ControlListItem(itemStack.ToSingleElementArray(), id.ToString(), removalUpdateRegionSet: rs));
        }
Exemple #13
0
        protected override PageContent getContent()
        {
            var content = new UiPageContent();

            var updateRegionSet = new UpdateRegionSet();

            content.Add(
                EwfTable.Create(
                    caption: "Caption",
                    subCaption: "Sub caption",
                    allowExportToExcel: true,
                    tableActions: new ButtonSetup(
                        "Remove Last Group",
                        behavior: new PostBackBehavior(
                            postBack: PostBack.CreateIntermediate(
                                updateRegionSet.ToCollection(),
                                id: "removeLastGroup",
                                modificationMethod: () => {
                if (GroupCount <= 0)
                {
                    throw new DataModificationException("No groups to remove.");
                }
                parametersModification.GroupCount -= 1;
            }))).ToCollection(),
                    selectedItemActions: SelectedItemAction
                    .CreateWithIntermediatePostBackBehavior <int>(
                        "Echo IDs",
                        null,
                        ids => AddStatusMessage(StatusMessageType.Info, StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)))
                    .Append(
                        SelectedItemAction.CreateWithIntermediatePostBackBehavior <int>(
                            "With confirmation",
                            null,
                            ids => AddStatusMessage(StatusMessageType.Info, StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)),
                            confirmationDialogContent: "Are you sure?".ToComponents()))
                    .Materialize(),
                    fields: new[] { new EwfTableField(size: 1.ToPercentage()), new EwfTableField(size: 2.ToPercentage()) },
                    headItems: EwfTableItem.Create("First Column".ToCell(), "Second Column".ToCell()).ToCollection(),
                    defaultItemLimit: DataRowLimit.Fifty,
                    tailUpdateRegions: new TailUpdateRegion(updateRegionSet.ToCollection(), 1).ToCollection())
                .AddItemGroups(Enumerable.Range(1, GroupCount).Select(getItemGroup).Materialize()));

            return(content);
        }
        private ComponentListItem getIdItem(int id)
        {
            var rs = new UpdateRegionSet();

            var items = new List <ComponentListItem>();

            items.Add(new TextControl("ID {0}".FormatWith(id), true).ToFormItem().ToListItem());
            items.Add(
                new EwfButton(
                    new StandardButtonStyle("Remove", buttonSize: ButtonSize.ShrinkWrap),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("id", id.ToString()),
                            modificationMethod: () => parametersModification.ItemIds = parametersModification.ItemIds.Where(i => i != id).ToArray()))).ToCollection()
                .ToComponentListItem());

            return(new StackList(items).ToCollection().ToComponentListItem(id.ToString(), removalUpdateRegionSets: rs.ToCollection()));
        }
Exemple #15
0
        private Control getItemLimitButton(DataRowLimit itemLimit, UpdateRegionSet updateRegionSet)
        {
            var text = itemLimit == DataRowLimit.Unlimited ? "All" : ((int)itemLimit).ToString();

            if (itemLimit == (DataRowLimit)CurrentItemLimit)
            {
                return(text.GetLiteralControl());
            }
            var validationDm = EwfPage.Instance.DataUpdate;             // This is a hack, but should be easily corrected when EnduraCode goal 768 is done.

            return
                (new PostBackButton(
                     PostBack.CreateIntermediate(
                         updateRegionSet.ToSingleElementArray(),
                         validationDm,
                         id: PostBack.GetCompositeId(postBackIdBase, itemLimit.ToString()),
                         firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)itemLimit)),
                     new TextActionControlStyle(text),
                     usesSubmitBehavior: false));
        }
Exemple #16
0
        private ComponentListItem getItemLimitButtonItem(DataRowLimit itemLimit, UpdateRegionSet updateRegionSet)
        {
            var text = itemLimit == DataRowLimit.Unlimited ? "All" : ((int)itemLimit).ToString();

            if (itemLimit == (DataRowLimit)CurrentItemLimit)
            {
                return(text.ToComponents().ToComponentListItem());
            }
            return
                (new EwfButton(
                     new StandardButtonStyle(text, buttonSize: ButtonSize.ShrinkWrap),
                     behavior:
                     new PostBackBehavior(
                         postBack:
                         PostBack.CreateIntermediate(
                             updateRegionSet.ToCollection(),
                             id: PostBack.GetCompositeId(postBackIdBase, itemLimit.ToString()),
                             firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)itemLimit)))).ToCollection()
                 .ToComponentListItem());
        }
Exemple #17
0
        // NOTE: This row also needs to include general actions, on the right. Don't forget about Export to Excel.
        private EwfTableItem[] getItemLimitingAndGeneralActionsItem(int fieldCount, UpdateRegionSet itemLimitingUpdateRegionSet)
        {
            if (defaultItemLimit == DataRowLimit.Unlimited)
            {
                return(new EwfTableItem[0]);
            }

            var itemCount = itemGroups.Sum(i => i.Items.Count);
            var cl        =
                new ControlLine(
                    new NamingPlaceholder(
                        "Item".ToQuantity(itemCount).GetLiteralControl().ToSingleElementArray(),
                        updateRegionSets: itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).Concat(tailUpdateRegions).SelectMany(i => i.Sets)),
                    "".GetLiteralControl(),
                    "Show:".GetLiteralControl());

            cl.AddControls(getItemLimitButton(DataRowLimit.Fifty, itemLimitingUpdateRegionSet));
            cl.AddControls(getItemLimitButton(DataRowLimit.FiveHundred, itemLimitingUpdateRegionSet));
            cl.AddControls(getItemLimitButton(DataRowLimit.Unlimited, itemLimitingUpdateRegionSet));
            return(new EwfTableItem(cl.ToCell(new TableCellSetup(fieldSpan: fieldCount))).ToSingleElementArray());
        }
        private ControlListItem getNonIdItem(int i)
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: PostBack.GetCompositeId("nonId", i.ToString()));

            var itemStack = ControlStack.Create(true);

            if (info.NonIdItemStates.ElementAt(i) == 1)
            {
                itemStack.AddControls(new EwfTextBox("Item {0}".FormatWith(i)));
            }
            else
            {
                itemStack.AddText("Item {0}".FormatWith(i));
            }
            itemStack.AddControls(
                new PostBackButton(pb, new ButtonActionControlStyle("Toggle", buttonSize: ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false));

            pb.AddModificationMethod(
                () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Select((state, index) => index == i ? (state + 1) % 2 : state));

            return(new ControlListItem(itemStack.ToSingleElementArray(), updateRegionSet: rs));
        }
        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));
        }
Exemple #20
0
        private static PhrasingComponent getFavoriteActionComponent(
            ArticlesRetrieval.Row article, ILookup <int, FavoritesTableRetrieval.Row> favoritesByArticleId)
        {
            var count = favoritesByArticleId[article.ArticleId].Count().ToString();

            if (AppTools.User == null)
            {
                return(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o")))));
            }

            var       rs = new UpdateRegionSet();
            EwfButton button;

            if (FavoritesTableRetrieval.GetRowMatchingPk(AppTools.User.UserId, article.ArticleId, returnNullIfNoMatch: true) == null)
            {
                button = new EwfButton(
                    new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o"))),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("favorite", article.ArticleId.ToString()),
                            modificationMethod: () => FavoritesModification.InsertRow(AppTools.User.UserId, article.ArticleId))));
            }
            else
            {
                button = new EwfButton(
                    new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart"))),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("unfavorite", article.ArticleId.ToString()),
                            modificationMethod: () => FavoritesModification.DeleteRows(
                                new FavoritesTableEqualityConditions.UserId(AppTools.User.UserId),
                                new FavoritesTableEqualityConditions.ArticleId(article.ArticleId)))));
            }
            return(new PhrasingIdContainer(button.ToCollection(), updateRegionSets: rs.ToCollection()));
        }
Exemple #21
0
        private IReadOnlyCollection <FlowComponent> getNonIdListRegionComponents()
        {
            var components = new List <FlowComponent>();

            var addRs    = new UpdateRegionSet();
            var removeRs = new UpdateRegionSet();

            components.Add(
                new LineList(
                    new EwfButton(
                        new StandardButtonStyle("Add Two Items"),
                        behavior: new PostBackBehavior(
                            postBack: PostBack.CreateIntermediate(
                                addRs.ToCollection(),
                                id: "nonIdAdd",
                                firstModificationMethod: () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Concat(new[] { 0, 0 }))))
                    .ToCollection()
                    .Append(
                        new EwfButton(
                            new StandardButtonStyle("Remove Two Items"),
                            behavior: new PostBackBehavior(
                                postBack: PostBack.CreateIntermediate(
                                    removeRs.ToCollection(),
                                    id: "nonIdRemove",
                                    firstModificationMethod: () =>
                                    parametersModification.NonIdItemStates =
                                        parametersModification.NonIdItemStates.Take(parametersModification.NonIdItemStates.Count() - 2)))))
                    .Select(i => (LineListItem)i.ToCollection().ToComponentListItem())));

            var stack = new StackList(
                Enumerable.Range(0, info.NonIdItemStates.Count()).Select(getNonIdItem),
                setup: new ComponentListSetup(
                    tailUpdateRegions: new[] { new TailUpdateRegion(addRs.ToCollection(), 0), new TailUpdateRegion(removeRs.ToCollection(), 2) }));

            components.Add(new Section("Control List With Non-ID Items", stack.ToCollection(), style: SectionStyle.Box));
            return(components);
        }
        private FormItem getTagFormItem(DataValue <IReadOnlyCollection <int> > tagIds)
        {
            var addUpdateRegions    = new UpdateRegionSet();
            var tagName             = new DataValue <string>();
            var removeUpdateRegions = new UpdateRegionSet();

            return(new FlowIdContainer(
                       FormState.ExecuteWithDataModificationsAndDefaultAction(
                           PostBack.CreateIntermediate(addUpdateRegions.ToCollection(), id: "addTag", modificationMethod: () => addTag(tagIds, tagName)).ToCollection(),
                           () => new TextControl(
                               "",
                               false,
                               maxLength: TagsTable.TagNameColumn.Size,
                               validationMethod: (postBackValue, validator) => tagName.Value = postBackValue))
                       .ToFormItem()
                       .ToComponentCollection(),
                       updateRegionSets: addUpdateRegions.ToCollection()).Append <FlowComponent>(new LineBreak())
                   .Append(
                       new PhrasingIdContainer(
                           getTagListComponents(tagIds, removeUpdateRegions),
                           updateRegionSets: addUpdateRegions.ToCollection().Append(removeUpdateRegions)))
                   .Materialize()
                   .ToFormItem(label: "Enter tags".ToComponents()));
        }
        protected override PageContent getContent()
        {
            var content = new UiPageContent();

            if (AppTools.User == null)
            {
                content.Add(
                    new GenericFlowContainer(
                        new GenericFlowContainer("Conduit".ToComponents()).Append <FlowComponent>(new Paragraph("A place to share your knowledge.".ToComponents()))
                        .Materialize(),
                        classes: ElementClasses.Banner));
            }

            var filter = ComponentStateItem.Create("filter", AppTools.User != null ? "user" : "global", v => true, false);
            var resultUpdateRegions = new UpdateRegionSet();

            content.Add(
                new GenericFlowContainer(
                    getArticleSection(filter.Value, resultUpdateRegions).Append(getTagSection(filter.Value, resultUpdateRegions)).Materialize(),
                    classes: ElementClasses.HomeContainer,
                    etherealContent: filter.ToCollection()));

            return(content);
        }
Exemple #24
0
        private IEnumerable <FlowComponent> getBasicRegionComponents()
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToCollection(), id: "basic");

            yield return(new Paragraph(
                             new EwfButton(new StandardButtonStyle("Toggle Basic Region Below"), behavior: new PostBackBehavior(postBack: pb)).ToCollection()));

            var regionComponents  = new List <FlowComponent>();
            var dynamicFieldValue = new DataValue <string>();

            FormState.ExecuteWithDataModificationsAndDefaultAction(
                pb.ToCollection(),
                () => {
                if (info.Toggled)
                {
                    regionComponents.AddRange(
                        dynamicFieldValue.ToTextControl(true, value: "This was just added!")
                        .ToFormItem(label: "Dynamic Field".ToComponents())
                        .ToComponentCollection());
                }
                else
                {
                    regionComponents.Add(new Paragraph("Nothing here yet.".ToComponents()));
                }
            });
            yield return(new FlowIdContainer(
                             new Section("Basic Update Region", regionComponents, style: SectionStyle.Box).ToCollection(),
                             updateRegionSets: rs.ToCollection()));

            pb.AddModificationMethod(() => parametersModification.Toggled = !parametersModification.Toggled);
            pb.AddModificationMethod(
                () => AddStatusMessage(
                    StatusMessageType.Info,
                    info.Toggled ? "Dynamic field value was '{0}'.".FormatWith(dynamicFieldValue.Value) : "Dynamic field added."));
        }
        private IReadOnlyCollection <PhrasingComponent> getGlobalTabComponents(DataValue <string> filter, UpdateRegionSet resultUpdateRegions)
        {
            const string label = "Global Feed";

            return(filter.Value != "user" && !filter.Value.StartsWith("tag")
                                       ? label.ToComponents()
                                       : new EwfButton(
                       new StandardButtonStyle(label),
                       behavior: new PostBackBehavior(
                           postBack: PostBack.CreateIntermediate(
                               resultUpdateRegions.ToCollection(),
                               id: "global",
                               modificationMethod: () => filter.Value = "global"))).ToCollection());
        }
        private IReadOnlyCollection <PhrasingComponent> getUserTabComponents(DataValue <string> filter, UpdateRegionSet resultUpdateRegions)
        {
            const string label = "Your Feed";

            return(AppTools.User != null
                                       ? filter.Value == "user" ? label.ToComponents() :
                   new EwfButton(
                       new StandardButtonStyle(label),
                       behavior: new PostBackBehavior(
                           postBack: PostBack.CreateIntermediate(
                               resultUpdateRegions.ToCollection(),
                               id: "user",
                               modificationMethod: () => filter.Value = "user"))).ToCollection()
                                       : Enumerable.Empty <PhrasingComponent>().Materialize());
        }
 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();
 /// <summary>
 /// Creates a tail update region, which you can use to append items to a list, truncate a list, and/or modify the items at the end of a list.
 /// </summary>
 /// <param name="set"></param>
 /// <param name="updatingItemCount">Pass zero if you only want to append items.</param>
 public TailUpdateRegion( UpdateRegionSet set, int updatingItemCount )
 {
     Set = set;
     UpdatingItemCount = updatingItemCount;
 }
Exemple #29
0
        // NOTE: This row also needs to include general actions, on the right. Don't forget about Export to Excel.
        private IReadOnlyCollection <EwfTableItem> getItemLimitingAndGeneralActionsItem(int fieldCount, UpdateRegionSet itemLimitingUpdateRegionSet)
        {
            if (defaultItemLimit == DataRowLimit.Unlimited)
            {
                return(new EwfTableItem[0]);
            }

            var itemCount = itemGroups.Sum(i => i.Items.Count);
            var list      =
                new LineList(
                    ((LineListItem)
                     new PhrasingIdContainer(
                         "Item".ToQuantity(itemCount).ToComponents(),
                         updateRegionSets:
                         itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).ToImmutableArray().Concat(tailUpdateRegions).SelectMany(i => i.Sets))
                     .ToCollection().ToComponentListItem()).ToCollection()
                    .Concat("".ToComponents().ToComponentListItem())
                    .Concat("Show:".ToComponents().ToComponentListItem())
                    .Concat(getItemLimitButtonItem(DataRowLimit.Fifty, itemLimitingUpdateRegionSet))
                    .Concat(getItemLimitButtonItem(DataRowLimit.FiveHundred, itemLimitingUpdateRegionSet))
                    .Concat(getItemLimitButtonItem(DataRowLimit.Unlimited, itemLimitingUpdateRegionSet)));

            return(new EwfTableItem(list.ToCollection().GetControls().ToCell(new TableCellSetup(fieldSpan: fieldCount))).ToCollection());
        }
Exemple #30
0
        void ControlTreeDataLoader.LoadData()
        {
            using (MiniProfiler.Current.Step("EWF - Load table data")) {
                FormState.ExecuteWithDataModificationsAndDefaultAction(
                    dataModifications,
                    () => {
                    if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any()))
                    {
                        Visible = false;
                        return;
                    }

                    SetUpTableAndCaption(this, style, classes, caption, subCaption);

                    var visibleItemGroupsAndItems = new List <Tuple <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> > >();
                    foreach (var itemGroup in itemGroups)
                    {
                        var visibleItems = itemGroup.Items.Take(CurrentItemLimit - visibleItemGroupsAndItems.Sum(i => i.Item2.Count)).Select(i => i());
                        visibleItemGroupsAndItems.Add(Tuple.Create <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> >(itemGroup, visibleItems.ToImmutableArray()));
                        if (visibleItemGroupsAndItems.Sum(i => i.Item2.Count) == CurrentItemLimit)
                        {
                            break;
                        }
                    }

                    var fields = GetFields(specifiedFields, headItems.AsReadOnly(), visibleItemGroupsAndItems.SelectMany(i => i.Item2));
                    if (!fields.Any())
                    {
                        fields = new EwfTableField().ToCollection();
                    }

                    addColumnSpecifications(fields);

                    var allVisibleItems = new List <EwfTableItem>();

                    var itemLimitingUpdateRegionSet = new UpdateRegionSet();
                    var headRows =
                        buildRows(
                            getItemLimitingAndGeneralActionsItem(fields.Count, itemLimitingUpdateRegionSet).Concat(getItemActionsItem(fields.Count)).ToList(),
                            Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(),
                            null,
                            false,
                            null,
                            null,
                            allVisibleItems).Concat(buildRows(headItems, fields, null, true, null, null, allVisibleItems)).ToArray();
                    if (headRows.Any())
                    {
                        Controls.Add(new WebControl(HtmlTextWriterTag.Thead).AddControlsReturnThis(headRows));
                    }

                    var bodyRowGroupsAndRows = new List <Tuple <WebControl, ImmutableArray <Control> > >();
                    var updateRegionSetListsAndStaticRowGroupCounts = new List <Tuple <IReadOnlyCollection <UpdateRegionSet>, int> >();
                    for (var visibleGroupIndex = 0; visibleGroupIndex < visibleItemGroupsAndItems.Count; visibleGroupIndex += 1)
                    {
                        var groupAndItems          = visibleItemGroupsAndItems[visibleGroupIndex];
                        var useContrastForFirstRow = visibleItemGroupsAndItems.Where((group, i) => i < visibleGroupIndex).Sum(i => i.Item2.Count) % 2 == 1;
                        var groupBodyRows          = buildRows(groupAndItems.Item2, fields, useContrastForFirstRow, false, null, null, allVisibleItems).ToImmutableArray();
                        var rowGroup =
                            new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                                buildRows(
                                    groupAndItems.Item1.GetHeadItems(fields.Count),
                                    Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(),
                                    null,
                                    true,
                                    null,
                                    null,
                                    allVisibleItems).Concat(new NamingPlaceholder(groupBodyRows).ToCollection()));
                        bodyRowGroupsAndRows.Add(Tuple.Create(rowGroup, groupBodyRows));

                        var cachedVisibleGroupIndex = visibleGroupIndex;
                        EwfPage.Instance.AddUpdateRegionLinker(
                            new LegacyUpdateRegionLinker(
                                rowGroup,
                                "tail",
                                from region in groupAndItems.Item1.RemainingData.Value.TailUpdateRegions
                                let staticRowCount = itemGroups[cachedVisibleGroupIndex].Items.Count - region.UpdatingItemCount
                                                     select new LegacyPreModificationUpdateRegion(region.Sets, () => groupBodyRows.Skip(staticRowCount), staticRowCount.ToString),
                                arg => groupBodyRows.Skip(int.Parse(arg))));

                        // If item limiting is enabled, include all subsequent item groups in tail update regions since any number of items could be appended.
                        if (defaultItemLimit != DataRowLimit.Unlimited)
                        {
                            updateRegionSetListsAndStaticRowGroupCounts.Add(
                                Tuple.Create <IReadOnlyCollection <UpdateRegionSet>, int>(
                                    groupAndItems.Item1.RemainingData.Value.TailUpdateRegions.SelectMany(i => i.Sets).ToImmutableArray(),
                                    visibleGroupIndex + 1));
                        }
                    }
                    Controls.Add(new NamingPlaceholder(bodyRowGroupsAndRows.Select(i => i.Item1)));

                    if (defaultItemLimit != DataRowLimit.Unlimited)
                    {
                        var oldItemLimit   = CurrentItemLimit;
                        var lowerItemLimit = new Lazy <int>(() => Math.Min(oldItemLimit, CurrentItemLimit));

                        var itemLimitingTailUpdateRegionControlGetter = new Func <int, IEnumerable <Control> >(
                            staticItemCount => {
                            var rowCount = 0;
                            for (var groupIndex = 0; groupIndex < bodyRowGroupsAndRows.Count; groupIndex += 1)
                            {
                                var rows  = bodyRowGroupsAndRows[groupIndex].Item2;
                                rowCount += rows.Length;
                                if (rowCount < staticItemCount)
                                {
                                    continue;
                                }
                                return(rows.Skip(rows.Length - (rowCount - staticItemCount)).Concat(bodyRowGroupsAndRows.Skip(groupIndex + 1).Select(i => i.Item1)));
                            }
                            return(ImmutableArray <Control> .Empty);
                        });

                        EwfPage.Instance.AddUpdateRegionLinker(
                            new LegacyUpdateRegionLinker(
                                this,
                                "itemLimitingTail",
                                new LegacyPreModificationUpdateRegion(
                                    itemLimitingUpdateRegionSet.ToCollection(),
                                    () => itemLimitingTailUpdateRegionControlGetter(lowerItemLimit.Value),
                                    () => lowerItemLimit.Value.ToString()).ToCollection(),
                                arg => itemLimitingTailUpdateRegionControlGetter(int.Parse(arg))));
                    }

                    EwfPage.Instance.AddUpdateRegionLinker(
                        new LegacyUpdateRegionLinker(
                            this,
                            "tail",
                            from region in
                            tailUpdateRegions.Select(i => new { sets = i.Sets, staticRowGroupCount = itemGroups.Count - i.UpdatingItemCount })
                            .Concat(updateRegionSetListsAndStaticRowGroupCounts.Select(i => new { sets = i.Item1, staticRowGroupCount = i.Item2 }))
                            select
                            new LegacyPreModificationUpdateRegion(
                                region.sets,
                                () => bodyRowGroupsAndRows.Skip(region.staticRowGroupCount).Select(i => i.Item1),
                                region.staticRowGroupCount.ToString),
                            arg => bodyRowGroupsAndRows.Skip(int.Parse(arg)).Select(i => i.Item1)));

                    var itemCount            = itemGroups.Sum(i => i.Items.Count);
                    var itemLimitingRowGroup = new List <Control>();
                    if (CurrentItemLimit < itemCount)
                    {
                        var nextLimit          = EnumTools.GetValues <DataRowLimit>().First(i => i > (DataRowLimit)CurrentItemLimit);
                        var itemIncrementCount = Math.Min((int)nextLimit, itemCount) - CurrentItemLimit;
                        var button             = new PostBackButton(
                            new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")),
                            usesSubmitBehavior: false,
                            postBack:
                            PostBack.CreateIntermediate(
                                itemLimitingUpdateRegionSet.ToCollection(),
                                id: PostBack.GetCompositeId(postBackIdBase, "showMore"),
                                firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit)));
                        var item        = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Count)));
                        var useContrast = visibleItemGroupsAndItems.Sum(i => i.Item2.Count) % 2 == 1;
                        itemLimitingRowGroup.Add(
                            new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                                buildRows(
                                    item.ToCollection().ToList(),
                                    Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(),
                                    useContrast,
                                    false,
                                    null,
                                    null,
                                    allVisibleItems)));
                    }
                    Controls.Add(
                        new NamingPlaceholder(
                            itemLimitingRowGroup,
                            updateRegionSets:
                            itemLimitingUpdateRegionSet.ToCollection()
                            .Concat(
                                itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).ToImmutableArray().Concat(tailUpdateRegions).SelectMany(i => i.Sets))));

                    // Assert that every visible item in the table has the same number of cells and store a data structure for below.
                    var cellPlaceholderListsForItems = TableOps.BuildCellPlaceholderListsForItems(allVisibleItems, fields.Count);

                    if (!disableEmptyFieldDetection)
                    {
                        AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems);
                    }
                });
            }
        }
 private FlowComponent getCommentFooter(CommentsTableRetrieval.Row comment, UsersTableRetrieval.Row author, UpdateRegionSet deleteUpdateRegions) =>
 new GenericFlowContainer(
     new GenericFlowContainer(
         new GenericPhrasingContainer(
             new EwfHyperlink(
                 Profile.GetInfo(comment.AuthorId),
                 new ImageHyperlinkStyle(
                     new ExternalResource(
                         author.ProfilePictureUrl.Any() ? author.ProfilePictureUrl : "https://static.productionready.io/images/smiley-cyrus.jpg"),
                     "")).ToCollection())
         .Append(
             new GenericPhrasingContainer(
                 new EwfHyperlink(Profile.GetInfo(comment.AuthorId), new StandardHyperlinkStyle(author.Username)).ToCollection()))
         .Append(new GenericPhrasingContainer(comment.CreationDateAndTime.ToDayMonthYearString(false).ToComponents()))
         .Materialize()).Concat <FlowComponent>(
         comment.AuthorId == AppTools.User?.UserId
                                                 ? new EwfButton(
             new StandardButtonStyle("Delete", icon: new ActionComponentIcon(new FontAwesomeIcon("fa-trash"))),
             behavior: new PostBackBehavior(
                 postBack: PostBack.CreateIntermediate(
                     deleteUpdateRegions.ToCollection(),
                     id: PostBack.GetCompositeId("delete", comment.CommentId.ToString()),
                     modificationMethod: () => CommentsModification.DeleteRows(new CommentsTableEqualityConditions.CommentId(comment.CommentId)))))
         .ToCollection()
                                                 : Enumerable.Empty <PhrasingComponent>())
     .Materialize());