diff options
163 files changed, 4556 insertions, 0 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..325bfc0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,51 @@ +# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. + +# Ignore git directory. +/.git/ +/.gitignore + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all default key files. +/config/master.key +/config/credentials/*.key + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/.keep + +# Ignore assets. +/node_modules/ +/app/assets/builds/* +!/app/assets/builds/.keep +/public/assets + +# Ignore CI service files. +/.github + +# Ignore Kamal files. +/config/deploy*.yml +/.kamal + +# Ignore development files +/.devcontainer + +# Ignore Docker-related files +/.dockerignore +/Dockerfile* diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8dc4323 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f92525c --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.kamal/secrets b/.kamal/secrets new file mode 100644 index 0000000..9a771a3 --- /dev/null +++ b/.kamal/secrets @@ -0,0 +1,17 @@ +# Secrets defined here are available for reference under registry/password, env/secret, builder/secrets, +# and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either +# password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git. + +# Example of extracting secrets from 1password (or another compatible pw manager) +# SECRETS=$(kamal secrets fetch --adapter 1password --account your-account --from Vault/Item KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY) +# KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD ${SECRETS}) +# RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY ${SECRETS}) + +# Use a GITHUB_TOKEN if private repositories are needed for the image +# GITHUB_TOKEN=$(gh config get -h github.com oauth_token) + +# Grab the registry password from ENV +KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD + +# Improve security by using a password manager. Never check config/master.key into git! +RAILS_MASTER_KEY=$(cat config/master.key) diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f9d86d4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +# Omakase Ruby styling for Rails +inherit_gem: { rubocop-rails-omakase: rubocop.yml } + +# Overwrite or add rules to create your own house style +# +# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` +# Layout/SpaceInsideArrayLiteralBrackets: +# Enabled: false diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..61b1268 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-3.2.8 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..20b3bf3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +# syntax=docker/dockerfile:1 +# check=error=true + +# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: +# docker build -t ferti . +# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name ferti ferti + +# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version +ARG RUBY_VERSION=3.2.8 +FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base + +# Rails app lives here +WORKDIR /rails + +# Install base packages +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Set production environment +ENV RAILS_ENV="production" \ + BUNDLE_DEPLOYMENT="1" \ + BUNDLE_PATH="/usr/local/bundle" \ + BUNDLE_WITHOUT="development" + +# Throw-away build stage to reduce size of final image +FROM base AS build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install && \ + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ + bundle exec bootsnap precompile --gemfile + +# Copy application code +COPY . . + +# Precompile bootsnap code for faster boot times +RUN bundle exec bootsnap precompile app/ lib/ + +# Precompiling assets for production without requiring secret RAILS_MASTER_KEY +RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile + + + + +# Final stage for app image +FROM base + +# Copy built artifacts: gems, application +COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" +COPY --from=build /rails /rails + +# Run and own only the runtime files as a non-root user for security +RUN groupadd --system --gid 1000 rails && \ + useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ + chown -R rails:rails db log storage tmp +USER 1000:1000 + +# Entrypoint prepares the database. +ENTRYPOINT ["/rails/bin/docker-entrypoint"] + +# Start server via Thruster by default, this can be overwritten at runtime +EXPOSE 80 +CMD ["./bin/thrust", "./bin/rails", "server"] @@ -0,0 +1,65 @@ +source "https://rubygems.org" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 8.0.2", ">= 8.0.2.1" +# The modern asset pipeline for Rails [https://github.com/rails/propshaft] +gem "propshaft" +# Use sqlite3 as the database for Active Record +gem "sqlite3", ">= 2.1" +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", ">= 5.0" +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ windows jruby ] + +# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable +gem "solid_cache" +gem "solid_queue" +gem "solid_cable" + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +# Deploy this application anywhere as a Docker container [https://kamal-deploy.org] +gem "kamal", require: false + +# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/] +gem "thruster", require: false + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" + + # Static analysis for security vulnerabilities [https://brakemanscanner.org/] + gem "brakeman", require: false + + # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] + gem "rubocop-rails-omakase", require: false +end + +group :development do + # Use console on exceptions pages [https://github.com/rails/web-console] + gem "web-console" +end + +group :test do + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem "capybara" + gem "selenium-webdriver" +end + +gem "chartkick", "~> 5.2" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1bc31ac --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,397 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + mail (>= 2.8.0) + actionmailer (8.0.2.1) + actionpack (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activesupport (= 8.0.2.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.2.1) + actionview (= 8.0.2.1) + activesupport (= 8.0.2.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.2.1) + actionpack (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.2.1) + activesupport (= 8.0.2.1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.2.1) + activesupport (= 8.0.2.1) + globalid (>= 0.3.6) + activemodel (8.0.2.1) + activesupport (= 8.0.2.1) + activerecord (8.0.2.1) + activemodel (= 8.0.2.1) + activesupport (= 8.0.2.1) + timeout (>= 0.4.0) + activestorage (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activesupport (= 8.0.2.1) + marcel (~> 1.0) + activesupport (8.0.2.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.3) + base64 (0.3.0) + bcrypt_pbkdf (1.1.1) + bcrypt_pbkdf (1.1.1-arm64-darwin) + bcrypt_pbkdf (1.1.1-x86_64-darwin) + benchmark (0.4.1) + bigdecimal (3.2.2) + bindex (0.8.1) + bootsnap (1.18.6) + msgpack (~> 1.2) + brakeman (7.1.0) + racc + builder (3.3.0) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + chartkick (5.2.0) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + crass (1.0.6) + date (3.4.1) + debug (1.11.0) + irb (~> 1.10) + reline (>= 0.3.8) + dotenv (3.1.8) + drb (2.2.3) + ed25519 (1.4.0) + erb (5.0.2) + erubi (1.13.1) + et-orbi (1.3.0) + tzinfo + fugit (1.11.1) + et-orbi (~> 1, >= 1.2.11) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + importmap-rails (2.2.2) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.8.1) + irb (1.15.2) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.14.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + json (2.13.2) + kamal (2.7.0) + activesupport (>= 7.0) + base64 (~> 0.2) + bcrypt_pbkdf (~> 1.0) + concurrent-ruby (~> 1.2) + dotenv (~> 3.1) + ed25519 (~> 1.4) + net-ssh (~> 7.3) + sshkit (>= 1.23.0, < 2.0) + thor (~> 1.3) + zeitwerk (>= 2.6.18, < 3.0) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + loofah (2.24.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.3) + mini_mime (1.1.5) + minitest (5.25.5) + msgpack (1.8.0) + net-imap (0.5.9) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-scp (4.1.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.5.1) + net-protocol + net-ssh (7.3.0) + nio4r (2.7.4) + nokogiri (1.18.9-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-musl) + racc (~> 1.4) + ostruct (0.6.3) + parallel (1.27.0) + parser (3.3.9.0) + ast (~> 2.4.1) + racc + pp (0.6.2) + prettyprint + prettyprint (0.2.0) + prism (1.4.0) + propshaft (1.2.1) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + psych (5.2.6) + date + stringio + public_suffix (6.0.2) + puma (6.6.1) + nio4r (~> 2.0) + raabro (1.4.0) + racc (1.8.1) + rack (3.2.0) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.2.1) + rack (>= 3) + rails (8.0.2.1) + actioncable (= 8.0.2.1) + actionmailbox (= 8.0.2.1) + actionmailer (= 8.0.2.1) + actionpack (= 8.0.2.1) + actiontext (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activemodel (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + bundler (>= 1.15.0) + railties (= 8.0.2.1) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.3.0) + rdoc (6.14.2) + erb + psych (>= 4.0.0) + regexp_parser (2.11.2) + reline (0.6.2) + io-console (~> 0.5) + rexml (3.4.1) + rubocop (1.79.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.25.0) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rails (2.33.3) + activesupport (>= 4.2.0) + lint_roller (~> 1.1) + rack (>= 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rails-omakase (1.1.0) + rubocop (>= 1.72) + rubocop-performance (>= 1.24) + rubocop-rails (>= 2.30) + ruby-progressbar (1.13.0) + rubyzip (3.0.1) + securerandom (0.4.1) + selenium-webdriver (4.35.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 4.0) + websocket (~> 1.0) + solid_cable (3.0.12) + actioncable (>= 7.2) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_cache (1.0.7) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_queue (1.2.1) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (>= 1.3.1) + fugit (~> 1.11.0) + railties (>= 7.1) + thor (>= 1.3.1) + sqlite3 (2.7.3-aarch64-linux-gnu) + sqlite3 (2.7.3-aarch64-linux-musl) + sqlite3 (2.7.3-arm-linux-gnu) + sqlite3 (2.7.3-arm-linux-musl) + sqlite3 (2.7.3-arm64-darwin) + sqlite3 (2.7.3-x86_64-darwin) + sqlite3 (2.7.3-x86_64-linux-gnu) + sqlite3 (2.7.3-x86_64-linux-musl) + sshkit (1.24.0) + base64 + logger + net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) + net-ssh (>= 2.8.0) + ostruct + stimulus-rails (1.3.4) + railties (>= 6.0.0) + stringio (3.1.7) + thor (1.4.0) + thruster (0.1.15) + thruster (0.1.15-aarch64-linux) + thruster (0.1.15-arm64-darwin) + thruster (0.1.15-x86_64-darwin) + thruster (0.1.15-x86_64-linux) + timeout (0.4.3) + turbo-rails (2.0.16) + actionpack (>= 7.1.0) + railties (>= 7.1.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (3.1.5) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.3) + useragent (0.16.11) + web-console (4.2.1) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.7.3) + +PLATFORMS + aarch64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + bootsnap + brakeman + capybara + chartkick (~> 5.2) + debug + importmap-rails + jbuilder + kamal + propshaft + puma (>= 5.0) + rails (~> 8.0.2, >= 8.0.2.1) + rubocop-rails-omakase + selenium-webdriver + solid_cable + solid_cache + solid_queue + sqlite3 (>= 2.1) + stimulus-rails + thruster + turbo-rails + tzinfo-data + web-console + +BUNDLED WITH + 2.6.9 diff --git a/README.md b/README.md new file mode 100644 index 0000000..7db80e4 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9a5ea73 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/images/.keep diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..fe93333 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,10 @@ +/* + * This is a manifest file that'll be compiled into application.css. + * + * With Propshaft, assets are served efficiently without preprocessing steps. You can still include + * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard + * cascading order, meaning styles declared later in the document or manifest will override earlier ones, + * depending on specificity. + * + * Consider organizing styles into separate files for maintainability. + */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..0d95db2 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/controllers/concerns/.keep diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb new file mode 100644 index 0000000..9619852 --- /dev/null +++ b/app/controllers/crops_controller.rb @@ -0,0 +1,70 @@ +class CropsController < ApplicationController + before_action :set_crop, only: %i[ show edit update destroy ] + + # GET /crops or /crops.json + def index + @crops = Crop.all + end + + # GET /crops/1 or /crops/1.json + def show + end + + # GET /crops/new + def new + @crop = Crop.new + end + + # GET /crops/1/edit + def edit + end + + # POST /crops or /crops.json + def create + @crop = Crop.new(crop_params) + + respond_to do |format| + if @crop.save + format.html { redirect_to @crop, notice: "Crop was successfully created." } + format.json { render :show, status: :created, location: @crop } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @crop.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /crops/1 or /crops/1.json + def update + respond_to do |format| + if @crop.update(crop_params) + format.html { redirect_to @crop, notice: "Crop was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @crop } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @crop.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /crops/1 or /crops/1.json + def destroy + @crop.destroy! + + respond_to do |format| + format.html { redirect_to crops_path, notice: "Crop was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_crop + @crop = Crop.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def crop_params + params.expect(crop: [ :name, :crop_type, :nno3, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo, :nnh4 ]) + end +end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 0000000..4e9d560 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,45 @@ +class DashboardController < ApplicationController + def index + # Raft allocation by crop type + @raft_data = raft_data_series + + # Nutrient target table + @latest_measurement = NutrientMeasurement.order(measured_on: :desc, created_at: :desc).first + @target = TargetNutrientCalculator.call + + # Measurement history table + @measurements = NutrientMeasurement.order(measured_on: :desc).limit(10) + + @npk_measurement_data = measurement_data_series(:nno3, :p, :k) + @ammonium_measurement_data = measurement_data_series(:nnh4) + end + + private + + def raft_data_series + data_series = [] + + counts = Raft.left_outer_joins(:crop) + .group("crops.name", "crops.crop_type") + .count + + counts.each do |(crop_name, crop_type), count| + name = (crop_name || "unassigned").titleize + type = (crop_type || "unassigned").titleize + data = { type => count } + data_series << { name:, data: } + end + + unassigned, assigned = data_series.partition { |s| s[:name].casecmp("unassigned").zero? } + assigned + unassigned + end + + def measurement_data_series(*nutrients) + nutrients.map do |formula| + { name: Nutrient.find_by!(formula:).name, + data: NutrientMeasurement + .order(:measured_on) + .pluck(:measured_on, formula) } + end + end +end diff --git a/app/controllers/fertilizer_products_controller.rb b/app/controllers/fertilizer_products_controller.rb new file mode 100644 index 0000000..ff0d945 --- /dev/null +++ b/app/controllers/fertilizer_products_controller.rb @@ -0,0 +1,70 @@ +class FertilizerProductsController < ApplicationController + before_action :set_fertilizer_product, only: %i[ show edit update destroy ] + + # GET /fertilizer_products or /fertilizer_products.json + def index + @fertilizer_products = FertilizerProduct.all + end + + # GET /fertilizer_products/1 or /fertilizer_products/1.json + def show + end + + # GET /fertilizer_products/new + def new + @fertilizer_product = FertilizerProduct.new + end + + # GET /fertilizer_products/1/edit + def edit + end + + # POST /fertilizer_products or /fertilizer_products.json + def create + @fertilizer_product = FertilizerProduct.new(fertilizer_product_params) + + respond_to do |format| + if @fertilizer_product.save + format.html { redirect_to @fertilizer_product, notice: "Fertilizer product was successfully created." } + format.json { render :show, status: :created, location: @fertilizer_product } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @fertilizer_product.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /fertilizer_products/1 or /fertilizer_products/1.json + def update + respond_to do |format| + if @fertilizer_product.update(fertilizer_product_params) + format.html { redirect_to @fertilizer_product, notice: "Fertilizer product was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @fertilizer_product } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @fertilizer_product.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /fertilizer_products/1 or /fertilizer_products/1.json + def destroy + @fertilizer_product.destroy! + + respond_to do |format| + format.html { redirect_to fertilizer_products_path, notice: "Fertilizer product was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_fertilizer_product + @fertilizer_product = FertilizerProduct.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def fertilizer_product_params + params.expect(fertilizer_product: [ :name, :purity ]) + end +end diff --git a/app/controllers/fertilizers_controller.rb b/app/controllers/fertilizers_controller.rb new file mode 100644 index 0000000..040c462 --- /dev/null +++ b/app/controllers/fertilizers_controller.rb @@ -0,0 +1,70 @@ +class FertilizersController < ApplicationController + before_action :set_fertilizer, only: %i[ show edit update destroy ] + + # GET /fertilizers or /fertilizers.json + def index + @fertilizers = Fertilizer.all + end + + # GET /fertilizers/1 or /fertilizers/1.json + def show + end + + # GET /fertilizers/new + def new + @fertilizer = Fertilizer.new + end + + # GET /fertilizers/1/edit + def edit + end + + # POST /fertilizers or /fertilizers.json + def create + @fertilizer = Fertilizer.new(fertilizer_params) + + respond_to do |format| + if @fertilizer.save + format.html { redirect_to @fertilizer, notice: "Fertilizer was successfully created." } + format.json { render :show, status: :created, location: @fertilizer } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @fertilizer.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /fertilizers/1 or /fertilizers/1.json + def update + respond_to do |format| + if @fertilizer.update(fertilizer_params) + format.html { redirect_to @fertilizer, notice: "Fertilizer was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @fertilizer } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @fertilizer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /fertilizers/1 or /fertilizers/1.json + def destroy + @fertilizer.destroy! + + respond_to do |format| + format.html { redirect_to fertilizers_path, notice: "Fertilizer was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_fertilizer + @fertilizer = Fertilizer.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def fertilizer_params + params.expect(fertilizer: [ :name, :formula, :nno3, :nnh4, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo ]) + end +end diff --git a/app/controllers/nutrient_measurement_controller.rb b/app/controllers/nutrient_measurement_controller.rb new file mode 100644 index 0000000..6d26bfa --- /dev/null +++ b/app/controllers/nutrient_measurement_controller.rb @@ -0,0 +1,4 @@ +class NutrientMeasurementController < ApplicationController + def index + end +end diff --git a/app/controllers/rafts_controller.rb b/app/controllers/rafts_controller.rb new file mode 100644 index 0000000..96d99fd --- /dev/null +++ b/app/controllers/rafts_controller.rb @@ -0,0 +1,54 @@ +class RaftsController < ApplicationController + before_action :set_collections, only: [ :editor ] + + def index + redirect_to editor_rafts_path + end + + def editor + # @beds, @crops set in before_action + end + + # 1) Assign ALL rafts + def assign_all + crop_id = normalized_crop_id(params[:crop_id]) + Raft.update_all(crop_id: crop_id) # nil ok + redirect_to editor_rafts_path, notice: "All rafts updated." + end + + # 2) Assign all rafts in ONE bed + def assign_bed + bed = Bed.find(params.require(:bed_id)) + crop_id = normalized_crop_id(params[:crop_id]) + bed.rafts.update_all(crop_id: crop_id) + redirect_to editor_rafts_path, notice: "Bed ##{bed.location} updated." + end + + # 3) Assign ONE raft + def assign_one + raft = Raft.find(params[:id]) + val = params[:crop_id].to_s + + if val.blank? || val.casecmp("null").zero? + # Skip validations; write NULL directly + raft.update_column(:crop_id, nil) + else + raft.update!(crop_id: val) + end + + redirect_to editor_rafts_path(anchor: "bed-#{raft.bed_id}"), notice: "Raft updated." + end + + private + + def set_collections + @beds = Bed.order(:location) + @crops = Crop.order(:name) + end + + # Accept "", "null" → nil to allow clearing + def normalized_crop_id(val) + return nil if val.blank? || val.to_s.downcase == "null" + val + end +end diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb new file mode 100644 index 0000000..bcc29e7 --- /dev/null +++ b/app/controllers/recipes_controller.rb @@ -0,0 +1,8 @@ +class RecipesController < ApplicationController + def show + @latest = NutrientMeasurement.order(:measured_on).last || NutrientMeasurement.new + @target = TargetNutrientCalculator.call + volume = (params[:volume].presence || 100_000).to_i + @recipe = FertilizerRecipeCalculator.call(@latest, @target, water_volume_l: volume) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb new file mode 100644 index 0000000..5d64d17 --- /dev/null +++ b/app/helpers/dashboard_helper.rb @@ -0,0 +1,8 @@ +module DashboardHelper + def fmt2(v) = number_with_precision(v, precision: 2) + + # Total nitrogen (NO3-N + NH4-N) + def total_n(measurement) + (measurement.nno3.to_f) + (measurement.nnh4.to_f) + end +end diff --git a/app/helpers/nutrients_helper.rb b/app/helpers/nutrients_helper.rb new file mode 100644 index 0000000..de98dc3 --- /dev/null +++ b/app/helpers/nutrients_helper.rb @@ -0,0 +1,21 @@ +module NutrientsHelper + NUTRIENTS = %i[nno3 p k ca mg s na cl si fe zn b mn cu mo nnh4].freeze + + def percent_delta(measured, target) + return 0.0 if target.to_f.zero? + ((measured.to_f - target.to_f) / target.to_f) * 100.0 + end + + def fmt(v) + number_with_precision(v, precision: 2, strip_insignificant_zeros: true) + end + + def delta_badge_class(delta) + d = delta.abs + case d + when d < 0 then "bg-info" + when 0..5 then "bg-secondary" + else "bg-warning" + end + end +end diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb new file mode 100644 index 0000000..02cb1a7 --- /dev/null +++ b/app/helpers/recipes_helper.rb @@ -0,0 +1,16 @@ +module RecipesHelper + def commercial_name_for(component) + # Try to find a FertilizerProduct via a join, but gracefully fallback. + if defined?(FertilizerProduct) && defined?(FertilizerComposition) + prod = FertilizerProduct.joins(:fertilizer_compositions) + .where(fertilizer_compositions: { fertilizer_component_id: component.id }) + .first + return prod.name if prod&.name.present? + end + component.name.presence || component.formula + end + + def fmt_kg(v) + number_with_precision(v.to_f, precision: 2, strip_insignificant_zeros: true) + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..beff742 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/app/models/bed.rb b/app/models/bed.rb new file mode 100644 index 0000000..33eafd2 --- /dev/null +++ b/app/models/bed.rb @@ -0,0 +1,4 @@ +class Bed < ApplicationRecord + has_many :rafts, -> { order(:location) }, dependent: :destroy + validates :location, presence: true, uniqueness: true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/models/concerns/.keep diff --git a/app/models/crop.rb b/app/models/crop.rb new file mode 100644 index 0000000..b0f168d --- /dev/null +++ b/app/models/crop.rb @@ -0,0 +1,4 @@ +class Crop < ApplicationRecord + has_many :rafts + enum :crop_type, { leafy: 0, fruit: 1, herb: 2 } +end diff --git a/app/models/fertilizer_component.rb b/app/models/fertilizer_component.rb new file mode 100644 index 0000000..701ae9b --- /dev/null +++ b/app/models/fertilizer_component.rb @@ -0,0 +1,3 @@ +class FertilizerComponent < ApplicationRecord + validates :name, presence: true +end diff --git a/app/models/fertilizer_composition.rb b/app/models/fertilizer_composition.rb new file mode 100644 index 0000000..cf2bb93 --- /dev/null +++ b/app/models/fertilizer_composition.rb @@ -0,0 +1,6 @@ +class FertilizerComposition < ApplicationRecord + belongs_to :fertilizer_product + belongs_to :fertilizer_component + + validates :percent_w, numericality: { greater_than: 0, less_than_or_equal_to: 100 } +end diff --git a/app/models/fertilizer_product.rb b/app/models/fertilizer_product.rb new file mode 100644 index 0000000..e41316b --- /dev/null +++ b/app/models/fertilizer_product.rb @@ -0,0 +1,7 @@ +class FertilizerProduct < ApplicationRecord + has_many :fertilizer_compositions, dependent: :destroy + has_many :fertilizer_components, through: :fertilizer_compositions + + validates :name, presence: true, uniqueness: true + validates :purity, numericality: { greater_than: 0, less_than_or_equal_to: 100 } +end diff --git a/app/models/nutrient.rb b/app/models/nutrient.rb new file mode 100644 index 0000000..c584668 --- /dev/null +++ b/app/models/nutrient.rb @@ -0,0 +1,7 @@ +class Nutrient < ApplicationRecord + validates :formula, presence: true, uniqueness: true + validates :name, presence: true + + before_update { raise ActiveRecord::ReadOnlyRecord } + before_destroy { raise ActiveRecord::ReadOnlyRecord } +end diff --git a/app/models/nutrient_measurement.rb b/app/models/nutrient_measurement.rb new file mode 100644 index 0000000..f1d6d5b --- /dev/null +++ b/app/models/nutrient_measurement.rb @@ -0,0 +1,4 @@ +class NutrientMeasurement < ApplicationRecord + validates :measured_on, presence: true + validates :measured_on, uniqueness: true +end diff --git a/app/models/raft.rb b/app/models/raft.rb new file mode 100644 index 0000000..af52700 --- /dev/null +++ b/app/models/raft.rb @@ -0,0 +1,5 @@ +class Raft < ApplicationRecord + belongs_to :bed + belongs_to :crop + validates :location, presence: true, uniqueness: { scope: :bed_id } +end diff --git a/app/services/fertilizer_recipe_calculator.rb b/app/services/fertilizer_recipe_calculator.rb new file mode 100644 index 0000000..28ba8aa --- /dev/null +++ b/app/services/fertilizer_recipe_calculator.rb @@ -0,0 +1,136 @@ +class FertilizerRecipeCalculator + NUTRIENTS = %i[nno3 p k ca mg s nnh4].freeze + + def self.call(latest, target, water_volume_l: 100_000) + new(latest, target, water_volume_l).call + end + + def initialize(latest, target, water_volume_l) + @latest = latest || NutrientMeasurement.new + @target = target || NutrientMeasurement.new + @vol_l = water_volume_l.to_f + end + + # Returns a Hash { FertilizerComponent => qty_kg } + def call + deltas_mg_per_l = NUTRIENTS.index_with do |k| + [ (value(@target, k) - value(@latest, k)), 0 ].max + end + + # mg/L * L = mg -> kg + needed_kg = deltas_mg_per_l.transform_values { |mg_l| mg_l * @vol_l / 1_000_000.0 } + + recipe = Hash.new(0.0) + + # 1) P via MAP or DAP (accounts NH4-N) + if (p_need = needed_kg[:p]) > 0 + map = fc_by_formula("MAP") || fc_by_name_like("monoammonium phosphate") + dap = fc_by_formula("DAP") || fc_by_name_like("diammonium phosphate") + carrier = [ map, dap ].compact.find { |c| positive?(c.p) } + if carrier + kg = kg_for(p_need, carrier.p) + recipe[carrier] += kg + needed_kg[:nnh4] = [ needed_kg[:nnh4] - kg * pct(carrier.nnh4), 0 ].max if positive?(carrier.nnh4) + needed_kg[:p] = 0 + end + end + + # 2) NO3-N via KNO3 then Ca(NO3)2 (accounts K/Ca) + if (n_need = needed_kg[:nno3]) > 0 + kno3 = fc_by_formula("KNO3") || fc_by_name_like("potassium nitrate") + can = fc_by_formula("Ca(NO3)2") || fc_by_name_like("calcium nitrate") + + if kno3&.nno3.to_f > 0 + kg = kg_for(n_need, kno3.nno3) + recipe[kno3] += kg + needed_kg[:k] = [ needed_kg[:k] - kg * pct(kno3.k), 0 ].max + n_need -= kg * pct(kno3.nno3) + end + + if n_need > 0 && can&.nno3.to_f > 0 + kg = kg_for(n_need, can.nno3) + recipe[can] += kg + needed_kg[:ca] = [ needed_kg[:ca] - kg * pct(can.ca), 0 ].max + n_need = 0 + end + + needed_kg[:nno3] = [ n_need, 0 ].max + end + + # 3) K via K2SO4 (accounts S) + if (k_need = needed_kg[:k]) > 0 + sop = fc_by_formula("K2SO4") || fc_by_name_like("potassium sulfate") + if sop&.k.to_f > 0 + kg = kg_for(k_need, sop.k) + recipe[sop] += kg + needed_kg[:s] = [ needed_kg[:s] - kg * pct(sop.s), 0 ].max + needed_kg[:k] = 0 + end + end + + # 4) Ca via Ca(NO3)2 (accounts NO3-N) + if (ca_need = needed_kg[:ca]) > 0 + can = recipe.keys.find { |c| norm_formula(c) == "ca(no3)2" } || + fc_by_formula("Ca(NO3)2") || fc_by_name_like("calcium nitrate") + if can&.ca.to_f > 0 + kg = kg_for(ca_need, can.ca) + recipe[can] += kg + needed_kg[:nno3] = [ needed_kg[:nno3] - kg * pct(can.nno3), 0 ].max + needed_kg[:ca] = 0 + end + end + + # 5) Mg via MgSO4 (accounts S) + if (mg_need = needed_kg[:mg]) > 0 + mgs = fc_by_formula("MgSO4") || fc_by_name_like("magnesium sulfate") + if mgs&.mg.to_f > 0 + kg = kg_for(mg_need, mgs.mg) + recipe[mgs] += kg + needed_kg[:s] = [ needed_kg[:s] - kg * pct(mgs.s), 0 ].max + needed_kg[:mg] = 0 + end + end + + # 6) S via K2SO4 or MgSO4 (whichever we already used or find) + if (s_need = needed_kg[:s]) > 0 + sop = recipe.keys.find { |c| norm_formula(c) == "k2so4" } || + fc_by_formula("K2SO4") || fc_by_name_like("potassium sulfate") + mgs = recipe.keys.find { |c| norm_formula(c) == "mgso4" } || + fc_by_formula("MgSO4") || fc_by_name_like("magnesium sulfate") + carrier = [ sop, mgs ].compact.find { |c| positive?(c.s) } + if carrier + kg = kg_for(s_need, carrier.s) + recipe[carrier] += kg + needed_kg[:k] = [ needed_kg[:k] - kg * pct(carrier.k), 0 ].max if positive?(carrier.k) + needed_kg[:mg] = [ needed_kg[:mg] - kg * pct(carrier.mg), 0 ].max if positive?(carrier.mg) + needed_kg[:s] = 0 + end + end + + recipe.delete_if { |_c, kg| kg < 0.01 } + recipe + end + + private + + def value(obj, key) = obj.public_send(key).to_f + + def fc_by_formula(formula) + FertilizerComponent.where("LOWER(formula) = ?", formula.to_s.downcase).first + end + + def fc_by_name_like(name) + FertilizerComponent.where("LOWER(name) LIKE ?", "%#{name.downcase}%").first + end + + def kg_for(need_kg_element, percent_in_product) + return 0.0 unless positive?(percent_in_product) + need_kg_element / pct(percent_in_product) + end + + def pct(v) = v.to_f / 100.0 + + def positive?(v) = v.to_f > 0.0 + + def norm_formula(c) = c.formula.to_s.downcase.gsub(/\s+/, "") +end diff --git a/app/services/target_nutrient_calculator.rb b/app/services/target_nutrient_calculator.rb new file mode 100644 index 0000000..e6cd378 --- /dev/null +++ b/app/services/target_nutrient_calculator.rb @@ -0,0 +1,33 @@ +class TargetNutrientCalculator + # Derive nutrient columns from the NutrientMeasurement table + NUTRIENT_COLUMNS = (NutrientMeasurement.column_names - %w[id measured_on created_at updated_at]) + .map!(&:to_sym) + .freeze + + # Returns an unsaved NutrientMeasurement with target concentrations (e.g., mg/L) + def self.call + rafts = Raft.includes(:crop).where.not(crop_id: nil) + total = rafts.count + return empty_measurement if total.zero? + + sums = Hash.new(0.0) + + rafts.each do |raft| + NUTRIENT_COLUMNS.each do |col| + v = raft.crop.public_send(col) + sums[col] += v.to_f if v + end + end + + targets = sums.transform_values { |s| s / total } + NutrientMeasurement.new({ measured_on: Date.current }.merge(targets)) + end + + private + + def empty_measurement + NutrientMeasurement.new( + { measured_on: Date.current }.merge(NUTRIENT_COLUMNS.index_with { 0.0 }) + ) + end +end diff --git a/app/views/application/_copyright_footer.html.erb b/app/views/application/_copyright_footer.html.erb new file mode 100644 index 0000000..4a6d240 --- /dev/null +++ b/app/views/application/_copyright_footer.html.erb @@ -0,0 +1,10 @@ +<footer class="footer mt-auto py-3"> + <div class="container d-flex justify-content-between"> + <span class="text-muted">© 2025 FAPG. All rights reserved.</span> + <ul class="list-inline"> + <li class="list-inline-item"><a href="#" class="text-muted">Privacy Policy</a></li> + <li class="list-inline-item"><a href="#" class="text-muted">Terms of Use</a></li> + <li class="list-inline-item"><a href="#" class="text-muted">Contact Us</a></li> + </ul> + </div> +</footer> diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb new file mode 100644 index 0000000..9fa250a --- /dev/null +++ b/app/views/application/_navbar.html.erb @@ -0,0 +1,33 @@ +<nav class="navbar navbar-expand-lg navbar-light bg-light"> + <div class="container-fluid"> + <span class="navbar-brand">FAPG</span> + + <button class="navbar-toggler" + type="button" + data-bs-toggle="collapse" + data-bs-target="#navbarSupportedContent" + aria-controls="navbarSupportedContent" + aria-expanded="false" + aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + + <div class="collapse navbar-collapse" id="navbarSupportedContent"> + <ul class="navbar-nav me-auto mb-2 mb-lg-0"> + <li class="nav-item"> + <%= link_to "Home", root_path, class: "nav-link" %> + </li> + <li class="nav-item"> + <%= link_to "Ferti", root_path, class: "nav-link" %> + </li> + <li class="nav-item"> + <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Inventory</a> + </li> + <li class="nav-item"> + <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Billing</a> + </li> + </ul> + + </div> + </div> +</nav> diff --git a/app/views/crops/_crop.html.erb b/app/views/crops/_crop.html.erb new file mode 100644 index 0000000..e9b9b4d --- /dev/null +++ b/app/views/crops/_crop.html.erb @@ -0,0 +1,92 @@ +<div id="<%= dom_id crop %>"> + <p> + <strong>Name:</strong> + <%= crop.name %> + </p> + + <p> + <strong>Crop type:</strong> + <%= crop.crop_type %> + </p> + + <p> + <strong>Nno3:</strong> + <%= crop.nno3 %> + </p> + + <p> + <strong>P:</strong> + <%= crop.p %> + </p> + + <p> + <strong>K:</strong> + <%= crop.k %> + </p> + + <p> + <strong>Ca:</strong> + <%= crop.ca %> + </p> + + <p> + <strong>Mg:</strong> + <%= crop.mg %> + </p> + + <p> + <strong>S:</strong> + <%= crop.s %> + </p> + + <p> + <strong>Na:</strong> + <%= crop.na %> + </p> + + <p> + <strong>Cl:</strong> + <%= crop.cl %> + </p> + + <p> + <strong>Si:</strong> + <%= crop.si %> + </p> + + <p> + <strong>Fe:</strong> + <%= crop.fe %> + </p> + + <p> + <strong>Zn:</strong> + <%= crop.zn %> + </p> + + <p> + <strong>B:</strong> + <%= crop.b %> + </p> + + <p> + <strong>Mn:</strong> + <%= crop.mn %> + </p> + + <p> + <strong>Cu:</strong> + <%= crop.cu %> + </p> + + <p> + <strong>Mo:</strong> + <%= crop.mo %> + </p> + + <p> + <strong>Nnh4:</strong> + <%= crop.nnh4 %> + </p> + +</div> diff --git a/app/views/crops/_form.html.erb b/app/views/crops/_form.html.erb new file mode 100644 index 0000000..90226b6 --- /dev/null +++ b/app/views/crops/_form.html.erb @@ -0,0 +1,107 @@ +<%= form_with(model: crop) do |form| %> + <% if crop.errors.any? %> + <div style="color: red"> + <h2><%= pluralize(crop.errors.count, "error") %> prohibited this crop from being saved:</h2> + + <ul> + <% crop.errors.each do |error| %> + <li><%= error.full_message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div> + <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> + </div> + + <div> + <%= form.label :crop_type, style: "display: block" %> + <%= form.number_field :crop_type %> + </div> + + <div> + <%= form.label :nno3, style: "display: block" %> + <%= form.text_field :nno3 %> + </div> + + <div> + <%= form.label :p, style: "display: block" %> + <%= form.text_field :p %> + </div> + + <div> + <%= form.label :k, style: "display: block" %> + <%= form.text_field :k %> + </div> + + <div> + <%= form.label :ca, style: "display: block" %> + <%= form.text_field :ca %> + </div> + + <div> + <%= form.label :mg, style: "display: block" %> + <%= form.text_field :mg %> + </div> + + <div> + <%= form.label :s, style: "display: block" %> + <%= form.text_field :s %> + </div> + + <div> + <%= form.label :na, style: "display: block" %> + <%= form.text_field :na %> + </div> + + <div> + <%= form.label :cl, style: "display: block" %> + <%= form.text_field :cl %> + </div> + + <div> + <%= form.label :si, style: "display: block" %> + <%= form.text_field :si %> + </div> + + <div> + <%= form.label :fe, style: "display: block" %> + <%= form.text_field :fe %> + </div> + + <div> + <%= form.label :zn, style: "display: block" %> + <%= form.text_field :zn %> + </div> + + <div> + <%= form.label :b, style: "display: block" %> + <%= form.text_field :b %> + </div> + + <div> + <%= form.label :mn, style: "display: block" %> + <%= form.text_field :mn %> + </div> + + <div> + <%= form.label :cu, style: "display: block" %> + <%= form.text_field :cu %> + </div> + + <div> + <%= form.label :mo, style: "display: block" %> + <%= form.text_field :mo %> + </div> + + <div> + <%= form.label :nnh4, style: "display: block" %> + <%= form.text_field :nnh4 %> + </div> + + <div> + <%= form.submit %> + </div> +<% end %> diff --git a/app/views/crops/edit.html.erb b/app/views/crops/edit.html.erb new file mode 100644 index 0000000..54c616c --- /dev/null +++ b/app/views/crops/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing crop" %> + +<h1>Editing crop</h1> + +<%= render "form", crop: @crop %> + +<br> + +<div> + <%= link_to "Show this crop", @crop %> | + <%= link_to "Back to crops", crops_path %> +</div> diff --git a/app/views/crops/index.html.erb b/app/views/crops/index.html.erb new file mode 100644 index 0000000..bae09fa --- /dev/null +++ b/app/views/crops/index.html.erb @@ -0,0 +1,16 @@ +<p style="color: green"><%= notice %></p> + +<% content_for :title, "Crops" %> + +<h1>Crops</h1> + +<div id="crops"> + <% @crops.each do |crop| %> + <%= render crop %> + <p> + <%= link_to "Show this crop", crop %> + </p> + <% end %> +</div> + +<%= link_to "New crop", new_crop_path %> diff --git a/app/views/crops/new.html.erb b/app/views/crops/new.html.erb new file mode 100644 index 0000000..4ef4da5 --- /dev/null +++ b/app/views/crops/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New crop" %> + +<h1>New crop</h1> + +<%= render "form", crop: @crop %> + +<br> + +<div> + <%= link_to "Back to crops", crops_path %> +</div> diff --git a/app/views/crops/show.html.erb b/app/views/crops/show.html.erb new file mode 100644 index 0000000..971f097 --- /dev/null +++ b/app/views/crops/show.html.erb @@ -0,0 +1,10 @@ +<p style="color: green"><%= notice %></p> + +<%= render @crop %> + +<div> + <%= link_to "Edit this crop", edit_crop_path(@crop) %> | + <%= link_to "Back to crops", crops_path %> + + <%= button_to "Destroy this crop", @crop, method: :delete %> +</div> diff --git a/app/views/dashboard/_raft_allocation.html.erb b/app/views/dashboard/_raft_allocation.html.erb new file mode 100644 index 0000000..ef95cdd --- /dev/null +++ b/app/views/dashboard/_raft_allocation.html.erb @@ -0,0 +1,9 @@ +<div class="card shadow mb-4"> + <div class="card-header d-flex justify-content-between align-items-center"> + <h5 class="mb-0">Raft Allocation</h5> + <%= link_to "Edit raft allocation", editor_rafts_path, class: "btn btn-sm btn-primary" %> + </div> + + <%= bar_chart @raft_data, stacked: true %> +</div> + diff --git a/app/views/dashboard/_recent_measurements.html.erb b/app/views/dashboard/_recent_measurements.html.erb new file mode 100644 index 0000000..bc63a60 --- /dev/null +++ b/app/views/dashboard/_recent_measurements.html.erb @@ -0,0 +1,22 @@ +<div class="card shadow mb-4"> + <div class="card-header d-flex justify-content-between align-items-center"> + <h5 class="mb-0">Nutrient Measurements</h5> + <div class="btn-group"> + <%#= link_to "Add new measurement", editor_rafts_path, class: "btn btn-sm btn-primary" %> + <%#= link_to "View all", editor_rafts_path, class: "btn btn-sm btn-secondary" %> + </div> + </div> + + <div class="card-body p-0"> + <div class="container mb-3"> + <%= line_chart @npk_measurement_data, + title: "NPK", + ytitle: "Concentration (mg/L)" %> + </div> + <div class="container mb-3"> + <%= line_chart @ammonium_measurement_data, + title: "Ammonium", + ytitle: "Concentration (mg/L)" %> + </div> + </div> +</div> diff --git a/app/views/dashboard/_target_table.html.erb b/app/views/dashboard/_target_table.html.erb new file mode 100644 index 0000000..b8f7e66 --- /dev/null +++ b/app/views/dashboard/_target_table.html.erb @@ -0,0 +1,40 @@ +<div class="card shadow mb-4"> + <div class="card-header d-flex justify-content-between align-items-center"> + <h5 class="mb-0">Target nutrient concentrations</h5> + <%= link_to "Get Ferti© recipe", ferti_recipe_path, class: "btn btn-sm btn-primary" %> + </div> + + <div class="table-responsive"> + <table class="table table-sm align-middle mb-0"> + <thead class="table-light"> + <tr> + <th scope="col" class="text-nowrap">Nutrient</th> + <th scope="col" class="text-end"> Latest (mg/L) + </th> + <th scope="col" class="text-end">Target (mg/L)</th> + <th scope="col" class="text-end">Δ %</th> + </tr> + </thead> + <tbody> + <% NutrientsHelper::NUTRIENTS.each do |n| %> + <% latest = @latest_measurement[n] || 0 %> + <% target = @target[n] || 0 %> + <% delta = target - latest %> + <tr> + <th scope="row" class="text-nowrap"><%= n.upcase %></th> + <td class="text-end"><%= fmt(latest) %></td> + <td class="text-end"><%= fmt(target) %></td> + <td class="text-end"> + <span class="badge <%= delta_badge_class(delta) %>"> + <%= fmt(delta) %>% + </span> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> + <div class="card-footer"> + Latest measurement: <%= @latest_measurement.measured_on || "none yet" %> + </div> +</div> diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb new file mode 100644 index 0000000..2902ada --- /dev/null +++ b/app/views/dashboard/index.html.erb @@ -0,0 +1,7 @@ +<h1 class="display-1">Ferti</h1> + +<%= render "raft_allocation" %> + +<%= render "target_table" %> + +<%= render "recent_measurements" %> diff --git a/app/views/fertilizer_products/_fertilizer_product.html.erb b/app/views/fertilizer_products/_fertilizer_product.html.erb new file mode 100644 index 0000000..d84a03d --- /dev/null +++ b/app/views/fertilizer_products/_fertilizer_product.html.erb @@ -0,0 +1,12 @@ +<div id="<%= dom_id fertilizer_product %>"> + <p> + <strong>Name:</strong> + <%= fertilizer_product.name %> + </p> + + <p> + <strong>Purity:</strong> + <%= fertilizer_product.purity %> + </p> + +</div> diff --git a/app/views/fertilizer_products/_form.html.erb b/app/views/fertilizer_products/_form.html.erb new file mode 100644 index 0000000..517fe09 --- /dev/null +++ b/app/views/fertilizer_products/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: fertilizer_product) do |form| %> + <% if fertilizer_product.errors.any? %> + <div style="color: red"> + <h2><%= pluralize(fertilizer_product.errors.count, "error") %> prohibited this fertilizer_product from being saved:</h2> + + <ul> + <% fertilizer_product.errors.each do |error| %> + <li><%= error.full_message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div> + <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> + </div> + + <div> + <%= form.label :purity, style: "display: block" %> + <%= form.text_field :purity %> + </div> + + <div> + <%= form.submit %> + </div> +<% end %> diff --git a/app/views/fertilizer_products/edit.html.erb b/app/views/fertilizer_products/edit.html.erb new file mode 100644 index 0000000..aa88dad --- /dev/null +++ b/app/views/fertilizer_products/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing fertilizer product" %> + +<h1>Editing fertilizer product</h1> + +<%= render "form", fertilizer_product: @fertilizer_product %> + +<br> + +<div> + <%= link_to "Show this fertilizer product", @fertilizer_product %> | + <%= link_to "Back to fertilizer products", fertilizer_products_path %> +</div> diff --git a/app/views/fertilizer_products/index.html.erb b/app/views/fertilizer_products/index.html.erb new file mode 100644 index 0000000..f624ffc --- /dev/null +++ b/app/views/fertilizer_products/index.html.erb @@ -0,0 +1,16 @@ +<p style="color: green"><%= notice %></p> + +<% content_for :title, "Fertilizer products" %> + +<h1>Fertilizer products</h1> + +<div id="fertilizer_products"> + <% @fertilizer_products.each do |fertilizer_product| %> + <%= render fertilizer_product %> + <p> + <%= link_to "Show this fertilizer product", fertilizer_product %> + </p> + <% end %> +</div> + +<%= link_to "New fertilizer product", new_fertilizer_product_path %> diff --git a/app/views/fertilizer_products/new.html.erb b/app/views/fertilizer_products/new.html.erb new file mode 100644 index 0000000..81aad79 --- /dev/null +++ b/app/views/fertilizer_products/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New fertilizer product" %> + +<h1>New fertilizer product</h1> + +<%= render "form", fertilizer_product: @fertilizer_product %> + +<br> + +<div> + <%= link_to "Back to fertilizer products", fertilizer_products_path %> +</div> diff --git a/app/views/fertilizer_products/show.html.erb b/app/views/fertilizer_products/show.html.erb new file mode 100644 index 0000000..ea97041 --- /dev/null +++ b/app/views/fertilizer_products/show.html.erb @@ -0,0 +1,10 @@ +<p style="color: green"><%= notice %></p> + +<%= render @fertilizer_product %> + +<div> + <%= link_to "Edit this fertilizer product", edit_fertilizer_product_path(@fertilizer_product) %> | + <%= link_to "Back to fertilizer products", fertilizer_products_path %> + + <%= button_to "Destroy this fertilizer product", @fertilizer_product, method: :delete %> +</div> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..bf61c9d --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + <head> + <title><%= content_for(:title) || "Ferti" %></title> + <meta name="viewport" content="width=device-width,initial-scale=1"> + <meta name="apple-mobile-web-app-capable" content="yes"> + <meta name="mobile-web-app-capable" content="yes"> + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> + <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> + + <link rel="icon" href="/icon.png" type="image/png"> + <link rel="icon" href="/icon.svg" type="image/svg+xml"> + <link rel="apple-touch-icon" href="/icon.png"> + + <%# Includes all stylesheet files in app/assets/stylesheets %> + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + + <!-- Bootstrap 5 CSS --> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> + + <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> + <script src="https://cdn.jsdelivr.net/npm/chartkick@5"></script> + + <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script> + + <%= javascript_importmap_tags %> + </head> + + <body> + <%= render "application/navbar" %> + + <div class="container"> + <%= yield %> + </div> + + <%= render "application/copyright_footer" %> + + <!-- Bootstrap JS (optional, for dropdowns, etc.) --> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> + </body> +</html> diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <style> + /* Email styles need to be inline */ + </style> + </head> + + <body> + <%= yield %> + </body> +</html> diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/nutrient_measurement/index.html.erb b/app/views/nutrient_measurement/index.html.erb new file mode 100644 index 0000000..d9f522e --- /dev/null +++ b/app/views/nutrient_measurement/index.html.erb @@ -0,0 +1,27 @@ +<h1>NutrientMeasurement#index</h1> +<p>Find me in app/views/nutrient_measurement/index.html.erb</p> + +<div class="table-responsive"> + <table class="table table-sm table-striped table-hover align-middle table-nutrient mb-0"> + <thead class="table-light"> + <tr> + <th>Date</th> + <th class="numeric" title="Total N = NO₃‑N + NH₄‑N">N (total)</th> + <th class="numeric">P</th> + <th class="numeric">K</th> + <th class="numeric" title="Ammonia nitrogen">NH₄‑N</th> + </tr> + </thead> + <tbody> + <% @measurements.each do |m| %> + <tr> + <td><%= l(m.measured_on) %></td> + <td class="numeric"><%= fmt2(total_n(m)) %></td> + <td class="numeric"><%= fmt2(m.p) %></td> + <td class="numeric"><%= fmt2(m.k) %></td> + <td class="numeric"><%= fmt2(m.nnh4) %></td> + </tr> + <% end %> + </tbody> + </table> +</div> diff --git a/app/views/pwa/manifest.json.erb b/app/views/pwa/manifest.json.erb new file mode 100644 index 0000000..f8908f0 --- /dev/null +++ b/app/views/pwa/manifest.json.erb @@ -0,0 +1,22 @@ +{ + "name": "Ferti", + "icons": [ + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512" + }, + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512", + "purpose": "maskable" + } + ], + "start_url": "/", + "display": "standalone", + "scope": "/", + "description": "Ferti.", + "theme_color": "red", + "background_color": "red" +} diff --git a/app/views/pwa/service-worker.js b/app/views/pwa/service-worker.js new file mode 100644 index 0000000..b3a13fb --- /dev/null +++ b/app/views/pwa/service-worker.js @@ -0,0 +1,26 @@ +// Add a service worker for processing Web Push notifications: +// +// self.addEventListener("push", async (event) => { +// const { title, options } = await event.data.json() +// event.waitUntil(self.registration.showNotification(title, options)) +// }) +// +// self.addEventListener("notificationclick", function(event) { +// event.notification.close() +// event.waitUntil( +// clients.matchAll({ type: "window" }).then((clientList) => { +// for (let i = 0; i < clientList.length; i++) { +// let client = clientList[i] +// let clientPath = (new URL(client.url)).pathname +// +// if (clientPath == event.notification.data.path && "focus" in client) { +// return client.focus() +// } +// } +// +// if (clients.openWindow) { +// return clients.openWindow(event.notification.data.path) +// } +// }) +// ) +// }) diff --git a/app/views/rafts/editor.html.erb b/app/views/rafts/editor.html.erb new file mode 100644 index 0000000..cde56d8 --- /dev/null +++ b/app/views/rafts/editor.html.erb @@ -0,0 +1,108 @@ +<div class="d-flex justify-content-between align-items-center mb-3"> + <h1 class="display-1">Rafts editor</h1> + <%= link_to "Back to dashboard", root_path, class: "btn btn-outline-secondary" %> +</div> + +<!-- Bulk assign all rafts --> +<div class="card"> + <div class="card-header">Assign ALL rafts</div> + <div class="card-body"> + <%= form_with url: assign_all_rafts_path, method: :patch, class: "row g-2", data: { turbo: false } do %> + <div class="col-12 col-md-6"> + <select class="form-select" name="crop_id"> + <option value="">— Unassigned (clear) —</option> + <% @crops.each do |crop| %> + <option value="<%= crop.id %>"><%= crop.name %></option> + <% end %> + </select> + </div> + <div class="col-12 col-md-auto"> + <button class="btn btn-primary">Apply to all</button> + </div> + <% end %> + </div> +</div> + +<div class="table-responsive"> + <table class="table table-sm table-striped text-center align-middle my-3"> + <thead> + <tr> + <th class="text-start">Bed</th> + <% max_cols = @beds.map { |b| b.rafts.count }.max %> + <% (1..max_cols).each do |i| %> + <th>R<%= i %></th> + <% end %> + </tr> + </thead> + <tbody> + <% @beds.each do |bed| %> + <tr> + <th><%= bed.location %></th> + <% bed.rafts.order(:location).each do |raft| %> + <td> + <% if raft.crop %> + <%= raft.crop.name %> + <% else %> + — + <% end %> + </td> + <% end %> + </tr> + <% end %> + </tbody> + </table> +</div> + +<!-- Per-bed tables --> +<% @beds.each do |bed| %> + <div class="card mb-3" id="bed-<%= bed.id %>"> + <div class="card-header d-flex flex-wrap gap-2 align-items-center"> + <span class="me-auto">Bed <strong>#<%= bed.location %></strong></span> + <%= form_with url: assign_bed_rafts_path, method: :patch, class: "d-flex gap-2 align-items-center", data: { turbo: false } do %> + <input type="hidden" name="bed_id" value="<%= bed.id %>"> + <select class="form-select" name="crop_id"> + <option value="">— Unassigned (clear) —</option> + <% @crops.each do |crop| %> + <option value="<%= crop.id %>"><%= crop.name %></option> + <% end %> + </select> + <button class="btn btn-primary">Apply</button> + <% end %> + </div> + <div class="card-body p-0"> + <div class="table-responsive"> + <table class="table table-sm mb-0 align-middle"> + <thead class="table-light"> + <tr> + <th class="text-nowrap text-center">Raft</th> + <th>Crop</th> + <th class="text-end">Actions</th> + </tr> + </thead> + <tbody> + <% bed.rafts.order(:location).each do |raft| %> + <tr> + <td class="text-center"><strong><%= raft.location %></strong></td> + <td style="max-width: 280px;"> + <%= form_with url: assign_one_raft_path(raft), method: :patch, class: "d-flex gap-2", data: { turbo: false } do %> + <select class="form-select" name="crop_id"> + <option value="">— Unassigned (clear) —</option> + <% @crops.each do |crop| %> + <option value="<%= crop.id %>" <%= "selected" if raft.crop_id == crop.id %>><%= crop.name %></option> + <% end %> + </select> + <button class="btn btn-outline-primary">Save</button> + <% end %> + </td> + <td class="text-end"> + <%= button_to "Clear", assign_one_raft_path(raft, crop_id: ""), method: :patch, + form: { data: { turbo: false } }, class: "btn btn-outline-secondary btn-sm" %> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> + </div> + </div> +<% end %> diff --git a/app/views/recipes/_table.html.erb b/app/views/recipes/_table.html.erb new file mode 100644 index 0000000..a42a0b9 --- /dev/null +++ b/app/views/recipes/_table.html.erb @@ -0,0 +1,32 @@ +<div class="table-responsive"> + <table class="table table-sm align-middle mb-0"> + <thead class="table-light"> + <tr> + <th>Fertilizer product</th> + <th class="text-muted">Component</th> + <th class="text-end">Qty (kg)</th> + <th class="text-end">Per portion (kg)</th> + </tr> + </thead> + <tbody> + <% pcount = [[portions.to_i, 2].max, 10].min %> + <% recipe&.each do |component, kg| %> + <% prod_name = commercial_name_for(component) %> + <tr> + <td><strong><%= prod_name %></strong></td> + <td class="text-muted"><small><%= component.name %></small></td> + <td class="text-end fw-semibold"><%= fmt_kg(kg) %></td> + <td class="text-end"><%= fmt_kg(kg / pcount.to_f) %></td> + </tr> + <% end %> + <% if recipe.blank? %> + <tr><td colspan="4" class="text-center text-muted">No supplementation required.</td></tr> + <% end %> + </tbody> + </table> +</div> + +<div class="card-footer small text-muted"> + Volume: <%= number_with_delimiter(volume) %> L — + Portions: <%= pcount %> +</div> diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb new file mode 100644 index 0000000..180fdae --- /dev/null +++ b/app/views/recipes/show.html.erb @@ -0,0 +1,108 @@ +<!-- app/views/recipes/show.html.erb --> +<%# Controls header %> +<div class="card shadow my-4"> + <div class="card-header d-flex flex-wrap gap-2 justify-content-between align-items-center"> + <h5 class="mb-0">Ferti© Recipe</h5> + + <div class="d-flex flex-wrap gap-2 align-items-center"> + <%= form_with url: ferti_recipe_path, method: :get, local: true, class: "d-flex flex-wrap gap-2 align-items-center", id: "recipe-form" do %> + <div class="d-flex align-items-center gap-2"> + <label class="mb-0 small text-nowrap" for="volume_select">Volume</label> + <select id="volume_select" name="volume" class="form-select form-select-sm"> + <% options = [["100 000 L", 100_000], ["200 000 L", 200_000], ["300 000 L", 300_000]] %> + <% current_volume = (params[:volume].presence || 100_000).to_i %> + <% options.each do |label, val| %> + <option value="<%= val %>" <%= 'selected' if val == current_volume %>><%= label %></option> + <% end %> + </select> + </div> + + <div class="vr" style="height: 24px;"></div> + + <div class="d-flex align-items-center gap-2"> + <label class="mb-0 small text-nowrap" for="portions_input">Portions</label> + <input id="portions_input" type="number" min="2" max="10" step="1" + class="form-control form-control-sm" value="<%= params[:portions].presence || 2 %>"> + </div> + <% end %> + + <%= link_to "Back", root_path, class: "btn btn-sm btn-secondary" %> + </div> + </div> + + <div class="table-responsive"> + <table class="table table-sm align-middle mb-0" id="recipe-table"> + <thead class="table-light"> + <tr> + <th>Product</th> + <th class="text-muted">Fertilizer</th> + <th class="text-end">Qty (kg)</th> + <th class="text-end">Per portion (kg)</th> + </tr> + </thead> + <tbody> + <% @recipe.each do |component, kg| %> + <% prod_name = commercial_name_for(component) %> + <tr data-total-kg="<%= kg %>"> + <td><strong><%= prod_name %></strong></td> + <td class="text-muted"><small><%= component.name %></small></td> + <td class="text-end fw-semibold"><%= fmt_kg(kg) %></td> + <td class="text-end per-portion-cell"><%= fmt_kg(kg / (params[:portions].presence || 2).to_f) %></td> + </tr> + <% end %> + <% if @recipe.blank? %> + <tr><td colspan="4" class="text-center text-muted">No supplementation required.</td></tr> + <% end %> + </tbody> + </table> + </div> + + <div class="card-footer small text-muted"> + Recipe based on latest measurement: <%= @latest.measured_on %> + </div> +</div> + +<%# Tiny vanilla JS: auto-submit on volume change; live per-portion update %> +<script> + (function() { + const form = document.getElementById('recipe-form'); + const volumeSelect = document.getElementById('volume_select'); + const portionsInput = document.getElementById('portions_input'); + const rows = document.querySelectorAll('#recipe-table tbody tr[data-total-kg]'); + + function clampPortions(n) { + n = parseInt(n || 2, 10); + if (isNaN(n)) n = 2; + return Math.min(10, Math.max(2, n)); + } + + function updatePerPortion() { + const n = clampPortions(portionsInput.value); + portionsInput.value = n; + rows.forEach(row => { + const total = parseFloat(row.getAttribute('data-total-kg') || '0'); + const cell = row.querySelector('.per-portion-cell'); + const per = (n > 0) ? (total / n) : 0; + cell.textContent = formatKg(per); + }); + } + + function formatKg(v) { + // match Rails number_with_precision(... precision: 2, strip zeros-ish) + const s = (Math.round(v * 100) / 100).toFixed(2); + return s.replace(/\.00$/, '').replace(/(\.\d)0$/, '$1'); + } + + volumeSelect.addEventListener('change', () => { + // submit with selected volume, keeping portions as a query param + const portions = clampPortions(portionsInput.value); + const url = new URL(form.action, window.location.origin); + url.searchParams.set('volume', volumeSelect.value); + url.searchParams.set('portions', portions); + window.location.assign(url.toString()); + }); + + portionsInput.addEventListener('input', updatePerPortion); + updatePerPortion(); + })(); +</script> diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 0000000..ace1c9b --- /dev/null +++ b/bin/brakeman @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +ARGV.unshift("--ensure-latest") + +load Gem.bin_path("brakeman", "brakeman") @@ -0,0 +1,2 @@ +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint new file mode 100755 index 0000000..57567d6 --- /dev/null +++ b/bin/docker-entrypoint @@ -0,0 +1,14 @@ +#!/bin/bash -e + +# Enable jemalloc for reduced memory usage and latency. +if [ -z "${LD_PRELOAD+x}" ]; then + LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) + export LD_PRELOAD +fi + +# If running the rails server then create or migrate existing database +if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then + ./bin/rails db:prepare +fi + +exec "${@}" diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4fbf10b --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..be3db3c --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require "fileutils" + +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args, exception: true) +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end +end diff --git a/bin/thrust b/bin/thrust new file mode 100755 index 0000000..36bde2d --- /dev/null +++ b/bin/thrust @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thruster", "thrust") diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..4a3c09a --- /dev/null +++ b/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..316a750 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,27 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Ferti + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 8.0 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..988a5dd --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..bfd4202 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: ferti_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..9179429 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +7jDV9/PMc5rXUDg80zXpTzhb856WzvtUFwrQT6hX6avsV6gfG2kbQZ6bw9dNhAuJG7biRAcqMMccziRtHW7xteFWXmlEdLEZVxyLJF1j692rThKblbhqwrl8A18Mtfo0urxfhwlvwpPlaML9RapsOtK4R4FrfOpRkxNRuJnvAzB+7ZTmB1fha+BhuDMJr4tz8EPC9F6S/rpR8k+jA4FSZDJnWjW1YzFK8A0YajIeGTWoQ09kTy2LmlZiR/7FpwfKEKaKaX+Mk1SmMRMQZhMpp6OM2CKRzy+dD9Rbv9HKa7LurLIqNOBSoh8CDqeMpquh299VaT6Gq3G4HXuUs6YH1hfWhOOFs0RZ91IJe83g9wYBUNVSjp/tkHo9E5IEorjvMcGRZUHuYqeFBgM1sS1uKXRKoBeI1UA+Nk72H5DRCP1VZuS0SvS4MGKtjzGJQVhyNGVXKAXt9xKQsSdoj0v1eJioHGKw0degKl/s/TbRXjE7QgPScBiBDkLe--ETBoZlP3MDy2hVMJ--xRfKKvHV54MospFJKlydjg==
\ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..2640cb5 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,41 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem "sqlite3" +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: storage/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: storage/test.sqlite3 + + +# Store production database in the storage/ directory, which by default +# is mounted as a persistent Docker volume in config/deploy.yml. +production: + primary: + <<: *default + database: storage/production.sqlite3 + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default + database: storage/production_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate diff --git a/config/deploy.yml b/config/deploy.yml new file mode 100644 index 0000000..600b1ae --- /dev/null +++ b/config/deploy.yml @@ -0,0 +1,116 @@ +# Name of your application. Used to uniquely configure containers. +service: ferti + +# Name of the container image. +image: your-user/ferti + +# Deploy to these servers. +servers: + web: + - 192.168.0.1 + # job: + # hosts: + # - 192.168.0.1 + # cmd: bin/jobs + +# Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. +# Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. +# +# Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. +proxy: + ssl: true + host: app.example.com + +# Credentials for your image host. +registry: + # Specify the registry server, if you're not using Docker Hub + # server: registry.digitalocean.com / ghcr.io / ... + username: your-user + + # Always use an access token rather than real password when possible. + password: + - KAMAL_REGISTRY_PASSWORD + +# Inject ENV variables into containers (secrets come from .kamal/secrets). +env: + secret: + - RAILS_MASTER_KEY + clear: + # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs. + # When you start using multiple servers, you should split out job processing to a dedicated machine. + SOLID_QUEUE_IN_PUMA: true + + # Set number of processes dedicated to Solid Queue (default: 1) + # JOB_CONCURRENCY: 3 + + # Set number of cores available to the application on each server (default: 1). + # WEB_CONCURRENCY: 2 + + # Match this to any external database server to configure Active Record correctly + # Use ferti-db for a db accessory server on same machine via local kamal docker network. + # DB_HOST: 192.168.0.2 + + # Log everything from Rails + # RAILS_LOG_LEVEL: debug + +# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation: +# "bin/kamal logs -r job" will tail logs from the first server in the job section. +aliases: + console: app exec --interactive --reuse "bin/rails console" + shell: app exec --interactive --reuse "bash" + logs: app logs -f + dbc: app exec --interactive --reuse "bin/rails dbconsole" + + +# Use a persistent storage volume for sqlite database files and local Active Storage files. +# Recommended to change this to a mounted volume path that is backed up off server. +volumes: + - "ferti_storage:/rails/storage" + + +# Bridge fingerprinted assets, like JS and CSS, between versions to avoid +# hitting 404 on in-flight requests. Combines all files from new and old +# version inside the asset_path. +asset_path: /rails/public/assets + +# Configure the image builder. +builder: + arch: amd64 + + # # Build image via remote server (useful for faster amd64 builds on arm64 computers) + # remote: ssh://docker@docker-builder-server + # + # # Pass arguments and secrets to the Docker build process + # args: + # RUBY_VERSION: ruby-3.2.8 + # secrets: + # - GITHUB_TOKEN + # - RAILS_MASTER_KEY + +# Use a different ssh user than root +# ssh: +# user: app + +# Use accessory services (secrets come from .kamal/secrets). +# accessories: +# db: +# image: mysql:8.0 +# host: 192.168.0.2 +# # Change to 3306 to expose port to the world instead of just local network. +# port: "127.0.0.1:3306:3306" +# env: +# clear: +# MYSQL_ROOT_HOST: '%' +# secret: +# - MYSQL_ROOT_PASSWORD +# files: +# - config/mysql/production.cnf:/etc/mysql/my.cnf +# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql +# directories: +# - data:/var/lib/mysql +# redis: +# image: redis:7.0 +# host: 192.168.0.2 +# port: 6379 +# directories: +# - data:/data diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..cac5315 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..4cc21c4 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,72 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Make code changes take effect immediately without server restart. + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true + + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + end + + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Make template changes take effect immediately. + config.action_mailer.perform_caching = false + + # Set localhost to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..1749607 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,89 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). + config.eager_load = true + + # Full error reports are disabled. + config.consider_all_requests_local = false + + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true + + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT with the current request id as a default log tag. + config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) + + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = "/up" + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "example.com" } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..c2095b1 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,53 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { "cache-control" => "public, max-age=3600" } + + # Show full error reports. + config.consider_all_requests_local = true + config.cache_store = :null_store + + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "example.com" } + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true +end diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..0086a32 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,3 @@ +# Pin npm packages by running ./bin/importmap + +pin "application" diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..4873244 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..b3076b3 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..c0b717f --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..3860f65 --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..6c349ae --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..a248513 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,41 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. +# +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..1b24155 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,32 @@ +Rails.application.routes.draw do + root "dashboard#index" + + get "ferti_recipe", to: "recipes#show" + resources :fertilizer_products + resources :raft_crops, only: [ :update ] + resources :rafts, only: [ :index ] do + collection do + get :editor # rafts/editor + patch :assign_all # bulk assign all rafts + patch :assign_bed # bulk assign per bed + end + member do + patch :assign_one # per raft + end + end + resources :crops + resources :nutrient_measurements + + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # Can be used by load balancers and uptime monitors to verify that the app is live. + get "up" => "rails/health#show", as: :rails_health_check + + # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb) + # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest + # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000..4942ab6 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/data/dolibarr_measurements.csv b/db/data/dolibarr_measurements.csv new file mode 100644 index 0000000..38be569 --- /dev/null +++ b/db/data/dolibarr_measurements.csv @@ -0,0 +1,44 @@ +date,nno3,p,k,ca,mg,s,na,cl,si,fe,zn,b,mn,cu,mo,nnh4 +08/05/2021,1.87,0.0031936,0.91,100.79,8.37,1.08666558,6.73,12.28,5.42,0.01,0.01,0.01,0.01,0.01,0.01,0.02 +02/07/2021,66.3,0.0095808,110.91,93.09,17.95,32.84663382,10.27,18.53,5.02,4.37,0.03,0.18,0.15,0,0,0.63 +12/07/2021,61.66,2.011968,122.53,73.5,17.44,47.64328569,0.45,0.82,0.36,1.76,0.05,0.13,0.32,0,0,0 +12/08/2021,67.27,0.351296,94.45,89.48,16.25,9.11665755,10.76,16.51,4.95,3.2,0.03,0.14,0.07,0,0,0.06 +06/09/2021,77.8,7.1153408,96.29,86.31,14.21,23.90664276,9.32,14.92,4.61,2.45,0.08,0.12,0.05,0.03,0,0.02 +21/09/2021,87.88,11.33728,117.24,90.64,17.25,29.90663676,9.92,15.96,4.68,2.4,0.08,0.27,0.12,0.04,0.01,0.02 +19/10/2021,77.84,13.4195072,121.91,94.71,18.3,33.19663347,12.36,15.28,4.47,2.72,0.11,0.74,0.04,0.04,0.02,0.03 +01/12/2021,57.09,6.6842048,81.46,61.45,10.52,17.72331561,17.36,23.05,2.11,1.27,0.17,0.32,0.01,0.03,0.02,0.07 +04/02/2022,43.56,6.5979776,63.1,63.72,9.92,17.3999826,17.08,21.15,1.44,1.6,0.22,0.34,0.01,0.04,0.01,0.03 +12/04/2022,38.36,6.5021696,83.48,49.75,6.42,14.14331919,29.8,38.85,0.23,0.3,0.2,0,0.02,0.01,0.4,0.07 +16/05/2022,24.63,0.542912,30.22,39.79,6.75,0.0666666,25.98,25.89,0.14,1.13,0.3,0.23,0.01,0.02,0.005,0.12 +15/06/2022,2.45,0.0606784,0.69,24.58,4.14,1.24999875,19.59,11.33,0.32,0.79,0.25,0.13,0.01,0.02,0.01,0.1 +04/07/2022,24.3,3.081824,42.34,39.79,8.09,0.41333292,19.79,11.32,1.24,0.7,0.18,0.07,0.02,0.01,0.005,0.68 +01/08/2022,4.88,0.2299392,27.77,22.48,6.71,18.68331465,23,5,0.64,0.97,0.17,0.04,0.005,0.005,0.005,0.07 +07/09/2022,29.28,2.07584,79.65,36.05,13.82,31.17663549,33.41,12.32,0.83,0.84,0.13,0.07,0.01,0.005,0.005,0.8 +24/10/2022,41.61,1.2646656,68.38,47.44,11.54,21.55664511,28.22,18.73,0.81,0.41,0.1,0.05,0.005,0.005,0.005,0.09 +21/11/2022,40.34,3.1105664,53.6,51.09,9.69,17.97331536,25.5,18.85,0.97,0.58,0.11,0.07,0.005,0.005,0.005,0.04 +09/01/2023,48.71,6.6171392,63.08,71.45,11.58,6.55666011,23.81,21.32,1.46,1.04,0.13,0.13,0.01,0.01,0.01,0.03 +21/02/2023,56.03,7.5273152,53.3,81.75,12.11,19.31998068,23.16,27.27,1.86,0.95,0.18,0.19,0.01,0.005,0.02,0.13 +20/04/2023,50.67,7.0546624,76.45,76.63,10.57,15.54331779,22.25,26.97,0.95,0.96,0.19,0.12,0.005,0.005,0.005,0.21 +07/06/2023,48.82,7.3005696,90.04,64.58,9.96,16.92664974,22.39,25.93,0.78,0.42,0.2,0.11,0.005,0.005,0.005,0.16 +13/07/2023,21.79,1.5712512,77.61,40.41,9.74,20.82331251,26.23,22.49,0.6,1.16,0.22,0.31,0,0,0.02,0.14 +17/07/2023,21.79,4.9213376,77.61,40.41,9.74,20.82331251,26.23,22.49,0.6,1.16,0.22,0.31,0.01,0.01,0.02,0.14 +23/08/2023,23.88,2.778432,97.75,49.74,26.25,31.24996875,31.11,16.43,1.33,0.8,0.18,0.14,0,0,0.01,1.01 +02/09/2023,23.88,2.778432,97.75,49.74,16.15,31.24996875,31.11,16.43,1.33,0.8,0.18,0.14,0,0,0.01,1.01 +13/10/2023,71.9,5.0905984,106.35,91.03,18.11,34.90663176,32.36,14.59,1.43,0.97,0.17,0.05,0,0,0,0.24 +28/12/2023,70.58,9.1368896,141.05,68.18,11.96,24.18664248,27.95,21.57,1.31,0.88,0.16,0.15,0,0,0.02,0.06 +16/01/2024,77.26,11.433088,149.17,68.71,12.14,23.24331009,29.88,27.04,1.15,1.14,0.26,0.14,0,0,0,0.09 +04/03/2024,84.65,13.4418624,185.21,66.05,15.61,30.69330264,40.12,36.82,0.66,0.93,0.39,0.35,0,0,0.03,0.16 +23/04/2024,69.17,11.2350848,116.41,52.96,14.07,28.95330438,80.73,37.54,0.57,0.79,0.42,0.38,0.01,0,0.03,0.16 +30/05/2024,46.74,7.520928,81.84,38.61,10.48,26.52997347,79.96,40.47,0.34,0.87,0.45,0.37,0,0.03,0.03,0.12 +05/07/2024,27.51,3.960064,75.58,27.78,8.29,25.99330734,92.2,44.74,0.32,0.59,0.45,0.37,0,0.03,0.03,0.15 +23/07/2024,16.55,2.4143616,83.62,16.52,4.9,20.45997954,79.04,40.51,0.32,0.77,0.43,0.26,0,0.03,0.02,0.43 +06/08/2024,0,0.3001984,74.41,6.82,2.56,17.28664938,78.79,35.04,0.42,0.9,0.37,0.29,0,0.03,0.02,0.13 +09/09/2024,18.3,2.87424,85.3,8.7,1.7,10.5666561,53.7,22.7,2.5,0.7,0.2,0.1,0,0,0,0 +01/10/2024,22.94,4.1740352,112.46,9.44,2,13.51998648,58.57,28.76,0.27,0.6,0.26,0.17,0,0.02,0,0.2 +22/11/2024,66,2.87424,127,33,9,7.333326,63,40,2.8,0.73,0.37,0.16,0.01,0.01,0.01,0 +20/01/2025,94.26,15.664608,146.27,76.06,14.24,32.05663461,64.29,46.99,0.45,0.37,0.48,0.16,0.08,0.03,0.01,0.11 +06/03/2025,95.82,20.007904,171.83,92.24,15.75,35.2332981,82.27,54.5,0.45,0.17,0.49,0.16,0.03,0.02,0,0.06 +04/04/2025,85.49,17.2646016,109.91,88.54,13.47,31.08663558,65.02,53.96,0.28,0.65,0.51,0.13,0.01,0.01,0,0 +22/05/2025,49.8,9.9927744,92.41,61.42,8.47,22.42331091,52.95,38.25,0.32,0.86,0.48,0.23,0.03,0,0.02,0.13 +11/06/2025,30.28,5.700576,50.2,48.96,5.73,22.10664456,51.34,33.41,0,0.96,0.51,0.26,0,0,0,0 +01/08/2025,1.34,0.4854272,77.64,16.45,5.52,22.93997706,58.45,25.83,0.5,0.48,0.44,0.17,0,0,0,0 diff --git a/db/data/nutrient_requirements.csv b/db/data/nutrient_requirements.csv new file mode 100644 index 0000000..61406b8 --- /dev/null +++ b/db/data/nutrient_requirements.csv @@ -0,0 +1,9 @@ +Nom,NNO3,P,K,Ca,Mg,S,Na,Cl,Si,Fe,Zn,B,Mn,Cu,Mo,NNH4 +Générique croissance,160,30,230,100,30,60,0,0,0,5,"0,15","0,3","0,5","0,15","0,05",0 +Générique floraison,130,60,300,100,30,60,0,0,0,2,"0,1","0,5","0,5","0,05","0,05",0 +Laitue,190,50,210,200,50,66,0,0,0,5,"0,15","0,3","0,5","0,15","0,05",0 +Tomate (cycle entier),140,50,352,180,50,168,0,0,0,5,"0,1","0,3","0,8","0,07","0,03",0 +Tomate 10-14 jours,100,40,200,100,20,53,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Tomate 1ere grappe,130,55,300,150,33,109,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Tomate à maturité,180,65,400,400,45,144,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Framboise - tous stades,70,12,88,90,24,48,0,0,50,0.56,"0,325",11,"0,11","0,032","0,01",0 diff --git a/db/migrate/20250820175727_create_nutrients.rb b/db/migrate/20250820175727_create_nutrients.rb new file mode 100644 index 0000000..d054375 --- /dev/null +++ b/db/migrate/20250820175727_create_nutrients.rb @@ -0,0 +1,10 @@ +class CreateNutrients < ActiveRecord::Migration[8.0] + def change + create_table :nutrients do |t| + t.string :formula + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20250820175742_create_nutrient_measurements.rb b/db/migrate/20250820175742_create_nutrient_measurements.rb new file mode 100644 index 0000000..b4bae51 --- /dev/null +++ b/db/migrate/20250820175742_create_nutrient_measurements.rb @@ -0,0 +1,27 @@ +class CreateNutrientMeasurements < ActiveRecord::Migration[8.0] + def change + create_table :nutrient_measurements do |t| + t.date :measured_on + t.float :nno3 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + t.float :nnh4 + + t.timestamps + end + + add_index :nutrient_measurements, :measured_on, unique: true + end +end diff --git a/db/migrate/20250823140019_create_crops.rb b/db/migrate/20250823140019_create_crops.rb new file mode 100644 index 0000000..e88abd3 --- /dev/null +++ b/db/migrate/20250823140019_create_crops.rb @@ -0,0 +1,26 @@ +class CreateCrops < ActiveRecord::Migration[8.0] + def change + create_table :crops do |t| + t.string :name + t.integer :crop_type, null: false, default: 1 + t.float :nno3 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + t.float :nnh4 + + t.timestamps + end + end +end diff --git a/db/migrate/20250823142743_create_beds.rb b/db/migrate/20250823142743_create_beds.rb new file mode 100644 index 0000000..3c23ad7 --- /dev/null +++ b/db/migrate/20250823142743_create_beds.rb @@ -0,0 +1,11 @@ +class CreateBeds < ActiveRecord::Migration[8.0] + def change + create_table :beds do |t| + t.integer :location, null: false + + t.timestamps + end + + add_index :beds, :location, unique: true + end +end diff --git a/db/migrate/20250823142858_create_rafts.rb b/db/migrate/20250823142858_create_rafts.rb new file mode 100644 index 0000000..6b7f006 --- /dev/null +++ b/db/migrate/20250823142858_create_rafts.rb @@ -0,0 +1,13 @@ +class CreateRafts < ActiveRecord::Migration[8.0] + def change + create_table :rafts do |t| + t.references :bed, null: false, foreign_key: true + t.integer :location, null: false + t.references :crop, null: true, foreign_key: true + + t.timestamps + end + + add_index :rafts, [ :bed_id, :location ], unique: true + end +end diff --git a/db/migrate/20250824121914_create_fertilizer_components.rb b/db/migrate/20250824121914_create_fertilizer_components.rb new file mode 100644 index 0000000..2e08fff --- /dev/null +++ b/db/migrate/20250824121914_create_fertilizer_components.rb @@ -0,0 +1,26 @@ +class CreateFertilizerComponents < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_components do |t| + t.string :name + t.string :formula + t.float :nno3 + t.float :nnh4 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + + t.timestamps + end + end +end diff --git a/db/migrate/20250824163242_create_fertilizer_products.rb b/db/migrate/20250824163242_create_fertilizer_products.rb new file mode 100644 index 0000000..024f82c --- /dev/null +++ b/db/migrate/20250824163242_create_fertilizer_products.rb @@ -0,0 +1,11 @@ +class CreateFertilizerProducts < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_products do |t| + t.string :name, null: false + t.decimal :purity, precision: 5, scale: 2, null: false, default: 100.00 + + t.timestamps + end + add_index :fertilizer_products, :name, unique: true + end +end diff --git a/db/migrate/20250824163257_create_fertilizer_compositions.rb b/db/migrate/20250824163257_create_fertilizer_compositions.rb new file mode 100644 index 0000000..b48954a --- /dev/null +++ b/db/migrate/20250824163257_create_fertilizer_compositions.rb @@ -0,0 +1,11 @@ +class CreateFertilizerCompositions < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_compositions do |t| + t.references :fertilizer_product, null: false, foreign_key: true + t.references :fertilizer_component, null: false, foreign_key: true + t.decimal :percent_w, precision: 6, scale: 3, null: false # e.g. 13.500 (% w/w) + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..b5f2e03 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,130 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].define(version: 2025_08_24_163257) do + create_table "beds", force: :cascade do |t| + t.integer "location", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["location"], name: "index_beds_on_location", unique: true + end + + create_table "crops", force: :cascade do |t| + t.string "name" + t.integer "crop_type", default: 1, null: false + t.float "nno3" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.float "nnh4" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "fertilizer_components", force: :cascade do |t| + t.string "name" + t.string "formula" + t.float "nno3" + t.float "nnh4" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "fertilizer_compositions", force: :cascade do |t| + t.integer "fertilizer_product_id", null: false + t.integer "fertilizer_component_id", null: false + t.decimal "percent_w", precision: 6, scale: 3, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["fertilizer_component_id"], name: "index_fertilizer_compositions_on_fertilizer_component_id" + t.index ["fertilizer_product_id"], name: "index_fertilizer_compositions_on_fertilizer_product_id" + end + + create_table "fertilizer_products", force: :cascade do |t| + t.string "name", null: false + t.decimal "purity", precision: 5, scale: 2, default: "100.0", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["name"], name: "index_fertilizer_products_on_name", unique: true + end + + create_table "nutrient_measurements", force: :cascade do |t| + t.date "measured_on" + t.float "nno3" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.float "nnh4" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["measured_on"], name: "index_nutrient_measurements_on_measured_on", unique: true + end + + create_table "nutrients", force: :cascade do |t| + t.string "formula" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "rafts", force: :cascade do |t| + t.integer "bed_id", null: false + t.integer "location", null: false + t.integer "crop_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["bed_id", "location"], name: "index_rafts_on_bed_id_and_location", unique: true + t.index ["bed_id"], name: "index_rafts_on_bed_id" + t.index ["crop_id"], name: "index_rafts_on_crop_id" + end + + add_foreign_key "fertilizer_compositions", "fertilizer_components" + add_foreign_key "fertilizer_compositions", "fertilizer_products" + add_foreign_key "rafts", "beds" + add_foreign_key "rafts", "crops" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..848db0d --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,13 @@ +# This file should ensure the existence of records required to run the application in every environment (production, +# development, test). The code here should be idempotent so that it can be executed at any point in every environment. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Example: +# +# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| +# MovieGenre.find_or_create_by!(name: genre_name) +# end + +Dir[Rails.root.join("db/seeds/*.rb")].sort.each do |seed| + load seed +end diff --git a/db/seeds/1_nutrients.rb b/db/seeds/1_nutrients.rb new file mode 100644 index 0000000..dab2249 --- /dev/null +++ b/db/seeds/1_nutrients.rb @@ -0,0 +1,24 @@ +NUTRIENTS = [ + [ "nno3", "nitrate" ], + [ "p", "phosphore" ], + [ "k", "potassium" ], + [ "ca", "calcium" ], + [ "mg", "magnésium" ], + [ "s", "soufre" ], + [ "na", "sodium" ], + [ "cl", "chlore" ], + [ "si", "silice" ], + [ "fe", "fer" ], + [ "zn", "zinc" ], + [ "b", "bore" ], + [ "mn", "manganèse" ], + [ "cu", "cuivre" ], + [ "mo", "molybdène" ], + [ "nnh4", "ammonium" ] +] + +NUTRIENTS.each do |formula, name| + Nutrient.find_or_create_by!(formula:) { |n| n.name = name } +end + +puts "Nutrients: #{Nutrient.count}" diff --git a/db/seeds/2_nutrient_measurements.rb b/db/seeds/2_nutrient_measurements.rb new file mode 100644 index 0000000..0ca14f1 --- /dev/null +++ b/db/seeds/2_nutrient_measurements.rb @@ -0,0 +1,27 @@ +require "csv" + +csv_path = Rails.root.join("db", "data", "dolibarr_measurements.csv") +abort "CSV not found: #{csv_path}" unless File.exist?(csv_path) + +CSV.foreach(csv_path, headers: true) do |row| + NutrientMeasurement.find_or_create_by!(measured_on: Date.parse(row["date"])) do |m| + m.nno3 = row["nno3"] + m.p = row["p"] + m.k = row["k"] + m.ca = row["ca"] + m.mg = row["mg"] + m.s = row["s"] + m.na = row["na"] + m.cl = row["cl"] + m.si = row["si"] + m.fe = row["fe"] + m.zn = row["zn"] + m.b = row["b"] + m.mn = row["mn"] + m.cu = row["cu"] + m.mo = row["mo"] + m.nnh4 = row["nnh4"] + end +end + +puts "NutrientMeasurements: #{NutrientMeasurement.count}" diff --git a/db/seeds/3_crops.rb b/db/seeds/3_crops.rb new file mode 100644 index 0000000..2957188 --- /dev/null +++ b/db/seeds/3_crops.rb @@ -0,0 +1,125 @@ +# crop_type: 0=leafy greens, 1=fruits, 2=herbs + +LEAFY = { + nno3: 150, + p: 31, + k: 210, + ca: 90, + mg: 24, + s: 32, + fe: 1.0, + mn: 0.25, + zn: 0.13, + b: 0.16, + cu: 0.023, + mo: 0.024, + nnh4: 5, + # keep low for leafy + na: 10, + cl: 5, + si: 20 +} + +HERB = LEAFY # Herbs run well on the Cornell leafy recipe + +TOMATO = { + # CEAC Stage 3 "multi-crop" / mature tomato + nno3: 190, + p: 47, + k: 350, + ca: 200, + mg: 65, + s: 102, + fe: 2.0, + mn: 0.55, + zn: 0.33, + b: 0.28, + cu: 0.05, + mo: 0.05, + nnh4: 0, + # CEAC recipes are NO3-N; keep NH4 minimal + na: 20, + cl: 25, + si: 20 +} + +HOT_PEPPER = { + # Mature greenhouse pepper (HortAmericas summary of UA recipes) + nno3: 180, + p: 50, + k: 280, + ca: 200, + mg: 45, + s: 20, + fe: 1.0, + mn: 0.55, + zn: 0.33, + b: 0.30, + cu: 0.05, + mo: 0.05, + nnh4: 15, + na: 20, + cl: 10, + si: 20 +} + +STRAWBERRY = { + # UA strawberry (Yamazaki) emphasizes lower EC; use conservative macros + nno3: 120, + p: 30, + k: 200, + ca: 120, + mg: 35, + s: 50, + fe: 1.5, + mn: 0.50, + zn: 0.20, + b: 0.30, + cu: 0.05, + mo: 0.05, + nnh4: 5, + na: 10, + cl: 5, + si: 20 +} + +RASPBERRY = { + # Sparse data; align with strawberry but a touch higher vigor + nno3: 140, + p: 35, + k: 230, + ca: 150, + mg: 40, + s: 50, + fe: 1.5, + mn: 0.50, + zn: 0.20, + b: 0.30, + cu: 0.05, + mo: 0.05, + nnh4: 5, + na: 15, + cl: 5, + si: 20 +} + +[ + [ "lettuce", 0, LEAFY ], + [ "kale", 0, LEAFY ], + [ "chinese cabbage", 0, LEAFY ], + [ "tomatoes", 1, TOMATO ], + [ "raspberries", 1, RASPBERRY ], + [ "strawberries", 1, STRAWBERRY ], + [ "hot peppers", 1, HOT_PEPPER ], + [ "parsley", 2, HERB ], + [ "chives", 2, HERB ], + [ "italian basil", 2, HERB ], + [ "dill", 2, HERB ] +].each do |name, type, nutrient_requirements| + Crop.find_or_create_by!(name: name) do |c| + c.crop_type = type + c.attributes = nutrient_requirements + end +end + +puts "Crops: #{Crop.count}" diff --git a/db/seeds/4_beds_and_rafts.rb b/db/seeds/4_beds_and_rafts.rb new file mode 100644 index 0000000..0105260 --- /dev/null +++ b/db/seeds/4_beds_and_rafts.rb @@ -0,0 +1,24 @@ +BEDS = 14 +RAFTS = 10 + +1.upto(BEDS) do |b| + bed = Bed.find_or_create_by!(location: b) + + crop_name = case b + when 1..2 then "tomatoes" + when 3 then "hot peppers" + when 4 then "chives" + when 5 then "italian basil" + when 6..7 then "chinese cabbage" + else "lettuce" + end + + 1.upto(RAFTS) do |r| + raft = bed.rafts.find_or_create_by!(location: r) do |raft| + raft.crop = Crop.find_by!(name: crop_name) + end + end +end + +puts "Beds: #{Bed.count}" +puts "Rafts: #{Raft.count}" diff --git a/db/seeds/5_fertilizer_components.rb.bkp b/db/seeds/5_fertilizer_components.rb.bkp new file mode 100644 index 0000000..8a1fc54 --- /dev/null +++ b/db/seeds/5_fertilizer_components.rb.bkp @@ -0,0 +1,38 @@ +FERTILIZER_COMPONENTS = [ + # Macros / bases + { name: "Potassium Nitrate", formula: "KNO3", nno3: 13.50, k: 38.60 }, + { name: "Calcium Nitrate", formula: "Ca(NO3)2·xH2O", nno3: 15.50, ca: 18.94 }, + { name: "Ammonium Nitrate", formula: "NH4NO3", nno3: 13.50, nnh4: 13.50 }, # total N ≈ 27 + { name: "Diammonium Phosphate", formula: "(NH4)2HPO4", p: 21.00 }, # NH4 can be added later if desired + + # Acids / buffers + { name: "Nitric Acid 53%", formula: "HNO3", nno3: 11.70 }, + { name: "Potassium Bicarbonate", formula: "KHCO3", k: 39.05 }, + { name: "Calcium Carbonate", formula: "CaCO3", ca: 38.00 }, + + # K–Mg–S complex (Patentkali-type blend) + { name: "Potassium Sulfate blend (K–Mg–S + NaCl)", formula: "K2SO4+MgSO4+NaCl", + p: 0.44, k: 22.66, mg: 6.16, s: 17.77, na: 2.16, cl: 3.34 }, + + # Sulfates (micros / secondary) + { name: "Magnesium Sulfate", formula: "MgSO4·7H2O", mg: 9.648, s: 13.016 }, + { name: "Manganese Sulfate", formula: "MnSO4", s: 7.17, mn: 12.00 }, + { name: "Zinc Sulfate (Fiza Zinc)", formula: "ZnSO4", zn: 12.00 }, + + # Chelates / traces + { name: "Iron DTPA 11.8%", formula: "Fe-DTPA", fe: 11.80 }, + { name: "HelioCopper (Cu chelate)", formula: "Cu-chelate", cu: 40.00 }, + + # Boron & Mo sources + { name: "Boron–Molybdenum (Boronia LS)", formula: "B+Mo", b: 13.50, mo: 0.028 }, + { name: "Boronia MO12 (10L)", formula: "B+Mn+Cu", b: 8.90, mn: 0.089, cu: 0.89 }, + { name: "Sodium Molybdate", formula: "Na2MoO4", mo: 39.50 } +] + +FERTILIZER_COMPONENTS.each do |attrs| + FertilizerComponent.find_or_create_by!(name: attrs[:name]) do |c| + c.attributes = attrs + end +end + +puts "Fertilizer components: #{FertilizerComponent.count}" diff --git a/db/seeds/6_fertilizer_products.rb b/db/seeds/6_fertilizer_products.rb new file mode 100644 index 0000000..6769bde --- /dev/null +++ b/db/seeds/6_fertilizer_products.rb @@ -0,0 +1,143 @@ +FERTILIZER_RECIPES = [ + { + name: "Multi K Reci", + purity: 99.0, + composition: [ + { component: { + name: "Potassium nitrate", + formula: "KNO3", + nno3: 13.0, + k: 46.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Fixa Mn", + purity: 98.0, + composition: [ + { component: { + name: "Manganese sulfate", + formula: "MnSO4·H2O", + mn: 32.0, + s: 18.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Multi-Cal Haïfa", + purity: 99.0, + composition: [ + { component: { + name: "Calcium nitrate", + formula: "Ca(NO3)2·4H2O", + nno3: 15.5, + ca: 19.0 }, + percent_w: 100.0 } + ] + }, + { + name: "DAP 18/46/00", + purity: 100.0, + composition: [ + { component: { + name: "Diammonium phosphate", + formula: "(NH4)2HPO4", + nnh4: 18.0, + p: 20.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Patenkali", + purity: 100.0, + composition: [ + { component: { + name: "Potassium sulfate", + formula: "K2SO4", + k: 50.0, + s: 18.0 + }, percent_w: 100.0 } + ] + }, + { + name: "Eso Top", + purity: 100.0, + composition: [ + { component: { + name: "Magnesium sulfate", + formula: "MgSO4·7H2O", + mg: 9.8, + s: 13.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Ammonitrate 27", + purity: 100.0, + composition: [ + { component: { + name: "Ammonium nitrate", + formula: "NH4NO3", + nno3: 13.5, + nnh4: 13.5 }, + percent_w: 100.0 } + ] + }, + { + name: "Fer chélaté", + purity: 100.0, + composition: [ + { component: { + name: "Iron chelate (EDDHA)", + formula: "Fe-EDDHA", + fe: 6.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Carbonate de calcium", + purity: 100.0, + composition: [ + { component: { + name: "Calcium carbonate", + formula: "CaCO3", + ca: 40.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Héliocuivre", + purity: 100.0, + composition: [ + { component: { + name: "Copper chelate (EDTA)", + formula: "Cu-EDTA", + cu: 14.0 }, + percent_w: 100.0 } + ] + } +] + +FERTILIZER_RECIPES.each do |recipe| + product = FertilizerProduct.find_or_create_by!(name: recipe[:name]) do |fp| + fp.purity = recipe[:purity] + end + + recipe[:composition].each do |c| + comp_attrs = c[:component] + component = FertilizerComponent.find_or_create_by!(name: comp_attrs[:name]) do |fc| + fc.formula = comp_attrs[:formula] + end + # update nutrient fields if missing + component.update!(comp_attrs.except(:name, :formula)) + + FertilizerComposition.find_or_create_by!( + fertilizer_product: product, + fertilizer_component: component + ) do |fc| + fc.percent_w = c[:percent_w] + end + end +end + +puts "FertilizerProducts: #{FertilizerProduct.count}" diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/tasks/.keep diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/log/.keep diff --git a/public/400.html b/public/400.html new file mode 100644 index 0000000..282dbc8 --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ +<!doctype html> + +<html lang="en"> + + <head> + + <title>The server cannot process the request due to a client error (400 Bad Request)</title> + + <meta charset="utf-8"> + <meta name="viewport" content="initial-scale=1, width=device-width"> + <meta name="robots" content="noindex, nofollow"> + + <style> + + *, *::before, *::after { + box-sizing: border-box; + } + + * { + margin: 0; + } + + html { + font-size: 16px; + } + + body { + background: #FFF; + color: #261B23; + display: grid; + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Aptos, Roboto, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: clamp(1rem, 2.5vw, 2rem); + -webkit-font-smoothing: antialiased; + font-style: normal; + font-weight: 400; + letter-spacing: -0.0025em; + line-height: 1.4; + min-height: 100vh; + place-items: center; + text-rendering: optimizeLegibility; + -webkit-text-size-adjust: 100%; + } + + a { + color: inherit; + font-weight: 700; + text-decoration: underline; + text-underline-offset: 0.0925em; + } + + b, strong { + font-weight: 700; + } + + i, em { + font-style: italic; + } + + main { + display: grid; + gap: 1em; + padding: 2em; + place-items: center; + text-align: center; + } + + main header { + width: min(100%, 12em); + } + + main header svg { + height: auto; + max-width: 100%; + width: 100%; + } + + main article { + width: min(100%, 30em); + } + + main article p { + font-size: 75%; + } + + main article br { + + display: none; + + @media(min-width: 48em) { + display: inline; + } + + } + + </style> + + </head> + + <body> + + <!-- This file lives in public/400.html --> + + <main> + <header> + <svg height="172" viewBox="0 0 480 172" width="480" xmlns="http://www.w3.org/2000/svg"><path d="m124.48 3.00509-45.6889 100.02991h26.2239v-28.1168h38.119v28.1168h21.628v35.145h-21.628v30.82h-37.308v-30.82h-72.1833v-31.901l50.2851-103.27391zm115.583 168.69891c-40.822 0-64.884-35.146-64.884-85.7015 0-50.5554 24.062-85.700907 64.884-85.700907 40.823 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.061 85.7015-64.884 85.7015zm0-133.2831c-17.572 0-22.709 21.8984-22.709 47.5816 0 25.6835 5.137 47.5815 22.709 47.5815 17.303 0 22.71-21.898 22.71-47.5815 0-25.6832-5.407-47.5816-22.71-47.5816zm140.456 133.2831c-40.823 0-64.884-35.146-64.884-85.7015 0-50.5554 24.061-85.700907 64.884-85.700907 40.822 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.062 85.7015-64.884 85.7015zm0-133.2831c-17.573 0-22.71 21.8984-22.71 47.5816 0 25.6835 5.137 47.5815 22.71 47.5815 17.302 0 22.709-21.898 22.709-47.5815 0-25.6832-5.407-47.5816-22.709-47.5816z" fill="#f0eff0"/><path d="m123.606 85.4445c3.212 1.0523 5.538 4.2089 5.538 8.0301 0 6.1472-4.209 9.5254-11.298 9.5254h-15.617v-34.0033h14.565c7.089 0 11.353 3.1566 11.353 9.2484 0 3.6551-2.049 6.3134-4.541 7.1994zm-12.904-2.9905h5.095c2.603 0 3.988-.9968 3.988-3.1013 0-2.1044-1.385-3.0459-3.988-3.0459h-5.095zm0 6.6456v6.5902h5.981c2.492 0 3.877-1.3291 3.877-3.2674 0-2.049-1.385-3.3228-3.877-3.3228zm43.786 13.9004h-8.362v-1.274c-.831.831-3.323 1.717-5.981 1.717-4.929 0-9.083-2.769-9.083-8.0301 0-4.818 4.154-7.9193 9.581-7.9193 2.049 0 4.486.6646 5.483 1.3845v-1.606c0-1.606-.942-2.9905-3.046-2.9905-1.606 0-2.548.7199-2.935 1.8275h-8.197c.72-4.8181 4.985-8.6393 11.409-8.6393 7.088 0 11.131 3.7659 11.131 10.2453zm-8.362-6.9779v-1.4399c-.554-1.0522-2.049-1.7167-3.655-1.7167-1.717 0-3.434.7199-3.434 2.3813 0 1.7168 1.717 2.4367 3.434 2.4367 1.606 0 3.101-.6645 3.655-1.6614zm27.996 6.9779v-1.994c-1.163 1.329-3.599 2.548-6.147 2.548-7.199 0-11.131-5.8151-11.131-13.0145s3.932-13.0143 11.131-13.0143c2.548 0 4.984 1.2184 6.147 2.5475v-13.0697h8.695v35.997zm0-9.1931v-6.5902c-.664-1.3291-2.159-2.326-3.821-2.326-2.99 0-4.763 2.4368-4.763 5.6488s1.773 5.5934 4.763 5.5934c1.717 0 3.157-.9415 3.821-2.326zm35.471-2.049h-3.101v11.2421h-8.806v-34.0033h15.285c7.31 0 12.35 4.1535 12.35 11.5744 0 5.1503-2.603 8.6947-6.757 10.2453l7.975 12.1836h-9.858zm-3.101-15.2849v8.1962h5.538c3.156 0 4.596-1.606 4.596-4.0981s-1.44-4.0981-4.596-4.0981zm36.957 17.8323h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.643 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.515-13.0143 7.643 0 11.962 5.095 11.962 12.5159v2.1598h-16.115c.277 2.9905 1.827 4.5965 4.32 4.5965 1.772 0 3.156-.7753 3.655-2.4921zm-3.822-10.0237c-2.049 0-3.433 1.2737-3.987 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.545-3.5997zm30.98 27.5234v-10.799c-1.163 1.329-3.6 2.548-6.147 2.548-7.2 0-11.132-5.9259-11.132-13.0145 0-7.144 3.932-13.0143 11.132-13.0143 2.547 0 4.984 1.2184 6.147 2.5475v-1.9937h8.695v33.726zm0-17.9981v-6.5902c-.665-1.3291-2.105-2.326-3.821-2.326-2.991 0-4.763 2.4368-4.763 5.6488s1.772 5.5934 4.763 5.5934c1.661 0 3.156-.9415 3.821-2.326zm36.789-15.7279v24.921h-8.695v-2.16c-1.329 1.551-3.821 2.714-6.646 2.714-5.482 0-8.75-3.5999-8.75-9.1379v-16.3371h8.64v14.288c0 2.1045.996 3.5997 3.212 3.5997 1.606 0 3.101-1.0522 3.544-2.769v-15.1187zm19.084 16.2263h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.643 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.515-13.0143 7.643 0 11.963 5.095 11.963 12.5159v2.1598h-16.116c.277 2.9905 1.828 4.5965 4.32 4.5965 1.772 0 3.156-.7753 3.655-2.4921zm-3.822-10.0237c-2.049 0-3.433 1.2737-3.987 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.545-3.5997zm13.428 11.0206h8.474c.387 1.3845 1.606 2.1598 3.156 2.1598 1.44 0 2.548-.5538 2.548-1.7168 0-.9414-.72-1.2737-1.939-1.5506l-4.873-.9969c-4.154-.886-6.867-2.8797-6.867-7.2547 0-5.3165 4.762-8.4178 10.633-8.4178 6.812 0 10.522 3.1567 11.297 8.0855h-8.03c-.277-1.0522-1.052-1.9937-3.046-1.9937-1.273 0-2.326.5538-2.326 1.6614 0 .7753.554 1.163 1.717 1.3845l4.929 1.163c4.541 1.0522 6.978 3.4335 6.978 7.4763 0 5.3168-4.818 8.2518-10.91 8.2518-6.369 0-10.965-2.88-11.741-8.2518zm27.538-.8861v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.205v6.7564h-5.205v8.307c0 1.9383.941 2.769 2.658 2.769.941 0 1.993-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.871 0-9.193-2.769-9.193-9.0819z" fill="#d30001"/></svg> + </header> + <article> + <p><strong>The server cannot process the request due to a client error.</strong> Please check the request and try again. If you’re the application owner check the logs for more information.</p> + </article> + </main> + + </body> + +</html> diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..c0670bc --- /dev/null +++ b/public/404.html @@ -0,0 +1,114 @@ +<!doctype html> + +<html lang="en"> + + <head> + + <title>The page you were looking for doesn’t exist (404 Not found)</title> + + <meta charset="utf-8"> + <meta name="viewport" content="initial-scale=1, width=device-width"> + <meta name="robots" content="noindex, nofollow"> + + <style> + + *, *::before, *::after { + box-sizing: border-box; + } + + * { + margin: 0; + } + + html { + font-size: 16px; + } + + body { + background: #FFF; + color: #261B23; + display: grid; + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Aptos, Roboto, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: clamp(1rem, 2.5vw, 2rem); + -webkit-font-smoothing: antialiased; + font-style: normal; + font-weight: 400; + letter-spacing: -0.0025em; + line-height: 1.4; + min-height: 100vh; + place-items: center; + text-rendering: optimizeLegibility; + -webkit-text-size-adjust: 100%; + } + + a { + color: inherit; + font-weight: 700; + text-decoration: underline; + text-underline-offset: 0.0925em; + } + + b, strong { + font-weight: 700; + } + + i, em { + font-style: italic; + } + + main { + display: grid; + gap: 1em; + padding: 2em; + place-items: center; + text-align: center; + } + + main header { + width: min(100%, 12em); + } + + main header svg { + height: auto; + max-width: 100%; + width: 100%; + } + + main article { + width: min(100%, 30em); + } + + main article p { + font-size: 75%; + } + + main article br { + + display: none; + + @media(min-width: 48em) { + display: inline; + } + + } + + </style> + + </head> + + <body> + + <!-- This file lives in public/404.html --> + + <main> + <header> + <svg height="172" viewBox="0 0 480 172" width="480" xmlns="http://www.w3.org/2000/svg"><path d="m124.48 3.00509-45.6889 100.02991h26.2239v-28.1168h38.119v28.1168h21.628v35.145h-21.628v30.82h-37.308v-30.82h-72.1833v-31.901l50.2851-103.27391zm115.583 168.69891c-40.822 0-64.884-35.146-64.884-85.7015 0-50.5554 24.062-85.700907 64.884-85.700907 40.823 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.061 85.7015-64.884 85.7015zm0-133.2831c-17.572 0-22.709 21.8984-22.709 47.5816 0 25.6835 5.137 47.5815 22.709 47.5815 17.303 0 22.71-21.898 22.71-47.5815 0-25.6832-5.407-47.5816-22.71-47.5816zm165.328-35.41581-45.689 100.02991h26.224v-28.1168h38.119v28.1168h21.628v35.145h-21.628v30.82h-37.308v-30.82h-72.184v-31.901l50.285-103.27391z" fill="#f0eff0"/><path d="m157.758 68.9967v34.0033h-7.199l-14.233-19.8814v19.8814h-8.584v-34.0033h8.307l13.125 18.7184v-18.7184zm28.454 21.5428c0 7.6978-5.15 13.0145-12.737 13.0145-7.532 0-12.738-5.3167-12.738-13.0145s5.206-13.0143 12.738-13.0143c7.587 0 12.737 5.3165 12.737 13.0143zm-8.528 0c0-3.4336-1.496-5.8703-4.209-5.8703-2.659 0-4.154 2.4367-4.154 5.8703s1.495 5.8149 4.154 5.8149c2.713 0 4.209-2.3813 4.209-5.8149zm13.184 3.8766v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.205v6.7564h-5.205v8.307c0 1.9383.941 2.769 2.658 2.769.941 0 1.994-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.87 0-9.193-2.769-9.193-9.0819zm37.027 8.5839h-8.806v-34.0033h23.924v7.6978h-15.118v6.7564h13.9v7.5316h-13.9zm41.876-12.4605c0 7.6978-5.15 13.0145-12.737 13.0145-7.532 0-12.738-5.3167-12.738-13.0145s5.206-13.0143 12.738-13.0143c7.587 0 12.737 5.3165 12.737 13.0143zm-8.529 0c0-3.4336-1.495-5.8703-4.208-5.8703-2.659 0-4.154 2.4367-4.154 5.8703s1.495 5.8149 4.154 5.8149c2.713 0 4.208-2.3813 4.208-5.8149zm35.337-12.4605v24.921h-8.695v-2.16c-1.329 1.551-3.821 2.714-6.646 2.714-5.482 0-8.75-3.5999-8.75-9.1379v-16.3371h8.64v14.288c0 2.1045.997 3.5997 3.212 3.5997 1.606 0 3.101-1.0522 3.544-2.769v-15.1187zm4.076 24.921v-24.921h8.694v2.1598c1.385-1.5506 3.822-2.7136 6.701-2.7136 5.538 0 8.806 3.5997 8.806 9.1377v16.3371h-8.639v-14.2327c0-2.049-1.053-3.5443-3.268-3.5443-1.717 0-3.156.9969-3.6 2.7136v15.0634zm44.113 0v-1.994c-1.163 1.329-3.6 2.548-6.147 2.548-7.2 0-11.132-5.8151-11.132-13.0145s3.932-13.0143 11.132-13.0143c2.547 0 4.984 1.2184 6.147 2.5475v-13.0697h8.695v35.997zm0-9.1931v-6.5902c-.665-1.3291-2.16-2.326-3.821-2.326-2.991 0-4.763 2.4368-4.763 5.6488s1.772 5.5934 4.763 5.5934c1.717 0 3.156-.9415 3.821-2.326z" fill="#d30001"/></svg> + </header> + <article> + <p><strong>The page you were looking for doesn’t exist.</strong> You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.</p> + </article> + </main> + + </body> + +</html> diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 0000000..9532a9c --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ +<!doctype html> + +<html lang="en"> + + <head> + + <title>Your browser is not supported (406 Not Acceptable)</title> + + <meta charset="utf-8"> + <meta name="viewport" content="initial-scale=1, width=device-width"> + <meta name="robots" content="noindex, nofollow"> + + <style> + + *, *::before, *::after { + box-sizing: border-box; + } + + * { + margin: 0; + } + + html { + font-size: 16px; + } + + body { + background: #FFF; + color: #261B23; + display: grid; + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Aptos, Roboto, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: clamp(1rem, 2.5vw, 2rem); + -webkit-font-smoothing: antialiased; + font-style: normal; + font-weight: 400; + letter-spacing: -0.0025em; + line-height: 1.4; + min-height: 100vh; + place-items: center; + text-rendering: optimizeLegibility; + -webkit-text-size-adjust: 100%; + } + + a { + color: inherit; + font-weight: 700; + text-decoration: underline; + text-underline-offset: 0.0925em; + } + + b, strong { + font-weight: 700; + } + + i, em { + font-style: italic; + } + + main { + display: grid; + gap: 1em; + padding: 2em; + place-items: center; + text-align: center; + } + + main header { + width: min(100%, 12em); + } + + main header svg { + height: auto; + max-width: 100%; + width: 100%; + } + + main article { + width: min(100%, 30em); + } + + main article p { + font-size: 75%; + } + + main article br { + + display: none; + + @media(min-width: 48em) { + display: inline; + } + + } + + </style> + + </head> + + <body> + + <!-- This file lives in public/406-unsupported-browser.html --> + + <main> + <header> + <svg height="172" viewBox="0 0 480 172" width="480" xmlns="http://www.w3.org/2000/svg"><path d="m124.48 3.00509-45.6889 100.02991h26.2239v-28.1168h38.119v28.1168h21.628v35.145h-21.628v30.82h-37.308v-30.82h-72.1833v-31.901l50.2851-103.27391zm115.583 168.69891c-40.822 0-64.884-35.146-64.884-85.7015 0-50.5554 24.062-85.700907 64.884-85.700907 40.823 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.061 85.7015-64.884 85.7015zm0-133.2831c-17.572 0-22.709 21.8984-22.709 47.5816 0 25.6835 5.137 47.5815 22.709 47.5815 17.303 0 22.71-21.898 22.71-47.5815 0-25.6832-5.407-47.5816-22.71-47.5816zm202.906 9.7326h-41.093c-2.433-7.2994-7.84-12.4361-17.302-12.4361-16.221 0-25.413 17.5728-25.954 34.8752v1.3517c5.137-7.0291 16.221-12.4361 30.82-12.4361 33.524 0 54.881 24.0612 54.881 53.7998 0 33.253-23.791 58.396-61.64 58.396-21.628 0-39.741-10.003-50.825-27.576-9.733-14.599-13.788-32.442-13.788-54.3406 0-51.9072 24.331-89.485807 66.236-89.485807 32.712 0 53.258 18.654107 58.665 47.851907zm-82.727 66.2355c0 13.247 9.463 22.439 22.71 22.439 12.977 0 22.439-9.192 22.439-22.439 0-13.517-9.462-22.7091-22.439-22.7091-13.247 0-22.71 9.1921-22.71 22.7091z" fill="#f0eff0"/><path d="m100.761 68.9967v34.0033h-7.1991l-14.2326-19.8814v19.8814h-8.5839v-34.0033h8.307l13.125 18.7184v-18.7184zm28.454 21.5428c0 7.6978-5.15 13.0145-12.737 13.0145-7.532 0-12.738-5.3167-12.738-13.0145s5.206-13.0143 12.738-13.0143c7.587 0 12.737 5.3165 12.737 13.0143zm-8.529 0c0-3.4336-1.495-5.8703-4.208-5.8703-2.659 0-4.154 2.4367-4.154 5.8703s1.495 5.8149 4.154 5.8149c2.713 0 4.208-2.3813 4.208-5.8149zm13.185 3.8766v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.205v6.7564h-5.205v8.307c0 1.9383.941 2.769 2.658 2.769.941 0 1.994-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.87 0-9.193-2.769-9.193-9.0819zm39.02-25.4194h9.083l12.958 34.0033h-9.027l-2.436-6.5902h-12.35l-2.381 6.5902h-8.806zm4.431 10.5222-3.489 9.5807h6.978zm17.44 11.0206c0-7.6978 5.095-13.0143 12.572-13.0143 6.701 0 10.854 3.9874 11.574 9.8023h-8.418c-.221-1.4953-1.384-2.6029-3.156-2.6029-2.437 0-3.988 2.2706-3.988 5.8149s1.551 5.7595 3.988 5.7595c1.772 0 2.935-1.0522 3.156-2.5475h8.418c-.72 5.7596-4.873 9.8025-11.574 9.8025-7.477 0-12.572-5.3167-12.572-13.0145zm25.676 0c0-7.6978 5.095-13.0143 12.572-13.0143 6.701 0 10.854 3.9874 11.574 9.8023h-8.418c-.221-1.4953-1.384-2.6029-3.156-2.6029-2.437 0-3.988 2.2706-3.988 5.8149s1.551 5.7595 3.988 5.7595c1.772 0 2.935-1.0522 3.156-2.5475h8.418c-.72 5.7596-4.873 9.8025-11.574 9.8025-7.477 0-12.572-5.3167-12.572-13.0145zm42.013 3.7658h8.031c-.887 5.7597-5.206 9.2487-11.686 9.2487-7.642 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.317-13.0143 12.516-13.0143 7.643 0 11.962 5.095 11.962 12.5159v2.1598h-16.115c.277 2.9905 1.827 4.5965 4.319 4.5965 1.773 0 3.157-.7753 3.655-2.4921zm-3.821-10.0237c-2.049 0-3.433 1.2737-3.987 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.545-3.5997zm23.4 16.7244v10.799h-8.694v-33.726h8.694v1.9937c1.163-1.3291 3.6-2.5475 6.148-2.5475 7.199 0 11.131 5.8703 11.131 13.0143 0 7.0886-3.932 13.0145-11.131 13.0145-2.548 0-4.985-1.219-6.148-2.548zm0-13.7893v6.5902c.665 1.3845 2.16 2.326 3.822 2.326 2.99 0 4.762-2.3814 4.762-5.5934s-1.772-5.6488-4.762-5.6488c-1.717 0-3.157.9969-3.822 2.326zm21.892 7.1994v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.206v6.7564h-5.206v8.307c0 1.9383.941 2.769 2.658 2.769.942 0 1.994-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.87 0-9.193-2.769-9.193-9.0819zm39.458 8.5839h-8.363v-1.274c-.83.831-3.322 1.717-5.981 1.717-4.928 0-9.082-2.769-9.082-8.0301 0-4.818 4.154-7.9193 9.581-7.9193 2.049 0 4.486.6646 5.482 1.3845v-1.606c0-1.606-.941-2.9905-3.045-2.9905-1.606 0-2.548.7199-2.936 1.8275h-8.196c.72-4.8181 4.984-8.6393 11.408-8.6393 7.089 0 11.132 3.7659 11.132 10.2453zm-8.363-6.9779v-1.4399c-.553-1.0522-2.049-1.7167-3.655-1.7167-1.716 0-3.433.7199-3.433 2.3813 0 1.7168 1.717 2.4367 3.433 2.4367 1.606 0 3.102-.6645 3.655-1.6614zm20.742 4.9839v1.994h-8.694v-35.997h8.694v13.0697c1.163-1.3291 3.6-2.5475 6.148-2.5475 7.199 0 11.131 5.8149 11.131 13.0143s-3.932 13.0145-11.131 13.0145c-2.548 0-4.985-1.219-6.148-2.548zm0-13.7893v6.5902c.665 1.3845 2.105 2.326 3.822 2.326 2.99 0 4.762-2.3814 4.762-5.5934s-1.772-5.6488-4.762-5.6488c-1.662 0-3.157.9969-3.822 2.326zm28.759-20.2137v35.997h-8.695v-35.997zm19.172 27.3023h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.643 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.516-13.0143 7.642 0 11.962 5.095 11.962 12.5159v2.1598h-16.116c.277 2.9905 1.828 4.5965 4.32 4.5965 1.772 0 3.157-.7753 3.655-2.4921zm-3.821-10.0237c-2.049 0-3.434 1.2737-3.988 3.5997h7.532c-.111-2.0491-1.384-3.5997-3.544-3.5997z" fill="#d30001"/></svg> + </header> + <article> + <p><strong>Your browser is not supported.</strong><br> Please upgrade your browser to continue.</p> + </article> + </main> + + </body> + +</html> diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..8bcf060 --- /dev/null +++ b/public/422.html @@ -0,0 +1,114 @@ +<!doctype html> + +<html lang="en"> + + <head> + + <title>The change you wanted was rejected (422 Unprocessable Entity)</title> + + <meta charset="utf-8"> + <meta name="viewport" content="initial-scale=1, width=device-width"> + <meta name="robots" content="noindex, nofollow"> + + <style> + + *, *::before, *::after { + box-sizing: border-box; + } + + * { + margin: 0; + } + + html { + font-size: 16px; + } + + body { + background: #FFF; + color: #261B23; + display: grid; + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Aptos, Roboto, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: clamp(1rem, 2.5vw, 2rem); + -webkit-font-smoothing: antialiased; + font-style: normal; + font-weight: 400; + letter-spacing: -0.0025em; + line-height: 1.4; + min-height: 100vh; + place-items: center; + text-rendering: optimizeLegibility; + -webkit-text-size-adjust: 100%; + } + + a { + color: inherit; + font-weight: 700; + text-decoration: underline; + text-underline-offset: 0.0925em; + } + + b, strong { + font-weight: 700; + } + + i, em { + font-style: italic; + } + + main { + display: grid; + gap: 1em; + padding: 2em; + place-items: center; + text-align: center; + } + + main header { + width: min(100%, 12em); + } + + main header svg { + height: auto; + max-width: 100%; + width: 100%; + } + + main article { + width: min(100%, 30em); + } + + main article p { + font-size: 75%; + } + + main article br { + + display: none; + + @media(min-width: 48em) { + display: inline; + } + + } + + </style> + + </head> + + <body> + + <!-- This file lives in public/422.html --> + + <main> + <header> + <svg height="172" viewBox="0 0 480 172" width="480" xmlns="http://www.w3.org/2000/svg"><path d="m124.48 3.00509-45.6889 100.02991h26.2239v-28.1168h38.119v28.1168h21.628v35.145h-21.628v30.82h-37.308v-30.82h-72.1833v-31.901l50.2851-103.27391zm130.453 51.63681c0-8.9215-6.218-15.4099-15.681-15.4099-10.273 0-15.95 7.5698-16.491 16.4913h-44.608c3.244-30.8199 25.683-55.421707 61.099-55.421707 36.498 0 59.477 20.816907 59.477 51.636807 0 21.3577-14.869 36.7676-31.901 52.7186l-27.305 27.035h59.747v37.308h-120.306v-27.846l57.044-56.7736c11.084-11.8954 18.925-20.0059 18.925-29.7385zm140.455 0c0-8.9215-6.218-15.4099-15.68-15.4099-10.274 0-15.951 7.5698-16.492 16.4913h-44.608c3.245-30.8199 25.684-55.421707 61.1-55.421707 36.497 0 59.477 20.816907 59.477 51.636807 0 21.3577-14.87 36.7676-31.902 52.7186l-27.305 27.035h59.747v37.308h-120.305v-27.846l57.043-56.7736c11.085-11.8954 18.925-20.0059 18.925-29.7385z" fill="#f0eff0"/><path d="m19.3936 103.554c-8.9715 0-14.84183-5.0952-14.84183-14.4544v-20.1029h8.86083v19.3276c0 4.8181 2.2706 7.3102 5.981 7.3102 3.6551 0 5.9257-2.4921 5.9257-7.3102v-19.3276h8.8608v20.1583c0 9.3038-5.8149 14.399-14.7865 14.399zm18.734-.554v-24.921h8.6947v2.1598c1.3845-1.5506 3.8212-2.7136 6.701-2.7136 5.538 0 8.8054 3.5997 8.8054 9.1377v16.3371h-8.6393v-14.2327c0-2.049-1.0522-3.5443-3.2674-3.5443-1.7168 0-3.1567.9969-3.5997 2.7136v15.0634zm36.8584-1.994v10.799h-8.6946v-33.726h8.6946v1.9937c1.163-1.3291 3.5997-2.5475 6.1472-2.5475 7.1994 0 11.1314 5.8703 11.1314 13.0143 0 7.0886-3.932 13.0145-11.1314 13.0145-2.5475 0-4.9842-1.219-6.1472-2.548zm0-13.7893v6.5902c.6646 1.3845 2.1599 2.326 3.8213 2.326 2.9905 0 4.7626-2.3814 4.7626-5.5934s-1.7721-5.6488-4.7626-5.6488c-1.7168 0-3.1567.9969-3.8213 2.326zm36.789-9.2485v8.3624c-1.052-.5538-2.215-.7753-3.6-.7753-2.381 0-3.987 1.0522-4.43 2.8244v14.6203h-8.6949v-24.921h8.6949v2.2152c1.218-1.6614 3.156-2.769 5.648-2.769 1.108 0 1.994.2215 2.382.443zm26.769 12.5713c0 7.6978-5.15 13.0145-12.737 13.0145-7.532 0-12.738-5.3167-12.738-13.0145s5.206-13.0143 12.738-13.0143c7.587 0 12.737 5.3165 12.737 13.0143zm-8.528 0c0-3.4336-1.496-5.8703-4.209-5.8703-2.659 0-4.154 2.4367-4.154 5.8703s1.495 5.8149 4.154 5.8149c2.713 0 4.209-2.3813 4.209-5.8149zm10.352 0c0-7.6978 5.095-13.0143 12.571-13.0143 6.701 0 10.855 3.9874 11.574 9.8023h-8.417c-.222-1.4953-1.385-2.6029-3.157-2.6029-2.437 0-3.987 2.2706-3.987 5.8149s1.55 5.7595 3.987 5.7595c1.772 0 2.935-1.0522 3.157-2.5475h8.417c-.719 5.7596-4.873 9.8025-11.574 9.8025-7.476 0-12.571-5.3167-12.571-13.0145zm42.013 3.7658h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.643 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.516-13.0143 7.642 0 11.962 5.095 11.962 12.5159v2.1598h-16.116c.277 2.9905 1.828 4.5965 4.32 4.5965 1.772 0 3.156-.7753 3.655-2.4921zm-3.821-10.0237c-2.049 0-3.434 1.2737-3.988 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.544-3.5997zm13.428 11.0206h8.473c.387 1.3845 1.606 2.1598 3.156 2.1598 1.44 0 2.548-.5538 2.548-1.7168 0-.9414-.72-1.2737-1.938-1.5506l-4.874-.9969c-4.153-.886-6.867-2.8797-6.867-7.2547 0-5.3165 4.763-8.4178 10.633-8.4178 6.812 0 10.522 3.1567 11.297 8.0855h-8.03c-.277-1.0522-1.052-1.9937-3.046-1.9937-1.273 0-2.326.5538-2.326 1.6614 0 .7753.554 1.163 1.717 1.3845l4.929 1.163c4.541 1.0522 6.978 3.4335 6.978 7.4763 0 5.3168-4.818 8.2518-10.91 8.2518-6.369 0-10.965-2.88-11.74-8.2518zm24.269 0h8.474c.387 1.3845 1.606 2.1598 3.156 2.1598 1.44 0 2.548-.5538 2.548-1.7168 0-.9414-.72-1.2737-1.939-1.5506l-4.873-.9969c-4.154-.886-6.867-2.8797-6.867-7.2547 0-5.3165 4.763-8.4178 10.633-8.4178 6.812 0 10.522 3.1567 11.297 8.0855h-8.03c-.277-1.0522-1.052-1.9937-3.046-1.9937-1.273 0-2.326.5538-2.326 1.6614 0 .7753.554 1.163 1.717 1.3845l4.929 1.163c4.541 1.0522 6.978 3.4335 6.978 7.4763 0 5.3168-4.818 8.2518-10.91 8.2518-6.369 0-10.965-2.88-11.741-8.2518zm47.918 7.6978h-8.363v-1.274c-.831.831-3.323 1.717-5.981 1.717-4.929 0-9.082-2.769-9.082-8.0301 0-4.818 4.153-7.9193 9.581-7.9193 2.049 0 4.485.6646 5.482 1.3845v-1.606c0-1.606-.941-2.9905-3.046-2.9905-1.606 0-2.547.7199-2.935 1.8275h-8.196c.72-4.8181 4.984-8.6393 11.408-8.6393 7.089 0 11.132 3.7659 11.132 10.2453zm-8.363-6.9779v-1.4399c-.554-1.0522-2.049-1.7167-3.655-1.7167-1.717 0-3.434.7199-3.434 2.3813 0 1.7168 1.717 2.4367 3.434 2.4367 1.606 0 3.101-.6645 3.655-1.6614zm20.742 4.9839v1.994h-8.695v-35.997h8.695v13.0697c1.163-1.3291 3.6-2.5475 6.147-2.5475 7.2 0 11.132 5.8149 11.132 13.0143s-3.932 13.0145-11.132 13.0145c-2.547 0-4.984-1.219-6.147-2.548zm0-13.7893v6.5902c.665 1.3845 2.105 2.326 3.821 2.326 2.991 0 4.763-2.3814 4.763-5.5934s-1.772-5.6488-4.763-5.6488c-1.661 0-3.156.9969-3.821 2.326zm28.759-20.2137v35.997h-8.695v-35.997zm19.172 27.3023h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.643 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.515-13.0143 7.643 0 11.962 5.095 11.962 12.5159v2.1598h-16.115c.277 2.9905 1.827 4.5965 4.32 4.5965 1.772 0 3.156-.7753 3.655-2.4921zm-3.822-10.0237c-2.049 0-3.433 1.2737-3.987 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.545-3.5997zm25.461-15.2849h24.311v7.6424h-15.561v5.3165h14.232v7.4763h-14.232v5.8703h15.561v7.6978h-24.311zm27.942 34.0033v-24.921h8.694v2.1598c1.385-1.5506 3.822-2.7136 6.701-2.7136 5.538 0 8.806 3.5997 8.806 9.1377v16.3371h-8.639v-14.2327c0-2.049-1.053-3.5443-3.268-3.5443-1.717 0-3.157.9969-3.6 2.7136v15.0634zm29.991-8.5839v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.206v6.7564h-5.206v8.307c0 1.9383.941 2.769 2.658 2.769.942 0 1.994-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.87 0-9.193-2.769-9.193-9.0819zm26.161-16.3371v24.921h-8.694v-24.921zm.61-6.7564c0 2.8244-2.271 4.652-4.929 4.652s-4.929-1.8276-4.929-4.652c0-2.8797 2.271-4.7073 4.929-4.7073s4.929 1.8276 4.929 4.7073zm5.382 23.0935v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.584v6.8671h5.206v6.7564h-5.206v8.307c0 1.9383.941 2.769 2.658 2.769.941 0 1.994-.2216 2.769-.5538v7.3654c-.997.443-2.88.775-4.818.775-5.87 0-9.193-2.769-9.193-9.0819zm29.22 17.3889h-8.584l3.655-9.414-9.303-24.312h9.026l4.763 14.1773 4.652-14.1773h8.639z" fill="#d30001"/></svg> + </header> + <article> + <p><strong>The change you wanted was rejected.</strong> Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.</p> + </article> + </main> + + </body> + +</html> diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..d77718c --- /dev/null +++ b/public/500.html @@ -0,0 +1,114 @@ +<!doctype html> + +<html lang="en"> + + <head> + + <title>We’re sorry, but something went wrong (500 Internal Server Error)</title> + + <meta charset="utf-8"> + <meta name="viewport" content="initial-scale=1, width=device-width"> + <meta name="robots" content="noindex, nofollow"> + + <style> + + *, *::before, *::after { + box-sizing: border-box; + } + + * { + margin: 0; + } + + html { + font-size: 16px; + } + + body { + background: #FFF; + color: #261B23; + display: grid; + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Aptos, Roboto, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: clamp(1rem, 2.5vw, 2rem); + -webkit-font-smoothing: antialiased; + font-style: normal; + font-weight: 400; + letter-spacing: -0.0025em; + line-height: 1.4; + min-height: 100vh; + place-items: center; + text-rendering: optimizeLegibility; + -webkit-text-size-adjust: 100%; + } + + a { + color: inherit; + font-weight: 700; + text-decoration: underline; + text-underline-offset: 0.0925em; + } + + b, strong { + font-weight: 700; + } + + i, em { + font-style: italic; + } + + main { + display: grid; + gap: 1em; + padding: 2em; + place-items: center; + text-align: center; + } + + main header { + width: min(100%, 12em); + } + + main header svg { + height: auto; + max-width: 100%; + width: 100%; + } + + main article { + width: min(100%, 30em); + } + + main article p { + font-size: 75%; + } + + main article br { + + display: none; + + @media(min-width: 48em) { + display: inline; + } + + } + + </style> + + </head> + + <body> + + <!-- This file lives in public/500.html --> + + <main> + <header> + <svg height="172" viewBox="0 0 480 172" width="480" xmlns="http://www.w3.org/2000/svg"><path d="m101.23 93.8427c-8.1103 0-15.4098 3.7849-19.7354 8.3813h-36.2269v-99.21891h103.8143v37.03791h-68.3984v24.8722c5.1366-2.7035 15.1396-5.9477 24.6014-5.9477 35.146 0 56.233 22.7094 56.233 55.4215 0 34.605-23.791 57.315-60.558 57.315-37.8492 0-61.64-22.169-63.8028-55.963h42.9857c1.0814 10.814 9.1919 19.195 21.6281 19.195 11.355 0 19.465-8.381 19.465-20.547 0-11.625-7.299-20.5463-20.006-20.5463zm138.833 77.8613c-40.822 0-64.884-35.146-64.884-85.7015 0-50.5554 24.062-85.700907 64.884-85.700907 40.823 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.061 85.7015-64.884 85.7015zm0-133.2831c-17.572 0-22.709 21.8984-22.709 47.5816 0 25.6835 5.137 47.5815 22.709 47.5815 17.303 0 22.71-21.898 22.71-47.5815 0-25.6832-5.407-47.5816-22.71-47.5816zm140.456 133.2831c-40.823 0-64.884-35.146-64.884-85.7015 0-50.5554 24.061-85.700907 64.884-85.700907 40.822 0 64.884 35.145507 64.884 85.700907 0 50.5555-24.062 85.7015-64.884 85.7015zm0-133.2831c-17.573 0-22.71 21.8984-22.71 47.5816 0 25.6835 5.137 47.5815 22.71 47.5815 17.302 0 22.709-21.898 22.709-47.5815 0-25.6832-5.407-47.5816-22.709-47.5816z" fill="#f0eff0"/><path d="m23.1377 68.9967v34.0033h-8.9162v-34.0033zm4.3157 34.0033v-24.921h8.6947v2.1598c1.3845-1.5506 3.8212-2.7136 6.701-2.7136 5.538 0 8.8054 3.5997 8.8054 9.1377v16.3371h-8.6393v-14.2327c0-2.049-1.0522-3.5443-3.2674-3.5443-1.7168 0-3.1567.9969-3.5997 2.7136v15.0634zm29.9913-8.5839v-9.5807h-3.655v-6.7564h3.655v-6.8671h8.5839v6.8671h5.2058v6.7564h-5.2058v8.307c0 1.9383.9415 2.769 2.6583 2.769.9414 0 1.9937-.2216 2.769-.5538v7.3654c-.9969.443-2.8798.775-4.8181.775-5.8703 0-9.1931-2.769-9.1931-9.0819zm32.3666-.1108h8.0301c-.8861 5.7597-5.2057 9.2487-11.6852 9.2487-7.6424 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.3165-13.0143 12.5159-13.0143 7.6424 0 11.9621 5.095 11.9621 12.5159v2.1598h-16.1156c.2769 2.9905 1.8275 4.5965 4.3196 4.5965 1.7722 0 3.1567-.7753 3.6551-2.4921zm-3.8212-10.0237c-2.0491 0-3.4336 1.2737-3.9874 3.5997h7.5317c-.1107-2.0491-1.3845-3.5997-3.5443-3.5997zm31.4299-6.3134v8.3624c-1.052-.5538-2.215-.7753-3.599-.7753-2.382 0-3.988 1.0522-4.431 2.8244v14.6203h-8.694v-24.921h8.694v2.2152c1.219-1.6614 3.157-2.769 5.649-2.769 1.108 0 1.994.2215 2.381.443zm2.949 25.0318v-24.921h8.694v2.1598c1.385-1.5506 3.821-2.7136 6.701-2.7136 5.538 0 8.806 3.5997 8.806 9.1377v16.3371h-8.64v-14.2327c0-2.049-1.052-3.5443-3.267-3.5443-1.717 0-3.157.9969-3.6 2.7136v15.0634zm50.371 0h-8.363v-1.274c-.83.831-3.323 1.717-5.981 1.717-4.929 0-9.082-2.769-9.082-8.0301 0-4.818 4.153-7.9193 9.581-7.9193 2.049 0 4.485.6646 5.482 1.3845v-1.606c0-1.606-.941-2.9905-3.046-2.9905-1.606 0-2.547.7199-2.935 1.8275h-8.196c.72-4.8181 4.984-8.6393 11.408-8.6393 7.089 0 11.132 3.7659 11.132 10.2453zm-8.363-6.9779v-1.4399c-.554-1.0522-2.049-1.7167-3.655-1.7167-1.717 0-3.433.7199-3.433 2.3813 0 1.7168 1.716 2.4367 3.433 2.4367 1.606 0 3.101-.6645 3.655-1.6614zm20.742-29.0191v35.997h-8.694v-35.997zm13.036 25.9178h9.248c.72 2.326 2.714 3.489 5.483 3.489 2.713 0 4.596-1.163 4.596-3.2674 0-1.6061-1.052-2.326-3.212-2.8244l-6.534-1.3845c-4.985-1.1076-8.751-3.7105-8.751-9.47 0-6.6456 5.538-11.0206 13.07-11.0206 8.307 0 13.014 4.5411 13.956 10.4114h-8.695c-.72-1.8829-2.27-3.3228-5.205-3.3228-2.548 0-4.265 1.1076-4.265 2.9905 0 1.4953 1.052 2.326 2.825 2.7137l6.645 1.5506c5.815 1.3845 9.027 4.5412 9.027 9.8023 0 6.9778-5.87 10.9654-13.291 10.9654-8.141 0-13.679-3.9322-14.897-10.6332zm46.509 1.3845h8.031c-.887 5.7597-5.206 9.2487-11.686 9.2487-7.642 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.317-13.0143 12.516-13.0143 7.643 0 11.962 5.095 11.962 12.5159v2.1598h-16.115c.277 2.9905 1.827 4.5965 4.319 4.5965 1.773 0 3.157-.7753 3.655-2.4921zm-3.821-10.0237c-2.049 0-3.433 1.2737-3.987 3.5997h7.532c-.111-2.0491-1.385-3.5997-3.545-3.5997zm31.431-6.3134v8.3624c-1.053-.5538-2.216-.7753-3.6-.7753-2.381 0-3.988 1.0522-4.431 2.8244v14.6203h-8.694v-24.921h8.694v2.2152c1.219-1.6614 3.157-2.769 5.649-2.769 1.108 0 1.994.2215 2.382.443zm18.288 25.0318h-7.809l-9.47-24.921h8.861l4.763 14.288 4.652-14.288h8.528zm25.614-8.6947h8.03c-.886 5.7597-5.206 9.2487-11.685 9.2487-7.642 0-12.682-5.2613-12.682-13.0145 0-7.6978 5.316-13.0143 12.516-13.0143 7.642 0 11.962 5.095 11.962 12.5159v2.1598h-16.116c.277 2.9905 1.828 4.5965 4.32 4.5965 1.772 0 3.157-.7753 3.655-2.4921zm-3.821-10.0237c-2.049 0-3.434 1.2737-3.988 3.5997h7.532c-.111-2.0491-1.384-3.5997-3.544-3.5997zm31.43-6.3134v8.3624c-1.052-.5538-2.215-.7753-3.6-.7753-2.381 0-3.987 1.0522-4.43 2.8244v14.6203h-8.695v-24.921h8.695v2.2152c1.218-1.6614 3.157-2.769 5.649-2.769 1.107 0 1.993.2215 2.381.443zm13.703-8.9715h24.312v7.6424h-15.562v5.3165h14.232v7.4763h-14.232v5.8703h15.562v7.6978h-24.312zm44.667 8.9715v8.3624c-1.052-.5538-2.215-.7753-3.6-.7753-2.381 0-3.987 1.0522-4.43 2.8244v14.6203h-8.695v-24.921h8.695v2.2152c1.218-1.6614 3.156-2.769 5.648-2.769 1.108 0 1.994.2215 2.382.443zm19.673 0v8.3624c-1.053-.5538-2.216-.7753-3.6-.7753-2.381 0-3.987 1.0522-4.43 2.8244v14.6203h-8.695v-24.921h8.695v2.2152c1.218-1.6614 3.156-2.769 5.648-2.769 1.108 0 1.994.2215 2.382.443zm26.769 12.5713c0 7.6978-5.15 13.0145-12.737 13.0145-7.532 0-12.738-5.3167-12.738-13.0145s5.206-13.0143 12.738-13.0143c7.587 0 12.737 5.3165 12.737 13.0143zm-8.529 0c0-3.4336-1.495-5.8703-4.208-5.8703-2.659 0-4.154 2.4367-4.154 5.8703s1.495 5.8149 4.154 5.8149c2.713 0 4.208-2.3813 4.208-5.8149zm28.082-12.5713v8.3624c-1.052-.5538-2.215-.7753-3.6-.7753-2.381 0-3.987 1.0522-4.43 2.8244v14.6203h-8.695v-24.921h8.695v2.2152c1.218-1.6614 3.157-2.769 5.649-2.769 1.107 0 1.993.2215 2.381.443z" fill="#d30001"/></svg> + </header> + <article> + <p><strong>We’re sorry, but something went wrong.</strong><br> If you’re the application owner check the logs for more information.</p> + </article> + </main> + + </body> + +</html> diff --git a/public/icon.png b/public/icon.png Binary files differnew file mode 100644 index 0000000..c4c9dbf --- /dev/null +++ b/public/icon.png diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..04b34bf --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ +<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg"> + <circle cx="256" cy="256" r="256" fill="red"/> +</svg> diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/script/.keep b/script/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/script/.keep diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/storage/.keep diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..cee29fd --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] +end diff --git a/test/controllers/crops_controller_test.rb b/test/controllers/crops_controller_test.rb new file mode 100644 index 0000000..71821b1 --- /dev/null +++ b/test/controllers/crops_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class CropsControllerTest < ActionDispatch::IntegrationTest + setup do + @crop = crops(:one) + end + + test "should get index" do + get crops_url + assert_response :success + end + + test "should get new" do + get new_crop_url + assert_response :success + end + + test "should create crop" do + assert_difference("Crop.count") do + post crops_url, params: { crop: { b: @crop.b, ca: @crop.ca, cl: @crop.cl, crop_type: @crop.crop_type, cu: @crop.cu, fe: @crop.fe, k: @crop.k, mg: @crop.mg, mn: @crop.mn, mo: @crop.mo, na: @crop.na, name: @crop.name, nnh4: @crop.nnh4, nno3: @crop.nno3, p: @crop.p, s: @crop.s, si: @crop.si, zn: @crop.zn } } + end + + assert_redirected_to crop_url(Crop.last) + end + + test "should show crop" do + get crop_url(@crop) + assert_response :success + end + + test "should get edit" do + get edit_crop_url(@crop) + assert_response :success + end + + test "should update crop" do + patch crop_url(@crop), params: { crop: { b: @crop.b, ca: @crop.ca, cl: @crop.cl, crop_type: @crop.crop_type, cu: @crop.cu, fe: @crop.fe, k: @crop.k, mg: @crop.mg, mn: @crop.mn, mo: @crop.mo, na: @crop.na, name: @crop.name, nnh4: @crop.nnh4, nno3: @crop.nno3, p: @crop.p, s: @crop.s, si: @crop.si, zn: @crop.zn } } + assert_redirected_to crop_url(@crop) + end + + test "should destroy crop" do + assert_difference("Crop.count", -1) do + delete crop_url(@crop) + end + + assert_redirected_to crops_url + end +end diff --git a/test/controllers/dashboard_controller_test.rb b/test/controllers/dashboard_controller_test.rb new file mode 100644 index 0000000..447c045 --- /dev/null +++ b/test/controllers/dashboard_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class DashboardControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get dashboard_index_url + assert_response :success + end +end diff --git a/test/controllers/fertilizer_products_controller_test.rb b/test/controllers/fertilizer_products_controller_test.rb new file mode 100644 index 0000000..dbdd44f --- /dev/null +++ b/test/controllers/fertilizer_products_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class FertilizerProductsControllerTest < ActionDispatch::IntegrationTest + setup do + @fertilizer_product = fertilizer_products(:one) + end + + test "should get index" do + get fertilizer_products_url + assert_response :success + end + + test "should get new" do + get new_fertilizer_product_url + assert_response :success + end + + test "should create fertilizer_product" do + assert_difference("FertilizerProduct.count") do + post fertilizer_products_url, params: { fertilizer_product: { name: @fertilizer_product.name, purity: @fertilizer_product.purity } } + end + + assert_redirected_to fertilizer_product_url(FertilizerProduct.last) + end + + test "should show fertilizer_product" do + get fertilizer_product_url(@fertilizer_product) + assert_response :success + end + + test "should get edit" do + get edit_fertilizer_product_url(@fertilizer_product) + assert_response :success + end + + test "should update fertilizer_product" do + patch fertilizer_product_url(@fertilizer_product), params: { fertilizer_product: { name: @fertilizer_product.name, purity: @fertilizer_product.purity } } + assert_redirected_to fertilizer_product_url(@fertilizer_product) + end + + test "should destroy fertilizer_product" do + assert_difference("FertilizerProduct.count", -1) do + delete fertilizer_product_url(@fertilizer_product) + end + + assert_redirected_to fertilizer_products_url + end +end diff --git a/test/controllers/nutrient_measurement_controller_test.rb b/test/controllers/nutrient_measurement_controller_test.rb new file mode 100644 index 0000000..02523e0 --- /dev/null +++ b/test/controllers/nutrient_measurement_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class NutrientMeasurementControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get nutrient_measurement_index_url + assert_response :success + end +end diff --git a/test/controllers/rafts_controller_test.rb b/test/controllers/rafts_controller_test.rb new file mode 100644 index 0000000..0d608d3 --- /dev/null +++ b/test/controllers/rafts_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RaftsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb new file mode 100644 index 0000000..2280833 --- /dev/null +++ b/test/controllers/recipes_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RecipesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/beds.yml b/test/fixtures/beds.yml new file mode 100644 index 0000000..330db85 --- /dev/null +++ b/test/fixtures/beds.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + number: 1 + +two: + number: 1 diff --git a/test/fixtures/crops.yml b/test/fixtures/crops.yml new file mode 100644 index 0000000..32cd3d5 --- /dev/null +++ b/test/fixtures/crops.yml @@ -0,0 +1,41 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + crop_type: 1 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 + +two: + name: MyString + crop_type: 1 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 diff --git a/test/fixtures/fertilizer_products.yml b/test/fixtures/fertilizer_products.yml new file mode 100644 index 0000000..5784aac --- /dev/null +++ b/test/fixtures/fertilizer_products.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + purity: 9.99 + +two: + name: MyString + purity: 9.99 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/fixtures/files/.keep diff --git a/test/fixtures/nutrient_measurements.yml b/test/fixtures/nutrient_measurements.yml new file mode 100644 index 0000000..8408647 --- /dev/null +++ b/test/fixtures/nutrient_measurements.yml @@ -0,0 +1,39 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + measured_on: 2025-08-20 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 + +two: + measured_on: 2025-08-20 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 diff --git a/test/fixtures/nutrients.yml b/test/fixtures/nutrients.yml new file mode 100644 index 0000000..f3c6fc9 --- /dev/null +++ b/test/fixtures/nutrients.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + formula: MyString + name: MyString + +two: + formula: MyString + name: MyString diff --git a/test/fixtures/rafts.yml b/test/fixtures/rafts.yml new file mode 100644 index 0000000..1869e29 --- /dev/null +++ b/test/fixtures/rafts.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + bed: one + location: 1 + +two: + bed: two + location: 1 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/helpers/.keep diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/integration/.keep diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/mailers/.keep diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/models/.keep diff --git a/test/models/bed_test.rb b/test/models/bed_test.rb new file mode 100644 index 0000000..67b50da --- /dev/null +++ b/test/models/bed_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class BedTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/crop_test.rb b/test/models/crop_test.rb new file mode 100644 index 0000000..52e4feb --- /dev/null +++ b/test/models/crop_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CropTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_composition_test.rb b/test/models/fertilizer_composition_test.rb new file mode 100644 index 0000000..5823d3e --- /dev/null +++ b/test/models/fertilizer_composition_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerCompositionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_product_test.rb b/test/models/fertilizer_product_test.rb new file mode 100644 index 0000000..2da4ee7 --- /dev/null +++ b/test/models/fertilizer_product_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_test.rb b/test/models/fertilizer_test.rb new file mode 100644 index 0000000..71c9769 --- /dev/null +++ b/test/models/fertilizer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/nutrient_measurement_test.rb b/test/models/nutrient_measurement_test.rb new file mode 100644 index 0000000..866c8f6 --- /dev/null +++ b/test/models/nutrient_measurement_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class NutrientMeasurementTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/nutrient_test.rb b/test/models/nutrient_test.rb new file mode 100644 index 0000000..61649ad --- /dev/null +++ b/test/models/nutrient_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class NutrientTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/raft_test.rb b/test/models/raft_test.rb new file mode 100644 index 0000000..adb1ef0 --- /dev/null +++ b/test/models/raft_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RaftTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/system/.keep diff --git a/test/system/crops_test.rb b/test/system/crops_test.rb new file mode 100644 index 0000000..bbf3e28 --- /dev/null +++ b/test/system/crops_test.rb @@ -0,0 +1,75 @@ +require "application_system_test_case" + +class CropsTest < ApplicationSystemTestCase + setup do + @crop = crops(:one) + end + + test "visiting the index" do + visit crops_url + assert_selector "h1", text: "Crops" + end + + test "should create crop" do + visit crops_url + click_on "New crop" + + fill_in "B", with: @crop.b + fill_in "Ca", with: @crop.ca + fill_in "Cl", with: @crop.cl + fill_in "Crop type", with: @crop.crop_type + fill_in "Cu", with: @crop.cu + fill_in "Fe", with: @crop.fe + fill_in "K", with: @crop.k + fill_in "Mg", with: @crop.mg + fill_in "Mn", with: @crop.mn + fill_in "Mo", with: @crop.mo + fill_in "Na", with: @crop.na + fill_in "Name", with: @crop.name + fill_in "Nnh4", with: @crop.nnh4 + fill_in "Nno3", with: @crop.nno3 + fill_in "P", with: @crop.p + fill_in "S", with: @crop.s + fill_in "Si", with: @crop.si + fill_in "Zn", with: @crop.zn + click_on "Create Crop" + + assert_text "Crop was successfully created" + click_on "Back" + end + + test "should update Crop" do + visit crop_url(@crop) + click_on "Edit this crop", match: :first + + fill_in "B", with: @crop.b + fill_in "Ca", with: @crop.ca + fill_in "Cl", with: @crop.cl + fill_in "Crop type", with: @crop.crop_type + fill_in "Cu", with: @crop.cu + fill_in "Fe", with: @crop.fe + fill_in "K", with: @crop.k + fill_in "Mg", with: @crop.mg + fill_in "Mn", with: @crop.mn + fill_in "Mo", with: @crop.mo + fill_in "Na", with: @crop.na + fill_in "Name", with: @crop.name + fill_in "Nnh4", with: @crop.nnh4 + fill_in "Nno3", with: @crop.nno3 + fill_in "P", with: @crop.p + fill_in "S", with: @crop.s + fill_in "Si", with: @crop.si + fill_in "Zn", with: @crop.zn + click_on "Update Crop" + + assert_text "Crop was successfully updated" + click_on "Back" + end + + test "should destroy Crop" do + visit crop_url(@crop) + click_on "Destroy this crop", match: :first + + assert_text "Crop was successfully destroyed" + end +end diff --git a/test/system/fertilizer_products_test.rb b/test/system/fertilizer_products_test.rb new file mode 100644 index 0000000..be82ed5 --- /dev/null +++ b/test/system/fertilizer_products_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class FertilizerProductsTest < ApplicationSystemTestCase + setup do + @fertilizer_product = fertilizer_products(:one) + end + + test "visiting the index" do + visit fertilizer_products_url + assert_selector "h1", text: "Fertilizer products" + end + + test "should create fertilizer product" do + visit fertilizer_products_url + click_on "New fertilizer product" + + fill_in "Name", with: @fertilizer_product.name + fill_in "Purity", with: @fertilizer_product.purity + click_on "Create Fertilizer product" + + assert_text "Fertilizer product was successfully created" + click_on "Back" + end + + test "should update Fertilizer product" do + visit fertilizer_product_url(@fertilizer_product) + click_on "Edit this fertilizer product", match: :first + + fill_in "Name", with: @fertilizer_product.name + fill_in "Purity", with: @fertilizer_product.purity + click_on "Update Fertilizer product" + + assert_text "Fertilizer product was successfully updated" + click_on "Back" + end + + test "should destroy Fertilizer product" do + visit fertilizer_product_url(@fertilizer_product) + click_on "Destroy this fertilizer product", match: :first + + assert_text "Fertilizer product was successfully destroyed" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..0c22470 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require_relative "../config/environment" +require "rails/test_help" + +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... + end +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tmp/.keep diff --git a/tmp/pids/.keep b/tmp/pids/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tmp/pids/.keep diff --git a/tmp/storage/.keep b/tmp/storage/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tmp/storage/.keep diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 0000000..1bc4299 --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1,3 @@ +/bundle/* +!/bundle/ +!/bundle/.keep
\ No newline at end of file diff --git a/vendor/bundle/.keep b/vendor/bundle/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/bundle/.keep diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/javascript/.keep |