Skip to content

Instantly share code, notes, and snippets.

@PNergard
Last active October 17, 2016 21:40
Show Gist options
  • Save PNergard/34d63e748650ee106bdb1edbaf335540 to your computer and use it in GitHub Desktop.
Save PNergard/34d63e748650ee106bdb1edbaf335540 to your computer and use it in GitHub Desktop.
A simple .aspx page that get all pages from Root-level and presents how many pages each editor has created as a simple html table.
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="EditorScoreBoard.aspx.cs" Inherits="AlloyDemoKit.EditorScoreBoard" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.datagrid table {
border-collapse: collapse;
text-align: left;
width: 100%;
}
.datagrid {
font: normal 12px/150% Arial, Helvetica, sans-serif;
background: #fff;
overflow: hidden;
border: 1px solid #006699;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.datagrid table td, .datagrid table th {
padding: 3px 10px;
}
.datagrid table thead th {
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #006699), color-stop(1, #00557F) );
background: -moz-linear-gradient( center top, #006699 5%, #00557F 100% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#006699', endColorstr='#00557F');
background-color: #006699;
color: #FFFFFF;
font-size: 15px;
font-weight: bold;
border-left: 1px solid #0070A8;
}
.datagrid table thead th:first-child {
border: none;
}
.datagrid table tbody td {
color: #00496B;
border-left: 1px solid #E1EEF4;
font-size: 12px;
font-weight: normal;
}
.datagrid table tbody .alt td {
background: #E1EEF4;
color: #00496B;
}
.datagrid table tbody td:first-child {
border-left: none;
}
.datagrid table tbody tr:last-child td {
border-bottom: none;
}
.datagrid table tfoot td div {
border-top: 1px solid #006699;
background: #E1EEF4;
}
.datagrid table tfoot td {
padding: 0;
font-size: 12px;
}
.datagrid table tfoot td div {
padding: 2px;
}
.datagrid table tfoot td ul {
margin: 0;
padding: 0;
list-style: none;
text-align: right;
}
.datagrid table tfoot li {
display: inline;
}
.datagrid table tfoot li a {
text-decoration: none;
display: inline-block;
padding: 2px 8px;
margin: 1px;
color: #FFFFFF;
border: 1px solid #006699;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #006699), color-stop(1, #00557F) );
background: -moz-linear-gradient( center top, #006699 5%, #00557F 100% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#006699', endColorstr='#00557F');
background-color: #006699;
}
.datagrid table tfoot ul.active, .datagrid table tfoot ul a:hover {
text-decoration: none;
border-color: #006699;
color: #FFFFFF;
background: none;
background-color: #00557F;
}
div.dhtmlx_window_active, div.dhx_modal_cover_dv {
position: fixed !important;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="datagrid">
<asp:Repeater ID="rptHighScore" runat="server">
<HeaderTemplate>
<table style="border: double;">
<thead>
<tr style="border-bottom: initial;">
<th>Name</th>
<th>Total created</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Name")%></td>
<td><%# Eval("Count")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody></table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
using EPiServer;
using EPiServer.Core;
using EPiServer.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AlloyDemoKit
{
public partial class EditorScoreBoard : SimplePage
{
IContentRepository repository = ServiceLocator.Current.GetInstance<IContentRepository>();
protected override void OnLoad(EventArgs e)
{
List<PageData> allPages = new List<PageData>();
FindDescendants(repository.Get<PageData>(ContentReference.RootPage), allPages);
var groupedResult = allPages.GroupBy(p => p.CreatedBy).
Select(group =>
new
{
Name = group.Key,
Count = group.Count()
});
rptHighScore.DataSource = groupedResult.OrderByDescending(r => r.Count);
rptHighScore.DataBind();
}
private void FindDescendants(PageData page, List<PageData> descendants)
{
var children = repository.GetChildren<PageData>(page.ContentLink);
foreach (var child in children)
{
if (child is PageData)
{
descendants.Add(child as PageData);
}
FindDescendants(child, descendants);
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AlloyDemoKit {
public partial class EditorScoreBoard {
/// <summary>
/// form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// rptHighScore control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Repeater rptHighScore;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment