Skip to content

Commit

Permalink
Add RequiredReports scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
zgary committed Nov 1, 2019
1 parent 4801ccf commit 2719f13
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 1 deletion.
74 changes: 74 additions & 0 deletions app/controllers/required_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class RequiredReportsController < ApplicationController
before_action :set_required_report, only: [:show, :edit, :update, :destroy]

# GET /required_reports
# GET /required_reports.json
def index
@required_reports = RequiredReport.all
end

# GET /required_reports/1
# GET /required_reports/1.json
def show
end

# GET /required_reports/new
def new
@required_report = RequiredReport.new
end

# GET /required_reports/1/edit
def edit
end

# POST /required_reports
# POST /required_reports.json
def create
@required_report = RequiredReport.new(required_report_params)

respond_to do |format|
if @required_report.save
format.html { redirect_to @required_report, notice: 'Required report was successfully created.' }
format.json { render :show, status: :created, location: @required_report }
else
format.html { render :new }
format.json { render json: @required_report.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /required_reports/1
# PATCH/PUT /required_reports/1.json
def update
respond_to do |format|
if @required_report.update(required_report_params)
format.html { redirect_to @required_report, notice: 'Required report was successfully updated.' }
format.json { render :show, status: :ok, location: @required_report }
else
format.html { render :edit }
format.json { render json: @required_report.errors, status: :unprocessable_entity }
end
end
end

# DELETE /required_reports/1
# DELETE /required_reports/1.json
def destroy
@required_report.destroy
respond_to do |format|
format.html { redirect_to required_reports_url, notice: 'Required report was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_required_report
@required_report = RequiredReport.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def required_report_params
params.require(:required_report).permit(:agency, :name, :description, :local_law, :charter_and_code, :frequency, :frequency_integer, :other_frequency_description, :start_date, :end_date, :last_published_date)
end
end
2 changes: 2 additions & 0 deletions app/helpers/required_reports_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module RequiredReportsHelper
end
2 changes: 2 additions & 0 deletions app/models/required_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class RequiredReport < ApplicationRecord
end
89 changes: 89 additions & 0 deletions app/views/required_reports/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<%= simple_form_for @required_report do |f| %>
<% if required_report.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(required_report.errors.count, "error") %> prohibited this required_report from being saved:</h2>

<ul>
<% required_report.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<%= f.input :name,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :agency,
as: :select,
collection: AgenciesService.select_all_options,
include_blank: true,
input_html: { class: 'form-control' }
%>

<%= f.input :description,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :local_law,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :charter_and_code,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :frequency,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :frequency_integer,
as: :integer,
input_html: { class: 'form-control' }
%>

<%= f.input :other_frequency_description,
as: :string,
input_html: { class: 'form-control' }
%>

<%= f.input :start_date,
as: :string,
input_html: { class: 'form-control', multiple: false, placeholder: 'YYYY-MM-DD' }
%>

<%= f.input :end_date,
as: :string,
input_html: { class: 'form-control', multiple: false, placeholder: 'YYYY-MM-DD' }
%>

<div class="actions">
<%= f.button :submit %>
</div>

<script>
$('#required_report_start_date').inputmask(
{
alias: 'datetime',
inputFormat: 'yyyy-mm-dd',
placeholder: '_',
showMaskOnHover: false,
min: '01/01/1600'
});

$('#required_report_end_date').inputmask(
{
alias: 'datetime',
inputFormat: 'yyyy-mm-dd',
placeholder: '_',
showMaskOnHover: false,
min: '01/01/1600'
});
</script>
<% end %>
2 changes: 2 additions & 0 deletions app/views/required_reports/_required_report.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! required_report, :id, :agency, :name, :description, :local_law, :charter_and_code, :frequency, :frequency_integer, :other_frequency_description, :start_date, :end_date, :last_published_date, :created_at, :updated_at
json.url required_report_url(required_report, format: :json)
6 changes: 6 additions & 0 deletions app/views/required_reports/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Required Report</h1>

<%= render 'form', required_report: @required_report %>

<%= link_to 'Show', @required_report %> |
<%= link_to 'Back', required_reports_path %>
47 changes: 47 additions & 0 deletions app/views/required_reports/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<p id="notice"><%= notice %></p>

<h1>Required Reports</h1>

<table>
<thead>
<tr>
<th>Agency</th>
<th>Name</th>
<th>Description</th>
<th>Local law</th>
<th>Charter and code</th>
<th>Frequency</th>
<th>Frequency integer</th>
<th>Other frequency description</th>
<th>Start date</th>
<th>End date</th>
<th>Last published date</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @required_reports.each do |required_report| %>
<tr>
<td><%= required_report.agency %></td>
<td><%= required_report.name %></td>
<td><%= required_report.description %></td>
<td><%= required_report.local_law %></td>
<td><%= required_report.charter_and_code %></td>
<td><%= required_report.frequency %></td>
<td><%= required_report.frequency_integer %></td>
<td><%= required_report.other_frequency_description %></td>
<td><%= required_report.start_date %></td>
<td><%= required_report.end_date %></td>
<td><%= required_report.last_published_date %></td>
<td><%= link_to 'Show', required_report %></td>
<td><%= link_to 'Edit', edit_required_report_path(required_report) %></td>
<td><%= link_to 'Destroy', required_report, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Required Report', new_required_report_path %>
1 change: 1 addition & 0 deletions app/views/required_reports/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @required_reports, partial: 'required_reports/required_report', as: :required_report
5 changes: 5 additions & 0 deletions app/views/required_reports/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Required Report</h1>

<%= render 'form', required_report: @required_report %>

<%= link_to 'Back', required_reports_path %>
59 changes: 59 additions & 0 deletions app/views/required_reports/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Agency:</strong>
<%= @required_report.agency %>
</p>

<p>
<strong>Name:</strong>
<%= @required_report.name %>
</p>

<p>
<strong>Description:</strong>
<%= @required_report.description %>
</p>

<p>
<strong>Local law:</strong>
<%= @required_report.local_law %>
</p>

<p>
<strong>Charter and code:</strong>
<%= @required_report.charter_and_code %>
</p>

<p>
<strong>Frequency:</strong>
<%= @required_report.frequency %>
</p>

<p>
<strong>Frequency integer:</strong>
<%= @required_report.frequency_integer %>
</p>

<p>
<strong>Other frequency description:</strong>
<%= @required_report.other_frequency_description %>
</p>

<p>
<strong>Start date:</strong>
<%= @required_report.start_date %>
</p>

<p>
<strong>End date:</strong>
<%= @required_report.end_date %>
</p>

<p>
<strong>Last published date:</strong>
<%= @required_report.last_published_date %>
</p>

<%= link_to 'Edit', edit_required_report_path(@required_report) %> |
<%= link_to 'Back', required_reports_path %>
1 change: 1 addition & 0 deletions app/views/required_reports/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "required_reports/required_report", required_report: @required_report
1 change: 1 addition & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ en:
associated_place: The place associated with this publication. Required if applicable.
required_report:
title: ''
description: ''
defaults:
based_near: A place name related to the work, such as its site of publication, or the city, state, or country the work contents are about. Calls upon the <a href='http://www.geonames.org'>GeoNames web service</a>.
contributor: A person or group you want to recognize for playing a role in the creation of the work, but not the primary role.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
end
end

resources :required_reports

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
19 changes: 19 additions & 0 deletions db/migrate/20191031204401_create_required_reports.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateRequiredReports < ActiveRecord::Migration[5.1]
def change
create_table :required_reports do |t|
t.string :agency, null: false
t.string :name, null: false
t.string :description
t.string :local_law
t.string :charter_and_code
t.string :frequency
t.integer :frequency_integer
t.string :other_frequency_description
t.date :start_date, null: false
t.date :end_date
t.date :last_published_date

t.timestamps
end
end
end
18 changes: 17 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190404170226) do
ActiveRecord::Schema.define(version: 20191031204401) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -286,6 +286,22 @@
t.index ["uri"], name: "index_qa_local_authority_entries_on_uri", unique: true
end

create_table "required_reports", force: :cascade do |t|
t.string "agency", null: false
t.string "name", null: false
t.string "description"
t.string "local_law"
t.string "charter_and_code"
t.string "frequency"
t.integer "frequency_integer"
t.string "other_frequency_description"
t.date "start_date", null: false
t.date "end_date"
t.date "last_published_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "roles", id: :serial, force: :cascade do |t|
t.string "name"
end
Expand Down
Loading

0 comments on commit 2719f13

Please sign in to comment.