still figuring out how to handle default note name...
This commit is contained in:
parent
e89f9f74fe
commit
41de9e60c4
@ -3,6 +3,7 @@ using BinaryDad.Notes.Services;
|
|||||||
|
|
||||||
namespace BinaryDad.Notes.Controllers
|
namespace BinaryDad.Notes.Controllers
|
||||||
{
|
{
|
||||||
|
[ApiController]
|
||||||
public class ApiController : ControllerBase
|
public class ApiController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly INoteService noteService;
|
private readonly INoteService noteService;
|
||||||
@ -12,6 +13,7 @@ namespace BinaryDad.Notes.Controllers
|
|||||||
this.noteService = noteService;
|
this.noteService = noteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("note/{noteName}")]
|
||||||
public string Note(string noteName) => noteService.GetText(noteName);
|
public string Note(string noteName) => noteService.GetText(noteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using BinaryDad.Notes.Models;
|
using BinaryDad.Notes.Models;
|
||||||
using BinaryDad.Notes.Services;
|
using BinaryDad.Notes.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -15,9 +15,14 @@ public class NoteController : Controller
|
|||||||
this.noteService = noteService;
|
this.noteService = noteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("{noteName=default}")]
|
[Route("{noteName?}")]
|
||||||
public IActionResult Index(string noteName)
|
public IActionResult Index(string noteName)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(noteName))
|
||||||
|
{
|
||||||
|
noteName = "default";
|
||||||
|
}
|
||||||
|
|
||||||
var model = new ContentModel
|
var model = new ContentModel
|
||||||
{
|
{
|
||||||
CurrentNote = noteName,
|
CurrentNote = noteName,
|
||||||
|
@ -4,9 +4,16 @@
|
|||||||
{
|
{
|
||||||
private readonly string filePath;
|
private readonly string filePath;
|
||||||
|
|
||||||
|
private static readonly string defaultFilePath = "notes";
|
||||||
|
|
||||||
public FileNoteService(IConfiguration configuration)
|
public FileNoteService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
filePath = configuration["FileNoteService:ContentFilePath"].Trim();
|
filePath = configuration["FileNoteService:ContentFilePath"];
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
|
{
|
||||||
|
filePath = defaultFilePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetText(string noteName)
|
public string GetText(string noteName)
|
||||||
|
@ -13,3 +13,10 @@
|
|||||||
|
|
||||||
<div class="toast" id="saved-indicator">Saved</div>
|
<div class="toast" id="saved-indicator">Saved</div>
|
||||||
<div class="toast" id="update-indicator">Updated</div>
|
<div class="toast" id="update-indicator">Updated</div>
|
||||||
|
|
||||||
|
@section Scripts
|
||||||
|
{
|
||||||
|
<script>
|
||||||
|
noteName = '@Model.CurrentNote';
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const noteName = document.location.pathname.substring(1);
|
let noteName = '';//document.location.pathname.substring(1);
|
||||||
|
|
||||||
let connection = new signalR.HubConnectionBuilder()
|
let connection = new signalR.HubConnectionBuilder()
|
||||||
.withAutomaticReconnect()
|
.withAutomaticReconnect()
|
||||||
@ -58,7 +58,7 @@ $(function () {
|
|||||||
|
|
||||||
// update content after reconnected
|
// update content after reconnected
|
||||||
connection.onreconnected(function() {
|
connection.onreconnected(function() {
|
||||||
$.get(`api/note?noteName=${noteName}`, function(content) {
|
$.get(`api/note/${noteName}`, function(content) {
|
||||||
$textarea.val(content);
|
$textarea.val(content);
|
||||||
showToast('#update-indicator');
|
showToast('#update-indicator');
|
||||||
console.log('Refreshed after disconnect');
|
console.log('Refreshed after disconnect');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user