Created the Forms model. Added styling elements. Still need to include a list of already known forms to add to system. Also locked forms and admin tab behind admin access.

This commit is contained in:
Ben 2024-02-16 17:22:09 -06:00
parent e52a9da39c
commit d0149a50e2
15 changed files with 143 additions and 24 deletions

View File

@ -47,4 +47,8 @@ class FormsController < ApplicationController
def form_params
params.require(:form).permit(:name) # Adjust attributes as needed
end
def check_admin
redirect_to(root_path, alert: "Not authorized") unless current_user.admin?
end
end

View File

@ -3,4 +3,10 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
def admin?
self.admin
end
end

View File

@ -12,7 +12,7 @@
</div>
<div class="actions text-center">
<%= f.submit "Resend confirmation instructions", class: 'btn btn-primary' %>
<%= f.submit "Resend confirmation instructions", class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -21,7 +21,7 @@
</div>
<div class="actions text-center">
<%= f.submit "Change my password", class: 'btn btn-primary' %>
<%= f.submit "Change my password", class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -12,7 +12,7 @@
</div>
<div class="actions text-center">
<%= f.submit "Send me reset password instructions", class: 'btn btn-primary' %>
<%= f.submit "Send me reset password instructions", class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -34,7 +34,7 @@
</div>
<div class="actions text-center">
<%= f.submit "Update", class: 'btn btn-primary' %>
<%= f.submit "Update", class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -22,7 +22,7 @@
</div>
<div class="actions text-center">
<%= f.submit "Sign up", class: 'btn btn-primary' %>
<%= f.submit "Sign up", class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -0,0 +1,36 @@
<%= form_with(model: form, local: true, html: { class: 'needs-validation', novalidate: true }) do |f| %>
<% if form.errors.any? %>
<div id="error_explanation" class="alert alert-danger">
<h4><%= pluralize(form.errors.count, "error") %> prohibited this form from being saved:</h4>
<ul>
<% form.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="mb-3">
<%= f.label :name, 'Form Name', class: 'form-label' %>
<%= f.text_field :name, class: 'form-control', placeholder: 'Enter form name' %>
</div>
<div class="mb-3">
<%= f.label :required, 'Required', class: 'form-label' %>
<%= f.check_box :required, class: 'form-check-input' %>
</div>
<div class="mb-3">
<%= f.label :program, 'Program', class: 'form-label' %>
<%= f.text_field :program, class: 'form-control', placeholder: 'Enter program name' %>
</div>
<div class="mb-3">
<%= f.label :role, 'Who/Role', class: 'form-label' %>
<%= f.text_field :role, class: 'form-control', placeholder: 'Enter role' %>
</div>
<div class="actions">
<%= f.submit 'Save', class: 'btn btn-dark' %>
</div>
<% end %>

View File

@ -1,2 +1,2 @@
<h1>Forms#edit</h1>
<p>Find me in app/views/forms/edit.html.erb</p>
<h1>Edit Form</h1>
<%= render 'form', form: @form %>

View File

@ -1,2 +1,34 @@
<h1>Forms Index</h1>
<p>Placeholder for listing forms.</p>
<div class="container mt-5">
<h1 class="mb-4 text-center">Forms</h1>
<div class="text-center mt-3">
<%= link_to 'New Form', new_form_path, class: 'btn btn-dark mb-3' %>
</div>
<table class="table">
<thead>
<tr>
<th>Form Name</th>
<th>Required/Optional</th>
<th>Program</th>
<th>Who/Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @forms.each do |form| %>
<tr>
<td><%= form.name %></td>
<td><%= form.required ? 'Required' : 'Optional' %></td>
<td><%= form.program %></td>
<td><%= form.role %></td>
<td>
<%= link_to 'Edit', edit_form_path(form), class: 'btn btn-info btn-sm' %>
<%= link_to 'Delete', form, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@ -1,2 +1,13 @@
<h1>Forms#new</h1>
<p>Find me in app/views/forms/new.html.erb</p>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<h1 class="mb-4 text-center">New Form</h1>
<%= render 'form', form: @form %>
<div class="mt-3 text-center">
<%= link_to 'Back to List', forms_path, class: "btn btn-secondary" %>
</div>
</div>
</div>
</div>

View File

@ -1,2 +1,19 @@
<h1>Forms#show</h1>
<p>Find me in app/views/forms/show.html.erb</p>
<h1><%= @form.name %></h1>
<p>
<strong>Required/Optional:</strong>
<%= @form.required ? 'Required' : 'Optional' %>
</p>
<p>
<strong>Program:</strong>
<%= @form.program %>
</p>
<p>
<strong>Who/Role:</strong>
<%= @form.role %>
</p>
<%= link_to 'Edit', edit_form_path(@form), class: 'btn btn-info' %> |
<%= link_to 'Back to Forms', forms_path, class: 'btn btn-secondary' %>

View File

@ -21,15 +21,16 @@
</li>
<!-- Admin Dropdown Menu -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Admin
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><%= link_to 'Forms', forms_path, class: 'dropdown-item' %></li>
<li><%= link_to 'Users', users_path, class: 'dropdown-item' %></li>
</ul>
</li>
<% if user_signed_in? && current_user.admin? %>
<li class="nav-item dropdown">
<%= link_to 'Admin', '#', class: 'nav-link dropdown-toggle', id: 'adminDropdown', role: 'button', data: { bs_toggle: 'dropdown' }, aria: { haspopup: 'true', expanded: 'false' } %>
<ul class="dropdown-menu" aria-labelledby="adminDropdown">
<li><%= link_to 'Forms', forms_path, class: 'dropdown-item' %></li>
<li><%= link_to 'Users', users_path, class: 'dropdown-item' %></li>
</ul>
</li>
<% end %>
<!-- Authentication links -->
<% if user_signed_in? %>

View File

@ -0,0 +1,8 @@
class AddDetailsToForms < ActiveRecord::Migration[7.1]
def change
add_column :forms, :name, :string
add_column :forms, :required, :boolean
add_column :forms, :program, :string
add_column :forms, :role, :string
end
end

6
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_02_15_231142) do
ActiveRecord::Schema[7.1].define(version: 2024_02_16_230305) do
create_table "bank_accounts", force: :cascade do |t|
t.string "institution_name"
t.string "account_type"
@ -75,6 +75,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_15_231142) do
create_table "forms", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.boolean "required"
t.string "program"
t.string "role"
end
create_table "participants", force: :cascade do |t|