about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/config/manifest.js2
-rw-r--r--app/assets/images/.keep0
-rw-r--r--app/assets/stylesheets/application.css15
-rw-r--r--app/assets/stylesheets/machines.scss3
-rw-r--r--app/assets/stylesheets/players.scss3
-rw-r--r--app/channels/application_cable/channel.rb4
-rw-r--r--app/channels/application_cable/connection.rb4
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/concerns/.keep0
-rw-r--r--app/controllers/machines_controller.rb49
-rw-r--r--app/controllers/players_controller.rb50
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/machines_helper.rb2
-rw-r--r--app/helpers/players_helper.rb2
-rw-r--r--app/javascript/channels/consumer.js6
-rw-r--r--app/javascript/channels/index.js5
-rw-r--r--app/javascript/packs/application.js17
-rw-r--r--app/jobs/application_job.rb7
-rw-r--r--app/mailers/application_mailer.rb4
-rw-r--r--app/models/application_record.rb3
-rw-r--r--app/models/concerns/.keep0
-rw-r--r--app/models/machine.rb4
-rw-r--r--app/models/player.rb2
-rw-r--r--app/views/layouts/application.html.erb15
-rw-r--r--app/views/layouts/mailer.html.erb13
-rw-r--r--app/views/layouts/mailer.text.erb1
-rw-r--r--app/views/machines/_form.html.erb21
-rw-r--r--app/views/machines/edit.html.erb4
-rw-r--r--app/views/machines/index.html.erb13
-rw-r--r--app/views/machines/new.html.erb4
-rw-r--r--app/views/machines/show.html.erb11
-rw-r--r--app/views/players/_form.html.erb29
-rw-r--r--app/views/players/edit.html.erb4
-rw-r--r--app/views/players/index.html.erb12
-rw-r--r--app/views/players/new.html.erb4
-rw-r--r--app/views/players/show.html.erb12
36 files changed, 329 insertions, 0 deletions
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
--- /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..d05ea0f
--- /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 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/SCSS
+ * 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/assets/stylesheets/machines.scss b/app/assets/stylesheets/machines.scss
new file mode 100644
index 0000000..1cabf09
--- /dev/null
+++ b/app/assets/stylesheets/machines.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Machines controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: https://sass-lang.com/
diff --git a/app/assets/stylesheets/players.scss b/app/assets/stylesheets/players.scss
new file mode 100644
index 0000000..a74761d
--- /dev/null
+++ b/app/assets/stylesheets/players.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Players controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: https://sass-lang.com/
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..09705d1
--- /dev/null
+++ b/app/controllers/application_controller.rb
@@ -0,0 +1,2 @@
+class ApplicationController < ActionController::Base
+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/machines_controller.rb b/app/controllers/machines_controller.rb
new file mode 100644
index 0000000..24c90e7
--- /dev/null
+++ b/app/controllers/machines_controller.rb
@@ -0,0 +1,49 @@
+class MachinesController < ApplicationController
+  def index
+    @machines = Machine.order("name")
+  end
+
+  def show
+    @machine = Machine.find(params[:id])
+  end
+
+  def new
+    @machine = Machine.new
+  end
+
+  def create
+    @machine = Machine.new(machine_params)
+
+    if @machine.save
+      redirect_to @machine
+    else
+      render :new
+    end
+  end
+
+  def edit
+    @machine = Machine.find(params[:id])
+  end
+
+  def update
+    @machine = Machine.find(params[:id])
+
+    if @machine.update(machine_params)
+      redirect_to @machine
+    else
+      render :edit
+    end
+  end
+
+  def destroy
+    @machine = Machine.find(params[:id])
+    @machine.destroy
+
+    redirect_to root_path
+  end
+
+  private
+    def machine_params
+      params.require(:machine).permit(:name, :edition)
+    end
+end
diff --git a/app/controllers/players_controller.rb b/app/controllers/players_controller.rb
new file mode 100644
index 0000000..e129114
--- /dev/null
+++ b/app/controllers/players_controller.rb
@@ -0,0 +1,50 @@
+class PlayersController < ApplicationController
+  def index
+    @players = Player.order("name")
+  end
+
+  def show
+    @player = Player.find(params[:id])
+  end
+
+  def new
+    @player = Player.new
+  end
+
+  def create
+    @player = Player.new(player_params)
+
+    if @player.save
+      redirect_to @player
+    else
+      render :new
+    end
+  end
+
+  def edit
+    @player = Player.find(params[:id])
+  end
+
+  def update
+    @player = Player.find(params[:id])
+
+    if @player.update(player_params)
+      redirect_to @player
+    else
+      render :edit
+    end
+  end
+
+  def destroy
+    @player = Player.find(params[:id])
+    @player.destroy
+
+    redirect_to player_path
+  end
+
+  private
+    def player_params
+      params.require(:player).permit(:name, :paid, :strikes)
+    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/machines_helper.rb b/app/helpers/machines_helper.rb
new file mode 100644
index 0000000..4fc933e
--- /dev/null
+++ b/app/helpers/machines_helper.rb
@@ -0,0 +1,2 @@
+module MachinesHelper
+end
diff --git a/app/helpers/players_helper.rb b/app/helpers/players_helper.rb
new file mode 100644
index 0000000..e8f775c
--- /dev/null
+++ b/app/helpers/players_helper.rb
@@ -0,0 +1,2 @@
+module PlayersHelper
+end
diff --git a/app/javascript/channels/consumer.js b/app/javascript/channels/consumer.js
new file mode 100644
index 0000000..0eceb59
--- /dev/null
+++ b/app/javascript/channels/consumer.js
@@ -0,0 +1,6 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the `rails generate channel` command.
+
+import { createConsumer } from "@rails/actioncable"
+
+export default createConsumer()
diff --git a/app/javascript/channels/index.js b/app/javascript/channels/index.js
new file mode 100644
index 0000000..0cfcf74
--- /dev/null
+++ b/app/javascript/channels/index.js
@@ -0,0 +1,5 @@
+// Load all the channels within this directory and all subdirectories.
+// Channel files must be named *_channel.js.
+
+const channels = require.context('.', true, /_channel\.js$/)
+channels.keys().forEach(channels)
diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js
new file mode 100644
index 0000000..9cd55d4
--- /dev/null
+++ b/app/javascript/packs/application.js
@@ -0,0 +1,17 @@
+// This file is automatically compiled by Webpack, along with any other files
+// present in this directory. You're encouraged to place your actual application logic in
+// a relevant structure within app/javascript and only use these pack files to reference
+// that code so it'll be compiled.
+
+require("@rails/ujs").start()
+require("turbolinks").start()
+require("@rails/activestorage").start()
+require("channels")
+
+
+// Uncomment to copy all static images under ../images to the output folder and reference
+// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
+// or the `imagePath` JavaScript helper below.
+//
+// const images = require.context('../images', true)
+// const imagePath = (name) => images(name, true)
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..286b223
--- /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..10a4cba
--- /dev/null
+++ b/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+  self.abstract_class = 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/machine.rb b/app/models/machine.rb
new file mode 100644
index 0000000..5563abb
--- /dev/null
+++ b/app/models/machine.rb
@@ -0,0 +1,4 @@
+class Machine < ApplicationRecord
+  validates :name, presence: true
+  validates :edition, presence: true
+end
diff --git a/app/models/player.rb b/app/models/player.rb
new file mode 100644
index 0000000..1bc55b4
--- /dev/null
+++ b/app/models/player.rb
@@ -0,0 +1,2 @@
+class Player < ApplicationRecord
+end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
new file mode 100644
index 0000000..4b286d2
--- /dev/null
+++ b/app/views/layouts/application.html.erb
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Pinrails</title>
+    <%= csrf_meta_tags %>
+    <%= csp_meta_tag %>
+
+    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
+    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
+  </head>
+
+  <body>
+    <%= yield %>
+  </body>
+</html>
diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb
new file mode 100644
index 0000000..cbd34d2
--- /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/machines/_form.html.erb b/app/views/machines/_form.html.erb
new file mode 100644
index 0000000..6d7aff3
--- /dev/null
+++ b/app/views/machines/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_with model: @machine do |form| %>
+  <div>
+    <%= form.label :name %><br>
+    <%= form.text_field :name %>
+    <% @machine.errors.full_messages_for(:name).each do |message| %>
+      <div><%= message %></div>
+    <% end %>
+  </div>
+
+  <div>
+    <%= form.label :edition %><br>
+    <%= form.text_field :edition %>
+    <% @machine.errors.full_messages_for(:edition).each do |message| %>
+      <div><%= message %></div>
+    <% end %>
+  </div>
+
+  <div>
+    <%= form.submit %>
+  </div>
+<% end %>
diff --git a/app/views/machines/edit.html.erb b/app/views/machines/edit.html.erb
new file mode 100644
index 0000000..7fd30ce
--- /dev/null
+++ b/app/views/machines/edit.html.erb
@@ -0,0 +1,4 @@
+<h1>Edit Pinball Machine</h1>
+
+<%= render "form", machine: @machine %>
+
diff --git a/app/views/machines/index.html.erb b/app/views/machines/index.html.erb
new file mode 100644
index 0000000..21717b9
--- /dev/null
+++ b/app/views/machines/index.html.erb
@@ -0,0 +1,13 @@
+<h1>Pinball Machines</h1>
+
+<p><%= @machines.count %> available machines</p>
+<ul>
+  <% @machines.each do |machine| %>
+    <li>
+      <%= link_to machine.name, machine %>
+    </li>
+  <% end %>
+</ul>
+
+<%= link_to "Add Machine", new_machine_path %>
+
diff --git a/app/views/machines/new.html.erb b/app/views/machines/new.html.erb
new file mode 100644
index 0000000..3422e15
--- /dev/null
+++ b/app/views/machines/new.html.erb
@@ -0,0 +1,4 @@
+<h1>New Pinball Machine</h1>
+
+<%= render "form", machine: @machine %>
+
diff --git a/app/views/machines/show.html.erb b/app/views/machines/show.html.erb
new file mode 100644
index 0000000..9be144a
--- /dev/null
+++ b/app/views/machines/show.html.erb
@@ -0,0 +1,11 @@
+<h1><%= @machine.name %></h1>
+
+<p>Edition: <%= @machine.edition %></p>
+
+<ul>
+  <li><%= link_to "Edit Pinball Machine", edit_machine_path(@machine) %></li>
+  <li><%= link_to "Delete", machine_path(@machine),
+    method: :delete,
+    data: { confirm: "Are you sure?" } %></li>
+</ul>
+
diff --git a/app/views/players/_form.html.erb b/app/views/players/_form.html.erb
new file mode 100644
index 0000000..3250304
--- /dev/null
+++ b/app/views/players/_form.html.erb
@@ -0,0 +1,29 @@
+<%= form_with model: @player do |form| %>
+  <div>
+    <%= form.label :name %><br>
+    <%= form.text_field :name %>
+    <% @player.errors.full_messages_for(:name).each do |message| %>
+      <div><%= message %></div>
+    <% end %>
+  </div>
+
+  <div>
+    <%= form.label :paid %><br>
+    <%= form.check_box :paid %>
+    <% @player.errors.full_messages_for(:paid).each do |message| %>
+      <div><%= message %></div>
+    <% end %>
+  </div>
+
+  <div>
+    <%= form.label :strikes %><br>
+    <%= form.number_field :strikes %>
+    <% @player.errors.full_messages_for(:strikes).each do |message| %>
+      <div><%= message %></div>
+    <% end %>
+  </div>
+
+  <div>
+    <%= form.submit %>
+  </div>
+<% end %>
diff --git a/app/views/players/edit.html.erb b/app/views/players/edit.html.erb
new file mode 100644
index 0000000..4c30fc1
--- /dev/null
+++ b/app/views/players/edit.html.erb
@@ -0,0 +1,4 @@
+<h1>Edit Player</h1>
+
+<%= render "form", machine: @player %>
+
diff --git a/app/views/players/index.html.erb b/app/views/players/index.html.erb
new file mode 100644
index 0000000..cedaad3
--- /dev/null
+++ b/app/views/players/index.html.erb
@@ -0,0 +1,12 @@
+<h1>Pinball Players</h1>
+
+<ul>
+  <% @players.each do |player| %>
+    <li>
+      <%= link_to player.name, player %>
+    </li>
+  <% end %>
+</ul>
+
+<%= link_to "Add player", new_player_path %>
+
diff --git a/app/views/players/new.html.erb b/app/views/players/new.html.erb
new file mode 100644
index 0000000..22f2de2
--- /dev/null
+++ b/app/views/players/new.html.erb
@@ -0,0 +1,4 @@
+<h1>New Player</h1>
+
+<%= render "form", player: @player %>
+
diff --git a/app/views/players/show.html.erb b/app/views/players/show.html.erb
new file mode 100644
index 0000000..21cf73f
--- /dev/null
+++ b/app/views/players/show.html.erb
@@ -0,0 +1,12 @@
+<h1><%= @player.name %></h1>
+
+<p>Strikes: <%= @player.strikes %></p>
+<p>Paid: <%= @player.paid %></p>
+
+<ul>
+  <li><%= link_to "Edit Pinball player", edit_player_path(@player) %></li>
+  <li><%= link_to "Delete", player_path(@player),
+    method: :delete,
+    data: { confirm: "Are you sure?" } %></li>
+</ul>
+