Add & Display Flights
This commit is contained in:
3
app/assets/javascripts/flights.coffee
Normal file
3
app/assets/javascripts/flights.coffee
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||||
15
app/assets/stylesheets/application.scss
Normal file
15
app/assets/stylesheets/application.scss
Normal file
@@ -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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import "bootstrap";
|
||||||
3
app/assets/stylesheets/flights.scss
Normal file
3
app/assets/stylesheets/flights.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the Flights controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||||
29
app/controllers/flights_controller.rb
Normal file
29
app/controllers/flights_controller.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
class FlightsController < ApplicationController
|
||||||
|
|
||||||
|
# Display past flights
|
||||||
|
def index
|
||||||
|
@flights = Flight.all
|
||||||
|
end
|
||||||
|
|
||||||
|
# Display single flight
|
||||||
|
def show
|
||||||
|
@flight = Flight.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@flight = Flight.new
|
||||||
|
@aircraft = Aircraft.all
|
||||||
|
@flight.date = Date.current
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@flight = Flight.new(params)
|
||||||
|
|
||||||
|
if @flight.save
|
||||||
|
redirect_to @flight
|
||||||
|
else
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
2
app/helpers/flights_helper.rb
Normal file
2
app/helpers/flights_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module FlightsHelper
|
||||||
|
end
|
||||||
12
app/models/aircraft.rb
Normal file
12
app/models/aircraft.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Aircraft < ApplicationRecord
|
||||||
|
has_one :inspection
|
||||||
|
has_many :engine
|
||||||
|
has_many :flights
|
||||||
|
|
||||||
|
validates :reg, presence: true
|
||||||
|
validates :serial, presence: true
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
return reg
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/models/engine.rb
Normal file
3
app/models/engine.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Engine < ApplicationRecord
|
||||||
|
belongs_to :aircraft
|
||||||
|
end
|
||||||
12
app/models/flight.rb
Normal file
12
app/models/flight.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Flight < ApplicationRecord
|
||||||
|
belongs_to :aircraft
|
||||||
|
validates :to, presence: true
|
||||||
|
validates :from, presence: true
|
||||||
|
validates :tach, presence: true
|
||||||
|
validates :hobbs, presence: true
|
||||||
|
validates :date, presence: true
|
||||||
|
|
||||||
|
def title
|
||||||
|
return aircraft.reg << " - " << date.to_s << " - " << time.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/models/inspection.rb
Normal file
3
app/models/inspection.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Inspection < ApplicationRecord
|
||||||
|
belongs_to :aircraft
|
||||||
|
end
|
||||||
9
app/views/flights/index.html.erb
Normal file
9
app/views/flights/index.html.erb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<h1>Flights</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @flights.each do |flight| %>
|
||||||
|
<li>
|
||||||
|
<%= link_to flight.title, flight %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
47
app/views/flights/new.html.erb
Normal file
47
app/views/flights/new.html.erb
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<h1>New Flight</h1>
|
||||||
|
|
||||||
|
<%= form_with model: @flight do |form| %>
|
||||||
|
<div>
|
||||||
|
<%= form.label :aircraft %><br>
|
||||||
|
<%= form.select :aircraft, @aircraft %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :date %><br>
|
||||||
|
<%= form.date_field :date %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :from %><br>
|
||||||
|
<%= form.text_field :from %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :to %><br>
|
||||||
|
<%= form.text_field :to %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :tach %><br>
|
||||||
|
<%= form.number_field :tach %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :hobbs %><br>
|
||||||
|
<%= form.number_field :hobbs %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :fuel %><br>
|
||||||
|
<%= form.check_box :fuel %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :oil %><br>
|
||||||
|
<%= form.check_box :oil %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
10
app/views/flights/show.html.erb
Normal file
10
app/views/flights/show.html.erb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<h1><%= @flight.date %></h1>
|
||||||
|
|
||||||
|
<h3><%= @flight.aircraft.reg %></h3>
|
||||||
|
<p> <b>From:</b> <%= @flight.from %></p>
|
||||||
|
<p> <b>To:</b> <%= @flight.to %></p>
|
||||||
|
<p> <b>Tach:</b> <%= @flight.tach %></p>
|
||||||
|
<p> <b>Hobbs:</b> <%= @flight.hobbs %></p>
|
||||||
|
<p> <b>Fuel Added:</b> <%= @flight.fuel %></p>
|
||||||
|
<p> <b>Oil Added:</b> <%= @flight.oil %></p>
|
||||||
|
<p> <b>Total Flight Time:</b> <%= @flight.time %></p>
|
||||||
15
db/migrate/20220114003540_create_aircrafts.rb
Normal file
15
db/migrate/20220114003540_create_aircrafts.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateAircrafts < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :aircrafts do |t|
|
||||||
|
t.string :reg
|
||||||
|
t.string :serial
|
||||||
|
t.float :tach
|
||||||
|
t.float :hobbs
|
||||||
|
t.date :purchase_date
|
||||||
|
t.float :purchase_tach
|
||||||
|
t.float :purchase_hobbs
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
db/migrate/20220114003600_create_engines.rb
Normal file
15
db/migrate/20220114003600_create_engines.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateEngines < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :engines do |t|
|
||||||
|
t.references :aircraft, foreign_key: true
|
||||||
|
t.date :oil_date
|
||||||
|
t.float :oil_tach
|
||||||
|
t.date :major_date
|
||||||
|
t.float :major_tach
|
||||||
|
t.date :top_date
|
||||||
|
t.float :top_tach
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
db/migrate/20220114003618_create_inspections.rb
Normal file
15
db/migrate/20220114003618_create_inspections.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateInspections < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :inspections do |t|
|
||||||
|
t.references :aircraft, foreign_key: true
|
||||||
|
t.date :annual_date
|
||||||
|
t.float :annual_tach
|
||||||
|
t.float :annual_hobbs
|
||||||
|
t.date :pitot_static
|
||||||
|
t.date :vor
|
||||||
|
t.date :elt
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
17
db/migrate/20220114003844_create_flights.rb
Normal file
17
db/migrate/20220114003844_create_flights.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class CreateFlights < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :flights do |t|
|
||||||
|
t.references :aircraft, foreign_key: true
|
||||||
|
t.date :date
|
||||||
|
t.string :from
|
||||||
|
t.string :to
|
||||||
|
t.float :tach
|
||||||
|
t.float :hobbs
|
||||||
|
t.boolean :oil
|
||||||
|
t.boolean :fuel
|
||||||
|
t.float :time
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
68
db/schema.rb
Normal file
68
db/schema.rb
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# Note that this schema.rb definition is the authoritative source for your
|
||||||
|
# database schema. If you need to create the application database on another
|
||||||
|
# system, you should be using db:schema:load, not running all the migrations
|
||||||
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define(version: 2022_01_14_003844) do
|
||||||
|
|
||||||
|
create_table "aircrafts", force: :cascade do |t|
|
||||||
|
t.string "reg"
|
||||||
|
t.string "serial"
|
||||||
|
t.float "tach"
|
||||||
|
t.float "hobbs"
|
||||||
|
t.date "purchase_date"
|
||||||
|
t.float "purchase_tach"
|
||||||
|
t.float "purchase_hobbs"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "engines", force: :cascade do |t|
|
||||||
|
t.integer "aircraft_id"
|
||||||
|
t.date "oil_date"
|
||||||
|
t.float "oil_tach"
|
||||||
|
t.date "major_date"
|
||||||
|
t.float "major_tach"
|
||||||
|
t.date "top_date"
|
||||||
|
t.float "top_tach"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["aircraft_id"], name: "index_engines_on_aircraft_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "flights", force: :cascade do |t|
|
||||||
|
t.integer "aircraft_id"
|
||||||
|
t.date "date"
|
||||||
|
t.string "from"
|
||||||
|
t.string "to"
|
||||||
|
t.float "tach"
|
||||||
|
t.float "hobbs"
|
||||||
|
t.boolean "oil"
|
||||||
|
t.boolean "fuel"
|
||||||
|
t.float "time"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["aircraft_id"], name: "index_flights_on_aircraft_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "inspections", force: :cascade do |t|
|
||||||
|
t.integer "aircraft_id"
|
||||||
|
t.date "annual_date"
|
||||||
|
t.float "annual_tach"
|
||||||
|
t.float "annual_hobs"
|
||||||
|
t.date "pitot_static"
|
||||||
|
t.date "vor"
|
||||||
|
t.date "elt"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["aircraft_id"], name: "index_inspections_on_aircraft_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
9
test/controllers/flights_controller_test.rb
Normal file
9
test/controllers/flights_controller_test.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class FlightsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test "should get index" do
|
||||||
|
get flights_index_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
19
test/fixtures/aircrafts.yml
vendored
Normal file
19
test/fixtures/aircrafts.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
reg: MyString
|
||||||
|
serial: MyString
|
||||||
|
tach: 1.5
|
||||||
|
hobbs: 1.5
|
||||||
|
purchase_date: 2022-01-13
|
||||||
|
purchase_tach: 1.5
|
||||||
|
purchase_hobbs: 1.5
|
||||||
|
|
||||||
|
two:
|
||||||
|
reg: MyString
|
||||||
|
serial: MyString
|
||||||
|
tach: 1.5
|
||||||
|
hobbs: 1.5
|
||||||
|
purchase_date: 2022-01-13
|
||||||
|
purchase_tach: 1.5
|
||||||
|
purchase_hobbs: 1.5
|
||||||
19
test/fixtures/engines.yml
vendored
Normal file
19
test/fixtures/engines.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
aircraft: one
|
||||||
|
oil_date: 2022-01-13
|
||||||
|
oil_tach: 1.5
|
||||||
|
major_date: 2022-01-13
|
||||||
|
major_tach: 1.5
|
||||||
|
top_date: 2022-01-13
|
||||||
|
top_tach: 1.5
|
||||||
|
|
||||||
|
two:
|
||||||
|
aircraft: two
|
||||||
|
oil_date: 2022-01-13
|
||||||
|
oil_tach: 1.5
|
||||||
|
major_date: 2022-01-13
|
||||||
|
major_tach: 1.5
|
||||||
|
top_date: 2022-01-13
|
||||||
|
top_tach: 1.5
|
||||||
23
test/fixtures/flights.yml
vendored
Normal file
23
test/fixtures/flights.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
aircraft: one
|
||||||
|
date: 2022-01-13
|
||||||
|
from: MyString
|
||||||
|
to: MyString
|
||||||
|
tach: 1.5
|
||||||
|
hobbs: 1.5
|
||||||
|
oil: false
|
||||||
|
fuel: false
|
||||||
|
time: 1.5
|
||||||
|
|
||||||
|
two:
|
||||||
|
aircraft: two
|
||||||
|
date: 2022-01-13
|
||||||
|
from: MyString
|
||||||
|
to: MyString
|
||||||
|
tach: 1.5
|
||||||
|
hobbs: 1.5
|
||||||
|
oil: false
|
||||||
|
fuel: false
|
||||||
|
time: 1.5
|
||||||
19
test/fixtures/inspections.yml
vendored
Normal file
19
test/fixtures/inspections.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
aircraft: one
|
||||||
|
annual_date: 2022-01-13
|
||||||
|
annual_tach: 1.5
|
||||||
|
annual_hobs: 1.5
|
||||||
|
pitot_static: 2022-01-13
|
||||||
|
vor: 2022-01-13
|
||||||
|
elt: 2022-01-13
|
||||||
|
|
||||||
|
two:
|
||||||
|
aircraft: two
|
||||||
|
annual_date: 2022-01-13
|
||||||
|
annual_tach: 1.5
|
||||||
|
annual_hobs: 1.5
|
||||||
|
pitot_static: 2022-01-13
|
||||||
|
vor: 2022-01-13
|
||||||
|
elt: 2022-01-13
|
||||||
7
test/models/aircraft_test.rb
Normal file
7
test/models/aircraft_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AircraftTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/engine_test.rb
Normal file
7
test/models/engine_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EngineTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/flight_test.rb
Normal file
7
test/models/flight_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class FlightTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/inspection_test.rb
Normal file
7
test/models/inspection_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class InspectionTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user