working nicely
This commit is contained in:
parent
8e7b9c9622
commit
400f20e916
@ -15,11 +15,12 @@ public class NoteController : Controller
|
|||||||
this.noteService = noteService;
|
this.noteService = noteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("{noteName?}")]
|
[Route("{noteName=default}")]
|
||||||
public IActionResult Index(string? noteName)
|
public IActionResult Index(string noteName)
|
||||||
{
|
{
|
||||||
var model = new ContentModel
|
var model = new ContentModel
|
||||||
{
|
{
|
||||||
|
CurrentNote = noteName,
|
||||||
Text = noteService.GetText(noteName),
|
Text = noteService.GetText(noteName),
|
||||||
NoteNames = noteService.GetNoteNames()
|
NoteNames = noteService.GetNoteNames()
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ namespace BinaryDad.Notes.Models;
|
|||||||
|
|
||||||
public class ContentModel
|
public class ContentModel
|
||||||
{
|
{
|
||||||
|
public string CurrentNote { get; set; } = string.Empty;
|
||||||
public ICollection<string> NoteNames { get; set; } = new List<string>();
|
public ICollection<string> NoteNames { get; set; } = new List<string>();
|
||||||
public string Text { get; set; } = string.Empty;
|
public string Text { get; set; } = string.Empty;
|
||||||
}
|
}
|
@ -2,18 +2,14 @@
|
|||||||
{
|
{
|
||||||
public class FileNoteService : INoteService
|
public class FileNoteService : INoteService
|
||||||
{
|
{
|
||||||
private readonly string defaultFileName;
|
|
||||||
private readonly string filePath;
|
private readonly string filePath;
|
||||||
|
|
||||||
public FileNoteService(IConfiguration configuration)
|
public FileNoteService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
defaultFileName = configuration["DefaultContentFileName"].Trim().ToLower();
|
filePath = configuration["FileNoteService:ContentFilePath"].Trim();
|
||||||
filePath = configuration["ContentFilePath"].Trim();
|
|
||||||
|
|
||||||
CheckFile(defaultFileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetText(string? noteName)
|
public string GetText(string noteName)
|
||||||
{
|
{
|
||||||
CheckFile(noteName);
|
CheckFile(noteName);
|
||||||
|
|
||||||
@ -27,7 +23,7 @@
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveText(string content, string? noteName)
|
public void SaveText(string content, string noteName)
|
||||||
{
|
{
|
||||||
File.WriteAllText(GetFilePath(noteName), content);
|
File.WriteAllText(GetFilePath(noteName), content);
|
||||||
}
|
}
|
||||||
@ -39,7 +35,7 @@
|
|||||||
File.Delete(filePath);
|
File.Delete(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckFile(string? noteName)
|
private void CheckFile(string noteName)
|
||||||
{
|
{
|
||||||
var filePath = GetFilePath(noteName);
|
var filePath = GetFilePath(noteName);
|
||||||
|
|
||||||
@ -50,10 +46,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFilePath(string? noteName)
|
private string GetFilePath(string noteName)
|
||||||
{
|
{
|
||||||
noteName = string.IsNullOrWhiteSpace(noteName) ? defaultFileName : noteName;
|
|
||||||
|
|
||||||
noteName = noteName.Trim().ToLower();
|
noteName = noteName.Trim().ToLower();
|
||||||
|
|
||||||
return Path.Combine(filePath, noteName);
|
return Path.Combine(filePath, noteName);
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
public interface INoteService
|
public interface INoteService
|
||||||
{
|
{
|
||||||
ICollection<string> GetNoteNames();
|
ICollection<string> GetNoteNames();
|
||||||
string GetText(string? noteName);
|
string GetText(string noteName);
|
||||||
void SaveText(string content, string? noteName);
|
void SaveText(string content, string noteName);
|
||||||
void DeleteNote(string noteName);
|
void DeleteNote(string noteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
<textarea id="content" name="content" spellcheck="false">@Model.Text</textarea>
|
<textarea id="content" name="content" spellcheck="false">@Model.Text</textarea>
|
||||||
|
|
||||||
<div class="note-names">
|
<div class="note-names">
|
||||||
@foreach (var note in Model.NoteNames)
|
@foreach (var note in Model.NoteNames.Order())
|
||||||
{
|
{
|
||||||
<a href="@note">@note</a>
|
var css = note.Equals(Model.CurrentNote, StringComparison.OrdinalIgnoreCase) ? "current" : null;
|
||||||
|
|
||||||
|
<a href="@note" class="@css">@note</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"DefaultContentFileName": "content",
|
"FileNoteService": {
|
||||||
"ContentFilePath": "notes"
|
"ContentFilePath": "notes"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1
notes/birds
Normal file
1
notes/birds
Normal file
@ -0,0 +1 @@
|
|||||||
|
some bird stufffg hfghf
|
1
notes/default
Normal file
1
notes/default
Normal file
@ -0,0 +1 @@
|
|||||||
|
default tesxtg dg
|
1
notes/sdfsds
Normal file
1
notes/sdfsds
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hi! Feel free to start typing. Every
|
@ -24,18 +24,23 @@ div.note-names {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 5px;
|
bottom: 5px;
|
||||||
left: 0;
|
left: 0;
|
||||||
font-size: 11px;
|
font-size: 14px;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.note-names a {
|
div.note-names a {
|
||||||
color: #666;
|
color: #666;
|
||||||
padding: 0 5px;
|
padding-left: 10px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.note-names a:not(:last-of-type) {
|
div.note-names a.current {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
div .note-names a:not(:last-of-type) {
|
||||||
border-right: 1px solid #666;
|
border-right: 1px solid #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -69,17 +74,17 @@ textarea {
|
|||||||
border-radius: 5px 5px 0 0;
|
border-radius: 5px 5px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast.show {
|
.toast.show {
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast#saved-indicator {
|
.toast#saved-indicator {
|
||||||
background-color: green;
|
background-color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast#update-indicator {
|
.toast#update-indicator {
|
||||||
background-color: orangered;
|
background-color: orangered;
|
||||||
}
|
}
|
||||||
|
|
||||||
form input[type=password] {
|
form input[type=password] {
|
||||||
display: block;
|
display: block;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user