Skip to content

Commit

Permalink
group by
Browse files Browse the repository at this point in the history
  • Loading branch information
meesaltena committed Mar 2, 2024
1 parent acfb12c commit 945a3ca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 29 deletions.
2 changes: 1 addition & 1 deletion AdsbMudBlazor/Components/CurrentlyTracked.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<MudText Class="mb-8">
Total flights currently being tracked by
<MudLink Href="@($"https://www.flightradar24.com/account/feed-stats/?id={feederService.FeederId}")">@feederService.FeederName</MudLink>:
<MudLink Href="@(feederService.FeederUrl)">@feederService.FeederName</MudLink>:
@if (flightCount != null) {
@flightCount
}
Expand Down
89 changes: 61 additions & 28 deletions AdsbMudBlazor/Components/Pages/RecentFlights.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,39 @@
<MyMudProviders />
<PageTitle>Recent flights</PageTitle>

<MudText Typo="Typo.h4" GutterBottom="true">Recent flights</MudText>


<CurrentlyTracked />

@* <MudPaper Class="relative d-flex flex-grow-1 flex-wrap justify-center align-center px-8 pb-8 pt-2" MaxWidth="608px" Height="60px" Elevation="0"> *@
@* <MudPaper Class="d-flex align-content-start flex-wrap flex-grow-1 gap-4 pa-4" MaxWidth="75%" Height="80px" Elevation="0"> *@
<MudPaper Class="d-flex align-content-start justify-center" MaxWidth="75%" Height="80px" Elevation="0">
<MudText Class=" ">Flights seen within the last minutes</MudText>
<MudTimePicker Class=" " TimeChanged="@OnTimeChanged" Time="@selectedTimeSpan" />
<MudSwitch Class=" " @bind-Value="@ShowOnlyValidDistance" Size="Size.Small" Label="Show valid distance only" Color="Color.Info" />
</MudPaper>
@* <MudPaper Class="d-flex align-content-start justify-center" MaxWidth="75%" Height="80px" Elevation="0">
<MudText Class=" "></MudText>
</MudPaper> *@

@if (flights == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}
else
{
<MudTable Items="@flights" Hover="true" SortLabel="Sort By" Elevation="0">
<MudTable Items="@flights" Hover="true" SortLabel="Sort By"
GroupBy="@_groupDefinition"
GroupHeaderStyle="background-color:var(--mud-palette-background-grey)"
GroupFooterClass="mb-4"
Filter="new Func<Flight,bool>(FilterFunc)"
Dense="true"
@ref="_tableRef"
Elevation="0">
<ToolBarContent>
<MudContainer Class="d-flex justify-space-between flex-grow-1 gap-2" >
<MudText Typo="Typo.h5" Class="mt-3 pr-10" GutterBottom="true">Recent flights</MudText>
<MudTimePicker Style="max-width:150px;margin-bottom: 20px;" Label="Seen within the last minutes:" Class="" TimeChanged="@OnTimeChanged" Time="@selectedTimeSpan" />
<MudSwitch Class="mt-5" @bind-Value="@ShowOnlyValidDistance" Size="Size.Small" Label="Show valid distance only" Color="Color.Info" />
<MudTextField @bind-Value="searchString1" Placeholder="Search" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
</MudContainer>
</ToolBarContent>
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<Flight, object>(x=>x.ModeS)">ICAO</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<Flight, object>(x=>x.Callsign)">Callsign</MudTableSortLabel></MudTh>
Expand All @@ -38,15 +52,20 @@ else
<MudTh><MudTableSortLabel SortBy="new Func<Flight, object>(x=>x.Lat)">Lat</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<Flight, object>(x=>x.Long)">Long</MudTableSortLabel></MudTh>
@* <MudTh><MudTableSortLabel SortBy="new Func<Flight, object>(x=> {if(x.Lat != 0 && x.Long != 0 && x.DistanceKm != null)
{return x.DistanceKm;} else return 0;})">Distance (km)</MudTableSortLabel></MudTh> *@
{return x.DistanceKm;} else return 0;})">Distance (km)</MudTableSortLabel></MudTh> *@
<MudTh><MudTableSortLabel SortBy="new Func<Flight, object>(x=> x.DistanceKm)">Distance (km)</MudTableSortLabel></MudTh>
</HeaderContent>


