Latest updates

This commit is contained in:
2022-04-07 12:45:09 +01:00
parent 557b43c911
commit 21b42c69a5
25 changed files with 412 additions and 14 deletions

View File

@@ -94,7 +94,7 @@ header {
background: var(--accent-bg);
border-bottom: 1px solid var(--border);
text-align: center;
padding: 2rem 0.5rem;
padding: 0;
width: 100vw;
position: relative;
box-sizing: border-box;
@@ -119,14 +119,14 @@ main {
h1,
h2,
h3 {
line-height: 1.1;
line-height: 0.1;
}
/* Format navigation */
nav {
font-size: 1rem;
line-height: 2;
padding: 1rem 0;
padding:0;
}
nav a {
@@ -164,7 +164,7 @@ h1 {
var(--base-fontsize) * var(--header-scale) * var(--header-scale) *
var(--header-scale) * var(--header-scale)
);
margin-top: calc(var(--line-height) * 1.5rem);
margin-top: calc(var(--line-height) * 1.1rem);
}
h2 {
@@ -179,7 +179,7 @@ h3 {
font-size: calc(
var(--base-fontsize) * var(--header-scale) * var(--header-scale)
);
margin-top: calc(var(--line-height) * 1.5rem);
margin-top: calc(var(--line-height) * 1.1rem);
}
h4 {
@@ -525,3 +525,7 @@ pre code {
margin: 0;
padding: 0;
}
nav>form {
display:inline;
}

View File

@@ -0,0 +1,75 @@
class CafsController < ApplicationController
before_action :set_caf, only: %i[ show edit update destroy ]
before_action :set_company
# GET /cafs or /cafs.json
def index
@cafs = Caf.all
end
# GET /cafs/1 or /cafs/1.json
def show
end
# GET /cafs/new
def new
@caf = Caf.new
end
# GET /cafs/1/edit
def edit
end
# POST /cafs or /cafs.json
def create
@caf = Caf.new(caf_params)
respond_to do |format|
if @caf.save
format.html { redirect_to caf_url(@caf), notice: "Caf was successfully created." }
format.json { render :show, status: :created, location: @caf }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @caf.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cafs/1 or /cafs/1.json
def update
respond_to do |format|
if @caf.update(caf_params)
format.html { redirect_to caf_url(@caf), notice: "Caf was successfully updated." }
format.json { render :show, status: :ok, location: @caf }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @caf.errors, status: :unprocessable_entity }
end
end
end
# DELETE /cafs/1 or /cafs/1.json
def destroy
@caf.destroy
respond_to do |format|
format.html { redirect_to cafs_url, notice: "Caf was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_caf
@caf = Caf.find(params[:id])
end
def set_company
@company = Company.find(params[:company_id])
end
# Only allow a list of trusted parameters through.
def caf_params
params.require(:caf).permit(:company_id, :name, :description)
end
end

View File

@@ -0,0 +1,70 @@
class CompaniesController < ApplicationController
before_action :set_company, only: %i[ show edit update destroy ]
# GET /companies or /companies.json
def index
@companies = Company.all
end
# GET /companies/1 or /companies/1.json
def show
end
# GET /companies/new
def new
@company = Company.new
end
# GET /companies/1/edit
def edit
end
# POST /companies or /companies.json
def create
@company = Company.new(company_params)
respond_to do |format|
if @company.save
format.html { redirect_to company_url(@company), notice: "Company was successfully created." }
format.json { render :show, status: :created, location: @company }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @company.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /companies/1 or /companies/1.json
def update
respond_to do |format|
if @company.update(company_params)
format.html { redirect_to company_url(@company), notice: "Company was successfully updated." }
format.json { render :show, status: :ok, location: @company }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @company.errors, status: :unprocessable_entity }
end
end
end
# DELETE /companies/1 or /companies/1.json
def destroy
@company.destroy
respond_to do |format|
format.html { redirect_to companies_url, notice: "Company was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_company
@company = Company.find(params[:id])
end
# Only allow a list of trusted parameters through.
def company_params
params.require(:company).permit(:name)
end
end

View File

@@ -0,0 +1,2 @@
module CafsHelper
end

3
app/models/caf.rb Normal file
View File

@@ -0,0 +1,3 @@
class Caf < ApplicationRecord
belongs_to :company
end

View File

@@ -1,4 +1,5 @@
class Company < ApplicationRecord
has_many :cafs
has_and_belongs_to_many :users
validates :name, presence: true
validates :name, uniqueness: true

View File

@@ -0,0 +1,17 @@
<div id="<%= dom_id caf %>">
<p>
<strong>Company:</strong>
<%= caf.company_id %>
</p>
<p>
<strong>Name:</strong>
<%= caf.name %>
</p>
<p>
<strong>Description:</strong>
<%= caf.description %>
</p>
</div>

View File

@@ -0,0 +1,2 @@
json.extract! caf, :id, :company_id, :name, :description, :created_at, :updated_at
json.url caf_url(caf, format: :json)

View File

@@ -0,0 +1,30 @@
<%= form_for( [company, caf] ) do |form| %>
<% if caf.errors.any? %>
<div style="color: red">
<h2><%= pluralize(caf.errors.count, "error") %> prohibited this caf from being saved:</h2>
<ul>
<% caf.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form.hidden_field :company_id, value: company.id %>
<div>
<%= form.label :name, style: "display: block" %>
<%= form.text_field :name %>
</div>
<div>
<%= form.label :description, style: "display: block" %>
<%= form.text_area :description %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,10 @@
<h1>Editing caf</h1>
<%= render "form", caf: @caf %>
<br>
<div>
<%= link_to "Show this caf", @caf %> |
<%= link_to "Back to cafs", cafs_path %>
</div>

View File

@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>
<h1>Cafs</h1>
<div id="cafs">
<% @cafs.each do |caf| %>
<%= render caf %>
<p>
<%= link_to "Show this caf", caf %>
</p>
<% end %>
</div>
<%= link_to "New caf", new_company_caf_path(@company) %>

View File

@@ -0,0 +1 @@
json.array! @cafs, partial: "cafs/caf", as: :caf

View File

@@ -0,0 +1,9 @@
<h1>New caf</h1>
<%= render partial: "form", locals: { company: @company, caf: @caf } %>
<br>
<div>
<%= link_to "Back to cafs", company_cafs_path(@company) %>
</div>

View File

@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>
<%= render @caf %>
<div>
<%= link_to "Edit this caf", edit_caf_path(@caf) %> |
<%= link_to "Back to cafs", cafs_path %>
<%= button_to "Destroy this caf", @caf, method: :delete %>
</div>

View File

@@ -0,0 +1 @@
json.partial! "cafs/caf", caf: @caf

View File

@@ -1,5 +1,4 @@
<h1>CAF Compliance Tracking</h1>
<h2>By Hidden Agenda Ltd</h2>
<% if !user_signed_in? %>
Not Signed in.
@@ -7,11 +6,28 @@ Not Signed in.
<% else %>
<%#= current_user.roletxt %>
<% if current_user.admin? %>
<h2>Companies</h2>
<%= link_to "Add Company", new_company_path %>
<h3>Companies <small><%= link_to "Add Company", new_company_path %></small></h3>
<ul>
<% @companies.each do |company| %>
<li><%= company.name %> <%= link_to "Edit", edit_company_path(company) %>
<ul>
<% company.users.each do |user|%>
<li><%= user.email %></li>
<% end %>
<li>Add user</li>
</ul>
<ul>
<% company.cafs.each do |caf| %>
<li><%= caf.name %>
<% end %>
<li><%= link_to "Add CAF", new_company_caf_path(company) %></li>
</ul>
<% end %>
</ul>
<p>
<%= link_to "Add User" %>
</p>
<% end %>
<% if current_user.user? %>

View File

@@ -41,3 +41,4 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart
bind 'tcp://0.0.0.0:3000'

View File

@@ -1,9 +1,9 @@
Rails.application.routes.draw do
devise_for :users
#resources :companies
namespace :admin do
resources :companies
devise_for :users
resources :companies do
resources :cafs
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

View File

@@ -0,0 +1,11 @@
class CreateCafs < ActiveRecord::Migration[7.0]
def change
create_table :cafs do |t|
t.references :company, null: false, foreign_key: true
t.string :name
t.text :description
t.timestamps
end
end
end

12
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.define(version: 2022_02_08_164226) do
ActiveRecord::Schema.define(version: 2022_02_10_171858) do
create_table "action_text_rich_texts", charset: "latin1", force: :cascade do |t|
t.string "name", null: false
@@ -50,6 +50,15 @@ ActiveRecord::Schema.define(version: 2022_02_08_164226) do
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "cafs", charset: "latin1", force: :cascade do |t|
t.bigint "company_id", null: false
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["company_id"], name: "index_cafs_on_company_id"
end
create_table "companies", charset: "latin1", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
@@ -87,4 +96,5 @@ ActiveRecord::Schema.define(version: 2022_02_08_164226) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "cafs", "companies"
end

View File

@@ -0,0 +1,48 @@
require "test_helper"
class CafsControllerTest < ActionDispatch::IntegrationTest
setup do
@caf = cafs(:one)
end
test "should get index" do
get cafs_url
assert_response :success
end
test "should get new" do
get new_caf_url
assert_response :success
end
test "should create caf" do
assert_difference("Caf.count") do
post cafs_url, params: { caf: { company_id: @caf.company_id, description: @caf.description, name: @caf.name } }
end
assert_redirected_to caf_url(Caf.last)
end
test "should show caf" do
get caf_url(@caf)
assert_response :success
end
test "should get edit" do
get edit_caf_url(@caf)
assert_response :success
end
test "should update caf" do
patch caf_url(@caf), params: { caf: { company_id: @caf.company_id, description: @caf.description, name: @caf.name } }
assert_redirected_to caf_url(@caf)
end
test "should destroy caf" do
assert_difference("Caf.count", -1) do
delete caf_url(@caf)
end
assert_redirected_to cafs_url
end
end

11
test/fixtures/cafs.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
company: one
name: MyString
description: MyText
two:
company: two
name: MyString
description: MyText

Binary file not shown.

7
test/models/caf_test.rb Normal file
View File

@@ -0,0 +1,7 @@
require "test_helper"
class CafTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

45
test/system/cafs_test.rb Normal file
View File

@@ -0,0 +1,45 @@
require "application_system_test_case"
class CafsTest < ApplicationSystemTestCase
setup do
@caf = cafs(:one)
end
test "visiting the index" do
visit cafs_url
assert_selector "h1", text: "Cafs"
end
test "should create caf" do
visit cafs_url
click_on "New caf"
fill_in "Company", with: @caf.company_id
fill_in "Description", with: @caf.description
fill_in "Name", with: @caf.name
click_on "Create Caf"
assert_text "Caf was successfully created"
click_on "Back"
end
test "should update Caf" do
visit caf_url(@caf)
click_on "Edit this caf", match: :first
fill_in "Company", with: @caf.company_id
fill_in "Description", with: @caf.description
fill_in "Name", with: @caf.name
click_on "Update Caf"
assert_text "Caf was successfully updated"
click_on "Back"
end
test "should destroy Caf" do
visit caf_url(@caf)
click_on "Destroy this caf", match: :first
assert_text "Caf was successfully destroyed"
end
end