diff --git a/.gitignore b/.gitignore index f92525c..1303e39 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +/app/assets/builds/* +!/app/assets/builds/.keep diff --git a/Gemfile b/Gemfile index c59db3d..eaf145f 100644 --- a/Gemfile +++ b/Gemfile @@ -61,3 +61,7 @@ group :test do gem "capybara" gem "selenium-webdriver" end + +gem "tailwindcss-rails" + +gem "tailwindcss-ruby", "3.4.13" diff --git a/Gemfile.lock b/Gemfile.lock index 85d0279..c0b311b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -285,7 +285,7 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - solid_cable (3.0.6) + solid_cable (3.0.7) actioncable (>= 7.2) activejob (>= 7.2) activerecord (>= 7.2) @@ -317,6 +317,13 @@ GEM stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.1.2) + tailwindcss-rails (3.3.1) + railties (>= 7.0.0) + tailwindcss-ruby (~> 3.0) + tailwindcss-ruby (3.4.13-aarch64-linux) + tailwindcss-ruby (3.4.13-arm-linux) + tailwindcss-ruby (3.4.13-arm64-darwin) + tailwindcss-ruby (3.4.13-x86_64-linux) thor (1.3.2) thruster (0.1.10) thruster (0.1.10-aarch64-linux) @@ -377,6 +384,8 @@ DEPENDENCIES solid_queue sqlite3 (>= 2.1) stimulus-rails + tailwindcss-rails + tailwindcss-ruby (= 3.4.13) thruster turbo-rails tzinfo-data diff --git a/Procfile.dev b/Procfile.dev new file mode 100644 index 0000000..da151fe --- /dev/null +++ b/Procfile.dev @@ -0,0 +1,2 @@ +web: bin/rails server +css: bin/rails tailwindcss:watch diff --git a/app/assets/builds/.keep b/app/assets/builds/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css new file mode 100644 index 0000000..8666d2f --- /dev/null +++ b/app/assets/stylesheets/application.tailwind.css @@ -0,0 +1,13 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* + +@layer components { + .btn-primary { + @apply py-2 px-4 bg-blue-200; + } +} + +*/ diff --git a/app/controllers/appointments_controller.rb b/app/controllers/appointments_controller.rb index 5769f51..225c751 100644 --- a/app/controllers/appointments_controller.rb +++ b/app/controllers/appointments_controller.rb @@ -1,12 +1,36 @@ class AppointmentsController < ApplicationController - helper_method :appointments + helper_method :appointments, :appointment - def index + before_action :check_created_by, only: [:edit, :update] + + def update + if appointment.update(appointment_params) + redirect_to appointments_path, notice: "Appointment updated!" + else + render :edit, status: :unprocessable_entity + end end private + def check_created_by + unless appointment.created_by?(Current.user) + redirect_to appointments_path, alert: "Can't modify appointment - you are not the creator." + end + end + + def appointment_params + params.require(:appointment).permit( + :requested_datetime, + :notes + ) + end + + def appointment + @appointment ||= Appointment.find(params[:id]) + end + def appointments - @appointments ||= Appointment.all + @appointments ||= Appointment.includes(:created_by).all end end diff --git a/app/javascript/application.js b/app/javascript/application.js index 0d7b494..d6605c6 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,3 +1,7 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" + +window.removeFlash = (closeButton) => { + closeButton.parentElement.remove(); +} diff --git a/app/models/appointment.rb b/app/models/appointment.rb index f0d75de..26fb918 100644 --- a/app/models/appointment.rb +++ b/app/models/appointment.rb @@ -2,4 +2,16 @@ class Appointment < ApplicationRecord belongs_to :created_by, foreign_key: :created_by_user_id, class_name: "User" validates :requested_datetime, presence: true + + after_save_commit -> { + broadcast_replace_to( + "appointments_list", + partial: "appointments/load_row", + locals: { appointment: self } + ) + } + + def created_by?(user) + created_by == user + end end diff --git a/app/views/appointments/_appointment.html.erb b/app/views/appointments/_appointment.html.erb index 1bb8f3d..f0eb703 100644 --- a/app/views/appointments/_appointment.html.erb +++ b/app/views/appointments/_appointment.html.erb @@ -1,5 +1,28 @@ -
+ Requested Time - <%= appointment.requested_datetime.strftime("%B %-d %Y at %I:%H%P") %> +
++ <%= truncate(appointment.notes, length: 40) %> +
+ +