private static List <GroupingViewComponent> GroupArticles(IEnumerable <Entry> entries, List <List <int> > layouts) { List <GroupingViewComponent> groupingViews = new List <GroupingViewComponent>(); LinkedList <Entry> list = new LinkedList <Entry>(entries); List <Entry> splits = new List <Entry>(); var head = list.First; int i = 0; var layout = layouts[0]; var layoutSize = layout.Count(e => e <= 12); while (head != null) { splits.Add(head.Value); head = head.Next; // number of elements is higher than current layout size if (splits.Count == layoutSize || head == null) { groupingViews.Add(GroupingViewComponent.ToViewModel(new Models.ViewModels.GroupingViewModel() { Grid = ArrangeArticles(splits, layout) })); if (head != null && i++ > layouts.Count - 1) { break; } layout = layouts[i]; layoutSize = layout.Count(e => e <= 12); splits = new List <Entry>(); } } return(groupingViews); }
private GroupingViewComponent GroupArticles( List <BasicArticle> entries, IEnumerable <int> layout) { List <RowViewComponent> rows = new List <RowViewComponent>(); int currWidth = 0; List <ViewComponent> components = new List <ViewComponent>(); List <ColumnViewComponent> columns = new List <ColumnViewComponent>(); int i = 0; foreach (var block in layout) { switch (block) { case 3: columns.Add(new ColumnViewComponent() { Width = block, Components = new List <ViewComponent>() { VerticalNarrowBlockViewComponent.ToViewModel(entries[i], columns.Count > 0) }, Rows = null }); currWidth += block; break; case 9: columns.Add(new ColumnViewComponent() { Width = block, Components = new List <ViewComponent>() { HorizontalLargeBlockViewComponent.ToViewModel(entries[i], columns.Count > 0) }, Rows = null }); currWidth += block; break; case 5: case 6: columns.Add(new ColumnViewComponent() { Width = block, Components = new List <ViewComponent>() { VerticalBlockViewComponent.ToViewModel(entries[i], columns.Count > 0) }, Rows = null }); currWidth += block; break; case 7: if (components.Any()) { components.Add(HorizontalMediumBlockViewComponent.ToViewModel(entries[i], columns.Count > 0)); columns.Add(new ColumnViewComponent() { Width = block, Components = components, Rows = null }); currWidth += block; components = new List <ViewComponent>(); } else { components.Add(HorizontalMediumBlockViewComponent.ToViewModel(entries[i], columns.Count > 0)); } break; } if (currWidth >= 12) { rows.Add(new RowViewComponent() { Columns = columns }); currWidth = 0; columns = new List <ColumnViewComponent>(); } ++i; } return(GroupingViewComponent.ToViewModel(new GroupingViewModel() { Grid = rows })); }