working with links

This commit is contained in:
Ryan Peters 2023-05-12 12:38:13 -04:00
parent 77e6ed78fd
commit 16f4dc9a76
15 changed files with 64 additions and 78 deletions

2
.vscode/launch.json vendored
View File

@ -17,7 +17,7 @@
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
"pattern": "\\bNow listening on:\\s+(http?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"

View File

@ -1,4 +1,5 @@
using BinaryDad.Notes.Services;
using BinaryDad.Notes.Models;
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
@ -15,8 +16,12 @@ public class HomeController : Controller
[Route("{noteName?}")]
public IActionResult Index(string? noteName)
{
var content = noteService.Get(noteName);
var model = new ContentModel
{
Text = noteService.GetText(noteName),
NoteNames = noteService.GetNoteNames()
};
return View((object)content);
return View(model);
}
}

7
Models/ContentModel.cs Normal file
View File

@ -0,0 +1,7 @@
namespace BinaryDad.Notes.Models;
public class ContentModel
{
public ICollection<string> NoteNames { get; set; }
public string Text { get; set; }
}

View File

@ -1,8 +0,0 @@
namespace BinaryDad.Notes.Models;
public class ErrorViewModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}

View File

@ -23,7 +23,7 @@ namespace BinaryDad.Notes
public async Task SaveNote(string content, string? noteName)
{
noteService.Save(content, noteName);
noteService.SaveText(content, noteName);
// find all other connections except for the current one
var clientConnections = NoteContext.ClientNotes

1
Notes/content Normal file
View File

@ -0,0 +1 @@
default page

1
Notes/homelab-stuff Normal file
View File

@ -0,0 +1 @@
some homelab stuff

1
Notes/my-notes Normal file
View File

@ -0,0 +1 @@
sdsada

1
Notes/sdfsfd Normal file
View File

@ -0,0 +1 @@
this is on weird page

View File

@ -8,29 +8,6 @@
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5015"
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7042;http://localhost:5015"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
},
"iisSettings": {

View File

@ -13,7 +13,7 @@
CheckFile(defaultFileName);
}
public string Get(string? noteName)
public string GetText(string? noteName)
{
CheckFile(noteName);
@ -22,10 +22,12 @@
public ICollection<string> GetNoteNames()
{
return Directory.GetFiles(filePath);
return Directory.GetFiles(filePath)
.Select(f => Path.GetFileName(f))
.ToList();
}
public void Save(string content, string? noteName)
public void SaveText(string content, string? noteName)
{
File.WriteAllText(GetFilePath(noteName), content);
}
@ -37,7 +39,7 @@
// ensure initialized
if (!File.Exists(filePath))
{
Save("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.", noteName);
SaveText("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.", noteName);
}
}

View File

@ -3,7 +3,7 @@
public interface INoteService
{
ICollection<string> GetNoteNames();
string Get(string? noteName);
void Save(string content, string? noteName);
string GetText(string? noteName);
void SaveText(string content, string? noteName);
}
}

View File

@ -1,6 +1,13 @@
@model string
@model ContentModel
<textarea id="content" name="content" spellcheck="false">@Model</textarea>
<textarea id="content" name="content" spellcheck="false">@Model.Text</textarea>
<div class="note-names">
@foreach (var note in Model.NoteNames)
{
<a href="@note">@note</a>
}
</div>
<div class="toast" id="saved-indicator">Saved</div>
<div class="toast" id="update-indicator">Updated</div>

View File

@ -1,25 +0,0 @@
@model ErrorViewModel
@{
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 <strong>Development</strong> environment will display more 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>

View File

@ -20,6 +20,23 @@ body {
min-height: 100%;
}
div.note-names {
position: fixed;
bottom: 0;
left: 0;
font-size: 11px;
}
div.note-names a {
color: #666;
padding: 0 5px;
text-decoration: none;
}
div.note-names a:not(:last-of-type) {
border-right: 1px solid #666;
}
textarea {
width: 100%;
height: 100%;
@ -52,14 +69,14 @@ textarea {
border-radius: 5px 5px 0 0;
}
.toast.show {
.toast.show {
bottom: 0;
}
}
.toast#saved-indicator {
.toast#saved-indicator {
background-color: green;
}
}
.toast#update-indicator {
.toast#update-indicator {
background-color: orangered;
}
}