From 942b11fcceda9ac5640714d90d3b472673ae16f5 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Sun, 16 Jun 2024 18:10:49 -0400 Subject: [PATCH] we have a dropdown that fires an onchange to post the new value. although, errors ensue --- Models/Enums.cs | 2 +- .../Controllers/ChannelsController.cs | 1 + WebInterface/Views/Channels/Details.cshtml | 36 +++++++++++++-- wwwroot/js/site.js | 46 +++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/Models/Enums.cs b/Models/Enums.cs index 40487e4..9cc016d 100644 --- a/Models/Enums.cs +++ b/Models/Enums.cs @@ -45,7 +45,7 @@ public static class Enumerations Type type = enumerationValue.GetType(); if (!type.IsEnum) { - throw new ArgumentException("EnumerationValue must be of Enum type", "enumerationValue"); + throw new ArgumentException("EnumerationValue must be of Enum type", nameof(enumerationValue)); } //Tries to find a DescriptionAttribute for a potential friendly name diff --git a/WebInterface/Controllers/ChannelsController.cs b/WebInterface/Controllers/ChannelsController.cs index 1e0efeb..326376a 100644 --- a/WebInterface/Controllers/ChannelsController.cs +++ b/WebInterface/Controllers/ChannelsController.cs @@ -1,3 +1,4 @@ +using System.ComponentModel; using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/WebInterface/Views/Channels/Details.cshtml b/WebInterface/Views/Channels/Details.cshtml index 7c35fe5..b35024b 100644 --- a/WebInterface/Views/Channels/Details.cshtml +++ b/WebInterface/Views/Channels/Details.cshtml @@ -1,3 +1,5 @@ +@using System.ComponentModel +@using Newtonsoft.Json @model Channel @Html.Raw(ViewData["breadcrumbs"]) @@ -10,11 +12,19 @@ Channel type - @Model.ChannelType + @(Model.ChannelType != null ? Enumerations.GetDescription(Model.ChannelType) : "?") Lewdness Filter Level - @(Model.LewdnessFilterLevel?.ToString() ?? "inherited") + + + Links Allowed @@ -34,7 +44,7 @@ Meanness Filter Level - @(Model.MeannessFilterLevel?.ToString() ?? "inherited") + @(Model.MeannessFilterLevel != null ? Enumerations.GetDescription(Model.MeannessFilterLevel.GetValueOrDefault()) : "inherited") Messages (count) @@ -58,3 +68,23 @@ + + +@section Scripts{ + +} \ No newline at end of file diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index b2f58e1..ad5f755 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -2,3 +2,49 @@ // for details on configuring this project to bundle and minify static web assets. // Write your JavaScript code. + +function testfunct(caller){ + console.log("[gibberish]"); + console.log(caller); +} +function postmodelupdate(model) +{ + //structure the model your (dang) self into a nice object + console.log(model); + //i know the page url. + console.log(window.location.pathname); + var components = window.location.pathname.split('/'); + if(components[2] !== "Details") + { + console.log("wtf are you doing? " + components[2] + " is something other than Details") + } + var type=components[1]; + var id=components[3]; + + //todo: figure out what the URL actually needs to be, rather than assuming you get a whole-ass server to yourself. + //you selfish fuck. What are you, fox? + var apiUrl = "/api/Channels/" + + console.log("dexter impression: I am now ready to post the following content:"); + console.log(JSON.stringify(model)); + fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(model), + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not "ok". which is not ok.'); + } + return response.json(); + }) + .then(returnedSuccessdata => { + // perhaps a success callback + console.log('returnedSuccessdata:', returnedSuccessdata); + }) + .catch(error => { + console.error('Error:', error); + }); +} \ No newline at end of file