aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-11-11 16:33:24 +0000
committerMatthew Lemon <y@yulqen.org>2024-11-11 16:33:24 +0000
commitb8d7a7cf7e78fe384c6c6e8e6812a252084ce1f0 (patch)
tree5ef297ac23775afb1bcffb68265749d08f282297 /app
parent97201e0bca203b6b303789374ffd7e4228e062a7 (diff)
Adds first pdfresource model
Diffstat (limited to 'app')
-rw-r--r--app/controllers/pdfresources_controller.rb70
-rw-r--r--app/helpers/pdfresources_helper.rb2
-rw-r--r--app/models/pdfresource.rb4
-rw-r--r--app/views/pdfresources/_form.html.erb67
-rw-r--r--app/views/pdfresources/_pdfresource.html.erb56
-rw-r--r--app/views/pdfresources/_pdfresource.json.jbuilder14
-rw-r--r--app/views/pdfresources/edit.html.erb8
-rw-r--r--app/views/pdfresources/index.html.erb21
-rw-r--r--app/views/pdfresources/index.json.jbuilder1
-rw-r--r--app/views/pdfresources/new.html.erb7
-rw-r--r--app/views/pdfresources/show.html.erb15
-rw-r--r--app/views/pdfresources/show.json.jbuilder1
12 files changed, 266 insertions, 0 deletions
diff --git a/app/controllers/pdfresources_controller.rb b/app/controllers/pdfresources_controller.rb
new file mode 100644
index 0000000..068b61a
--- /dev/null
+++ b/app/controllers/pdfresources_controller.rb
@@ -0,0 +1,70 @@
+class PdfresourcesController < ApplicationController
+ before_action :set_pdfresource, only: %i[ show edit update destroy ]
+
+ # GET /pdfresources or /pdfresources.json
+ def index
+ @pdfresources = Pdfresource.all
+ end
+
+ # GET /pdfresources/1 or /pdfresources/1.json
+ def show
+ end
+
+ # GET /pdfresources/new
+ def new
+ @pdfresource = Pdfresource.new
+ end
+
+ # GET /pdfresources/1/edit
+ def edit
+ end
+
+ # POST /pdfresources or /pdfresources.json
+ def create
+ @pdfresource = Pdfresource.new(pdfresource_params)
+
+ respond_to do |format|
+ if @pdfresource.save
+ format.html { redirect_to @pdfresource, notice: "Pdfresource was successfully created." }
+ format.json { render :show, status: :created, location: @pdfresource }
+ else
+ format.html { render :new, status: :unprocessable_entity }
+ format.json { render json: @pdfresource.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /pdfresources/1 or /pdfresources/1.json
+ def update
+ respond_to do |format|
+ if @pdfresource.update(pdfresource_params)
+ format.html { redirect_to @pdfresource, notice: "Pdfresource was successfully updated." }
+ format.json { render :show, status: :ok, location: @pdfresource }
+ else
+ format.html { render :edit, status: :unprocessable_entity }
+ format.json { render json: @pdfresource.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /pdfresources/1 or /pdfresources/1.json
+ def destroy
+ @pdfresource.destroy!
+
+ respond_to do |format|
+ format.html { redirect_to pdfresources_path, status: :see_other, notice: "Pdfresource was successfully destroyed." }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_pdfresource
+ @pdfresource = Pdfresource.find(params.expect(:id))
+ end
+
+ # Only allow a list of trusted parameters through.
+ def pdfresource_params
+ params.expect(pdfresource: [ :name, :stripe_product_id, :price, :age_range, :curriculum, :feature_slot, :description, :card_description, pdfs: [], thumbnails: [] ])
+ end
+end
diff --git a/app/helpers/pdfresources_helper.rb b/app/helpers/pdfresources_helper.rb
new file mode 100644
index 0000000..1f400cc
--- /dev/null
+++ b/app/helpers/pdfresources_helper.rb
@@ -0,0 +1,2 @@
+module PdfresourcesHelper
+end
diff --git a/app/models/pdfresource.rb b/app/models/pdfresource.rb
new file mode 100644
index 0000000..6131034
--- /dev/null
+++ b/app/models/pdfresource.rb
@@ -0,0 +1,4 @@
+class Pdfresource < ApplicationRecord
+ has_many_attached :pdfs
+ has_many_attached :thumbnails
+end
diff --git a/app/views/pdfresources/_form.html.erb b/app/views/pdfresources/_form.html.erb
new file mode 100644
index 0000000..a75121a
--- /dev/null
+++ b/app/views/pdfresources/_form.html.erb
@@ -0,0 +1,67 @@
+<%= form_with(model: pdfresource, class: "contents") do |form| %>
+ <% if pdfresource.errors.any? %>
+ <div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
+ <h2><%= pluralize(pdfresource.errors.count, "error") %> prohibited this pdfresource from being saved:</h2>
+
+ <ul>
+ <% pdfresource.errors.each do |error| %>
+ <li><%= error.full_message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="my-5">
+ <%= form.label :name %>
+ <%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :stripe_product_id %>
+ <%= form.text_field :stripe_product_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :pdfs %>
+ <%= form.file_field :pdfs, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :thumbnails %>
+ <%= form.file_field :thumbnails, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :price %>
+ <%= form.text_field :price, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :age_range %>
+ <%= form.text_field :age_range, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :curriculum %>
+ <%= form.text_field :curriculum, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :feature_slot %>
+ <%= form.number_field :feature_slot, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :description %>
+ <%= form.textarea :description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="my-5">
+ <%= form.label :card_description %>
+ <%= form.textarea :card_description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ </div>
+
+ <div class="inline">
+ <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
+ </div>
+<% end %>
diff --git a/app/views/pdfresources/_pdfresource.html.erb b/app/views/pdfresources/_pdfresource.html.erb
new file mode 100644
index 0000000..d947dd1
--- /dev/null
+++ b/app/views/pdfresources/_pdfresource.html.erb
@@ -0,0 +1,56 @@
+<div id="<%= dom_id pdfresource %>">
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Name:</strong>
+ <%= pdfresource.name %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Stripe product:</strong>
+ <%= pdfresource.stripe_product_id %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Pdfs:</strong>
+ <% pdfresource.pdfs.each do |pdf| %>
+ <div><%= link_to pdf.filename, pdf %></div>
+ <% end %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Thumbnails:</strong>
+ <% pdfresource.thumbnails.each do |thumbnail| %>
+ <div><%= link_to thumbnail.filename, thumbnail %></div>
+ <% end %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Price:</strong>
+ <%= pdfresource.price %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Age range:</strong>
+ <%= pdfresource.age_range %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Curriculum:</strong>
+ <%= pdfresource.curriculum %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Feature slot:</strong>
+ <%= pdfresource.feature_slot %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Description:</strong>
+ <%= pdfresource.description %>
+ </p>
+
+ <p class="my-5">
+ <strong class="block font-medium mb-1">Card description:</strong>
+ <%= pdfresource.card_description %>
+ </p>
+
+</div>
diff --git a/app/views/pdfresources/_pdfresource.json.jbuilder b/app/views/pdfresources/_pdfresource.json.jbuilder
new file mode 100644
index 0000000..6bb63a6
--- /dev/null
+++ b/app/views/pdfresources/_pdfresource.json.jbuilder
@@ -0,0 +1,14 @@
+json.extract! pdfresource, :id, :name, :stripe_product_id, :pdfs, :thumbnails, :price, :age_range, :curriculum, :feature_slot, :description, :card_description, :created_at, :updated_at
+json.url pdfresource_url(pdfresource, format: :json)
+json.pdfs do
+ json.array!(pdfresource.pdfs) do |pdf|
+ json.id pdf.id
+ json.url url_for(pdf)
+ end
+end
+json.thumbnails do
+ json.array!(pdfresource.thumbnails) do |thumbnail|
+ json.id thumbnail.id
+ json.url url_for(thumbnail)
+ end
+end
diff --git a/app/views/pdfresources/edit.html.erb b/app/views/pdfresources/edit.html.erb
new file mode 100644
index 0000000..6738cf1
--- /dev/null
+++ b/app/views/pdfresources/edit.html.erb
@@ -0,0 +1,8 @@
+<div class="mx-auto md:w-2/3 w-full">
+ <h1 class="font-bold text-4xl">Editing pdfresource</h1>
+
+ <%= render "form", pdfresource: @pdfresource %>
+
+ <%= link_to "Show this pdfresource", @pdfresource, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+ <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+</div>
diff --git a/app/views/pdfresources/index.html.erb b/app/views/pdfresources/index.html.erb
new file mode 100644
index 0000000..ff29982
--- /dev/null
+++ b/app/views/pdfresources/index.html.erb
@@ -0,0 +1,21 @@
+<div class="w-full">
+ <% if notice.present? %>
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
+ <% end %>
+
+ <% content_for :title, "Pdfresources" %>
+
+ <div class="flex justify-between items-center">
+ <h1 class="font-bold text-4xl">Pdfresources</h1>
+ <%= link_to "New pdfresource", new_pdfresource_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
+ </div>
+
+ <div id="pdfresources" class="min-w-full">
+ <% @pdfresources.each do |pdfresource| %>
+ <%= render pdfresource %>
+ <p>
+ <%= link_to "Show this pdfresource", pdfresource, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+ </p>
+ <% end %>
+ </div>
+</div>
diff --git a/app/views/pdfresources/index.json.jbuilder b/app/views/pdfresources/index.json.jbuilder
new file mode 100644
index 0000000..945d359
--- /dev/null
+++ b/app/views/pdfresources/index.json.jbuilder
@@ -0,0 +1 @@
+json.array! @pdfresources, partial: "pdfresources/pdfresource", as: :pdfresource
diff --git a/app/views/pdfresources/new.html.erb b/app/views/pdfresources/new.html.erb
new file mode 100644
index 0000000..5bd072b
--- /dev/null
+++ b/app/views/pdfresources/new.html.erb
@@ -0,0 +1,7 @@
+<div class="mx-auto md:w-2/3 w-full">
+ <h1 class="font-bold text-4xl">New pdfresource</h1>
+
+ <%= render "form", pdfresource: @pdfresource %>
+
+ <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+</div>
diff --git a/app/views/pdfresources/show.html.erb b/app/views/pdfresources/show.html.erb
new file mode 100644
index 0000000..3c4fe66
--- /dev/null
+++ b/app/views/pdfresources/show.html.erb
@@ -0,0 +1,15 @@
+<div class="mx-auto md:w-2/3 w-full flex">
+ <div class="mx-auto">
+ <% if notice.present? %>
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
+ <% end %>
+
+ <%= render @pdfresource %>
+
+ <%= link_to "Edit this pdfresource", edit_pdfresource_path(@pdfresource), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+ <%= link_to "Back to pdfresources", pdfresources_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
+ <div class="inline-block ml-2">
+ <%= button_to "Destroy this pdfresource", @pdfresource, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
+ </div>
+ </div>
+</div>
diff --git a/app/views/pdfresources/show.json.jbuilder b/app/views/pdfresources/show.json.jbuilder
new file mode 100644
index 0000000..492dde3
--- /dev/null
+++ b/app/views/pdfresources/show.json.jbuilder
@@ -0,0 +1 @@
+json.partial! "pdfresources/pdfresource", pdfresource: @pdfresource