diff --git a/app/assets/javascripts/flights.coffee b/app/assets/javascripts/flights.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/flights.coffee @@ -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/ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000..0a9e2ef --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -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"; diff --git a/app/assets/stylesheets/flights.scss b/app/assets/stylesheets/flights.scss new file mode 100644 index 0000000..4f2bba8 --- /dev/null +++ b/app/assets/stylesheets/flights.scss @@ -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/ diff --git a/app/controllers/flights_controller.rb b/app/controllers/flights_controller.rb new file mode 100644 index 0000000..2a3c6f7 --- /dev/null +++ b/app/controllers/flights_controller.rb @@ -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 diff --git a/app/helpers/flights_helper.rb b/app/helpers/flights_helper.rb new file mode 100644 index 0000000..d03ef57 --- /dev/null +++ b/app/helpers/flights_helper.rb @@ -0,0 +1,2 @@ +module FlightsHelper +end diff --git a/app/models/aircraft.rb b/app/models/aircraft.rb new file mode 100644 index 0000000..c4153f9 --- /dev/null +++ b/app/models/aircraft.rb @@ -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 diff --git a/app/models/engine.rb b/app/models/engine.rb new file mode 100644 index 0000000..c392b25 --- /dev/null +++ b/app/models/engine.rb @@ -0,0 +1,3 @@ +class Engine < ApplicationRecord + belongs_to :aircraft +end diff --git a/app/models/flight.rb b/app/models/flight.rb new file mode 100644 index 0000000..9dfb3ce --- /dev/null +++ b/app/models/flight.rb @@ -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 diff --git a/app/models/inspection.rb b/app/models/inspection.rb new file mode 100644 index 0000000..a35f08b --- /dev/null +++ b/app/models/inspection.rb @@ -0,0 +1,3 @@ +class Inspection < ApplicationRecord + belongs_to :aircraft +end diff --git a/app/views/flights/index.html.erb b/app/views/flights/index.html.erb new file mode 100644 index 0000000..d7f2ce1 --- /dev/null +++ b/app/views/flights/index.html.erb @@ -0,0 +1,9 @@ +

Flights

+ + diff --git a/app/views/flights/new.html.erb b/app/views/flights/new.html.erb new file mode 100644 index 0000000..2ac169e --- /dev/null +++ b/app/views/flights/new.html.erb @@ -0,0 +1,47 @@ +

New Flight

+ +<%= form_with model: @flight do |form| %> +
+ <%= form.label :aircraft %>
+ <%= form.select :aircraft, @aircraft %> +
+ +
+ <%= form.label :date %>
+ <%= form.date_field :date %> +
+ +
+ <%= form.label :from %>
+ <%= form.text_field :from %> +
+ +
+ <%= form.label :to %>
+ <%= form.text_field :to %> +
+ +
+ <%= form.label :tach %>
+ <%= form.number_field :tach %> +
+ +
+ <%= form.label :hobbs %>
+ <%= form.number_field :hobbs %> +
+ +
+ <%= form.label :fuel %>
+ <%= form.check_box :fuel %> +
+ +
+ <%= form.label :oil %>
+ <%= form.check_box :oil %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/flights/show.html.erb b/app/views/flights/show.html.erb new file mode 100644 index 0000000..55be754 --- /dev/null +++ b/app/views/flights/show.html.erb @@ -0,0 +1,10 @@ +

<%= @flight.date %>

+ +

<%= @flight.aircraft.reg %>

+

From: <%= @flight.from %>

+

To: <%= @flight.to %>

+

Tach: <%= @flight.tach %>

+

Hobbs: <%= @flight.hobbs %>

+

Fuel Added: <%= @flight.fuel %>

+

Oil Added: <%= @flight.oil %>

+

Total Flight Time: <%= @flight.time %>

diff --git a/db/migrate/20220114003540_create_aircrafts.rb b/db/migrate/20220114003540_create_aircrafts.rb new file mode 100644 index 0000000..b69cd6b --- /dev/null +++ b/db/migrate/20220114003540_create_aircrafts.rb @@ -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 diff --git a/db/migrate/20220114003600_create_engines.rb b/db/migrate/20220114003600_create_engines.rb new file mode 100644 index 0000000..f42b6c0 --- /dev/null +++ b/db/migrate/20220114003600_create_engines.rb @@ -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 diff --git a/db/migrate/20220114003618_create_inspections.rb b/db/migrate/20220114003618_create_inspections.rb new file mode 100644 index 0000000..d48a1ce --- /dev/null +++ b/db/migrate/20220114003618_create_inspections.rb @@ -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 diff --git a/db/migrate/20220114003844_create_flights.rb b/db/migrate/20220114003844_create_flights.rb new file mode 100644 index 0000000..992ff3e --- /dev/null +++ b/db/migrate/20220114003844_create_flights.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..2b36d38 --- /dev/null +++ b/db/schema.rb @@ -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 diff --git a/test/controllers/flights_controller_test.rb b/test/controllers/flights_controller_test.rb new file mode 100644 index 0000000..6a724b3 --- /dev/null +++ b/test/controllers/flights_controller_test.rb @@ -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 diff --git a/test/fixtures/aircrafts.yml b/test/fixtures/aircrafts.yml new file mode 100644 index 0000000..81323d1 --- /dev/null +++ b/test/fixtures/aircrafts.yml @@ -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 diff --git a/test/fixtures/engines.yml b/test/fixtures/engines.yml new file mode 100644 index 0000000..f742b60 --- /dev/null +++ b/test/fixtures/engines.yml @@ -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 diff --git a/test/fixtures/flights.yml b/test/fixtures/flights.yml new file mode 100644 index 0000000..0129f07 --- /dev/null +++ b/test/fixtures/flights.yml @@ -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 diff --git a/test/fixtures/inspections.yml b/test/fixtures/inspections.yml new file mode 100644 index 0000000..fb27f8b --- /dev/null +++ b/test/fixtures/inspections.yml @@ -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 diff --git a/test/models/aircraft_test.rb b/test/models/aircraft_test.rb new file mode 100644 index 0000000..3fd31b9 --- /dev/null +++ b/test/models/aircraft_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AircraftTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/engine_test.rb b/test/models/engine_test.rb new file mode 100644 index 0000000..916bfd0 --- /dev/null +++ b/test/models/engine_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class EngineTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/flight_test.rb b/test/models/flight_test.rb new file mode 100644 index 0000000..8421c93 --- /dev/null +++ b/test/models/flight_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FlightTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/inspection_test.rb b/test/models/inspection_test.rb new file mode 100644 index 0000000..f0147ba --- /dev/null +++ b/test/models/inspection_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class InspectionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end