Skip to content

Commit dba9a9f

Browse files
authored
Merge pull request #98 from telerik/tilelayout-add-remove-tiles
kb-tilelayout-add-remove-tiles
2 parents 1db7699 + fe020ea commit dba9a9f

33 files changed

+958
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30907.101
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AddRemoveTiles", "AddRemoveTiles\AddRemoveTiles.csproj", "{8C7C76F1-E9B7-423D-8C67-E20C8A32B42C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8C7C76F1-E9B7-423D-8C67-E20C8A32B42C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8C7C76F1-E9B7-423D-8C67-E20C8A32B42C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8C7C76F1-E9B7-423D-8C67-E20C8A32B42C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8C7C76F1-E9B7-423D-8C67-E20C8A32B42C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {DB4DA000-662F-4EF7-A507-DCAA9C6D5ABF}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
4+
<PropertyGroup>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.24.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<Content Update="wwwroot\css\site.css">
14+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
15+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
16+
</Content>
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<h1>Page not found</h1>
7+
<p>Sorry, but there's nothing here!</p>
8+
</NotFound>
9+
</Router>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace AddRemoveTiles.Components.Tiles
4+
{
5+
public class ResizeContext
6+
{
7+
public event EventHandler OnResizeInvoked;
8+
9+
public void NotifyResizeInvoked()
10+
{
11+
OnResizeInvoked.Invoke(null, new EventArgs());
12+
}
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@using AddRemoveTiles.Components.Tiles
2+
@using AddRemoveTiles.Models
3+
4+
@switch (TileContent)
5+
{
6+
case "TotalStreams":
7+
<TotalStreams></TotalStreams>
8+
break;
9+
case "TotalDownloads":
10+
<TotalDownloads></TotalDownloads>
11+
break;
12+
case "TotalReach":
13+
<TotalReach></TotalReach>
14+
break;
15+
case "TotalRevenue":
16+
<TotalRevenue></TotalRevenue>
17+
break;
18+
case "WeeklyRecap":
19+
<WeeklyRecap Podcasts="@Podcasts"></WeeklyRecap>
20+
break;
21+
case "PerformanceTrend":
22+
<PerformanceTrend Podcasts="@Podcasts"></PerformanceTrend>
23+
break;
24+
case "TopEpisodes":
25+
<TopEpisodes Podcasts="@Podcasts"></TopEpisodes>
26+
break;
27+
28+
default:
29+
break;
30+
}
31+
32+
33+
@code {
34+
[Parameter]
35+
public string TileContent { get; set; }
36+
37+
[Parameter]
38+
public IEnumerable<PodcastViewModel> Podcasts { get; set; }
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Microsoft.AspNetCore.Components;
3+
4+
namespace AddRemoveTiles.Components.Tiles
5+
{
6+
public abstract class ChartTileContentBase : ComponentBase, IDisposable
7+
{
8+
[CascadingParameter]
9+
public ResizeContext ResizeContext { get; set; }
10+
11+
protected override void OnInitialized()
12+
{
13+
if (ResizeContext != null)
14+
{
15+
ResizeContext.OnResizeInvoked += Resize;
16+
}
17+
18+
base.OnInitialized();
19+
}
20+
21+
public void Dispose()
22+
{
23+
if (ResizeContext != null)
24+
{
25+
ResizeContext.OnResizeInvoked -= Resize;
26+
}
27+
}
28+
29+
public abstract void Resize(object sender, EventArgs e);
30+
}
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@using AddRemoveTiles.Models
2+
3+
@inherits ChartTileContentBase
4+
5+
<TelerikChart Width="100%" Height="100%" @ref="@ChartRef">
6+
<ChartSeriesItems>
7+
<ChartSeries Type="@ChartSeriesType.Column"
8+
Data="@Podcasts"
9+
Field="@( nameof(PodcastViewModel.Views) )"
10+
CategoryField="@( nameof(PodcastViewModel.Date) )"
11+
Aggregate="@ChartSeriesAggregate.Sum">
12+
</ChartSeries>
13+
</ChartSeriesItems>
14+
<ChartCategoryAxes>
15+
<ChartCategoryAxis Type="@ChartCategoryAxisType.Date" BaseUnit="@ChartCategoryAxisBaseUnit.Fit">
16+
<ChartCategoryAxisLabels Format="{0:d MMM}">
17+
<ChartCategoryAxisLabelsRotation Angle="@LabelsRotation" />
18+
</ChartCategoryAxisLabels>
19+
<ChartCategoryAxisMajorGridLines Visible="false" />
20+
<ChartCategoryAxisMajorTicks Visible="false" />
21+
</ChartCategoryAxis>
22+
</ChartCategoryAxes>
23+
<ChartValueAxes>
24+
<ChartValueAxis>
25+
<ChartValueAxisLabels Step="3" />
26+
</ChartValueAxis>
27+
</ChartValueAxes>
28+
</TelerikChart>
29+
30+
@code {
31+
[Parameter]
32+
public IEnumerable<PodcastViewModel> Podcasts { get; set; }
33+
34+
TelerikChart ChartRef { get; set; }
35+
36+
string LabelsRotation = "auto";
37+
38+
public override void Resize(object sender, EventArgs e)
39+
{
40+
ChartRef.Refresh();
41+
}
42+
}
43+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@using AddRemoveTiles.Models
2+
@using Telerik.DataSource
3+
@using Telerik.DataSource.Extensions
4+
5+
<TelerikGrid Data=@TopNPodcasts TotalCount=@Total OnRead=@ReadItems
6+
Sortable="true" Height="100%" Pageable="false" ScrollMode="@GridScrollMode.Scrollable"
7+
OnStateInit="@((GridStateEventArgs<PodcastViewModel> args) => OnStateInit(args))">
8+
<GridColumns>
9+
<GridColumn Field="@( nameof(PodcastViewModel.Name) )" Title="Podcast Episode" Width="320px" />
10+
<GridColumn Field="@( nameof(PodcastViewModel.Streams) )" Width="150px" />
11+
<GridColumn Field="@( nameof(PodcastViewModel.Downloads) )" Width="150px" />
12+
</GridColumns>
13+
</TelerikGrid>
14+
15+
@code {
16+
[Parameter]
17+
public IEnumerable<PodcastViewModel> Podcasts { get; set; }
18+
19+
[Parameter]
20+
public int TopN { get; set; } = 5;
21+
22+
IEnumerable<PodcastViewModel> TopNPodcasts { get; set; }
23+
int Total { get; set; }
24+
DataSourceRequest CurrentRequest { get; set; }
25+
26+
protected void ReadItems(GridReadEventArgs args)
27+
{
28+
CurrentRequest = args.Request;
29+
UpdateTopEpisodes();
30+
}
31+
32+
void UpdateTopEpisodes()
33+
{
34+
if (CurrentRequest != null && Podcasts != null)
35+
{
36+
CurrentRequest.PageSize = 5;
37+
var datasourceResult = Podcasts.ToDataSourceResult(CurrentRequest);
38+
39+
TopNPodcasts = (datasourceResult.Data as IEnumerable<PodcastViewModel>).ToList();
40+
Total = datasourceResult.Total;
41+
42+
StateHasChanged();
43+
}
44+
}
45+
46+
protected override void OnParametersSet()
47+
{
48+
UpdateTopEpisodes();
49+
base.OnParametersSet();
50+
}
51+
52+
void OnStateInit(GridStateEventArgs<PodcastViewModel> args)
53+
{
54+
args.GridState = new GridState<PodcastViewModel>()
55+
{
56+
SortDescriptors = new List<SortDescriptor>
57+
{
58+
new SortDescriptor { Member = nameof(PodcastViewModel.Streams), SortDirection = ListSortDirection.Descending }
59+
}
60+
};
61+
}
62+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@using AddRemoveTiles.Services
2+
3+
@inject DashboardDataService DataService
4+
5+
<h2>@Downloads.ToString("N0")</h2>
6+
7+
@code{
8+
int Downloads { get; set; }
9+
protected override async Task OnInitializedAsync()
10+
{
11+
Downloads = await DataService.GetDownloads();
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@using AddRemoveTiles.Services
2+
3+
@inject DashboardDataService DataService
4+
5+
<h2>@Reach.ToString("N0")</h2>
6+
7+
@code{
8+
int Reach { get; set; }
9+
protected override async Task OnInitializedAsync()
10+
{
11+
Reach = await DataService.GetReach();
12+
}
13+
}

0 commit comments

Comments
 (0)