From 67c23015ab856c598b485f2343b4a6f781ab93e5 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Wed, 2 Oct 2024 14:34:50 -0500 Subject: [PATCH] Continue converting to composition api --- app/controllers/application_controller.rb | 14 +- app/controllers/calculator_controller.rb | 4 +- app/controllers/users_controller.rb | 4 +- app/javascript/components/AppAutocomplete.vue | 2 +- app/javascript/components/AppConfirm.vue | 36 ++- app/javascript/components/AppDatePicker.vue | 2 +- app/javascript/components/AppModal.vue | 7 +- app/javascript/components/AppPager.vue | 4 +- app/javascript/components/LogShow.vue | 2 +- .../components/RecipeEditIngredientEditor.vue | 306 +++++++++--------- .../components/RecipeEditIngredientItem.vue | 73 ++--- app/javascript/components/RecipeShow.vue | 201 +++++------- app/javascript/components/TaskItemEdit.vue | 53 +-- app/javascript/components/TaskItemList.vue | 182 +++++------ .../components/TaskListDropdownItem.vue | 52 ++- .../components/TaskListMiniForm.vue | 44 ++- app/javascript/components/The404Page.vue | 5 +- app/javascript/components/TheAboutPage.vue | 6 +- .../components/TheAdminUserEditor.vue | 5 +- .../components/TheAdminUserList.vue | 23 +- app/javascript/components/TheCalculator.vue | 121 +++---- app/javascript/components/TheFood.vue | 41 +-- app/javascript/components/TheFoodCreator.vue | 98 +++--- app/javascript/components/TheFoodEditor.vue | 56 ++-- app/javascript/components/TheFoodList.vue | 158 ++++----- app/javascript/components/TheLog.vue | 37 +-- app/javascript/components/TheLogCreator.vue | 65 ++-- app/javascript/components/TheLogEditor.vue | 55 ++-- app/javascript/components/TheLogList.vue | 82 ++--- app/javascript/components/TheNotesList.vue | 77 ++--- app/javascript/components/TheRecipe.vue | 65 ++-- .../components/TheRecipeCreator.vue | 56 ++-- app/javascript/components/TheRecipeEditor.vue | 55 ++-- app/javascript/components/TheRecipeList.vue | 4 +- app/javascript/components/TheTaskListList.vue | 121 +++---- app/javascript/components/TheUserCreator.vue | 52 ++- app/javascript/components/TheUserEditor.vue | 85 +++-- app/javascript/components/UserEdit.vue | 18 +- app/javascript/components/UserLogin.vue | 66 ++-- 39 files changed, 1013 insertions(+), 1324 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 897aa46..106f07d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,8 +42,18 @@ class ApplicationController < ActionController::Base if owner yield if block_given? else - flash[:warning] = "Operation Not Permitted" - redirect_to root_path + respond_to do |format| + format.html do + flash[:warning] = "Operation Not Permitted" + redirect_to root_path + end + + format.json do + render json: { error: "Operation Not Permitted" }, status: current_user.nil? ? :unauthorized : :forbidden + end + end + + end end diff --git a/app/controllers/calculator_controller.rb b/app/controllers/calculator_controller.rb index 8a714f4..85647ae 100644 --- a/app/controllers/calculator_controller.rb +++ b/app/controllers/calculator_controller.rb @@ -34,8 +34,10 @@ class CalculatorController < ApplicationController begin input_unit = UnitConversion.parse(input) + input_unit.unitwise rescue UnitConversion::UnparseableUnitError => e - data[:errors][:input] << 'invalid string' + data[:errors][:input] << e.message + input_unit = nil end if !input_unit.nil? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fb0f873..cd1bf6c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -50,7 +50,7 @@ class UsersController < ApplicationController if @user.save set_current_user(@user) format.html { redirect_to root_path, notice: 'User created.' } - format.json { render :show, status: :created, location: @user } + format.json { render json: UserSerializer.for(@user), status: :created, location: @user } else format.html { render :new } format.json { render json: @user.errors, status: :unprocessable_entity } @@ -68,7 +68,7 @@ class UsersController < ApplicationController respond_to do |format| if @user.update(user_params) format.html { redirect_to root_path, notice: 'User updated.' } - format.json { render :show, status: :created, location: @user } + format.json { render json: UserSerializer.for(@user) , status: :created, location: @user } else format.html { render :edit } format.json { render json: @user.errors, status: :unprocessable_entity } diff --git a/app/javascript/components/AppAutocomplete.vue b/app/javascript/components/AppAutocomplete.vue index af5f595..7e9c922 100644 --- a/app/javascript/components/AppAutocomplete.vue +++ b/app/javascript/components/AppAutocomplete.vue @@ -145,7 +145,7 @@ emit("update:modelValue", newValue); if (newValue.length >= Math.max(1, props.minLength)) { - this.updateOptions(newValue); + updateOptions(newValue); } else { isListOpen.value = false; } diff --git a/app/javascript/components/AppConfirm.vue b/app/javascript/components/AppConfirm.vue index d73946b..c59711f 100644 --- a/app/javascript/components/AppConfirm.vue +++ b/app/javascript/components/AppConfirm.vue @@ -1,31 +1,33 @@ \ No newline at end of file diff --git a/app/javascript/components/AppDatePicker.vue b/app/javascript/components/AppDatePicker.vue index 1141547..dfd0b27 100644 --- a/app/javascript/components/AppDatePicker.vue +++ b/app/javascript/components/AppDatePicker.vue @@ -1,5 +1,5 @@ diff --git a/app/javascript/components/RecipeEditIngredientItem.vue b/app/javascript/components/RecipeEditIngredientItem.vue index 74b551b..8703d15 100644 --- a/app/javascript/components/RecipeEditIngredientItem.vue +++ b/app/javascript/components/RecipeEditIngredientItem.vue @@ -44,55 +44,50 @@ -