Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions BlazorDashboard/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
28 changes: 28 additions & 0 deletions BlazorDashboard/BlazorDashboard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Content Remove="wwwroot\bootstrap\css\bootstrap.min.css" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\bootstrap\css\bootstrap.min.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\assets\fonts\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions BlazorDashboard/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
55 changes: 55 additions & 0 deletions BlazorDashboard/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@page "/fetchdata"
@inject HttpClient Http

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[] forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public string Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
89 changes: 89 additions & 0 deletions BlazorDashboard/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@using Services;
@using Domain.Entities;

@inject SensorServiceClient client;

@page "/"

<div class="row sales layout-top-spacing">
<div class="col-xl-12 col-lg-12 col-md-8 col-8">
<div class="widget">
<div class="widget-heading">
<h5>Hi there!</h5>
</div>

<div class="widget-content">
<p class="info-detail">Welcome home!</p>
@if (Weather != null)
{
<p>
<i class="fas fa-thermometer-half"></i> @(Weather.Temperature)°C
</p>
<p><i class="fas fa-cloud"></i> Kinda cloudy</p>
}

</div>

</div>
</div>

<div class="col-xl-12 col-lg-12 col-md-4 col-4">
<div class="widget">
<div class="widget-heading">

</div>
</div>
</div>

<div class="col-xl-12 col-lg-12 col-md-8 col-8 layout-top-spacing">
<div class="widget widget-chart-one">
<div class="widget-heading">
@if (Home != null)
{
<h5>@Home.Name</h5>
<ul class="tabs tab-pills">
<li>
<i class="fas fa-thermometer-half"></i> 23.2C
</li>
<li>
<i class="fas fa-tint"></i> 52%H
</li>
<li>
<select>
@foreach (var room in Rooms)
{
<option value="@room.Id">@room.Name</option>
}
</select>
</li>
</ul>
}

</div>

<div class="widget-content">

</div>
</div>
</div>
</div>


@code {
public Home Home { get; set; }
public List<Room> Rooms { get; set; }

public Weather Weather { get; set; }

protected override async Task OnInitializedAsync()
{
var homes = await this.client.GetHomes();
this.Home = homes[0];

var rooms = await this.client.GetRooms(this.Home);
this.Rooms = rooms;

var weather = await this.client.GetWeatherToday(this.Home);
this.Weather = weather.Last();
}
}
30 changes: 30 additions & 0 deletions BlazorDashboard/Pages/Todo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@page "/todo"

<h3>Todo (@todos.Count(todo => !todo.IsDone))</h3>

<ul>
@foreach (var todo in todos)
{
<li>
<input type="checkbox" @bind="todo.IsDone" />
<input @bind="todo.Title" />
</li>
}
</ul>

<input placeholder="Something todo" @bind="newTodo" />
<button class="btn-primary" @onclick="AddTodo">Add todo</button>

@code {
private IList<TodoItem> todos = new List<TodoItem>();
private string newTodo;

private void AddTodo()
{
if (!string.IsNullOrWhiteSpace(newTodo))
{
todos.Add(new TodoItem { Title = newTodo });
newTodo = string.Empty;
}
}
}
27 changes: 27 additions & 0 deletions BlazorDashboard/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using BlazorDashboard.Services;

namespace BlazorDashboard
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://sensor-service.mcostea.com") });
builder.Services.AddSingleton(sp => new SensorServiceClient(new HttpClient { BaseAddress = new Uri("http://sensor-service.mcostea.com") }));

await builder.Build().RunAsync();
}
}
}
29 changes: 29 additions & 0 deletions BlazorDashboard/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18753",
"sslPort": 44339
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorDashboard": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:16722;http://localhost:4260",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
40 changes: 40 additions & 0 deletions BlazorDashboard/Services/SensorServiceClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Domain.Entities;

namespace BlazorDashboard.Services
{
public class SensorServiceClient
{
public HttpClient httpClient { get; set; }

public SensorServiceClient(HttpClient httpClient)
{
this.httpClient = httpClient;
}

public async Task<List<Home>> GetHomes()
{
return await this.httpClient.GetFromJsonAsync<List<Home>>("api/homes");
}

public async Task<List<Room>> GetRooms(Home home)
{
return await this.httpClient.GetFromJsonAsync<List<Room>>("api/homes/" + home.Id.ToString() + "/room");
}

public async Task<List<Weather>> GetWeatherToday(Home home)
{
var startOfDay = DateTime.Today.ToUniversalTime();
var now = DateTime.UtcNow;

var uri = "api/homes/" + home.Id.ToString() + "/weather?startDate=" + startOfDay.ToString("s") + "&endDate=" + now.ToString("s");


return await this.httpClient.GetFromJsonAsync<List<Weather>>(uri);
}
}
}
56 changes: 56 additions & 0 deletions BlazorDashboard/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@using Microsoft.JSInterop
@inject IJSRuntime JSRuntime

@inherits LayoutComponentBase
<!-- BEGIN NAVBAR -->
<div class="header-container">
<header class="header navbar navbar-expand-sm">

<a href="javascript:void(0);" class="sidebarCollapse" data-placement="bottom" @onclick="ToggleSidebar" @onclick:preventDefault ><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></a>

<div class="nav-logo align-self-center">
<a class="navbar-brand" href="index.html"><img alt="logo" src="assets/img/90x90.jpg"> <span class="navbar-brand-name">CORK</span></a>
</div>

</header>
</div>
<!-- END NAVBAR -->
<!-- BEGIN MAIN CONTAINER -->
<div class="main-container @(SidebarOpen ? "topbar-closed sbar-open" : "")" id="container">

<div class="overlay @(SidebarOpen ? "show" : "")" @onclick="ToggleSidebar"></div>
<div class="search-overlay"></div>

<!-- BEGIN TOPBAR -->
<div class="topbar-nav header navbar" role="banner">
<NavMenu />
</div>
<!-- END TOPBAR -->
<!-- BEGIN CONTENT AREA -->
<div id="content" class="main-content">
<div class="layout-px-spacing">


<!-- CONTENT AREA -->

@Body

<!-- CONTENT AREA -->

</div>

</div>
<!-- END CONTENT AREA -->

</div>
<!-- END MAIN CONTAINER -->

@code
{
public bool SidebarOpen { get; set; }

public void ToggleSidebar()
{
SidebarOpen = !SidebarOpen;
}
}
Loading