<GroupHeaderTemplate>
<MudTh Class="mud-table-cell-custom-group" colspan="12">@($"{context.GroupName}: {context.Key}") </MudTh>
</GroupHeaderTemplate>
<RowTemplate>
<MudTd DataLabel="ICAO">
<MudLink Href="@($"https://www.planespotters.net/hex/{context.ModeS}")">@context.ModeS</MudLink>
</MudTd>
<MudTd DataLabel="Callsign">
<MudLink Href="@($"http://www.flightradar24.com/{context.Callsign}")">@context.Callsign</MudLink>
<MudLink Target="_blank" Href="@($"http://www.flightradar24.com/{context.Callsign}")">@context.Callsign</MudLink>
</MudTd>
<MudTd DataLabel="Altitude (ft.)">@context.Alt</MudTd>
<MudTd DataLabel="Squawk">@context.Squawk</MudTd>
Expand All @@ -61,9 +80,24 @@ else
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>

<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="mt-3" OnClick="@((args) => _tableRef?.ExpandAllGroups())">Expand all groups</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="mt-3 ml-3" OnClick="@((args) => _tableRef?.CollapseAllGroups())">Collapse all groups</MudButton>

}

@code {
private MudTable<Flight> _tableRef;
private TableGroupDefinition<Flight> _groupDefinition = new()
{
GroupName = "Plane",
Indentation = false,
Expandable = true,
IsInitiallyExpanded = false,
Selector = (e) => e.ModeS
};


public bool ShowOnlyValidDistance { get; set; } = true;
private IEnumerable<Flight> flights
{
Expand All @@ -86,21 +120,25 @@ else
};
private string searchString1 = "";

// Filter="new Func<Flight,bool>(FilterFunc1)"
// private bool FilterFunc1(Flight flight) => FilterFunc(flight, searchString1);
// private bool FilterFunc(Flight element, string searchString)
// {
// if (string.IsNullOrWhiteSpace(searchString))
// return true;
// if (element.Sign.Contains(searchString, StringComparison.OrdinalIgnoreCase))
// return true;
// if (element.Name.Contains(searchString, StringComparison.OrdinalIgnoreCase))
// return true;
// if ($"{element.Number} {element.Position} {element.Molar}".Contains(searchString))
// return true;
// return false;
// }
private bool FilterFunc(Flight flight) => FilterFunc(flight, searchString1);
private bool FilterFunc(Flight element, string searchString)
{
if (string.IsNullOrWhiteSpace(searchString))
return true;
if (element.Callsign.Contains(searchString, StringComparison.OrdinalIgnoreCase))
return true;
if (element.ModeS.Contains(searchString, StringComparison.OrdinalIgnoreCase))
return true;
if (element.Squawk.Contains(searchString, StringComparison.OrdinalIgnoreCase))
return true;
if (element.Alt.Contains(searchString, StringComparison.OrdinalIgnoreCase))
return true;
return false;
}

// public void OnRowClick(TableRowClickEventArgs<Flight> f)
// {
// }
private async Task OnTimeChanged(TimeSpan? value)
{
Expand All @@ -121,9 +159,4 @@ else
// DateTime oldest = DateTime.UtcNow.Subtract(timeSpan);
}

// private async IAsyncEnumerable<Flight> GetFlightsAsync()
// {
// return await flightsService.GetRecentFlightsAsync(selectedTimeSpan ?? value ?? TimeSpan.FromMinutes(5));
// }
}

0 comments on commit 945a3ca

Please sign in to comment.