예제 #1
0
        private static void AddRowHeaders(IPaper paper, Entity entity, PaperContext ctx, DataWrapperEnumerable rows)
        {
            // Adicionando os campos autodetectados
            //
            var keys = rows.EnumerateKeys().ToArray();

            foreach (var key in keys)
            {
                var header = rows.GetHeader(key);
                entity.AddRowHeader(header);
            }

            // Adicionando os campos personalizados
            //
            var headers = paper._Call <IEnumerable <HeaderInfo> >("GetRowHeaders", rows.DataSource);

            if (headers != null)
            {
                if (!(headers is IList))
                {
                    headers = headers.ToArray();
                }

                entity.AddRowHeaders(headers);

                // Ocultando as colunas não personalizadas
                //
                entity.ForEachRowHeader((e, h) =>
                {
                    h.Hidden = !headers.Any(x => x.Name.EqualsIgnoreCase(h.Name));
                });
            }

            // Adicionando informação de ordenação
            //
            var sort = paper._Get <Sort>("Sort");

            if (sort != null)
            {
                entity.ForEachRowHeader((e, h) =>
                                        AddRowHeaderSortInfo(paper, ctx, sort, e, h)
                                        );
            }
        }
예제 #2
0
        private static void AddRowsAndLinks(IPaper paper, Entity entity, PaperContext ctx, DataWrapperEnumerable cards)
        {
            var keys = cards.EnumerateKeys().ToArray();

            foreach (DataWrapper card in cards)
            {
                var rowEntity = new Entity();
                rowEntity.AddRel(Rel.Card);

                foreach (var key in keys)
                {
                    var value = card.GetValue(key);
                    rowEntity.AddProperty(key, value);
                }

                var linkRenderers = paper._Call <IEnumerable <ILink> >("GetCardLinks", card.DataSource);
                if (linkRenderers != null)
                {
                    foreach (var linkRenderer in linkRenderers)
                    {
                        var link = linkRenderer.RenderLink(ctx);
                        if (link != null)
                        {
                            link.Rel?.Remove(RelNames.Link);
                            var isSelf = (link.Rel?.Contains(RelNames.Self) == true);
                            if (!isSelf)
                            {
                                link.AddRel(RelNames.Self);
                            }
                            rowEntity.AddLink(link);
                        }
                    }
                }

                entity.AddEntity(rowEntity);
            }
        }