From fea9476a591559bd8fdcf17b64e5114c592a5b08 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 11 Nov 2024 16:55:14 +0100 Subject: C'est l'heure d'assurer le suivi de quelques flacons! --- app/assets/config/manifest.js | 2 ++ app/assets/images/.keep | 0 app/assets/stylesheets/application.css | 15 +++++++++ app/channels/application_cable/channel.rb | 4 +++ app/channels/application_cable/connection.rb | 4 +++ app/controllers/application_controller.rb | 4 +++ app/controllers/concerns/.keep | 0 app/controllers/wines_controller.rb | 49 ++++++++++++++++++++++++++++ app/helpers/application_helper.rb | 2 ++ app/helpers/wines_helper.rb | 2 ++ app/jobs/application_job.rb | 7 ++++ app/mailers/application_mailer.rb | 4 +++ app/models/application_record.rb | 3 ++ app/models/concerns/.keep | 0 app/models/wine.rb | 4 +++ app/views/layouts/application.html.erb | 22 +++++++++++++ app/views/layouts/mailer.html.erb | 13 ++++++++ app/views/layouts/mailer.text.erb | 1 + app/views/pwa/manifest.json.erb | 22 +++++++++++++ app/views/pwa/service-worker.js | 26 +++++++++++++++ app/views/wines/_form.html.erb | 33 +++++++++++++++++++ app/views/wines/edit.html.erb | 5 +++ app/views/wines/index.html.erb | 16 +++++++++ app/views/wines/new.html.erb | 5 +++ app/views/wines/show.html.erb | 17 ++++++++++ 25 files changed, 260 insertions(+) create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/wines_controller.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/wines_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/wine.rb create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100644 app/views/pwa/manifest.json.erb create mode 100644 app/views/pwa/service-worker.js create mode 100644 app/views/wines/_form.html.erb create mode 100644 app/views/wines/edit.html.erb create mode 100644 app/views/wines/index.html.erb create mode 100644 app/views/wines/new.html.erb create mode 100644 app/views/wines/show.html.erb (limited to 'app') diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..5918193 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..288b9ab --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end 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 diff --git a/app/controllers/wines_controller.rb b/app/controllers/wines_controller.rb new file mode 100644 index 0000000..9129dee --- /dev/null +++ b/app/controllers/wines_controller.rb @@ -0,0 +1,49 @@ +class WinesController < ApplicationController + def index + @wines = Wine.all + end + + def show + @wine = Wine.find(params[:id]) + end + + def new + @wine = Wine.new + end + + def create + @wine = Wine.new(wine_params) + + if @wine.save + redirect_to @wine + else + render :new, status: :unprocessable_entity + end + end + + def edit + @wine = Wine.find(params[:id]) + end + + def update + @wine = Wine.find(params[:id]) + + if @wine.update(wine_params) + redirect_to @wine + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @wine = Wine.find(params[:id]) + @wine.destroy + + redirect_to root_path, status: :see_other + end + + private + def wine_params + params.require(:wine).permit(:name, :year, :variety, :notes) + 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/wines_helper.rb b/app/helpers/wines_helper.rb new file mode 100644 index 0000000..bb7bcfc --- /dev/null +++ b/app/helpers/wines_helper.rb @@ -0,0 +1,2 @@ +module WinesHelper +end 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/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/wine.rb b/app/models/wine.rb new file mode 100644 index 0000000..a47022e --- /dev/null +++ b/app/models/wine.rb @@ -0,0 +1,4 @@ +class Wine < ApplicationRecord + validates :name, presence: true + validates :year, presence: true +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..ef26703 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,22 @@ + + + + <%= content_for(:title) || "Flacon" %> + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + + + + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + + + + <%= yield %> + + 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 @@ + + + + + + + + + <%= yield %> + + 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/pwa/manifest.json.erb b/app/views/pwa/manifest.json.erb new file mode 100644 index 0000000..7a1a68b --- /dev/null +++ b/app/views/pwa/manifest.json.erb @@ -0,0 +1,22 @@ +{ + "name": "Flacon", + "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": "Flacon.", + "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/wines/_form.html.erb b/app/views/wines/_form.html.erb new file mode 100644 index 0000000..fe676b2 --- /dev/null +++ b/app/views/wines/_form.html.erb @@ -0,0 +1,33 @@ + + +<%= form_with model: wine do |form| %> +
+ <%= form.label :name %>
+ <%= form.text_field :name %> + <% wine.errors.full_messages_for(:name).each do |message| %> +
<%= message %>
+ <% end %> +
+ +
+ <%= form.label :year %>
+ <%= form.text_field :year %> + <% wine.errors.full_messages_for(:year).each do |message| %> +
<%= message %>
+ <% end %> +
+ +
+ <%= form.label :variety %>
+ <%= form.text_field :variety %> +
+ +
+ <%= form.label :notes %>
+ <%= form.text_field :notes %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/wines/edit.html.erb b/app/views/wines/edit.html.erb new file mode 100644 index 0000000..a97c707 --- /dev/null +++ b/app/views/wines/edit.html.erb @@ -0,0 +1,5 @@ + + +

Edit Wine

+ +<%= render "form", wine: @wine %> diff --git a/app/views/wines/index.html.erb b/app/views/wines/index.html.erb new file mode 100644 index 0000000..0202ada --- /dev/null +++ b/app/views/wines/index.html.erb @@ -0,0 +1,16 @@ + + +

Wines#index

+

List of wines

+ +<%= link_to "Add Wine", new_wine_path %> + + diff --git a/app/views/wines/new.html.erb b/app/views/wines/new.html.erb new file mode 100644 index 0000000..eeb6fd6 --- /dev/null +++ b/app/views/wines/new.html.erb @@ -0,0 +1,5 @@ + + +

Add Wine

+ +<%= render "form", wine: @wine %> diff --git a/app/views/wines/show.html.erb b/app/views/wines/show.html.erb new file mode 100644 index 0000000..cd8925d --- /dev/null +++ b/app/views/wines/show.html.erb @@ -0,0 +1,17 @@ + + +
  • <%= link_to "Back to homepage", root_path %>
  • + +

    <%= @wine.name %>

    +

    <%= @wine.year %>

    +

    <%= @wine.notes %>

    + + -- cgit v1.2.3