Initial commit
This commit is contained in:
26
Pages/Error.cshtml
Normal file
26
Pages/Error.cshtml
Normal file
@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model ErrorModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
32
Pages/Error.cshtml.cs
Normal file
32
Pages/Error.cshtml.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace NikolaNet.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
85
Pages/Index.cshtml
Normal file
85
Pages/Index.cshtml
Normal file
@ -0,0 +1,85 @@
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
Model.token = Request.Cookies["Auth"];
|
||||
}
|
||||
|
||||
@if (string.IsNullOrEmpty(Model.token))
|
||||
{
|
||||
<form asp-page-handler="SetToken" method="post">
|
||||
<div class="card" id="login_card">
|
||||
<div class="card-header">
|
||||
Login with Token
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Enter your authorization token below:</p>
|
||||
<input asp-for="token" id="token" />
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card-deck" style="display: none;">
|
||||
|
||||
<input id="json_data" type="hidden" value="" />
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" id="vehicle_name">Vehicle Name</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted" id="vehicle_vin"></h6>
|
||||
<p class="card-text">Current Battery Status: <a id="battery_level"></a>%</p>
|
||||
<p class="card-text">Range: <a id="battery_range"></a> <a id="range_units"></a></p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a href="#" class="card-link" target="_blank" rel="noopener noreferrer" id="locate_vehicle_btn">Locate
|
||||
Vehicle</a>
|
||||
<a href="/?handler=Command&command=@Tesla.BasicCommands.Flash" class="card-link">Flash</a>
|
||||
<a href="/?handler=Command&command=@Tesla.BasicCommands.Honk" class="card-link">Honk</a>
|
||||
<a href="/?handler=Command&command=door_lock" class="card-link" id="lock_unlock_btn">Lock</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-header">
|
||||
Climate
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Climate Status: <a id="climate_status"></a></p>
|
||||
<p class="card-text">Outside Temp: <a id="outside_temp"></a> <a class="temp_units"></a></p>
|
||||
<p class="card-text">Inside Temp: <a id="inside_temp"></a> <a class="temp_units"></a></p>
|
||||
<p class="card-text">Climate Set Temp: <input asp-for="climateTemp" type="number" id="climate_setting" />
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a href="/?handler=Command&command=@Tesla.BasicCommands.ClimateOn" class="card-link">Start Climate</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" id="charge_state_card" style="width: 18rem; display: none;">
|
||||
<div class="card-header">
|
||||
Charge Status
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Connected Cable: <a id="connected_cable"></a></p>
|
||||
<p class="card-text">Current power: <a id="current_current"></a> kW</p>
|
||||
<p id="till_full" class="card-text" style="display: none;">Time till full: <a id="time_to_full"></a></p>
|
||||
</div>
|
||||
|
||||
<div class="card-footer">
|
||||
<small class="text-muted" id="connection_ind"></small>
|
||||
<a asp-page-handler="Command" id="charge_ctrl_btn" class="card-link">Stop Charging</a>
|
||||
<a asp-page-handler="Command" id="toggle_charge_port" class="card-link">Unlock Charge Port</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
}
|
||||
83
Pages/Index.cshtml.cs
Normal file
83
Pages/Index.cshtml.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Tesla;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NikolaNet.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
private string VehicleName;
|
||||
public Vehicle[] vehicles;
|
||||
public int currentIndex = 0;
|
||||
public DataResponse vehicleDataResponse;
|
||||
public string jsonData;
|
||||
public string token {get; set;}
|
||||
public string climateTemp {get; set;}
|
||||
public string GetVehicleName()
|
||||
{
|
||||
return VehicleName;
|
||||
}
|
||||
public IndexModel(ILogger<IndexModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
public Client setupClient()
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) {
|
||||
token = Request.Cookies["Auth"];
|
||||
}
|
||||
Client c = new Client();
|
||||
c.setToken($"Bearer {token}");
|
||||
vehicles = c.ListVehicles();
|
||||
c.vehicle_id = vehicles[currentIndex].id_s;
|
||||
return c;
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnGetCommand()
|
||||
{
|
||||
Client c = setupClient();
|
||||
if (Request.Query["command"].Equals(BasicCommands.ClimateOn)) {
|
||||
//c.RunCommand(ExtendedCommands.SetClimateTemp, $"{{\"driver_temp\": \"{Request.Form["climateTemp"]}\"}}");
|
||||
return;
|
||||
}
|
||||
c.RunCommand(Request.Query["command"]);
|
||||
|
||||
}
|
||||
public void OnGetFrunk() {
|
||||
}
|
||||
public void OnPostSetToken() {
|
||||
this.token = Request.Form["token"];
|
||||
Response.Cookies.Append("Auth", token);
|
||||
}
|
||||
|
||||
|
||||
public JsonResult OnGetJsonData()
|
||||
{
|
||||
Client c = setupClient();
|
||||
VehicleName = vehicles[currentIndex].display_name;
|
||||
vehicleDataResponse = c.GetVehicleData().response;
|
||||
if (vehicleDataResponse.gui_settings.gui_temperature_units.Equals("F"))
|
||||
{
|
||||
vehicleDataResponse.climate_state.outside_temp = (int)(vehicleDataResponse.climate_state.outside_temp * 1.8) + 32;
|
||||
vehicleDataResponse.climate_state.inside_temp = (int)(vehicleDataResponse.climate_state.inside_temp * 1.8) + 32;
|
||||
vehicleDataResponse.climate_state.driver_temp_setting = (int)(vehicleDataResponse.climate_state.driver_temp_setting * 1.8) + 32;
|
||||
}
|
||||
jsonData = JsonConvert.SerializeObject(vehicleDataResponse);
|
||||
|
||||
return new JsonResult(jsonData);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Pages/Privacy.cshtml
Normal file
8
Pages/Privacy.cshtml
Normal file
@ -0,0 +1,8 @@
|
||||
@page
|
||||
@model PrivacyModel
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Nothing is stored server-side. Delete the "Auth" cookie and that's all we have.</p>
|
||||
24
Pages/Privacy.cshtml.cs
Normal file
24
Pages/Privacy.cshtml.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace NikolaNet.Pages
|
||||
{
|
||||
public class PrivacyModel : PageModel
|
||||
{
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Pages/Shared/_Layout.cshtml
Normal file
51
Pages/Shared/_Layout.cshtml
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Nikola.Net</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">NikolaNet</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2021 - NikolaNet - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
|
||||
</body>
|
||||
</html>
|
||||
2
Pages/Shared/_ValidationScriptsPartial.cshtml
Normal file
2
Pages/Shared/_ValidationScriptsPartial.cshtml
Normal file
@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||
3
Pages/_ViewImports.cshtml
Normal file
3
Pages/_ViewImports.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@using NikolaNet
|
||||
@namespace NikolaNet.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
3
Pages/_ViewStart.cshtml
Normal file
3
Pages/_ViewStart.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
Reference in New Issue
Block a user