From ed4a8ea43d1ed2ce4f3fc53582f8a89e8ff70e49 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Mon, 4 Dec 2023 18:18:47 -0600 Subject: [PATCH] ts support, public api support --- .gitignore | 7 ++++-- Unbinder/.dockerignore | 4 +++- Unbinder/.eslintrc.js | 5 +++++ .../Api/IngredientApiController.cs | 19 ++++++++++++++++ Unbinder/Program.cs | 1 + Unbinder/Unbinder.csproj | 5 ++++- Unbinder/Views/Recipe/Create.cshtml | 8 ++++++- Unbinder/Views/Recipe/Search.cshtml | 8 +++---- Unbinder/Views/Shared/_Layout.cshtml | 2 ++ Unbinder/libman.json | 7 +++++- Unbinder/package.json | 21 ++++++++++++++++++ Unbinder/tsconfig.json | 21 ++++++++++++++++++ Unbinder/wwwroot/css/site.css | 18 +++++++++++++++ Unbinder/wwwroot/favicon.ico | Bin 0 -> 5430 bytes Unbinder/wwwroot/ts/createRecipe.ts | 18 +++++++++++++++ Unbinder/wwwroot/ts/index.ts | 0 16 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 Unbinder/.eslintrc.js create mode 100644 Unbinder/Controllers/Api/IngredientApiController.cs create mode 100644 Unbinder/package.json create mode 100644 Unbinder/tsconfig.json create mode 100644 Unbinder/wwwroot/css/site.css create mode 100644 Unbinder/wwwroot/favicon.ico create mode 100644 Unbinder/wwwroot/ts/createRecipe.ts create mode 100644 Unbinder/wwwroot/ts/index.ts diff --git a/.gitignore b/.gitignore index 4505dc2..b62c4c9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __notes__ *.env UnbinderSandbox +package-lock.json # Files for/generated by Docker Compose secrets @@ -44,8 +45,8 @@ bld/ # Visual Studio 2015/2017 cache/options directory .vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -wwwroot/ +wwwroot/lib/ +wwwroot/js/ # Visual Studio 2017 auto generated files Generated\ Files/ @@ -370,3 +371,5 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd +/Unbinder/wwwroot/lib +/Unbinder/wwwroot/js diff --git a/Unbinder/.dockerignore b/Unbinder/.dockerignore index 114f161..5fa34c3 100644 --- a/Unbinder/.dockerignore +++ b/Unbinder/.dockerignore @@ -1 +1,3 @@ -__notes__ \ No newline at end of file +__notes__ +db_data +.eslintrc.js diff --git a/Unbinder/.eslintrc.js b/Unbinder/.eslintrc.js new file mode 100644 index 0000000..59f25f9 --- /dev/null +++ b/Unbinder/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + extends: [ + 'semistandard' + ] +}; diff --git a/Unbinder/Controllers/Api/IngredientApiController.cs b/Unbinder/Controllers/Api/IngredientApiController.cs new file mode 100644 index 0000000..9e901a6 --- /dev/null +++ b/Unbinder/Controllers/Api/IngredientApiController.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Unbinder.Repositories; + +namespace Unbinder.Controllers.Api +{ + [ApiController] + public class IngredientApiController(IIngredientRepository repository) : ControllerBase + { + private readonly IIngredientRepository _repository = repository; + + [HttpGet] + [Route("/api/ingredients")] + public IActionResult GetAll() + { + var result = _repository.GetAll; + return result == null ? NotFound() : Ok(result); + } + } +} \ No newline at end of file diff --git a/Unbinder/Program.cs b/Unbinder/Program.cs index 121d6c9..3a3f289 100644 --- a/Unbinder/Program.cs +++ b/Unbinder/Program.cs @@ -32,6 +32,7 @@ builder.Services.AddDbContext(options => // configure MVC builder.Services.AddControllersWithViews(); +builder.Services.AddControllers(); // map additional controllers for exposed REST API routes builder.Services.AddRazorPages(); builder.Services.AddCors(options => diff --git a/Unbinder/Unbinder.csproj b/Unbinder/Unbinder.csproj index ea96bf1..82a9c69 100644 --- a/Unbinder/Unbinder.csproj +++ b/Unbinder/Unbinder.csproj @@ -21,12 +21,15 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - diff --git a/Unbinder/Views/Recipe/Create.cshtml b/Unbinder/Views/Recipe/Create.cshtml index 655e544..40fa6af 100644 --- a/Unbinder/Views/Recipe/Create.cshtml +++ b/Unbinder/Views/Recipe/Create.cshtml @@ -28,6 +28,12 @@ +
+ +
+ - \ No newline at end of file + + + \ No newline at end of file diff --git a/Unbinder/Views/Recipe/Search.cshtml b/Unbinder/Views/Recipe/Search.cshtml index 7211df1..ebfe937 100644 --- a/Unbinder/Views/Recipe/Search.cshtml +++ b/Unbinder/Views/Recipe/Search.cshtml @@ -33,12 +33,12 @@ message.innerHTML = query ? `Viewing ${@Model.ToArray().Length} results for: ${query}` : "Enter a new search term below:"; // handle search updates on client side - searchButton.onclick = async () => { - const newResult = await fetch(`/api/recipe/search?q=${textField.value}`); + searchButton.onclick = () => { + // const newResult = await fetch(`/api/recipe/search?q=${textField.value}`); - console.log(newResult); + // console.log(newResult); - const newResultJson = await newResult.json(); + // const newResultJson = await newResult.json(); window.location.search = `?q=${textField.value}`; } }); diff --git a/Unbinder/Views/Shared/_Layout.cshtml b/Unbinder/Views/Shared/_Layout.cshtml index 3d2d6a7..a7f6b71 100644 --- a/Unbinder/Views/Shared/_Layout.cshtml +++ b/Unbinder/Views/Shared/_Layout.cshtml @@ -2,8 +2,10 @@ @ViewBag.Title + + diff --git a/Unbinder/libman.json b/Unbinder/libman.json index ceee271..7911521 100644 --- a/Unbinder/libman.json +++ b/Unbinder/libman.json @@ -1,5 +1,10 @@ { "version": "1.0", "defaultProvider": "cdnjs", - "libraries": [] + "libraries": [ + { + "library": "pdf.js@4.0.269", + "destination": "wwwroot/lib/pdf.js/" + } + ] } \ No newline at end of file diff --git a/Unbinder/package.json b/Unbinder/package.json new file mode 100644 index 0000000..6d8f0d4 --- /dev/null +++ b/Unbinder/package.json @@ -0,0 +1,21 @@ +{ + "name": "unbinder", + "version": "1.0.0", + "description": "", + "main": "wwwroot/js/index.js", + "scripts": { + "build": "tsc", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Mikayla Dobson", + "license": "ISC", + "devDependencies": { + "eslint": "^8.55.0", + "eslint-config-semistandard": "^17.0.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-n": "^15.7.0", + "eslint-plugin-promise": "^6.1.1", + "typescript": "^5.3.2" + } +} diff --git a/Unbinder/tsconfig.json b/Unbinder/tsconfig.json new file mode 100644 index 0000000..147ce57 --- /dev/null +++ b/Unbinder/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "noImplicitAny": false, + "noEmitOnError": true, + "removeComments": false, + "sourceMap": true, + "lib": ["ES2015", "DOM"], + "module": "CommonJS", + "target": "ES5", + "moduleResolution": "Node", + "outDir": "wwwroot/js" + }, + "include": [ + "wwwroot/ts/**/*" + ], + "exclude": [ + "node_modules", + "wwwroot/js" + ] +} diff --git a/Unbinder/wwwroot/css/site.css b/Unbinder/wwwroot/css/site.css new file mode 100644 index 0000000..f27e5ad --- /dev/null +++ b/Unbinder/wwwroot/css/site.css @@ -0,0 +1,18 @@ +html { + font-size: 14px; +} + +@media (min-width: 768px) { + html { + font-size: 16px; + } +} + +html { + position: relative; + min-height: 100%; +} + +body { + margin-bottom: 60px; +} \ No newline at end of file diff --git a/Unbinder/wwwroot/favicon.ico b/Unbinder/wwwroot/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..63e859b476eff5055e0e557aaa151ca8223fbeef GIT binary patch literal 5430 zcmc&&Yj2xp8Fqnv;>&(QB_ve7>^E#o2mu=cO~A%R>DU-_hfbSRv1t;m7zJ_AMrntN zy0+^f&8be>q&YYzH%(88lQ?#KwiCzaCO*ZEo%j&v;<}&Lj_stKTKK>#U3nin@AF>w zb3ONSAFR{u(S1d?cdw53y}Gt1b-Hirbh;;bm(Rcbnoc*%@jiaXM|4jU^1WO~`TYZ~ zC-~jh9~b-f?fX`DmwvcguQzn*uV}c^Vd&~?H|RUs4Epv~gTAfR(B0lT&?RWQOtduM z^1vUD9{HQsW!{a9|0crA34m7Z6lpG^}f6f?={zD+ zXAzk^i^aKN_}s2$eX81wjSMONE#WVdzf|MT)Ap*}Vsn!Xbv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)$y?6FO$DWl$jUGV`F1G_^E&E>sY*YnA~ruv3=z9F8&&~Xpm<<75?N3 z>x~`I&M9q)O1=zWZHN9hZWx>RQ}zLP+iL57Q)%&_^$Sme^^G7;e-P~CR?kqU#Io#( z(nH1Wn*Ig)|M>WLGrxoU?FZrS`4GO&w;+39A3f8w{{Q7eg|$+dIlNFPAe+tN=FOYU z{A&Fg|H73+w1IK(W=j*L>JQgz$g0 z7JpKXLHIh}#$wm|N`s}o-@|L_`>*(gTQ~)wr3Eap7g%PVNisKw82im;Gdv#85x#s+ zoqqtnwu4ycd>cOQgRh-=aEJbnvVK`}ja%+FZx}&ehtX)n(9nVfe4{mn0bgijUbNr7Tf5X^$*{qh2%`?--%+sbSrjE^;1e3>% zqa%jdY16{Y)a1hSy*mr0JGU05Z%=qlx5vGvTjSpTt6k%nR06q}1DU`SQh_ZAeJ}A@`hL~xvv05U?0%=spP`R>dk?cOWM9^KNb7B?xjex>OZo%JMQQ1Q zB|q@}8RiP@DWn-(fB;phPaIOP2Yp)XN3-Fsn)S3w($4&+p8f5W_f%gac}QvmkHfCj$2=!t`boCvQ zCW;&Dto=f8v##}dy^wg3VNaBy&kCe3N;1|@n@pUaMPT?(aJ9b*(gJ28$}(2qFt$H~u5z94xcIQkcOI++)*exzbrk?WOOOf*|%k5#KV zL=&ky3)Eirv$wbRJ2F2s_ILQY--D~~7>^f}W|Aw^e7inXr#WLI{@h`0|jHud2Y~cI~Yn{r_kU^Vo{1gja { + const ingredients = await getAllIngredients(); + console.log({ ingredients }); + + const dropdown = document.getElementById('ingredient-selector'); + + ingredients.forEach(ingredient => { + const option = document.createElement('option'); + option.value = ingredient.id; + option.innerText = ingredient.name; + dropdown.appendChild(option); + }); +}); diff --git a/Unbinder/wwwroot/ts/index.ts b/Unbinder/wwwroot/ts/index.ts new file mode 100644 index 0000000..e69de29